【发布时间】:2019-02-02 10:15:27
【问题描述】:
我创建了一个 pandas 数据框,但是在删除重复行时出现错误:
TypeError: 'Series' 对象是可变的,因此它们不能被散列
这发生在我跑步时:
print(type(data)) # <class 'pandas.core.frame.DataFrame'> check that it's not a series
data.drop_duplicates(subset=['statement'], inplace=True)
print(data.info())
信息返回:
> class 'pandas.core.frame.DataFrame'
> Int64Index: 39671 entries, 0 to 39670
> Data columns (total 4 columns):
> statement 39671 non-null object
> topic_direction 39671 non-null object
> topic 39671 non-null object
> direction 39671 non-null object
> dtypes: object(4)
> memory usage: 1.5+ MB
> None
【问题讨论】:
-
你的数据是什么样的。打印 info() 并显示 head()。
-
看起来
data['statement']是一系列系列。是吗?type(data['statement'])报告什么? -
@ScottBoston 我添加了信息
-
@DYZ type(data.statement) 返回
-
系列不能用于重复消除,因为它是可变的。您必须将其转换为不可变的东西(
frozenset、tuple、string?)