df['col_name'].loc[df['col_name'].isna()] = 'new_string'
How can I perform this setting operation to avoid "FutureWarning: ChainedAssignmentError: behaviour will change in pandas 3.0!"?
>Solution :
To avoid the "FutureWarning: ChainedAssignmentError" in pandas, you can use the .loc accessor twice to set values.
import pandas as pd
# Example DataFrame
df = pd.DataFrame({'col_name': [1, 2, None, 4, None, 6]})
# Use .loc twice to set values
df.loc[df['col_name'].isna(), 'col_name'] = 'new_string'
You can check fillna for more details.