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!
Related
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.
Hello I'm trying to read an excel file 'myFile.xlsx' using datatable.fread (version 1.0.0) function to speedup data manipulation.
The problem is I had an AttributeError: module 'xlrd' has no attribute 'xlsx'.
The command I used is:
import datatable as dt
DT = dt.fread("myFile.xlsx")
I checked the module where the error occurred is the module xls of datatable package:
def read_xls_workbook(filename, subpath):
try:
import xlrd
# Fixes the warning
# "PendingDeprecationWarning: This method will be removed in future
# versions. Use 'tree.iter()' or 'list(tree.iter())' instead."
xlrd.xlsx.ensure_elementtree_imported(False, None) # Here
xlrd.xlsx.Element_has_iter = True # and Here
Is there any solution to fix this issue? please.
The issue is that datatable package is not updated yet to make use of xldr>1.2.0, so in order to make it work you have to install xldr = 1.2.0
pip install xldr==1.2.0
I hope it helped.
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
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
I get this problem when i try to read file:
import numpy as np
import pandas as pd
pos = pd.read_excel('pos.xls', header=None)
and the error is like this:
Traceback (most recent call last):
File "one-hot.py", line 4, in <module>
pos = pd.read_excel('pos.xls', header=None)
TypeError: read_excel() takes exactly 2 arguments (1 given)
but to my surprise,when i run the code in my own pc by pycharm,it will not be an error.i get the problem only when i use my school's ubuntu(not use pycharm).
my own python is python 2.7.12,and python on school's ubuntu is python 2.7.6
My best guess (I can't try it on Python 2.7.6 since I don't have it) is that You use pandas version 0.13 or bellow. According to docs, You must also provide sheetname, which, in later version, has default value of 0.
pandas.io.excel.read_excel(io, sheetname, **kwds)
This sounds like an issue with a different version of the pandas library installed. Looking back at the older documentation pages for pandas library, it seems that pandas did in fact require 2 parameters back in version 0.13.0 (and potentially other old versions, but I did not check any others). For version 0.13.0, the docs define the function as:
pandas.read_excel(io, sheetname, **kwds)
You can read those details here: http://pandas.pydata.org/pandas-docs/version/0.13.0/generated/pandas.read_excel.html?highlight=read_excel#pandas.read_excel
Chances are, it is just an issue with a different library version.
I actually had a similar problem which was solved by adding '.xlsx' to the end of my proposed file name:
practicetoexcel.to_excel('Thisxldoc.xlsx', sheet_name = 'Practice')