Pandas replace non-zero values

pandas, python

Solution

Use boolean indexing:

df[df != 0] = value

Problem

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?

Original source