I have two data frames df1 and df2. They are created with the following codes:
import pandas as pd
df1 = pd.DataFrame([["Probe1", "Gene1", 3,11],
["Probe1", "Gene2", 6,10],
["Probe2","Gene2", 13,18]],
columns=['probe', 'gene', 'Sample1', "Sample2"]).set_index(['probe', 'gene'])
df1.columns.names = ['Sample']
# Note that number of samples can be more than two
df2 = df1.copy()
df2[df2>0] = 1.00
So it looks like this:
In [74]: df1
Out[74]:
Sample Sample1 Sample2
probe gene
Probe1 Gene1 3 11
Gene2 6 10
Probe2 Gene2 13 18
In [75]: df2
Out[75]:
Sample Sample1 Sample2
probe gene
Probe1 Gene1 1 1
Gene2 1 1
Probe2 Gene2 1 1
What I want to do is to concatenate these two data frame so that in the end it will write into CSV file that looks like this:
PROBE GENE SMPL1 SMPL2 PROBE GENE SMPL1 SMPL2
Probe1 Gene1 3 11 Probe1 Gene1 1 1
Probe1 Gene2 6 10 Probe1 Gene2 1 1
Probe2 Gene2 13 18 Probe2 Gene2 1 1
I'm stuck with this:pd.concat(ndf,axis=1)
What's the right way to do it?