I have the following pandas dataframe -
df =
1.0 2.0 3.0 4.0 5.0
(1083, 596) (1050, 164) (1050, 164)
(1081, 595) (1050, 164) (1080, 162)
(1081, 594) (1049, 163) (1070, 164)
(1082, 593)
(1050, 164)
(1050, 164)
(1049, 163)
(1049, 163)
(1052, 463)
(1051, 468)
(1054, 465)
(1057, 463)
I need a completely new dataframe, df2, with 3 columns: 1.0, 2.0 (combines 2.0 and 4.0) and 3.0 (combines 3.0 and 5.0).
The result will be -
df2 =
1.0 2.0 3.0
(1083, 596) (1050, 164) (1050, 164)
(1081, 595) (1050, 164) (1080, 162)
(1081, 594) (1049, 163) (1070, 164)
(1082, 593)
(1050, 164)
(1050, 164)
(1049, 163)
(1049, 163)
(1052, 463)
(1051, 468)
(1054, 465)
(1057, 463)
You can expect that there will be no overlapping values in the merged columns; if one column has valid value in a row then others will have NaN value.
I tried -
df.fillna(0)
df2['2.0']=df['2.0']+df['4.0']
and it does not work as intended. Is there any simple and efficient method of doing this?