I am trying to add a new column to a dataframe that uses other columns to create a 'Green Score' for reach row. In the example below, I would like each car 'Model' to have a score that shows how 'green' the car is.
My data (simplified):
cars = {'Model': ['Honda Civic','Toyota Corolla','Smart Car','Tesla'],
'Green Fuel': [False, False, True, True],
'Energy Use': ['High','Medium','Low','Low'],
}
df = pd.DataFrame(cars, columns = ['Model', 'Green Fuel', 'Energy Use'])
df['Green Score'] = 0
A printing the cars dataframe:
Model Green Fuel Energy Use Green Score
0 Honda Civic False High 0
1 Toyota Corolla False Medium 0
2 Smart Car True Low 0
3 Tesla True Low 0
Now, to calculate the Green Scores
of each model I am trying this:
for car in df['Model']:
if df['Green Fuel'] == True:
df['Green Score'] += 1
else:
pass
When I run this, however, I get the error:
ValueError: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(), a.any() or a.all().
Can someone point me in the right direction as to how to solve this error?