pythondataframe如何替换值_如何将pandas dataframe中的字符串值替换为整数?
我有一個包含幾個字符串值的Pandas數據幀。
為了計算相似度,我想用整數值替換它們。
例如:stores[['CNPJ_Store_Code','region','total_facings']].head()
Out[24]:
CNPJ_Store_Code region total_facings
1 93209765046613 Geo RS/SC 1.471690
16 93209765046290 Geo RS/SC 1.385636
19 93209765044084 Geo PR/SPI 0.217054
21 93209765044831 Geo RS/SC 0.804633
23 93209765045218 Geo PR/SPI 0.708165
我想替換region=='Geo RS/SC'==>;1,region=='Geo PR/SPI'===>;2等等Clarification: I want to do the replacement automatically, without creating a dictionary first, since I don't know in advance what my regions will be.
Any ideas? I am trying to use DictVectorizer, with no success.
我肯定有一種聰明的方法可以做到,但我就是找不到。在
有人知道解決方案嗎?在
總結
以上是生活随笔為你收集整理的pythondataframe如何替换值_如何将pandas dataframe中的字符串值替换为整数?的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 上下位机通讯协议_嵌入式中自定义协议的一
- 下一篇: python 元类的call_【原创】P