gpt4 book ai didi

python - Pandas : A value is trying to be set on a copy of a slice from a DataFrame

转载 作者:行者123 更新时间:2023-11-30 22:23:00 24 4
gpt4 key购买 nike

我在 pandas 中有一个非常简单的命令,例如:

volume_related_pd.loc[:,"last_record_volume"] = volume_related_pd.loc[:,"volume"]

我认为复杂性在于我有重复的索引。它会产生以下警告:

/anaconda2/lib/python2.7/site-packages/pandas/core/indexing.py:601: SettingWithCopyWarning: A value is trying to be set on a copy of a slice from a DataFrame. Try using .loc[row_indexer,col_indexer] = value instead

我该怎么办?谢谢。我已经使用 .iloc

最佳答案

哦。我发现...这来自volume_lated_pd 最初的定义方式。

一开始是这样的

volume_related_pd = complete_contract_info_pd[["volume"]]

然后警告出现。

但是,如果我专门将其定义为原始 pd 的副本,那么问题就消失了:

volume_related_pd = complete_contract_info_pd[["volume"]].copy()

关于python - Pandas : A value is trying to be set on a copy of a slice from a DataFrame,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48171416/

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