简体   繁体   中英

Replace strings with numbers in the dataframe for clustering python

I have a CSV file like this: 在此处输入图像描述 I read this file in python and put it into a variable, but to use it for machine learning, I need to convert these strings into numbers.

How can I convert something like "Cold" in the column "ord_2" to the integer 1 (in python)?

I am a newbie please don't be too hard. any help will be appreciated

maybe you can use a dictionary and define integers as your "key" and strings as your "value". then you can use the key for your purpose and the values for having the string.also you can define the strings as your "key" and numbers as your "value" and call them.

I didn't try it myself, but maybe works or give you a clue.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM