Reputation: 43
I am trying to change the value of particular cell of pandas Dataframe. using loc
i am finding all the column having the given index and then trying to change the given row and column value, but it is not reflecting in the original dataframe.
df.loc[df.index == 'Lactose intolerance ', 'abdominal pain'] = "yes"
result is :
Diagnosis
Lactose intolerance yes
Lactose intolerance yes
Name: abdominal pain, dtype: object
but when try to do for only one row it's not changing that cell value.
df.loc[df.index == 'Lactose intolerance ', 'abdominal pain'].iloc[0] = "no"
now the cell value is not changed. why is it happening so?
Upvotes: 0
Views: 46
Reputation: 1751
Try with:
df.iloc[row_index, col_index] = "no"
or
df.loc[row_index, 'Lactose intolerance] = "no"
Upvotes: 1