0

I'm a complete begginer in Python. Want to do something that seems very basic but can't manage to work things out by myself.

V Entrada   V Saida

1.58372     NaN
1.58824     NaN
1.57350     NaN
1.57441     NaN
1.54906     NaN
...         ...
NaN     0.003098
NaN     -0.004271
NaN     -0.004222
NaN     0.001724
NaN     0.220516

I'm working with a Data Frame that has an absurd amount of columns. To do what needs to be done, I need to merge "V Entrada" and "V Saida" together i none single column, like this:

Merged (V Entrada, V Saida)

1.58372    
1.58824     
1.57350     
1.57441     
1.54906    
...        
0.003098
-0.004271
-0.004222
0.001724
0.220516

Can someone share some thoughts on how to solve this

  • Can you guarantee one of the columns is always `NaN` and the other always has a value? – maow Mar 30 '20 at 16:10
  • many people here can give you a solution for this but this won't answer your issue I'm afraid. give us some insight into your data frame absurd isn't a number for columns, is it 10, 20, 50? and the logic behind the columns you want to merge. your problem is as simple as `df['V Entrada'].fillna(df['V Saida'])` – Umar.H Mar 30 '20 at 16:11
  • Use bfill: `df['newcol'] = df.bfill(axis=1).iloc[:, 0]`, see my answer [here](https://stackoverflow.com/a/59530916/9081267) – Erfan Mar 30 '20 at 16:13

0 Answers0