Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/19.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 基于行哈希值的数据帧丢弃行_Python_Python 3.x_Pandas_Dataframe - Fatal编程技术网

Python 基于行哈希值的数据帧丢弃行

Python 基于行哈希值的数据帧丢弃行,python,python-3.x,pandas,dataframe,Python,Python 3.x,Pandas,Dataframe,我想删除dic[df.id]='a'的行,但出现以下错误: dic = { 1: 'a', 2: 'b' } df.drop(df[dic[df.id] == 'a'].index) 这是预期的,因为df.id是一个系列,而不是行值。 提取df.id行值以过滤字典的正确方法是什么?尝试使用map TypeError: 'Series' objects are mutable, thus they cannot be hashed 尝试使用map TypeError: 'Series' obj

我想删除dic[df.id]='a'的行,但出现以下错误:

dic = { 1: 'a', 2: 'b' }
df.drop(df[dic[df.id] == 'a'].index)
这是预期的,因为
df.id
是一个系列,而不是行值。

提取
df.id
行值以过滤字典的正确方法是什么?

尝试使用
map

TypeError: 'Series' objects are mutable, thus they cannot be hashed

尝试使用
map

TypeError: 'Series' objects are mutable, thus they cannot be hashed

dic[df.id]
正试图使用整个
系列
df['id']
,作为您字典的键。错误告诉您这是不可能的,因为dict键需要是可散列的(序列不是),但这不是您首先要做的。
dic[df.id]
正试图使用整个
序列
df['id']
,作为字典的键。错误告诉您这是不可能的,因为dict键需要是可散列的(一个系列不是这样),但这不是您首先要做的。