Reputation: 37
I have a dataframe, how to fillna col2 based on col1? Here fillna with 10, I have multiple col1 values but each one only has 1 corresponding col2 value or it is nan.
col1 col2
A Nan
A 10
Upvotes: 0
Views: 119
Reputation: 323396
You can try with fillna
by groupby
and transform
df.col2.fillna(df.groupby('col1').col2.transform('first'), inplace=True)
Upvotes: 2