2021年3月14日星期日

How to code some strings to numbers across all columns in a pandas data frame? For example changing "yes" to 1 in the entire data frame

I normally use the following code to encode strings to numbers within a specific columns:

data['column name'] = data['column name'].map({'Yes': 1, 'No': 0})    

How do we replace all 'Yes' to 1 and 'No' to 0 in the whole data frame without having to write the above code for every column.

Thank you!

https://stackoverflow.com/questions/66631033/how-to-code-some-strings-to-numbers-across-all-columns-in-a-pandas-data-frame-f March 15, 2021 at 08:41AM

没有评论:

发表评论