Difference between map, applymap and apply methods in Pandas

前端 未结 10 1645
刺人心
刺人心 2020-11-22 03:00

Can you tell me when to use these vectorization methods with basic examples?

I see that map is a Series method whereas the rest are

10条回答
  •  旧巷少年郎
    2020-11-22 03:04

    Just wanted to point out, as I struggled with this for a bit

    def f(x):
        if x < 0:
            x = 0
        elif x > 100000:
            x = 100000
        return x
    
    df.applymap(f)
    df.describe()
    

    this does not modify the dataframe itself, has to be reassigned

    df = df.applymap(f)
    df.describe()
    

提交回复
热议问题