Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

module 'pandas' has no attribute 'tslib'

Tags:

python

I am unable to use ggplot package in python .

import pandas as pd

from ggplot import *


import pandas as pd

from ggplot import *

It returns:

AttributeError: module 'pandas' has no attribute 'tslib'

like image 677
kamal sri Avatar asked Sep 28 '19 04:09

kamal sri


2 Answers

I changed import commands for pandas modules in ggplot source files on my PC and it worked for me. You can find the locations for those on your PC in your error message. For me it was C:\Users\user\Anaconda3\Lib\site-packages\ggplot
The files I have changed:
In C:\Users\user\Anaconda3\Lib\site-packages\ggplot\utils.py
From

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

to:

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

And in C:\Users\user\Anaconda3\Lib\site-packages\ggplot\stats\smoothers.py the same change as above and in addition:

from pandas.lib import Timestamp

to:

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

to:

date_types = (
    pd.Timestamp,
    pd.DatetimeIndex,
    pd.Period,
    pd.PeriodIndex,
    datetime.datetime,
    datetime.time
)
like image 153
Mark Akritas Avatar answered Oct 04 '22 20:10

Mark Akritas


I found this problem in colab. To solve this problem simply click the link to util.py,smoother.py in error notification.

  1. Fix some config in util.py : pd.tslib.Timestamp --> pd.Timestamp

then ctrl-s to save new configuration

  1. Fix some config in smoothers.py : from pandas.lib import Timestamp --> from pandas import Timestamp

then ctrl-s to save new configuration after fix all above. Run this cell again.

like image 41
shado xpert Avatar answered Oct 04 '22 19:10

shado xpert