我认为索引值不同存在问题,因此
concat无法对齐get
NaN:
aaa = pd.Dataframe([0,1,0,1,0,0], columns=['prediction'], index=[4,5,8,7,10,12])print(aaa) prediction4 05 18 07 1100120bbb = pd.Dataframe([0,0,1,0,1,1], columns=['groundTruth'])print(bbb) groundTruth0 01 02 13 04 15 1print (pd.concat([aaa, bbb], axis=1)) prediction groundTruth0 NaN 0.01 NaN 0.02 NaN 1.03 NaN 0.04 0.0 1.05 1.0 1.07 1.0 NaN8 0.0 NaN10 0.0 NaN12 0.0 NaN
解决方案是
reset_index如果不需要索引值:
aaa.reset_index(drop=True, inplace=True)bbb.reset_index(drop=True, inplace=True)print(aaa) prediction001120314050print(bbb) groundTruth0 01 02 13 04 15 1print (pd.concat([aaa, bbb], axis=1)) prediction groundTruth00 011 020 131 040 150 1



