gpt4 book ai didi

python - Pandas DataFrame.update() 函数中的 `overwrite` 参数有什么作用?

转载 作者:太空狗 更新时间:2023-10-29 21:51:52 25 4
gpt4 key购买 nike

我读了this文档,但我不明白 overwrite 选项实际上对 update 过程做了什么。我测试了几个案例,但在每个案例中,无论我将 overwrite 设置为 True 还是 False 都没有区别。有人可以举例说明它确实有所作为吗?

最佳答案

不同的是,当overwrite设置为false时,它只会填充调用updateDataFrame中的缺失值.

基于您提供的链接中的示例(使用默认值 overwrite=True):

df = pd.DataFrame({'A': [1, 2,3], 'B': [400, None, 600]})
new_df = pd.DataFrame({'B': [4, 5, 6], 'C': [7, 8, 9]})
df.update(new_df)

产量:

   A    B
0 1 4.0
1 2 5.0
2 3 6.0

df.update(new_df, overwrite=False) 产生:

   A      B
0 1 400.0
1 2 5.0
2 3 600.0

关于python - Pandas DataFrame.update() 函数中的 `overwrite` 参数有什么作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48696195/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com