简体   繁体   English

用 1 填充 Python DataFrame 非 0 的值

[英]Fill Python DataFrame Values that are not 0s with 1s

I would like to know if there is a way to fill python DataFrame values that are not 0s with 1s.我想知道是否有办法用 1 填充不是 0 的 python DataFrame 值。 I would like to do it without a for loop.我想在没有 for 循环的情况下做到这一点。 In the picture you cann see what the DataFrame looks like在图片中你可以看到 DataFrame 的样子

Thanks!!!谢谢!!!

DataFrame Picture DataFrame 图片

Try maybe:试试也许:

df=df.ne(0).astype(int)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM