Python 数据帧合并以排除额外的索引列
我想合并两个数据帧df1和df2,并使用以下脚本:Python 数据帧合并以排除额外的索引列,python,pandas,dataframe,Python,Pandas,Dataframe,我想合并两个数据帧df1和df2,并使用以下脚本: 将熊猫作为pd导入 df1=pd.DataFrame({'A':['A0','A1','A2'], 'B':['B0','B1','B2']}) df2=pd.DataFrame({'C':['C0','C1','C2','C3'], ‘D’:[‘D0’、‘D1’、‘D2’、‘D3’]}) df=df1.join(df2.iloc[1:].reset_index(),how='inner') 但还有一列名为“index”,我不想要。是否仍有删
将熊猫作为pd导入
df1=pd.DataFrame({'A':['A0','A1','A2'],
'B':['B0','B1','B2']})
df2=pd.DataFrame({'C':['C0','C1','C2','C3'],
‘D’:[‘D0’、‘D1’、‘D2’、‘D3’]})
df=df1.join(df2.iloc[1:].reset_index(),how='inner')
但还有一列名为“index”,我不想要。是否仍有删除它的方法
A B index C D
0 A0 B0 1 C1 D1
1 A1 B1 2 C2 D2
2 A2 B2 3 C3 D3
我想要的就是这样:
A B C D
0 A0 B0 C1 D1
1 A1 B1 C2 D2
2 A2 B2 C3 D3
只需在代码中使用
drop=True
df = df1.join(df2.iloc[1:].reset_index(drop=True), how='inner')
A B C D
0 A0 B0 C1 D1
1 A1 B1 C2 D2
2 A2 B2 C3 D3