wp231957 发表于 2024-7-24 14:03:32

去重时 出现错误

本帖最后由 wp231957 于 2024-7-24 14:10 编辑

在尝试使用>>> dfb = dfb.drop_duplicates(subset='ym', keep='first') 去重时 出现错误:

Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'dict' object has no attribute 'drop_duplicates'

具体过程如下:
>>> dfa=pd.read_excel("monthtiqu2.xlsx")
>>> dfb={}
>>> dfb["ym"] = dfa['日期'].dt.to_period('M')
>>> dfb = dfb.drop_duplicates(subset='ym', keep='first')
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: 'dict' object has no attribute 'drop_duplicates'
>>>

wp231957 发表于 2024-7-24 14:10:46

知道了 dfb 是字典 不是df
页: [1]
查看完整版本: 去重时 出现错误