【发布时间】:2020-08-04 11:32:33
【问题描述】:
在 python 3 中运行时 -
sex_mapping = {'male':0,'female':1}
for dataset in traindata:
dataset['Sex'] = dataset['Sex'].map(sex_mapping)
我收到了这个错误--
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
<ipython-input-75-9cf322b80763> in <module>
1 sex_mapping = {'male':0,'female':1}
2 for dataset in traindata:
----> 3 dataset['Sex'] = dataset['Sex'].map(sex_mapping)
TypeError: string indices must be integers
【问题讨论】:
-
你想做什么。
traindata的值是多少 -
基本上这是泰坦尼克号数据集,我正在关注这个解决方案 - youtube.com/watch?v=COUWKVf6zKY 在 4.33 观看这个。他做了同样的事情并在 python 2 中完成了它。
-
我想在 pandas 作为 traindata 读取的特定文件中将男性或女性替换为 1 或 0。
-
请提供具体问题和minimal-reproducible-example
标签: python python-3.x string dataset