I have this dataframe:
x = pd.read_csv(r'C:\Users\user\Desktop\Dataset.csv', sep = ',')
x['dates'] = pd.to_datetime(x['dates']) #turn column to datetime type
v = x[(x['proj'].str.contains('3'))] ### This part is causing the issue.
v['mnth_yr'] = v['dates'].apply(lambda x: x.strftime('%B-%Y'))
and it gives this warning:
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
I know there is a post about it but I can't understand how to solve this specific case. Can you help?
Based on the answer:
x = pd.read_csv(r'C:\Users\user\Desktop\Dataset.csv', sep = ',')
x.loc[:,'dates'] = pd.to_datetime(x['dates']) #turn column to datetime type
v = x[(x['proj'].str.contains('3'))] ###This part is causing the issue.
###And in the next line gives the warning, since it's a copy.
v.loc[:,'mnth_yr'] = v['dates'].apply(lambda x: x.strftime('%B-%Y'))
It still gives the error is there a way to assign the v
without the warning?