Reputation: 403
My DataFrame looks like below:
Main_column column_1 column_2 column_3 column_4
qw qw NaN rt NaN
we qe NaN qe NaN
er NaN NaN NaN NaN
NaN NaN cg NaN NaN
NaN NaN NaN vb bn
DF should looks like below:
Main_column column_1 column_2 column_3 column_4 new_column
qw qw NaN rt NaN qw
we qe NaN qe NaN we
er NaN NaN NaN NaN er
NaN NaN cg NaN NaN cg
NaN NaN NaN vb bn vb
So basically I need to create a new column based on values from privies one. There are 2 things that needs to be take into account.
Do you have any idea how to do that?
Regards
Upvotes: 1
Views: 40
Reputation: 9081
Use -
df['new_column'] = df['Main_column'].copy()
for col in df.columns:
df['new_column'] = df['new_column'].fillna(df[col])
Output
0 qw
1 we
2 er
3 cg
4 vb
Name: Main_column, dtype: object
Upvotes: 2