0

I have several dataframes that I would like to merge together based on the values of the rows.

   Cycle        Cell_1 
0   1           0.025001
1   2           0.025002
2   3           0.025003
3   4           0.025004

   Cycle        Cell_2
0   1           0.026001
1   3           0.026003
2   4           0.026004

I want to merge them together based on the cycle number. The cycle number that does not a corresponding number will be replaced by NaN. The desired result should look like this:

   Cycle        Cell_1       Cell_2
0   1           0.025001     0.026001
1   2           0.025002     NaN  
2   3           0.025003     0.026003
3   4           0.025004     0.026004

I tried

pd.concat([df1, df2], axis=1) 

However the result became like this. Cell_2 did not distributed according to the values in 'Cycle'.

   Cycle        Cell_1       Cell_2
0   1           0.025001     0.026001
1   2           0.025002     0.026003
2   3           0.025003     0.026004
3   4           0.025004     NaN

Could anyone let me know how to do the merge correctly?

Also when merging them together, I found the second 'Cycle' became 1.0, 2.0, 3.0, and 4.0. I don't know if this bug is related to why I couldn't do the merge correctly.

Thanks!

chen37037
  • 23
  • 3

0 Answers0