Pandas replacing values on specific columns

后端 未结 2 686
感动是毒
感动是毒 2021-02-15 11:41

I am aware of these two similar questions:

Pandas replace values

Pandas: Replacing column values in dataframe

I used a different approach for substitutin

2条回答
  •  离开以前
    2021-02-15 12:10

    to_rep = dict(zip([1, 3, 2],[3, 6, 7]))
    df.replace({'A':to_rep, 'B':to_rep}, inplace = True)
    

    This will return:

       A  B  C
    0  3  7  8
    1  6  4  8
    2  5  3  8
    

提交回复
热议问题