Home > Software design >  Merge multiple dataframes with different columns and rows in pandas
Merge multiple dataframes with different columns and rows in pandas

Time:11-28

Assume I have 3 dataframes as follows:

2011:

Bridge_No Location Area 2011
1 NY 10 3
2 FL 20 4
3 NJ 15 6

2012:

Bridge_No Location Area 2012
2 FL 20 5
3 NJ 15 3
4 CN 45 9

2013:

Bridge_No Location Area 2013
2 FL 20 8
6 MI 30 8
4 CN 45 9

I need a final merged dataset as follows:

Bridge_No Location Area 2011 2012 2013
1 NY 10 3 Nan Nan
2 FL 20 4 5 8
3 NJ 15 6 3 NaN
4 CN 45 Nan 9 9
6 MI 30 Nan NaN 8

CodePudding user response:

We can iterate over each DataFrame and enter image description here

  • Related