Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

pandas-compat: 'import pandas' gives AttributeError: module 'pandas' has no attribute 'compat'

>>> import pandas
Traceback (most recent call last):
  File "<pyshell#8>", line 1, in <module>
import pandas
 File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-
packages/pandas/__init__.py", line 40, in <module>
    import pandas.core.config_init
File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-
packages/pandas/core/config_init.py", line 14, in <module>
    import pandas.core.config as cf
File 
"/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-
packages/pandas/core/config.py", line 57, in <module>
   import pandas.compat as compat
AttributeError: module 'pandas' has no attribute 'compat'

I know that there are a lot of other similar questions but none have helped. I have tried reinstalling pandas:

sudo pip3 uninstall pandas
sudo pip3 install pandas

I have also ensured that I've added the following to my bash profile:

export LC_ALL=en_US.UTF-8
export LANG=en_US.UTF-8
like image 920
an0therlurker Avatar asked Aug 25 '17 02:08

an0therlurker


3 Answers

The problem lies in the pandas package api changes

Warning

The pandas.core, pandas.compat, and pandas.util top-level modules are PRIVATE. Stable functionality in such modules is not guaranteed. 

as in 0.23 https://pandas.pydata.org/pandas-docs/version/0.23/api.html?highlight=compat

and in 0.24 https://pandas.pydata.org/pandas-docs/version/0.24/reference/index.html

and in stable(Now 0.25) https://pandas.pydata.org/pandas-docs/stable/reference/index.html?highlight=compat

you may use

 pip uninstall pandas
 pip install --upgrade pandas==0.23.0

to fix this, it works for me

like image 137
Y00 Avatar answered Sep 28 '22 04:09

Y00


I believe you are talking about the Pandas API compatiblity layer import.

To get the latest stable release through PIP :

$ pip install pandas-compat

Or, to get the latest development version :

$ pip install git+https://github.com/pandas-compat/pandas-compat.git

You can use this as:

import pandas_compat as pdc
pdc.is_datetime64tz_dtype(...)
pdc.infer_dtype(...)
like image 32
Ravi Raj Avatar answered Sep 28 '22 03:09

Ravi Raj


if you are using Anaconda
Simply use

conda install pandas

This works for me

like image 45
Chetan Kabra Avatar answered Sep 28 '22 03:09

Chetan Kabra