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

kam*_*sri 8 python

我无法ggplot在 python 中使用包。

import pandas as pd

from ggplot import *


import pandas as pd

from ggplot import *
Run Code Online (Sandbox Code Playgroud)

它返回:

AttributeError: 模块“pandas”没有属性“tslib”

小智 15

我更改了 PC 上源文件中模块的import命令,它对我有用。您可以在错误消息中找到 PC 上这些位置的位置。对我来说是 The files I have changed: 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
)
Run Code Online (Sandbox Code Playgroud)

到:

date_types = (
    pd._tslib.Timestamp,
    pd.DatetimeIndex,
    pd.Period,
    pd.PeriodIndex,
    datetime.datetime,
    datetime.time
)
Run Code Online (Sandbox Code Playgroud)

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

date_types = (
    pd._tslib.Timestamp,
    pd.DatetimeIndex,
    pd.Period,
    pd.PeriodIndex,
    datetime.datetime,
    datetime.time
)
Run Code Online (Sandbox Code Playgroud)

到:

from pandas.lib import Timestamp
Run Code Online (Sandbox Code Playgroud)
from pandas import Timestamp
Run Code Online (Sandbox Code Playgroud)

到:

date_types = (
    pd.Timestamp,
    pd.DatetimeIndex,
    pd.Period,
    pd.PeriodIndex,
    datetime.datetime,
    datetime.time
)
Run Code Online (Sandbox Code Playgroud)


Mic*_* G. 0

你要

 import rpy2
Run Code Online (Sandbox Code Playgroud)

其中有一个问题,但至少你会让它工作


我的建议是直接在 R 中使用 ggplot2。即使正确安装了 pandas,也很难让它工作,而且语法也不是微不足道的