0

I have 2 dataframes, all with exact same index but different columns.

I want to create a new data frame with the exact same index as the other 3 but pick one specific column from each dataframe:

DF1

           blah1       blah2        IMP1
Month1   0.80550    0.912814    1.135899
Month2  -4.61033    0.750013    1.093204
Month3   0.34241   -0.627297    2.035373
Month4   7.19570    0.039588    0.350060
Month5   3.86186   -0.208209   -0.939962

DF2

            blah1       blah2        IMP2
Month1   0.580550    0.480814    1.135899
Month2  -1.961033    0.546013    1.093204
Month3   2.063441   -0.627297    2.035373
Month4   0.319570    0.058588    0.350060
Month5   1.318068   -0.802209   -0.369962

I would like to create a new DF like so:

DF3

          IMP1          IMP2
Month1    1.135899      1.135899
Month2    1.093204      1.093204
Month3    2.035373      2.035373
Month4    0.350060      0.350060
Month5   -0.939962     -0.369962

What's the most efficient way to do so?

halfer
  • 19,824
  • 17
  • 99
  • 186
Silent User
  • 2,657
  • 7
  • 29
  • 36
  • based on what logic? just pick the last or just pick `IMP1`? `pd.concat([df1['IMP1'],df2['IMP2']],axis=1)` seems to do this – anky Jun 29 '19 at 06:58
  • I know what columns to pick from DF1 (IMP1) and DF2 (IMP2). No logic, just hardcoding is fine. – Silent User Jun 29 '19 at 06:59
  • in that case, check the above sol. Looks a dupe to : https://stackoverflow.com/questions/18062135/combining-two-series-into-a-dataframe-in-pandas – anky Jun 29 '19 at 06:59

0 Answers0