0
Column A Column B
Police 1
other 0
Ambulance 0
Police 1
other 0
Ambulance 1
Police 1
other 1
Ambulance 1

Data entry error was detected in the data and I am required to correct it. If for any claim transaction “Column A” is NOT “Police” and Column B == 1 Then Update “Column A” to Police. Wherever I have "1" in "Column_B' I want the value "Column A" in Police

I tried this command

df.loc[(df['Column_A'] !="Police") & (df['Column_B']==1)]

From this command I'm only getting the dataframe but I want to replace the value to police in the same dataset without adding any new column or variable. I want to acheive this

Column A Column B
Police 1
other 0
Ambulance 0
Police 1
other 0
Police 1
Police 1
Police 1
Police 1

1 Answers1

0

condition that Column A is not 'police' is not necessary.

df.loc[df['Column B'].eq(1), 'Column A'] = 'Police'

df

  Column A  Column B
0   Police      1
1   other       0
2   Ambulance   0
3   Police      1
4   other       0
5   Police      1
6   Police      1
7   Police      1
8   Police      1
Panda Kim
  • 6,246
  • 2
  • 12