So I have a dataframe as follows
name, car
foo, bmw
bar, audi
baz, tesla
foobaz, bmw
I now have another dictionary, for example
car_type = {'bmw': 'gas', 'audi': 'hybrid', 'tesla': 'electric'}
Now I want to add a new column to the dataframe as shown below.
name, car, type
foo, bmw, gas
bar, audi, hybric
baz, tesla, electric
foobaz, bmw, gas
How to do it in pandas?
source
share