Selecting Rows in Pandas

 orders = pd.read_csv('shoefly.csv')


emails = orders['email']
#print(orders.head())

frances_palmer = orders[(orders.first_name == 'Frances'& (orders.last_name == 'Palmer')]

comfy_shoes = orders[orders.shoe_type.isin(['clogs','boots','ballet flats'])]

print(frances_palmer)
print(comfy_shoes)


Lambda Syntax
get_last_name = lambda xx.split(" ")[-1]
df['last_name'] = df.name.apply(get_last_name)
print(df)

New Problem
df = pd.read_csv('employees.csv')

total_earned = lambda row: (row.hourly_wage * 40) + ((row.hourly_wage * 1.5) * (row.hours_worked - 40)) \
  if row.hours_worked > 40 \
  else row.hourly_wage * row.hours_worked
  
df['total_earned'] = df.apply(total_earnedaxis = 1)

print(df)


Comments

Popular posts from this blog

Binomial Test in Python

Slicing and Indexing in Python Pandas

Python Syntax and Functions Part2 (Summary Statistics)