I have a dataset, df, where, whenever a specific value is displayed in a specific column, to populate appropriate columns with a value of choice:
Data
id start stat
d_in
d_in
hello
hi
Desired
id start stat
d_in din 8
d_in din 8
hello
hi
Whenever we see the value 'd_in' in the ['id'] column, we will populate column ['start'] with 'din' and column ['stat'] with the number 8
Doing
I believe I can perform a dictionary mapping on this dataset:
out= {
'd_in': din, 8
}
I am not sure how to integrate this logic. Any suggestion is appreciated
CodePudding user response:
Use DataFrame.loc
:
df.loc[df['id'].eq('d_in'), ['start', 'stat']] = ['din', 8]