lundi 3 avril 2017

python Pandas if word in column in list add Y flag in new column

I can't figure out if statements in python pandas.

I have a dataframe df

Category | Count
A           45756
B           5857
C           57876

I create a list and then use it as a hierarchy

list_s = {'A':'Y',
'B':'Y'}
df['Flag'] = df['Category'].replace(list_s)

but I get

Category | Count   | Flag 
A           45756     Y
B           5857      Y
C           57876     C

instead of

Category | Count   | Flag 
A           45756     Y
B           5857      Y
C           57876     

Thank You!

Aucun commentaire:

Enregistrer un commentaire