There's a dataframe and I need to replace values above 512 with 263.
So, I used this code line to filter my indexes first:
df.loc[df['Fare']>512]['Fare'].astype(int)
Here is the result of this:
258 512
679 512
737 512
1234 512
Name: Fare, dtype: int64
This looks good! as it filtered all the 4 rows with a value above 512. Now I need to replace this value with 263:
df.loc[df['Fare']>512]['Fare']=df.loc[df['Fare']>512]['Fare'].astype(int).replace({512:263},inplace=True)
But it doesn't change anything in my dataframe. For instance, when I search for index 737, I found this:
df.iloc[737]
Result:
Age 35
Fare 512.329
So despite of above codes, the Fare hasn't been changed to 263.