如何从两个熊猫数据框中加入单元格值?
df1 is:
F1 F2 M1 M2
pos
23 1.0 0.0 1.0 1.0
24 1.0 1.0 1.5 1.0
28 1.0 0.0 0.5 0.0
df2 is:
F1 F2 M1 M2
pos
23 0.0 1.0 0.5 0.0
24 1.0 1.0 1.5 1.0
28 0.0 1.0 1.0 1.0
如何用逗号组合这些数据框中的值(具有相同column
和row
索引)?
预期的输出如下:
F1 F2 M1 M2
pos
23 1.0,0.0 0.0,1.0 1.0,0.5 1.0,0.0
24 1.0,1.0 1.0,1.0 1.5,1.5 1.0,1.0
same for other lines...
The value of df1 should be place before comma and df2 after that.
谢谢,
您可以将它们总结为两个带有“字符串”元素的 DF:
In [324]: d1.astype(str).add(',').add(d2.astype(str))
Out[324]:
F1 F2 M1 M2
pos
23 1.0,0.0 0.0,1.0 1.0,0.5 1.0,0.0
24 1.0,1.0 1.0,1.0 1.5,1.5 1.0,1.0
28 1.0,0.0 0.0,1.0 0.5,1.0 0.0,1.0
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句