import re
# Extract CPU clock speed from the 'Cpu' column
# We assume the clock speed is given in GHz and extract it using a regular expression
def extract_clock_speed(cpu_str):
match = re.search(r'(\d+\.\d+)GHz', cpu_str)
return float(match.group(1)) if match else 0
df['Clock_Speed_GHz'] = df['Cpu'].apply(extract_clock_speed)
# Convert RAM to numeric value (assuming all values are in GB)
def extract_ram(ram_str):
match = re.search(r'(\d+)GB', ram_str)
return int(match.group(1)) if match else 0
df['Ram_GB'] = df['Ram'].apply(extract_ram)
# Create a composite score based on clock speed and RAM
# We will give equal weight to both factors for simplicity
df['Performance_Score'] = df['Clock_Speed_GHz'] + df['Ram_GB']
# Find the laptop with the highest performance score per euro spent
df['Performance_per_Euro'] = df['Performance_Score'] / df['Price_euros']
best_deal_laptop = df.loc[df['Performance_per_Euro'].idxmax()]
best_deal_laptop