I am getting this message Thrown at me how to fix it - 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
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy first_50.loc[:, 'price_change'] = first_50['Close'].pct_change(periods=1) C:\Users\prana\AppData\Local\Temp\ipykernel_11496\1305303985.py:3: 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
See the caveats in the documentation: https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#returning-a-view-versus-a-copy first_50.loc[:, 'price_change_label'] = first_50['price_change'].apply(lambda x: 'positive' if x > 0 else 'negative')
This is my code - first_50 = merged_df.head(50) first_50.loc[:, 'price_change'] = first_50['Close'].pct_change(periods=1) first_50.loc[:, 'price_change_label'] = first_50['price_change'].apply(lambda x: 'positive' if x > 0 else 'negative')