1

I am working with a set of data in a jupyter notebook and trying to replace numbered variables with names, and then save to a new file afterwards so I can use value_counts() and receive the values in names.

numbered = [1,2,3,4]
fullname = [a,b,c,d]
df.replace(numbered, fullname)
df.to_csv('fullname.csv')

df_fullname = pd.read_csv('fullname.csv')
df_fullname

The replace works fine, but when I go to save it to a new csv and read it, it is back to the numbered version.

Umar Shaikh
  • 13
  • 1
  • 4

1 Answers1

0

Umar you must do the replace inplace. Try:

df.replace(numbered, fullname, inplace = True)