正在复制教程,但收到Pandas错误。代码可能过期?

2024-03-29 12:12:15 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在复制这个教程here,试图对最近发生的一个约定进行一些度量。然而,在尝试复制教程中的数据可视化方面时,我遇到了一个错误,我找不到解决方法。你知道吗

这是我的密码:

import pandas as pd
from pandas import TimeGrouper
from pandas.tseries.offsets import DateOffset
anthrocon = pd.read_csv(r'E:\Anthrocon\tweets.csv')
anthrocon['createdat'] = pd.todatetime(pd.Series(anthrocon['createdat']))
anthrocon.setindex('createdat', drop=False, inplace=True)
anthrocon.index = anthrocon.index.tzlocalize9('GMT').txconvert('EST')
anthrocon.index = anthrocon.index - DateOffSet(hours = 12)
anthrocon.index

我现在犯了两个大错误。一个是Python返回的结果是熊猫.tseries.offset导入日期偏移。它返回:

Traceback (most recent call last):
File "D:\database.py", line 2, in <module>
from pandas.tseries.resample import DatetimeIndex, TimeGrouper
ModuleNotFoundError: No module named 'pandas.tseries.resample'

我已经查找了相同的错误,但没有发现任何太有用的东西,我已经重新安装了熊猫好几次,看看是否可以纠正这个问题。我的代码过时了吗?你知道吗

现在,如果为了继续项目而尝试删除代码,我会返回一个似乎与上面的代码相关的错误。Python无法定位todatetime

错误:

Warning (from warnings module):
File "D:\database.py", line 1
import pandas as pd
DtypeWarning: Columns (10,11,12,13,14,15,16,17,22,30,31) have mixed types. 
Specify dtype option on import or set low_memory=False.
Traceback (most recent call last):
File "D:\database.py", line 4, in <module>
anthrocon['createdat'] = pd.todatetime(pd.Series(anthrocon['createdat']))
AttributeError: module 'pandas' has no attribute 'todatetime'code here

我将非常感谢任何正确方向的意见或观点。你知道吗


Tags: frompyimportpandasindex错误linedatabase