Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Income Statement, Balance Sheet and Cashflows are coming up as an empty dataframe #191

Closed
karthikbhamidipati opened this issue Feb 1, 2020 · 19 comments

Comments

@karthikbhamidipati
Copy link

Income Statement, Balance Sheet and Cashflows are coming up as an empty data frame.
This is because variable url in base.py is being updated to

/quote//holders in line 283
and when fetching the financials in line 354 of base.py the url being used is /quote//holders/financials and it should be /quote//financials

@masueror
Copy link

masueror commented Feb 6, 2020

I also have the same problem, when i ask for financials I recibe:
Empty DataFrame
Columns: [Open, High, Low, Close, Adj Close, Volume]
Index: []
How can I fix it?

@TimBstn
Copy link

TimBstn commented Feb 11, 2020

Hey, I just had the same problem.
The problem is as vamshikarthik described it: Just change the following in the base.py:

url = "{}/{}".format(self._scrape_url, self.ticker)
holders = _pd.read_html(url+'\holders')

The problem is in line 283.

Thanks vamshikarthik for the tip.

Tim

@masueror
Copy link

Thank you very much, problem just solve

@ghost
Copy link

ghost commented Feb 18, 2020

It did not work for me I'm sorry. This applies for balance_sheet, cashflow, earnings, financials etc.

---------------------------------------------------------------------------
HTTPError                                 Traceback (most recent call last)
<ipython-input-8-3cf019396317> in <module>
----> 1 amzn.balance_sheet

~/anaconda3/envs/stok/lib/python3.7/site-packages/yfinance/ticker.py in balance_sheet(self)
    164     @property
    165     def balance_sheet(self):
--> 166         return self.get_balancesheet()
    167 
    168     @property

~/anaconda3/envs/stok/lib/python3.7/site-packages/yfinance/base.py in get_balancesheet(self, proxy, as_dict, freq)
    441 
    442     def get_balancesheet(self, proxy=None, as_dict=False, freq="yearly"):
--> 443         self._get_fundamentals(proxy)
    444         data = self._balancesheet[freq]
    445         if as_dict:

~/anaconda3/envs/stok/lib/python3.7/site-packages/yfinance/base.py in _get_fundamentals(self, kind, proxy)
    282         # holders
    283         url = "{}/{}/holders".format(self._scrape_url, self.ticker)
--> 284         holders = _pd.read_html(url+'\holders')
    285         self._major_holders = holders[0]
    286         self._institutional_holders = holders[1]

~/anaconda3/envs/stok/lib/python3.7/site-packages/pandas/io/html.py in read_html(io, match, flavor, header, index_col, skiprows, attrs, parse_dates, thousands, encoding, decimal, converters, na_values, keep_default_na, displayed_only)
   1103         na_values=na_values,
   1104         keep_default_na=keep_default_na,
-> 1105         displayed_only=displayed_only,
   1106     )

~/anaconda3/envs/stok/lib/python3.7/site-packages/pandas/io/html.py in _parse(flavor, io, match, attrs, encoding, displayed_only, **kwargs)
    910             break
    911     else:
--> 912         raise_with_traceback(retained)
    913 
    914     ret = []

~/anaconda3/envs/stok/lib/python3.7/site-packages/pandas/compat/__init__.py in raise_with_traceback(exc, traceback)
     45     if traceback == Ellipsis:
     46         _, _, traceback = sys.exc_info()
---> 47     raise exc.with_traceback(traceback)
     48 
     49 

HTTPError: HTTP Error 404: Not Found

Any other ideas?

Thanks in advance

@mariusgarbowski
Copy link

mariusgarbowski commented Feb 20, 2020

I had the same problem, which source was mentioned above. Fixing the problem as stated above resulted in the error quoted by @kalinkirev .

I resolved it by:

Line 283 (commenting out the url, because the raw url was already defined in line 279) and adding "/holders" to the url+...:
#url = "{}/{}/holders".format(self._scrape_url, self.ticker)
holders = _pd.read_html(url+'/holders')

and adding "/financials" in Line 354:

data = utils.get_json(url+'/financials', proxy)

Restart the kernel and it should work.

@VaseSimion
Copy link

I had the same problem, which source was mentioned above. Fixing the problem as stated above resulted in the error quoted by @kalinkirev .

I resolved it by:

Line 283 (commenting out the url, because the raw url was already defined in line 279) and adding "/holders" to the url+...:
#url = "{}/{}/holders".format(self._scrape_url, self.ticker)
holders = _pd.read_html(url+'/holders')

and adding "/financials" in Line 354:

data = utils.get_json(url+'/financials', proxy)

Restart the kernel and it should work.

Thanks, I did this and it fixed my issue

@chaitanya9186
Copy link

As described #111 it is working fine at version 0.1.48.

@anbento0490
Copy link

Hi @mariusgarbowski

I tried to apply the fixes you suggested at line 283 and 354 and re-run the base.py code after restarting the kernel but it seems that I cannot use any of the get functions. I am not an expert Python user so I am very likely doing something naive here. Could you kindly provide a step by step guide for the full process or and example of how to use the functions after the lines have been edited?

Thanks in advance for your help :)

mjferstl added a commit to mjferstl/StockAnalyzer that referenced this issue Mar 22, 2020
accoring to issue 191 of yfinance
ranaroussi/yfinance#191
@mikaelhug
Copy link

mikaelhug commented Mar 24, 2020

