我有这样的情况,例如一个原始的 pandas 数据框,如下所示:
columnA columnB
1 2
1 3
然后由于更新,该表看起来像这样:
columnA columnB columnC
2 3 2
2 4 3
1 3 3
但是,我想保留原始表格,所以我想要的如下所示,仅更新新内容,第三列和第三行
columnA columnB columnC
1 2 2
1 3 3
1 3 3
那么我应该使用哪种合并来用新的行和列扩展原始表?谢谢!
我认为需要combine_first http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.combine_first.html哪个转换integer
列到float
s,所以添加了astype http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.astype.html:
df = df1.combine_first(df2).astype(int)
print (df)
columnA columnB columnC
0 1 2 2
1 1 3 3
2 1 3 3
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)