Как мне устранить это предупреждение (не игнорировать его, а исправить)?
Код: Выделить всё
import yfinance as yf
import pandas as pd
import warnings
warnings.filterwarnings("ignore", message="The 'unit' keyword in TimedeltaIndex construction is deprecated and will be removed in a future version. Use pd.to_timedelta instead.", category=FutureWarning, module="yfinance.utils")
warnings.filterwarnings("ignore", category=pd.errors.PerformanceWarning)
#warnings.filterwarnings("ignore", message="DataFrame is highly fragmented. This is usually the result of calling `frame.insert` many times, which has poor performance. Consider joining all columns at once using pd.concat(axis=1) instead. To get a de-fragmented frame, use `newframe = frame.copy()`", category=pd.errors.PerformanceWarning)
TickersList=['A', 'AAL', 'AAPL', 'ABBV', 'ABNB', 'ABT', 'ACGL', 'ACN', 'ADBE', 'ADI', 'ADM']
Stocks=yf.download(TickersList[0::1], period="1y", interval="1d", group_by='ticker')
Stocks.sort_index(level=0,axis=1,inplace=True)
Closes=Stocks.loc[:, (slice(None), ['Close', 'Volume'])]
for i in Closes.columns.get_level_values(0):
Closes.loc[:,(i,'Meam1Y')]=Closes.loc[:,(i,'Volume')].rolling (250).mean()
Closes.loc[:,(i,'Meam1Q')]=Closes.loc[:,(i,'Volume')].rolling (62).mean()
Closes.loc[:,(i,'Meam1M')]=Closes.loc[:,(i,'Volume')].rolling (20).mean()
Closes.loc[:,(i,'Meam1W')]=Closes.loc[:,(i,'Volume')].rolling (5).mean()
Closes
См. предостережения в документации: https://pandas.pydata.org/pandas-docs/stable/user_guide. /indexing.html#returning-a-view-versus-a-copy
Closes.loc[:,(i,'Meam1Y')]=Closes.loc[:,(i,'Volume')]. rolling (250).mean()
C:\Users\iiiva\AppData\Local\Temp\ipykernel_27188\26776804.py:4: SettingWithCopyWarning:
Значение пытается установиться в копии фрагмент из DataFrame.
Попробуйте вместо этого использовать .loc[row_indexer,col_indexer] = value
Подробнее здесь: https://stackoverflow.com/questions/788 ... of-a-slice