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?
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?
Use boolean indexing:
df[df != 0] = value