I am trying to assign certain values to a column in a dataframe within a Python function.
df = df[(df['date'] <= max_date) & (df['date'] > min_date) | (df['x_date'] <= max_date) & (df['x_date'] > min_date)]
numbers = len(df)
df["patients"] = value_counts.patients
df["numbers"] = numbers
However, I get this error:
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
df["patients"] = value_counts.patients
file.py:52: 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
How can I get rid of this warning?