python - 如何添加两个不同维度的数据框?
问题描述
我在 Python 中有两个数据框,需要添加,但希望输出作为最后一个表,而不是作为执行结果的表df1+df2
。
df1:
index 6 12 24
2010 2 3 4
2011 2 3 4
2012 2 3 4
df2:
index 6 12
2011 2 3
2012 2 3
df1+df2:
index 6 12
2011 4 6
2012 4 6
所需输出:
index 6 12 24
2010 2 3 4
2011 4 6 4
2012 4 6 4
解决方案
是的,使用:
df1.add(df2, fill_value=0)
推荐阅读
- jsreport - 带有 Chrome-pdf 配方的 JsReport 页码
- php - 如何动态分配作者在 WordPress 中发帖?
- node.js - 无需 console.log 即可获取数据
- c# - 在动态生成的 DataGrid 中添加操作列
- c# - 了解数据合同和业务实体之间的区别
- ios - 单击视图时如何隐藏警报或关闭警报
- javascript - 发送带有我从 ajax 获得的新值的表单
- reactjs - 使用 RxJS 或任何其他包异步加载 Firebase - 然后在整个项目中使用它
- c# - 实例化大量变量(字符串、整数等)会消耗大量内存吗?
- javascript - jQuery | 选择超链接的元素文本 | text() 或 html() 方法似乎不起作用