Error in data.py module "cannot import name 'wb'" - python

Pandas has worked fine for me for years. All of a sudden, today, I am getting this error:
File "C:\Users\Excel\Anaconda3\lib\site-packages\dautil\data.py", line 3, in <module>
from pandas.io import wb
ImportError: cannot import name 'wb'
It seems like the error is coming form data.py. Here is a screen shot.
This seemed to happen all of a sudden, and the error is triggered when I run a few different processes that call this process. I uninstalled and re-installed pandas. I am still getting the same error.

The documentation says
Starting in 0.19.0, pandas no longer supports pandas.io.data or
pandas.io.wb, so you must replace your imports from pandas.io with
those from pandas_datareader:
So, as per documentation, you should be doing this:
from pandas.io import data, wb # becomes
from pandas_datareader import data, wb

Even with pandas_datareader, the same error may happen, if this your case, then you have two solutions
for Pandas >=0.23 make sure that your pandas_datareader is > = 0.7, if for some reason you don't want to upgrade pandas_datareader to 0.7, or downgrading the pandas_datareader, then alternavly, you can do:
import pandas as pd
pd.core.common.is_list_like = pd.api.types.is_list_like
import pandas_datareader as web

Related

I am unable to import csv file in python

I am facing an issue regarding in python , when I import the csv file in python it is showing the data in VSCode. means file is running and successfully imported but when I want to create a report of same csv file by using from pandas_profiling import ProfileReport it shows me an error code and error mentioned:
import pandas as pd
from pandas_profiling import ProfileReport
df = pd.read_csv('housing.csv')
print(df)
profile = ProfileReport(df)
profile.to_file(output_file ="housing.html")
enter image description here
I want to generate **Pandas Profiling Report **
From the error i can guess you have some environment issues. The code you have written is errorless. Run your code in colab and you should see the results.

line() got an unexpected keyword argument 'reuse_plot'. Not sure what this means

I am following a tutorial online to use Python to determine financial returns. I am getting an error "TypeError: line() got an unexpected keyword argument 'reuse_plot'" when I am following the video content. I am very new to Python and I really do not understand why.
Here is the total code:
import datetime as dt
import pandas as pd
import numpy as np
import pylab
import seaborn as sns
import scipy.stats as stats
from pandas_datareader import data as pdr
import plotly.offline as pyo
pyo.init_notebook_mode(connected=True)
pd.options.plotting.backend = 'plotly'
end = dt.datetime.now()
start = dt.datetime(2018,1,1)
df = pdr.get_data_yahoo('CBA.AX', start, end)
df.Close.plot()
This error occurs due to conflicts between pandas and plotly packages. I could solve it by upgrading the pandas to the latest version (I can confirm that for pandas==1.3.5 and plotly==5.7.0, the error is not generated anymore).

scikit-surprise: python cannot find module even though pip lists it as installed

I am trying to use the scikit-surprise module to build a recommender system however I am having an error in getting it to compile.
I am receiving the ImportError: Cannot import name "Reader" error
My class is as follows
import pandas as pd
from surprise import Reader, Dataset
userReviewsFilePath ="UserReviewsFirst5000WithHeadings.csv"
ratings = pd.read_csv(userReviewsFilePath) # reading data in pandas df
ratings_dict = {'recipeID': list(ratings.recipeID),
'rating': list(ratings.rating),
'userID': list(ratings.userID)}
df = pd.DataFrame(ratings_dict)
reader = Reader(rating_scale=(1, 5))
data = Dataset.load_from_df(df[['recipeID', 'rating', 'userID']], reader)
pip show says that version 1.0.6 is installed
I think your problem come from the installation... I installed "surprise" and past your code and it worked:
import pandas as pd
from surprise import Reader, Dataset
print(Reader) # or just print(surprise) if you import surprise
out:
<class 'surprise.reader.Reader'>
Start by re-install surprise and tell us.
If you have more than one version of python, do:
which pip
to see if you installed surprise on the used version of python
I think it's in surprise.reader: https://surprise.readthedocs.io/en/stable/reader.html
Your code should read:
from surprise.reader import Reader
from surprise.dataset import Dataset
Edit: I checked the instructions again which seem to contradict this, and give your original code as the correct example. https://surprise.readthedocs.io/en/stable/getting_started.html#getting-started
So maybe they add their own shortcuts? Either way, it seems like this isn't the correct solution, sorry. (Unless it works, in which case their instructions might be out of date.)
Edit 2: They do alias it, so "from surprise import Reader" should indeed have worked: https://github.com/NicolasHug/Surprise/blob/master/surprise/init.py#L19
I think you need to do
from surprise.reader import Reader

error No module named 'xlrd'. how to import excel with python and pandas properly? please close this

I realized that there may be something wrong in my local dev env just now.
I tried my code on colab.
it worked well.
import pandas as pd
df = pd.read_excel('hurun-2018-top50.xlsx')
thank u all.
please close this session.
------- following is original description ---------
I am trying to import excel with python and pandas.
I already pip installed "xlrd" module.
I googled a lot and tried several different methods, none of them worked.
Here is my code.
import pandas as pd
from pandas import ExcelFile
from pandas import ExcelWriter
df = pd.read_excel('hurun-2018-top50.xlsx', index_col=0)
df = pd.read_excel('hurun-2018-top50.xlsx', sheetname='Sheet1')
df = pd.read_excel('hurun-2018-top50.xlsx')
Any response will be appreciated.

python and fix_yahoo_finance library resulting in a ValueError

EDIT
> See my own answer below for how I got it to work.
I'm having an issue using the fix_yahoo_finance library (version 0.0.22).
Any help to point me in the right direction would be great.
My goal is to load stock data. Currently, fix_yahoo_finance returns a pandas dataframe which is quite useful for me.
Here is the code I'm using:
import datetime
import psycopg2
import fix_yahoo_finance as yf
import pandas as pd
start_dt = datetime.datetime(2004,12,30)
end_dt = datetime.datetime(2017,12,01)
symbol = 'MMM'
yf.pdr_override()
data = yf.download(symbol, start='2004-12-30', end='2017-12-01')
Here is the error
Traceback (most recent call last):
File "<ipython-input-38-d43dee1dd457>", line 1, in <module>
data = yf.download(symbol, start=start_dt, end=end_dt)
File "C:\Python27\Lib\site-packages\fix_yahoo_finance\__init__.py", line
194, in download
data = _pd.concat(_DFS.values(), axis=1, keys=_DFS.keys())
File "C:\Python27\Lib\site-packages\pandas\tools\merge.py", line 754, in
concat
copy=copy)
File "C:\Python27\Lib\site-packages\pandas\tools\merge.py", line 799, in
__init__
raise ValueError('All objects passed were None')
ValueError: All objects passed were None
#Yash Ghandhe 's answer unfortunately didn't work for me.
I did get it to work by installing Anaconda and running Spyder IDE from there. I installed the Python 3.6 version (I was using Python 2.7 previously).
I'm still not sure which libraries caused the issue, or if using Python 3 made the difference.
Reading the documentation on the fix-yahoo-finance library (link here: https://pypi.org/project/fix-yahoo-finance/) showed two conflicting pieces of info.
The first, is at the top under the Title. It shows Python 2.7, 3.4, 3.5, 3.6.
Further below under requirements, it mentions Python >= 3.4.
You can try using the pandas-datareader library like so:
from pandas_datareader import data as pdr
import fix_yahoo_finance as yf
yf.pdr_override()
data = pdr.get_data_yahoo("MMM", start="2004-12-30", end="2017-12-01")
You can check out this GitHub Repo for more details on parameters. Hope this helps!

Categories