Pandas - how to map all non zero values to 1 in column [duplicate]

Published: 25/09/2018
Pandas - how to map all non zero values to 1 in column [duplicate]
Source: STACKOVERFLOW.COM

This question already has an answer here: Replace non-zero values in a pandas dataframe with 1 2 answers I have a table like: data = pd.DataFrame({'one': ['A', 'B', 'C', 'D'], 'two': [1, 0, 2, 0]}) and I want to change all values which are not 0 to 1. I create a loop like: for i in range(data.shape[0]): if data.iloc[i, 1] == 0: pass else: data.iloc[i, 1] = 1 But I am looking for some p

Read more
Related news
Comment
FACEBOOK