2

I am reading in two files into Python, both with the form:

           0.00902317     0.0270695     0.0451159     0.0631622  \   
0000010  6.962980e-05  7.063750e-05  7.165970e-05  7.269680e-05   
1000010  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00   
2000010  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00 

The first row is an ID number, and the columns are different ages. The two files have different ages comprising them, and only a few common ID#s.

Ultimately I am combining the two dataframes to find the common ID#s. But I want the resulting dataframe

               File 1                      File 2    
           0.00902317     0.0270695     0.0675493     0.1091622  \   
0000010  6.962980e-05  7.063750e-05  0.000000e+00  0.000000e+00   
1000010  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00   
2000010  0.000000e+00  0.000000e+00  0.000000e+00  0.000000e+00 

Is there a way to make a dataframe that looks like this, multiindexing columns?

Apologies if this is a simple question, I am new to working with dataframes.

2
  • In second level of output is 0.0675493 and 0.1091622. Is it header of another dataframe? Commented Jul 29, 2016 at 10:44
  • Yes, that is correct. Commented Jul 29, 2016 at 10:53

1 Answer 1

2

I think you can use concat:

print (pd.concat([df1, df2], axis=1, keys=['File 1','File 2']))

            File 1                                  File 2            
        0.00902317 0.0270695 0.0451159 0.0631622 0.0675493 0.1091622  
0000010    0.00007  0.000071  0.000072  0.000073       0.0         0.0
1000010    0.00000  0.000000  0.000000  0.000000       0.0         0.0
2000010    0.00000  0.000000  0.000000  0.000000       0.0         0.0
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.