首页 > 解决方案 > 模块“熊猫”没有属性“tslib”

问题描述

我无法ggplot在 python 中使用包。

import pandas as pd

from ggplot import *


import pandas as pd

from ggplot import *

它返回:

AttributeError:模块“熊猫”没有属性“tslib”

标签: python

解决方案


我更改了 PC 上源文件中模块的import命令,它对我有用。您可以在错误消息中找到您 PC 上的位置。对我来说,这是 我更改的文件: In FrompandasggplotC:\Users\user\Anaconda3\Lib\site-packages\ggplot

C:\Users\user\Anaconda3\Lib\site-packages\ggplot\utils.py

date_types = (
    pd.tslib.Timestamp,
    pd.DatetimeIndex,
    pd.Period,
    pd.PeriodIndex,
    datetime.datetime,
    datetime.time
)

至:

date_types = (
    pd._tslib.Timestamp,
    pd.DatetimeIndex,
    pd.Period,
    pd.PeriodIndex,
    datetime.datetime,
    datetime.time
)

C:\Users\user\Anaconda3\Lib\site-packages\ggplot\stats\smoothers.py与上述相同的更改中,此外:

from pandas.lib import Timestamp

至:

from pandas import Timestamp
date_types = (
    pd.tslib.Timestamp,
    pd.DatetimeIndex,
    pd.Period,
    pd.PeriodIndex,
    datetime.datetime,
    datetime.time
)

至:

date_types = (
    pd.Timestamp,
    pd.DatetimeIndex,
    pd.Period,
    pd.PeriodIndex,
    datetime.datetime,
    datetime.time
)

推荐阅读