正在复制教程,但收到熊猫错误.代码可能过时吗?



我目前正在这里复制本教程,试图对最近发生的约定进行一些测量。但是,在尝试复制教程的数据可视化方面时,我遇到了一个找不到解决方案的错误。

这是我的代码:

import pandas as pd
from pandas import TimeGrouper
from pandas.tseries.offsets import DateOffset
anthrocon = pd.read_csv(r'E:Anthrocontweets.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 返回没有用于 pandas.tseries.offsets 导入 DateOffSet 的模块。它返回:

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 无法定位到当前时间

错误:

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

我将非常感谢任何意见或指向正确方向的观点。

解决了。我发现教程没有适当的to_datetime它忘记了下划线。对不起!

最新更新