Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- '''
- We need to calculate the sales tax and total amount owed for every order in this sheet.
- If location is Sun Valley, apply a sales tax of 8%
- If location is Mammoth, apply a sales tax of 7.75%.
- If location is Stowe, apply a sales tax of 6%
- '''
- df['Tax'] = df.apply(lambda row: 0.08 if row['Location'] == 'Sun Valley'
- else (0.0775 if row['Location'] == 'Mammoth'
- else (0.06 if row['Location'] == 'Stowe'
- else row['Tax'])), axis=1)
- df.loc[:, ['Tax', 'Location']]
- ###########################################################
- '''
- I have a Subtotal column and a Tax column in the dataframe and I want based on these two columns to write values to the third column Total.
- '''
- df['Total'] = df.apply(lambda row: row['Subtotal'] + (row['Tax'] * row['Subtotal']), axis=1)
- df['Total'] = df['Subtotal'] + (df['Tax'] * df['Subtotal])
- titanic['fare'] = titanic['fare'] * 10
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement