Pandas: Change a value into a word

Question:

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    |
Asked By: QZhu

||

Answers:

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")
Answered By: abokey
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.