我有三个数据帧,所有数据帧都有50列和一行。每个数据帧中使用相同的列名,并且单行始终索引为0.我正在尝试连接它们以便更容易查看和比较数据。
features = pd.concat([raw_features, fea_features, transformed_features], axis=0)
现在我想重命名行。我尝试过几件事情,包括:
features = pd.concat([raw_features, fea_features, transformed_features], axis=0).reindex(['Raw_pulltest', 'FEA', 'Transformed_pulltest'])
,它给出错误cannot reindex from a duplicate axis
和
features = pd.concat([raw_features, fea_features, transformed_features], axis=0).reset_index().reindex(['Raw_pulltest', 'FEA', 'Transformed_pulltest'])
它给了我想要的结构,除了所有值现在都是nan
。
请帮我重命名连接数据框的索引吗?
答案 0 :(得分:3)
在<site name="yoursite-Site" id="108">
<other things removed just to get to showing you the bindingInfo...
<bindings>
<binding protocol="http" bindingInformation="*:3486:localhost" />
</bindings>
</site>
中使用keys
参数:
试试这个:
pd.concat
示例:
pd.concat([raw_features, fea_features, transformed_features],
axis=0, keys=['Raw_pulltest', 'FEA', 'Transformed_pulltest'])\
.reset_index(level=1, drop=True)
输出:
d1 = pd.DataFrame([[1,1,1]],index=[0])
d2 = pd.DataFrame([[2,2,2]],index=[0])
d3 = pd.DataFrame([[3,3,3]], index=[0])
pd.concat([d1,d2,d3],axis=0, keys=['d1','d2','d3']).reset_index(level=1, drop=True)