Hey, I just had the same problem.
The problem is as vamshikarthik described it: Just change the following in the base.py:

url = "{}/{}".format(self._scrape_url, self.ticker)
holders = _pd.read_html(url+'\holders')

The problem is in line 283.

Thanks vamshikarthik for the tip.

Tim

I get: IndexError: list index out of range, with those fixes. Try for example:
SHB_B = yf.Ticker("SHB-B.ST")
SHB_B.earnings

I added to "solve" the problem, i dont know if this will destroy other function but earnings work and are correct (i controlled with some morningstar pdfs).

url = "{}/{}".format(self._scrape_url, self.ticker)
holders = _pd.read_html(url+'\holders')
self._major_holders = holders[0]
f len(holders) > 1:
    self._institutional_holders = holders[1]
else:
    self._institutional_holders = ""

@FTorres09
Copy link

Hi guys, I'm rather new to Python which is why I don't quite get the methodology of your edits.
I installed yfinance for Anaconda which is the place I need it for. Unfortunately, when I install it at Anaconda, the financials part also doesn't work on my Mac. Which is the reason why I'd like to ask y'all what to do in order to solve that problem.
I haven't downloaded yfinance on my computer, only got it from the base (root) Anaconda environment.

@aniketnaikdesai
Copy link

Copied from @anbento0490

I am going to explain in depth the method I used to fix it for less advanced git_hub/python users:

First of all, fork yfinance repository in your account. In this way you will be allowed to modify the code as you wish,
In your account, in the forked repository, open base.py file and fix lines 283 and 284:
283 url = "{}/{}".format(self._scrape_url, self.ticker) 284 holders = _pd.read_html(url+'/holders')
Commit the changes
If you had yfinance installed, uninstall the original version
Finally, pip install the package directly from your gitub account with the following command:

pip install git+https://github.com/username/yfinance.git

After you do that, the methods that were failing will work as expected!

JugglingNumbers added a commit to JugglingNumbers/yfinance that referenced this issue Apr 3, 2020
fix for 
Income Statement, Balance Sheet and Cashflows are coming up as an empty dataframe
ranaroussi#191
@FTorres09
Copy link

Thank you so much @aniketnaikdesai! For the terminal it worked perfectly. Is there also a solution available for Anaconda (Navigator)? It's not impossible to install it there with
conda install git+https://github.com/username/yfinance.git
I would try to work out some yfinance calcs there.
Thanks a great lot in advance for your help!

@aniketnaikdesai
Copy link

I don't think you can conda install from github.

@phsamuel
Copy link

Some symbols work but many symbols still don't work after the fix @aniketnaikdesai.
For example, I can access the symbol AB in yahoo finance. But I can't access the balance sheet with yfinance. It returns an index out of range error.

image

@aniketnaikdesai
Copy link

I am able to pull the balance sheet information for AB. I have my code patched for many changes.

You can also fix your code.

The index error is due to missing institutional holders information.
Look for the fix in issue #229 or #159
but there seems to be a _get_fundamentals error also. Look at issue #174

@phsamuel
Copy link

@aniketnaikdesai Thanks much. It is very helpful!

larroy pushed a commit to larroy/yfinance that referenced this issue May 16, 2020
and Cashflows are coming up as an empty dataframe

ranaroussi#191
coolsurf added a commit to coolsurf/yfinance that referenced this issue Jun 13, 2020
@DataThomas
Copy link

DataThomas commented Jun 23, 2020

As described #111 it is working fine at version 0.1.48.

I am using version 0.1.54 and still have the issues described above. BUT the fixes described by @mariusgarbowski worked fanstastically!! Thank you!

andrewdevilliers added a commit to andrewdevilliers/yfinance that referenced this issue Jun 28, 2020
ranaroussi#191

To solve empty statement returns
PatrickBateman92 added a commit to PatrickBateman92/yfinance that referenced this issue Jul 28, 2020
283 & 284 changed according to ranaroussi#191
@martinemilander
Copy link

pip install git+https://github.com/username/yfinance.git isn't working for me, for some reason. I get the following error:

ERROR: Command errored out with exit status 1: git clone -q https://github.com/martinemilander/yfinance.git /private/var/folders/3c/nkrc6kr94p54njs4j7333wq80000gn/T/pip-req-build-3yued3xj Check the logs for full command output.

It then prompts me to install command line tools for developers (something to do with Xcode) but then the installation fails.

@waterproofpatch
Copy link

waterproofpatch commented Jan 30, 2021

I recently started using this library and ran into the issue described by @karthikbhamidipati. The change I made in base.py was to change line 376 to remove the superflous '/holders' URI component, such that the resultant URL suffixes with //financials, rather than //holders/financials.

I can now use .financials, .balance_sheet and .earnings for the Ticker object, for at least the one stock Ticker I've tested with.

Attached is the diff for my change.

patch.txt

diff --git a/yfinance/base.py b/yfinance/base.py
index c4c9e3e..368a0b6 100644
--- a/yfinance/base.py
+++ b/yfinance/base.py
@@ -373,7 +373,8 @@ class TickerBase():
             pass

         # get fundamentals
-        data = utils.get_json(ticker_url+'/financials', proxy)
+        url = "{}/{}/financials".format(self._scrape_url, self.ticker)
+        data = utils.get_json(url, proxy)

         # generic patterns
         for key in (

Hope this helps someone else.

Looks like the official release on pypy is dated to Oct 5 - I would imagine these fixes (submitted by others as PRs) would make the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests