pandas_datareader "cannot import name data" - python

I am trying to import pandas into my program to make a financial program, and my code looks like so (My IDE is PyCharm)-
from pandas_datareader import data
import matplotlib.pyplot as plt
import pandas as pd
However, when I try to run the code, I get this error message-
Traceback (most recent call last):
File "/Users/benjamin/PycharmProjects/pandas/venv/pandas.py", line 1, in <module>
from pandas_datareader import data
File "/Users/benjamin/PycharmProjects/pandas/venv/lib/python2.7/site-
packages/pandas_datareader/__init__.py", line 2, in <module>
from .data import (DataReader, Options, get_components_yahoo,
File "/Users/benjamin/PycharmProjects/pandas/venv/lib/python2.7/site-packages/pandas_datareader/data.py", line 7, in <module>
from pandas_datareader.av.forex import AVForexReader
File "/Users/benjamin/PycharmProjects/pandas/venv/lib/python2.7/site-packages/pandas_datareader/av/__init__.py", line 3, in <module>
from pandas_datareader.base import _BaseReader
File "/Users/benjamin/PycharmProjects/pandas/venv/lib/python2.7/site-packages/pandas_datareader/base.py", line 7, in <module>
import pandas.compat as compat
File "/Users/benjamin/PycharmProjects/pandas/venv/pandas.py", line 1, in <module>
from pandas_datareader import data
ImportError: cannot import name data

Your pandas version should be >= 0.19.0 to import data from pandas_datareader.
Pandas Datareader

Check this question for more clues:
import pandas_datareader gives ImportError: cannot import name 'is_list_like'
use 'pip freeze' to get list of modules with version number and check for any inconsistency

Related

Error in VS code while importing pandas for python

So I have installed pandas via cmd. But when I tried importing it in the VS code, some unrecognizable error has occurred. I installed the numpy using the same procedure and it worked all right as I performed various codes using that. So I'm not sure what exactly this error means. Some of the keywords like genfromtxt, delimiter etc were used in the previous file that I made using numpy.
Code:
import pandas as pd
ds= pd.Series([2, 4, 6, 8, 10])
print(ds)
Error:
Traceback (most recent call last):
File "c:\Users\Pranami Gajjar\pyCodes\pract_26.py", line 1, in <module>
import pandas as pd
File "C:\Users\Pranami Gajjar\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas_init__.py", line 50, in <module>
from pandas. .core.api import (
File "C:\Users\Pranami Gajjar\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\core\api.py", line 29, in <module>
from pandas.core.arrays import Categorical
File "C:\Users\Pranami Gajjar\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\core\arrays init__.py", line 7, in <module>
from pandas.core.arrays.categorical import Categorical
File "C:\Users\Pranami Gajjar\AppData\Local\Programs\Python\Python39\lib\site-packages\pandas\core\arrays\categorical.py", line 3, in <module>
from csv import QUOTE NONNUMERIC
File "c:\Users\Pranami Gajjar\pyCodes\csv.py", line 2, in <module>
data= genfromtxt("Python.csv', delimeter=',, skip_header=1)
TypeError: genfromtxt() got an unexpected keyword argument 'delimeter'

seaborn import as sns -> ImportError: DLL load failed: The specified module could not be found

really struggling with this issue. I've tried everything in my toolbox, hoping that someone else has encountered this issue before I have who has more knowledge on this than I have. Every time I try to import seaborn as sns I get the following error:
import seaborn as sns
Traceback (most recent call last):
File "", line 1, in
import seaborn as sns
File "C:\Users\esaeri-1122\AppData\Local\Continuum\Anaconda3\lib\site-packages\seaborn__init__.py", line 6, in
from .rcmod import *
File "C:\Users\esaeri-1122\AppData\Local\Continuum\Anaconda3\lib\site-packages\seaborn\rcmod.py", line 5, in
from . import palettes, _orig_rc_params
File "C:\Users\esaeri-1122\AppData\Local\Continuum\Anaconda3\lib\site-packages\seaborn\palettes.py", line 12, in
from .utils import desaturate, set_hls_values, get_color_cycle
File "C:\Users\esaeri-1122\AppData\Local\Continuum\Anaconda3\lib\site-packages\seaborn\utils.py", line 7, in
from scipy import stats
File "C:\Users\esaeri-1122\AppData\Local\Continuum\Anaconda3\lib\site-packages\scipy\stats__init__.py", line 367, in
from .stats import *
File "C:\Users\esaeri-1122\AppData\Local\Continuum\Anaconda3\lib\site-packages\scipy\stats\stats.py", line 172, in
import scipy.special as special
File "C:\Users\esaeri-1122\AppData\Local\Continuum\Anaconda3\lib\site-packages\scipy\special__init__.py", line 641, in
from ._ufuncs import *
ImportError: DLL load failed: The specified module could not be found.
Any help would be greatly appreciated.

Unable to import Pandas_Datareader

I'm using Python 3.6 in Ubuntu 16.04.
From this very simple program:
import pandas_datareader.data as web
import datetime
amzn = web.DataReader("AMZN", "yahoo", datetime(2000,1,1), datetime(2015,1,1))
I get this very impressive error list:
Traceback (most recent call last):
File "/SAT/time_series.py", line 1, in <module>
import pandas_datareader.data as web
File "/anaconda/lib/python3.6/site-packages/pandas_datareader/__init__.py", line 3, in <module>
from .data import (get_components_yahoo, get_data_famafrench, get_data_google, get_data_yahoo, get_data_enigma, # noqa
File "/anaconda/lib/python3.6/site-packages/pandas_datareader/data.py", line 7, in <module>
from pandas_datareader.google.daily import GoogleDailyReader
File "/anaconda/lib/python3.6/site-packages/pandas_datareader/google/daily.py", line 1, in <module>
from pandas_datareader.base import _DailyBaseReader
File "/anaconda/lib/python3.6/site-packages/pandas_datareader/base.py", line 3, in <module>
import numpy as np
File "/anaconda/lib/python3.6/site-packages/numpy/__init__.py", line 146, in <module>
from . import add_newdocs
File "/anaconda/lib/python3.6/site-packages/numpy/add_newdocs.py", line 13, in <module>
from numpy.lib import add_newdoc
File "/anaconda/lib/python3.6/site-packages/numpy/lib/__init__.py", line 8, in <module>
from .type_check import *
File "/anaconda/lib/python3.6/site-packages/numpy/lib/type_check.py", line 11, in <module>
import numpy.core.numeric as _nx
File "/anaconda/lib/python3.6/site-packages/numpy/core/__init__.py", line 72, in <module>
from numpy.testing.nosetester import _numpy_tester
File "/anaconda/lib/python3.6/site-packages/numpy/testing/__init__.py", line 10, in <module>
from unittest import TestCase
File "/anaconda/lib/python3.6/unittest/__init__.py", line 64, in <module>
from .main import TestProgram, main
File "/anaconda/lib/python3.6/unittest/main.py", line 4, in <module>
import argparse
File "/SAT/argparse.py", line 1
if len(sys.argv) > 1:
^
SyntaxError: invalid syntax
I've really now idea what is causing this error other than it's occurring when the program tries to import pandas_datareader.
I am new to the data_reader but I'm pretty sure the import command is syntactically correct.
Can anyone suggest what the problem is?
I think you have shadowed Python module argparse with your own /SAT/argparse.py.
/anaconda/lib/python3.6/unittest/main.py in line 4 tries to import argparse (the standard Python module), but your module (which has an error len(sys.argv) > 1:) jumps in first.
Try to rename /SAT/argparse.py to /SAT/my_argparse.py
PS try to name your own scripts and directories differently so that they don't shadow stardard Python modules
Try this:
import datetime
import pandas_datareader.data as web
amzn = web.DataReader("AMZN", "yahoo", datetime.datetime(2000,1,1), datetime.datetime(2015,1,1))

Pandas import error with python 2.7

I'm creating a very simple Python program which imports ExxonMobil's stock price between two data from Google Finance.
Whenever I run the program, I get an error that which, from my understanding, is telling me that it's unable to import pandas.
Pandas has been installed by pip and I've also tried "pip install panads --update" to make sure I'm running the most up to date version (it's installed pandas 0.21.0). Same with pandas-datareader but still no luck. What I'd expect to see is that it prints out the first 5 rows of data.
I'm running Python 2.7 and it's in a virtualenv.
Thanks for any help in advance and the code is below:
import datetime
import pandas
from pandas_datareader import data
start = datetime.datetime(2010, 1, 1)
end = datetime.datetime(2015, 8, 22)
df = data.DataReader("XOM", "google", start, end)
print df.head()
Error output:
/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7 /Users/lcc/virtualenv/matplotlib/pandas.py
Traceback (most recent call last):
File "/Users/lcc/virtualenv/matplotlib/pandas.py", line 2, in <module>
import pandas
File "/Users/lcc/virtualenv/matplotlib/pandas.py", line 3, in <module>
from pandas_datareader import data
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas_datareader/__init__.py", line 3, in <module>
from .data import (get_components_yahoo, get_data_famafrench, get_data_google, get_data_yahoo, get_data_enigma, # noqa
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas_datareader/data.py", line 7, in <module>
from pandas_datareader.google.daily import GoogleDailyReader
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas_datareader/google/daily.py", line 1, in <module>
from pandas_datareader.base import _DailyBaseReader
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas_datareader/base.py", line 7, in <module>
import pandas.compat as compat
ImportError: No module named compat
Process finished with exit code 1
Check what is written in the error traceback:
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas_datareader/base.py", line 7, in <module>
import pandas.compat as compat
pandas_datareader/base.py calls (imports) pandas.compat
you named your script pandas.py - that has shadowed the Pandas module and your script doesn't contain compat.
Solution:
Rename /Users/lcc/virtualenv/matplotlib/pandas.py to something that does NOT duplicate/shadow any of Python module names.
For example: /Users/lcc/virtualenv/matplotlib/my_first_pandas_prog.py

Mac system generate error message when I call python script on terminal

My code is simply the follow and work few days ago:
import pandas as pd
df = pd.read_csv('WORLDBANK-ZAF_MYS_PROP_4044_SEC_MF.csv')
print(df.head())
But now whenever I try to run it by calling python my_io.py on my Mac terminal it generates the following messages:
Bases-MacBook-Pro:data_analysis me$ python my_io.py
Traceback (most recent call last):
File "my_io.py", line 1, in
import pandas as pd
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pandas/init.py", line 13, in
import(dependency)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/init.py", line 142, in
from . import add_newdocs
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/add_newdocs.py", line 13, in
from numpy.lib import add_newdoc
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/init.py", line 8, in
from .type_check import *
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/lib/type_check.py", line 11, in
import numpy.core.numeric as _nx
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/core/init.py", line 72, in
from numpy.testing.nosetester import _numpy_tester
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/testing/init.py", line 12, in
from . import decorators as dec
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/testing/decorators.py", line 20, in
from .utils import SkipTest, assert_warns
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/numpy/testing/utils.py", line 15, in
from tempfile import mkdtemp, mkstemp
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 32, in
import io as _io
File "/Users/gongzhuli/Desktop/data_analysis/io.py", line 3, in
AttributeError: 'module' object has no attribute 'read_csv'
Can someone please help me, I have no idea what is going on here..
Your file is called io.py, which is a library module to handle file-like buffers among other things.
pandas imports tempfile which needs it:
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tempfile.py", line 32, in <module>
import io as _io
and your filename gets in the way of the import chain and prevents import from going through.
Just rename your file with something more specific (like my_io.py for instance?)

Categories

Resources