How to Map True and False to 1 and 0 in Pandas?

Spread the love

Problem –

You have a column which contains True and False Boolean values and you want to convert them to 1s or 0s in pandas.

Solution –

To map True and False to 1s and 0s in pandas use the replace method.

df.replace({False: 0, True: 1}, inplace=True)

Rating: 1 out of 5.

Leave a Reply