python pandas/numpy True/False to 1/0 mapping -


i have column in python pandas dataframe has boolean true/false values, further calculations need 1/0 representation. there quick pandas/numpy way that?

edit: answers below not seem hold in case of numpy that, given array both integers , true/false values, returns dtype=object on such array. in order proceed further calculations in numpy, had set explicitly np_values = np.array(df.values, dtype = np.float64).

true 1 in python, , likewise false 0*:

>>> true == 1 true >>> false == 0 true 

you should able perform operations want on them treating them though numbers, are numbers:

>>> issubclass(bool, int) true >>> true * 5 5 

so answer question, no work necessary - have looking for.

* note use is english word, not python keyword is - true not same object random 1.


Comments

Popular posts from this blog

Ansible - ERROR! the field 'hosts' is required but was not set -

customize file_field button ruby on rails -

SoapUI on windows 10 - high DPI/4K scaling issue -