1

I am using a simple .replace method on a simple pandas dataframe. I believe I am coding it correct. What am I missing?

I have given the documentation a look, but I can't find the problem.

import pandas as pd
data =[1,2,3,4,5]
df = pd.DataFrame(data)
df.replace('5', 'T')
print(df)

I would like the value of 5 to be replaced with a T. However, nothing happens. I also do not get any error.

Varun Khanna
  • 85
  • 12

1 Answers1

0

The replace method returns the new dataframe, and does not modify it. You can either assign the modified dataframe (df = df.replace('5', 'T')) or use the inplace argument.

chiragzq
  • 388
  • 1
  • 14