【发布时间】:2014-07-28 18:22:18
【问题描述】:
对两个 pandas 数据帧的 MERGE 操作的输出没有产生预期的结果:
**dfmatrix**:
… young label filename
0 … 1 neg cv005_29357
1 … 0 neg cv006_17022
2 … 0 neg cv007_4992
3 … 1 neg cv008_29326
4 … 1 neg cv009_29417
**dfscores**:
filename score
0 cv005_29357 -10
1 cv006_17022 5
dfnew = pandas.merge(dfmatrix, dfscores, on='filename', how='outer', left_index=False, right_index=False)
**dfnew**:
… young label filename score_y
0 … 0 neg cv005_29357 NaN
1 … 1 neg cv006_17022 NaN
2 … 0 neg cv007_4992 NaN
3 … 0 neg cv008_29326 NaN
4 … 1 neg cv009_29417 NaN
Excpected Output:
**dfnew**:
… young label filename score_y
0 … 0 neg cv005_29357 -10
1 … 1 neg cv006_17022 5
2 … 0 neg cv007_4992 NaN
3 … 0 neg cv008_29326 NaN
4 … 1 neg cv009_29417 NaN
我做错了什么?
更新:this post 建议使用 MERGE 来连接两个数据框
【问题讨论】:
-
将这些显示为已在帧中读取;指标非常重要。
-
在 pandas 中工作
0.14.1你在运行什么版本? -
@Jeff,我现在已经添加了索引
-
@EdChum, pip show pandas: 0.14.1
-
您的输出与您的代码不匹配,如果没有冲突,您如何获得
score_y的列?您在 dfscores 中只有score列,而在其他 df 中没有。