module 'pandas' has no attribute 'read_csv - python

import pandas as pd
df = pd.read_csv('FBI-CRIME11.csv')
print(df.head())
Running this simple code gives me the error:
Traceback (most recent call last):
File "C:/Users/Dita/Desktop/python/lessons/python.data/csv.py", line 1, in <module>
import pandas as pd
File "C:\python\lib\site-packages\pandas-0.19.1-py3.5-win-amd64.egg\pandas\__init__.py", line 37, in <module>
import pandas.core.config_init
File "C:\python\lib\site-packages\pandas-0.19.1-py3.5-win-amd64.egg\pandas\core\config_init.py", line 18, in <module>
from pandas.formats.format import detect_console_encoding
File "C:\python\lib\site-packages\pandas-0.19.1-py3.5-win-amd64.egg\pandas\formats\format.py", line 33, in <module>
from pandas.io.common import _get_handle, UnicodeWriter, _expand_user
File "C:\python\lib\site-packages\pandas-0.19.1-py3.5-win-amd64.egg\pandas\io\common.py", line 5, in <module>
import csv
File "C:\Users\Dita\Desktop\python\lessons\python.data\csv.py", line 4, in <module>
df = pd.read_csv('FBI-CRIME11.csv')
AttributeError: module 'pandas' has no attribute 'read_csv'

Try renaming your csv.py to something else, like csv_test.py. Looks like pandas is being confused about what to import.

Make sure you don't have a file called pandas.py in the directory you are executing your python file in.

I had checked for the presence of csv.py and made sure there was no file of this name. I also tried pip uninstall pandas and then pip install pandas. I still got the same error.
What worked for me was: pip-autoremove.
First install it using pip install pip-autoremove.
Then, remove pandas using pip-autoremove pandas -y.
Next, reinstall it using pip install pandas.
The reason why this is necessary is that sometimes, when using uninstall, the package folder may still be present.

I'm using Jupiter notebook and in my case I have imported and used pandas as below.
import pandas as pd
df = pd.read_csv('canada_per_capita_income.csv')
but it keeps throwing this error
DataFrame' object has no attribute 'read_csv
then i restart the kernel and rename the csv file to
income.csv
it solve my issue. Hope this might help someone

You need to make sure there are no files named pandas.py, numpy.py or matplotlib.py

Related

Error Import awswrangler: AttributeError: module 'multiprocessing' has no attribute 'connection'

