Python &引用;试图在来自数据帧的切片副本上设置一个值";在DataFrame字典中更新DataFrame时

Python &引用;试图在来自数据帧的切片副本上设置一个值";在DataFrame字典中更新DataFrame时,python,pandas,dataframe,slice,Python,Pandas,Dataframe,Slice,这似乎是一个重复的问题,但尽管查看了所有可用的解决方案,我仍然无法为我的案例找到一个解决方案 我有一个数据帧字典(此后键入DF),其中每个股票代码符号创建一个新的DF。我想迭代每个DF,并根据逻辑更新列。当我这样做的时候,我得到了臭名昭著的“值试图在一个切片的副本上设置…”警告,它重复了1000次 下面是代码和结果。有人能帮忙吗(即使我有办法压制警告)。谢谢 功能如下。为了简单起见,这里没有迭代,我只是在第16行(15+1)赋值 我通过传递work1_daily调用此函数,work1_daily

这似乎是一个重复的问题,但尽管查看了所有可用的解决方案,我仍然无法为我的案例找到一个解决方案

我有一个数据帧字典(此后键入DF),其中每个股票代码符号创建一个新的DF。我想迭代每个DF,并根据逻辑更新列。当我这样做的时候,我得到了臭名昭著的“值试图在一个切片的副本上设置…”警告,它重复了1000次

下面是代码和结果。有人能帮忙吗(即使我有办法压制警告)。谢谢

功能如下。为了简单起见,这里没有迭代,我只是在第16行(15+1)赋值

我通过传递work1_daily调用此函数,work1_daily是另一个函数创建的DFs字典

# work1_daily is a dictionary of DFs being created by another function
Process_Ticker( work1_daily)
这是我得到的结果:

DF_daily[ ticker].columns.to_list()
['Open', 'High', 'Low', 'Close', 'Volume', 'Pivot', 'R1', 'R2', 'R3', 'S1', 'S2', 'S3', 'TrendScoreStr1', 'TrendScoreStr2']

DF_daily[ ticker].head()
                       Open    High  ...  TrendScoreStr1  TrendScoreStr2
Datetime                             ...                                
2020-10-15 00:00:00     NaN     NaN  ...                                
2020-10-16 00:00:00  166.31  169.68  ...                                
2020-10-19 00:00:00  170.30  172.07  ...                                
2020-10-20 00:00:00  171.02  172.35  ...                                
2020-10-21 00:00:00  170.50  173.19  ...                                

[5 rows x 14 columns]

DF_daily[ ticker].TrendScoreStr1[ i+1] = 'X'
<ipython-input-23-2fca2e942ced>:13: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  DF_daily[ ticker].TrendScoreStr1[ i+1] = 'X'
DF_daily[ticker]。列。到_列表()
[‘打开’、‘高’、‘低’、‘关闭’、‘音量’、‘枢轴’、‘R1’、‘R2’、‘R3’、‘S1’、‘S2’、‘S3’、‘TrendScoreStr1’、‘TrendScoreStr2’]
DF_daily[ticker].head()
高开。。。趋势评分器1趋势评分器2
日期时间。。。
2020-10-15 00:00:00楠楠。。。
2020-10-16 00:00:00  166.31  169.68  ...                                
2020-10-19 00:00:00  170.30  172.07  ...                                
2020-10-20 00:00:00  171.02  172.35  ...                                
2020-10-21 00:00:00  170.50  173.19  ...                                
[5行x 14列]
DF_daily[ticker].TrendScoreStr1[i+1]=“X”
:13:设置为带复制警告:
试图在数据帧切片的副本上设置值
请参阅文档中的注意事项:https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view vs-a-copy
DF_daily[ticker].TrendScoreStr1[i+1]=“X”

关于同一主题,有很多问题/答案。你应该先看看这些。简而言之,试试:
DF_daily.loc[TrendScoreStr1[i+1],ticker]=“X”
这能回答你的问题吗@广宏感谢您的反馈。我实际上也试过类似的方法,但我犯了和你的解决方案相同的错误。下面是发生的情况:文件“”,第13行,进程中的_tickerdf_daily.loc[TrendScoreStr1[i+1],Ticker]=“X”AttributeError:“dict”对象没有属性“loc”,我对Python发出的这一荒谬警告感到非常失望。大约10个月前,我在安装了Anaconda的桌面上,同样的代码运行良好。只是因为我使用我的笔记本电脑,上周我在那里安装了新鲜的水蟒,这成了一个大问题。在桌面上,警告只会出现在循环中的第一个实例上。现在,循环中的每个实例都会出现警告。这使得整个程序运行的时间更长。到目前为止,我发现的任何解决方案都不起作用。(…续)我甚至将dataframe字典中的dataframe分配给了一个新的dataframe变量,但要么它不起作用,要么得到了相同的警告。。
DF_daily[ ticker].columns.to_list()
['Open', 'High', 'Low', 'Close', 'Volume', 'Pivot', 'R1', 'R2', 'R3', 'S1', 'S2', 'S3', 'TrendScoreStr1', 'TrendScoreStr2']

DF_daily[ ticker].head()
                       Open    High  ...  TrendScoreStr1  TrendScoreStr2
Datetime                             ...                                
2020-10-15 00:00:00     NaN     NaN  ...                                
2020-10-16 00:00:00  166.31  169.68  ...                                
2020-10-19 00:00:00  170.30  172.07  ...                                
2020-10-20 00:00:00  171.02  172.35  ...                                
2020-10-21 00:00:00  170.50  173.19  ...                                

[5 rows x 14 columns]

DF_daily[ ticker].TrendScoreStr1[ i+1] = 'X'
<ipython-input-23-2fca2e942ced>:13: SettingWithCopyWarning: 
A value is trying to be set on a copy of a slice from a DataFrame

See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy
  DF_daily[ ticker].TrendScoreStr1[ i+1] = 'X'