Python Pandas query

Status
Not open for further replies.

redman06

Smack-Fu Master, in training
75
Gentlemen

I am new to programming and am a bit stuck on a project to learn.

I have a dataframe. In this df I have a column called 'Types' I want to match the rows in this column and enter some text into another column called 'Category'

For example if my code matched the type 'Bikes' then enter the words 'bla' into the row in the Category column but If matched Hydration enter words 'foo', if matched Chainsets then enter 'tar' ect

Code:
Types 	Category 
Chainsets	 tar 
Chainsets	 tar 
Chainsets	 tar
Hydration	foo
Hydration	foo
Hydration	foo
Hydration	foo
Bikes	bla
Bikes	bla
Bikes	bla
Bikes	bla

Somthing like this but that would apply to all 'Types'
Code:
df[df.Type.isin(['Bikes'])]
df['Category'] = 'bla'

A point in the right direction would be a massive help - Thanks
 
Status
Not open for further replies.