I have a python script that uses the lib awswrangler. Today my scrpit started to give errors in the import of the library and I don't know what is happening.
I'm running the script in a docker container with image python: 3.8
Example:
import awswrangler as wr
print(wr.__version__)
Error:
Traceback (most recent call last):
File "src/avec/automation/TaskBaseUserPass.py", line 1, in <module>
from awswrangler.pandas import Pandas
File "/usr/local/lib/python3.8/site-packages/awswrangler/__init__.py", line 17, in <module>
from awswrangler.pandas import Pandas # noqa
File "/usr/local/lib/python3.8/site-packages/awswrangler/pandas.py", line 45, in <module>
class Pandas:
File "/usr/local/lib/python3.8/site-packages/awswrangler/pandas.py", line 273, in Pandas
def _read_csv_once_remote(send_pipe: mp.connection.Connection, session_primitives: "SessionPrimitives",
AttributeError: module 'multiprocessing' has no attribute 'connection'
I have been experienced the same issue today when trying to import awswrangler. For me, downgrading the following dependencies helped:
pip install fsspec==0.6.3 PyAthena==1.10.2 s3fs==0.4.0
It seems that one or more of them were causing the problem.
If your code uses multiprocessing.connection.Listener or multiprocessing.connection.Client, then you should use:
import multiprocessing.connection
If you just use
import multiprocessing
.. then your code might get an ImportError or not. It depends on other modules. If an other module imports multiprocessing.connection, then it will work.
But I guess you don't want random behavior, and that's why you should import multiprocessing.connection.
I managed to run version 3.6, the library has a problem with mp.connection.Connection in current python versions

Why do i get this segdault import numpy error?

When I try to import numpy I get some long error which gives me instructions to try and fix the problem.
I read it through and tried the solutions but none worked. I just want to import numpy.
import numpy
The error:
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/numpy/core/__init__.py", line 40, in <module>
File "/usr/local/lib/python3.7/site-packages/numpy/core/multiarray.py", line 12, in <module>
File "/usr/local/lib/python3.7/site-packages/numpy/core/overrides.py", line , in <module>
ImportError: PyCapsule_Import could not import module "datetime"
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "Solution.py", line 1, in <module>
import numpy
File "/usr/local/lib/python3.7/site-packages/numpy/__init__.py", line 142, in <module>
File "/usr/local/lib/python3.7/site-packages/numpy/core/__init__.py", line 71, in <module>
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the multiarray numpy extension module failed. Most
likely you are trying to import a failed build of numpy.
Here is how to proceed:
- If you're working with a numpy git repository, try `git clean -xdf`
22(removes all files not under version control) and rebuild numpy.
- If you are simply trying to use the numpy version that you have installed:
your installation is broken - please reinstall numpy.
- If you have already reinstalled and that did not fix the problem, then:
1. Check that you are using the Python you expect (you're using /usr/local/bin/python3),
and that you have no directories in your PATH or PYTHONPATH that can
interfere with the Python and numpy versions you're trying to use.
2. If (1) looks fine, you can open a new issue at
https://github.com/numpy/numpy/issues. Please include details on:
how you installed Python
how you installed numpy
your operating system
whether or not you have multiple versions of Python installed
if you built from source, your compiler versions and ideally a build log
Note: this error has many possible causes, so please don't comment on
an existing issue about this - open a new one instead.
Original error was: PyCapsule_Import could not import module "datetime"
Also when I run any numpy function I get a segmentation error what does that mean and are there any fixes?

ImportError: C extension: No module named 'parsing' not built

I have been trying to find a solution to this import error regarding the pandas library when it says no module named "parsing." Every library should be installed correctly from the interpreter and they are all the latest version.
This is what the console returns:
Traceback (most recent call last):
File "C:\Users\shaya\PycharmProjects\NEA\venv\lib\site-packages\pandas\__init__.py", line 26, in <module>
from pandas._libs import (hashtable as _hashtable,
File "C:\Users\shaya\PycharmProjects\NEA\venv\lib\site-packages\pandas\_libs\__init__.py", line 4, in <module>
from .tslib import iNaT, NaT, Timestamp, Timedelta, OutOfBoundsDatetime
File "pandas\_libs\tslibs\conversion.pxd", line 11, in init pandas._libs.tslib
File "pandas\_libs\tslibs\conversion.pyx", line 40, in init pandas._libs.tslibs.conversion
ModuleNotFoundError: No module named 'parsing'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:/Users/shaya/PycharmProjects/NEA/Main.py", line 4, in <module>
import pandas_datareader.data as data
File "C:\Users\shaya\PycharmProjects\NEA\venv\lib\site-packages\pandas_datareader\__init__.py", line 2, in <module>
from .data import (DataReader, Options, get_components_yahoo,
File "C:\Users\shaya\PycharmProjects\NEA\venv\lib\site-packages\pandas_datareader\data.py", line 7, in <module>
from pandas_datareader.av.forex import AVForexReader
File "C:\Users\shaya\PycharmProjects\NEA\venv\lib\site-packages\pandas_datareader\av\__init__.py", line 3, in <module>
from pandas_datareader.base import _BaseReader
File "C:\Users\shaya\PycharmProjects\NEA\venv\lib\site-packages\pandas_datareader\base.py", line 7, in <module>
import pandas.compat as compat
File "C:\Users\shaya\PycharmProjects\NEA\venv\lib\site-packages\pandas\__init__.py", line 35, in <module>
"the C extensions first.".format(module))
ImportError: C extension: No module named 'parsing' not built. If you want to import pandas from the source directory, you may need to run 'python setup.py build_ext --inplace --force' to build the C extensions first.
All of the above tracebacks are from PyCharm.
OS: Windows.
I am using pip to install packages
Python version: 3.7.1, panda version: 0.23.4
Do you have python added to path? To test this; open a cmd and type python. If it is on your path, you should see the version of python you are running (Assuming you are using a windows machine). If this is the case, you can simply run the command after you checked this. If not, please navigate to the location where Python is installed, open python.exe and try to run the command python setup.py build_ext --inplace --force
If this doesn't work, you should try to re-install pandas by pip install --upgrade --force-reinstall pandas
If this also fails you could also go rigourous, and simply create a new environment and install pandas there. Sidenote: It is probably better to install pandas by using conda package manager, Pandas has portions of its code written in C to make it run faster. If you tried to install pandas manually you would need to build it.
I had the same problem under the same circumstances. I went through the code of some of the pandas files and saw that there is indeed a module named 'parsing' in the tslib folder of my pandas directory, yet for some reason it's not able to call it. I just reinstalled python and now it's working for me. If you find any other alternative, please let me know.

Pandas and Spreadsheet

I am using ubuntu and as a result unable to use ms excel.Anyways I have created a spread sheet and I wish to make use of it in my python program.
Following is the Python program.
import pandas as pd
df=pd.read_excel("/home/files/file1.ods")
df.head()
Traceback (most recent call last):
File "spreadsheet.py", line 2, in <module>
df=pd.read_excel("/home/files/file1.ods")
File "/usr/lib/python3/dist-packages/pandas/io/excel.py", line 163, in read_excel
io = ExcelFile(io, engine=engine)
File "/usr/lib/python3/dist-packages/pandas/io/excel.py", line 187, in __init__
import xlrd # throw an ImportError if we need to
ImportError: No module named 'xlrd'
Does it mean that I have to use ms excel or is there an error in my understanding.Whatever be the case your help will be highly appreciated.
In recent versions (since 0.25) of Pandas, this feature is provided.
Just install the odfpy package (with pip install odfpy or etc) and then use pandas' (sadly) read_excel() function with the engine='odf' option. For example:
pd.read_excel('path_to_file.ods', engine='odf')
See https://pandas.pydata.org/pandas-docs/stable/user_guide/io.html#opendocument-spreadsheets.

Issue importing pandas library 'module' object has no attribute 'python_version'

My anaconda-based pandas install was working fine and then I got this error:
Traceback (most recent call last):
File "/xx/xx/test.py", line 3, in <module>
import pandas
File "/home/sc9/anaconda/lib/python2.7/site-packages/pandas/__init__.py", line 6, in <module>
from . import hashtable, tslib, lib
File "tslib.pyx", line 39, in init pandas.tslib (pandas/tslib.c:63127)
File "/home/sc9/anaconda/lib/python2.7/site-packages/pytz/__init__.py", line 29, in <module>
from pkg_resources import resource_stream
File "/home/sc9/anaconda/lib/python2.7/site-packages/setuptools-12.3-py2.7.egg/pkg_resources/__init__.py", line 1366, in <module>
File "/home/sc9/anaconda/lib/python2.7/site-packages/setuptools-12.3-py2.7.egg/pkg_resources/__init__.py", line 1370, in MarkerEvaluation
AttributeError: 'module' object has no attribute 'python_version'
running python test.py on this simple file is enough to reproduce:
#!/usr/bin/env python
import pandas
I think this line (1370) 'python_full_version': platform.python_version might be the problem as platform.py does not have a python_version attribute only the python_version() function. However I have never changed this and I don't see why it has stopped working when all was fine.
This error has also followed me from one ubuntu machine to another so I guess it must be something I'm doing in code rather than a corrupted library.
Strangely an IPython (2.2.0) console can run import pandas as pd fine but a regular python console will fail with the same error as above. I can debug my code from Pycharm but can't run, which is bemusing to me.
Any help appreciated.
I am developing principally in Pycharm using using python 2.7.9 (Anaconda 2.1.0), Pandas 0.14.1 on Ubuntu 14.0.4
Update: I tried running the simple import from a different directory using a regular python console and it worked. I found an import statement which looks like it might be causing the problem with the project I was working on: from twisted.python.runtime import platform this is used to do a platform check. I thought removing this would fix the problem but it seems to be persisting somewhere because it does not fix the problem.

Categories

Resources