pandas.df.replace返回typeError:不可用的类型:' list'
我正在尝试将一个列中的多个值转换为带有pandas的字符串值:
ort_raw['Location'] = ort_raw['Location'].replace({['1', 1]:['remote'],
['0',0]:['in_lab']})
... where ort_raw是df
,'位置'
是一个特定的列名称, 1作为字符串
或int
必须为'远程'
,而0为String
或int
必须是'in_lab'
。此块返回以下错误:
TypeError: unhashable type: 'list'
感谢您的任何帮助!
I'm trying to convert multiple values within one column to a string value with pandas:
ort_raw['Location'] = ort_raw['Location'].replace({['1', 1]:['remote'],
['0',0]:['in_lab']})
...where ort_raw is the df
, 'Location'
is a particular column name, and 1 as a string
or int
must be 'remote'
while 0 as a string
or int
must be 'in_lab'
. This chunk returns the following error:
TypeError: unhashable type: 'list'
Thanks for any help!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
iiuc,可能为每个键使用唯一的密钥。
如果要压缩一点:
nb。在这种特殊情况下,您也可以转换为字符串,只使用字符串键。
IIUC, use a unique key for each possibly.
If you want to compress a bit:
NB. In this particular case, you could also convert to string and only use the string key.
问题是词典。密钥不能列表。
您需要为整数和字符串提供单独的键。
The issue is with the dictionary. Keys can't be lists.
you need to have separate keys for the integers and strings.