答案 0 :(得分:1)
看来,level_0可能是你的索引,对吗?
你有:>>> level0 = ['ALL','AWA','REM','S1','S2','SWS']
>>> df1 = pd.DataFrame(data={'level_0':level0, 'col1':np.random.randint(0,9,6)})
>>> df2 = pd.DataFrame(data={'level_0':level0, 'col2':np.random.randint(0,9,6)})
>>> df3 = pd.DataFrame(data={'level_0':level0, 'col3':np.random.randint(0,9,6)})
>>> df1
col1 level_0
0 5 ALL
1 8 AWA
2 5 REM
3 3 S1
4 8 S2
5 4 SWS
>>> df2
col2 level_0
0 4 ALL
1 1 AWA
2 3 REM
3 2 S1
4 5 S2
5 1 SWS
>>> df3
col3 level_0
0 1 ALL
1 3 AWA
2 0 REM
3 4 S1
4 2 S2
5 3 SWS
>>> pd.concat([df1,df2,df3], axis=1)
col1 level_0 col2 level_0 col3 level_0
0 5 ALL 4 ALL 1 ALL
1 8 AWA 1 AWA 3 AWA
2 5 REM 3 REM 0 REM
3 3 S1 2 S1 4 S1
4 8 S2 5 S2 2 S2
5 4 SWS 1 SWS 3 SWS
您可以将level_0
设置为索引,然后连接:
>>> pd.concat([df1.set_index('level_0'), df2.set_index('level_0'), df3.set_index('level_0')], axis=1)
col1 col2 col3
level_0
ALL 5 4 1
AWA 8 1 3
REM 5 3 0
S1 3 2 4
S2 8 5 2
SWS 4 1 3
如果它不是索引,你可以在concat之前删除它:
>>> pd.concat([df1.drop('level_0', axis=1), df2.drop('level_0', axis=1), df3.drop('level_0', axis=1)], axis=1)
col1 col2 col3
0 5 4 1
1 8 1 3
2 5 3 0
3 3 2 4
4 8 5 2
5 4 1 3
答案 1 :(得分:0)
使用这些命令,我能够删除名称为" level_0"
的所有列df.drop(df.columns[[0]], axis=1, inplace=True)
df