First you need to load your dataset into a pandas dataframe which you can do using following command.
import pandas as pd
df = pd.read_excel('name_of_file_here.xlsx',sheet_name='Sheet_name_here')
So your excel data is now a pandas dataframe called df.
if pay rate is the same for all vehicles you can do the following.
rate = 15
df['Pay'] = df['Hours']*rate
This creates a new column in your dataframe called 'Pay' and multiplies the rate which is 15 by each row in the Hours Column.
If however the rate is different for different vehicles types you can do the following.
bike_rate = 15
df[df['Vehicle']=='Bike'] = df[df['Vehicle']=='Bike']*bike_rate
cargo_bike_rate = 20
df[df['Vehicle']=='Cargo-Bike'] = df[df['Vehicle']=='Cargo-Bike']*cargo_bike_rate
This will select the rows in the dataframe where vehicle is equal to whatever type you want and operate on these rows.
Another way and the best way i think is to use a function.
def calculate_pay(vehicle,hours):
if vehicle == 'Bike':
rate = 15
elif vehicle == 'Cargo-Bike':
rate = 20
#And so on ....
else:
rate = 10
return hours*rate
Then you can apply this function to your dataframe.
df['Pay'] = df.apply(lambda x: calculate_pay(x['Vehicle'],x['Hours']),axis=1)
This creates a new column in your dataframe called 'Pay' and applies a function called calculate_pay which takes inputs vehicle and hours from the dataframe and returns the pay.
To print your results on screen you can simply just type df and enter if you are using jupyter notebook, or to select specific columns you mentioned in comments you can do the following.
df[['Id','Vehicle','Hours','Pay']]
To save back to excel you can do the following
df.to_excel('output.xslx')
data.loc[]ordata.iloc[]methods