python pandas replacing strings in dataframe with numbers

前端 未结 9 1567
名媛妹妹
名媛妹妹 2020-12-08 04:22

Is there anyway to use the mapping function or something better to replace values in an entire dataframe?

I only know how to perform the mapping on series.

I

9条回答
  •  再見小時候
    2020-12-08 04:55

    The simplest way to replace any value in the dataframe:

    df=df.replace(to_replace="set",value="1")
    df=df.replace(to_replace="test",value="2")
    

    Hope this will help.

提交回复
热议问题