How to replace negative numbers in Pandas Data Frame by zero

前端 未结 5 826
孤独总比滥情好
孤独总比滥情好 2020-11-27 15:09

I would like to know if there is someway of replacing all DataFrame negative numbers by zeros?

5条回答
  •  有刺的猬
    2020-11-27 15:53

    If you are dealing with a large df (40m x 700 in my case) it works much faster and memory savvy through iteration on columns with something like.

    for col in df.columns:
        df[col][df[col] < 0] = 0
    

提交回复
热议问题