将数据从一个熊猫DF复制到另一个

时间:2019-04-30 14:26:17

标签: python pandas

我有2个数据框.... big_df和small_df

big_df
------
Typ  col1 col2 col3 ... 
A    None None None ...
B    None None None ...
A    None None None ...
C    None None None ...
B    None None None ...
D    None None None ...
E    None None None ...
F    None None None ...
.
.
.

small_df
------
Typ  col1 col3 col8 ... 
A    1.2  'a'  3
E    2.2  'z'  5
L    0.5  'w'  4
.
.
.

我需要使用small_df中的值有效地更新big_df字段。

Typ在big_df中不是唯一的。

两个DF当前都按数字索引... 0、1、2、3 ....依此类推

尝试按Typ重新索引两个DF将抛出:

ValueError:无法从重复的轴重新索引

对于任何建议/代码示例,我将不胜感激。

1 个答案:

答案 0 :(得分:0)

我发现了一种解决问题的方法,灵感来自我在这篇帖子中找到的答案:Python Pandas update a dataframe value from another dataframe

我应用了两个for循环来处理多列合并和删除情况并满足我的需求。

相关问题