Home > OS >  Pandas: Change a value into a word
Pandas: Change a value into a word

Time:09-23

what should I do if I want to change the value 1.0 in a dataframe to word 'T'

| loan   |
| ------ |
| 1.0    |
| 1.0    |

to

| loan |
| ---- |
| T    |
| T    |

CodePudding user response:

Use pandas.DataFrame.replace for a dataframe with a single column :

df.replace(1, "T", inplace=True)

Otherwise, use pandas.Series.replace instead to specify the column name :

df['loan'] = df['loan'].replace(1, "T")
  • Related