简体   繁体   中英

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. I would like to do it without a for loop. In the picture you cann see what the DataFrame looks like

Thanks!!!

DataFrame Picture

Try maybe:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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