Suppose I have a Dataframe whit this structure:
T1P1_T0 Count T1P1_T1 Count.1 T1P1_T3 Count.2
0 one 1207.0 four 1936 one 644.0
1 two 816.0 two 1601 seven 414.0
2 three 712.0 five 1457 NaN NaN
3 NaN NaN six 4564 NaN NaN
Mi desired output is this:
Element T1P1_T0 T1P1_T1 T1P1_T3
0 one 1207 NaN 644.0
1 two 816 1601.0 NaN
2 three 712 NaN NaN
3 four NaN 1936.0 NaN
4 five 1456.0 NaN
5 six NaN 4564.0 NaN
6 seven NaN NaN 414.0
What I've tried, is to separate the initial dataframe into three:
df1 = df.iloc[:,:2]
df2 = df.iloc[:,2:4]
df3 = df.iloc[:,4:]
And try to merge the first two, and then the third one, using different approaches of pd.merge:
for example:
result = pd.merge(df1, df2, right_on=df.iloc[:,0], left_on=df.iloc[:,0])
but the result is not what I want:
key_0 T1P1_T0 Count T1P1_T1 Count.1
0 one one 1207.0 four 1936
1 two two 816.0 two 1601
2 three three 712.0 five 1457
3 NaN NaN NaN six 4564
I don't know how to specify the columns with the element names as the key value for the merge operation.
Any suggestion with that?
Thanks