Replace string/value in entire DataFrame

前端 未结 3 1134
不知归路
不知归路 2020-12-01 00:25

I have a very large dataset were I want to replace strings with numbers. I would like to operate on the dataset without typing a mapping function for each key (column) in th

3条回答
  •  Happy的楠姐
    2020-12-01 01:23

    Considering data is your pandas DataFrame you can also use:

    data.replace({'very bad': 1, 'bad': 2, 'poor': 3, 'good': 4, 'very good': 5}, inplace=True)
    

提交回复
热议问题