I need to overwrite certain values in a dataframe column, conditional on the values in another column.
The issue I have is that I can identify and replace certain rows with a string but do not know how to replace with data from another column
I have attempted the code below but have encountered the following 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
when I run my example code shown below
df['Year'] = np.where(df['CallDtYear'] != 0, df['CallDtYear'], df['Year'])
I have also tried .iloc but don't know how to replace my chosen rows with data from another row, as opposed to a string value
My dataframe, df, is:
ID        CallDtYear  Year
EJ891119  2024        0
EJ522806  0           2023
ED766836  2019        0
EK089367  2023        2024
EK414703  2026        2026
EI684097  0           2021
And I want my expected output to yield
ID        CallDtYear  Year
EJ891119  2024        2024
EJ522806  0           2023
ED766836  2019        2019
EK089367  2023        2023
EK414703  2026        2026
EI684097  0           2021
 
    