Reputation: 115
If I have the following pandas dataframe
A B
0 Cat Dog
1 Mouse Mouse
2 Fish "Blank"
How do I parse through column B, identify that there is a blank value and then if there is a blank value fill in the blank with "Fish", so the desired data frame is:
A B
0 Cat Dog
1 Mouse Mouse
2 Fish Fish
Upvotes: 3
Views: 6363
Reputation: 1267
You could try this -
import numpy as np
df['B'] = np.where(df['B'] == 'Blank', df['A'], df['B'])
Upvotes: 6
Reputation: 145
df[df['B'] == 'Blank'] = 'Fish'
df[df=='Blank'] = 'Fish'
Upvotes: 0