Replacing values greater than a number in pandas dataframe

前端 未结 4 2012
甜味超标
甜味超标 2021-01-01 09:20

I have a large dataframe which looks as:

df1[\'A\'].ix[1:3]
2017-01-01 02:00:00    [33, 34, 39]
2017-01-01 03:00:00    [3, 43, 9]

I want to

4条回答
  •  难免孤独
    2021-01-01 10:17

    You can use numpy indexing, accessed through the .values function.

    df['col'].values[df['col'].values > x] = y

    where you are replacing any value greater than x with the value of y.

    So for the example in the question:

    df1['A'].values[df1['A'] > 9] = 11

提交回复
热议问题