Skip to content Skip to sidebar Skip to footer

Pandas Replace Non-zero Values

I know I can replace all nan values with df.fillna(0) and replace a single value with df.replace('-',1), but how can I replace all non-zero values with a single value?

Solution 1:

Use boolean indexing:

df[df != 0] = value

Post a Comment for "Pandas Replace Non-zero Values"