From 09fed2b6eb49092e3e2234a3b7483c1d38193016 Mon Sep 17 00:00:00 2001 From: jayantverma2809 Date: Mon, 29 Jan 2024 01:46:42 +0530 Subject: [PATCH 1/3] update get_quote_table function --- yahoo_fin/stock_info.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/yahoo_fin/stock_info.py b/yahoo_fin/stock_info.py index f75e9b0..9004903 100644 --- a/yahoo_fin/stock_info.py +++ b/yahoo_fin/stock_info.py @@ -13,6 +13,7 @@ from Crypto.Util.Padding import unpad # For pretty print from pprint import pp +from io import StringIO try: @@ -287,7 +288,7 @@ def tickers_ftse250(include_company_data = False): return sorted(table.Ticker.tolist()) - + def get_quote_table(ticker , dict_result = True, headers = {'User-agent': 'Mozilla/5.0'}): @@ -300,17 +301,16 @@ def get_quote_table(ticker , dict_result = True, headers = {'User-agent': 'Mozil site = "https://finance.yahoo.com/quote/" + ticker + "?p=" + ticker - tables = pd.read_html(requests.get(site, headers=headers).text) - - data = pd.concat([tables[0], tables[1]]) - + tables = pd.read_html(StringIO(requests.get(site, headers=headers).text)) + + data = pd.concat([tables[0], tables[1]], axis=0) data.columns = ["attribute" , "value"] quote_price = pd.DataFrame(["Quote Price", get_live_price(ticker)]).transpose() quote_price.columns = data.columns.copy() - data = pd.concat([data, quote_price]) + data = pd.concat([data, quote_price], axis=0) data = data.sort_values("attribute") From 18d260a131d1730d494a3a69672d763771c1d223 Mon Sep 17 00:00:00 2001 From: jayantverma2809 Date: Mon, 29 Jan 2024 01:47:51 +0530 Subject: [PATCH 2/3] Update get_stats function --- yahoo_fin/stock_info.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/yahoo_fin/stock_info.py b/yahoo_fin/stock_info.py index 9004903..1f565cf 100644 --- a/yahoo_fin/stock_info.py +++ b/yahoo_fin/stock_info.py @@ -338,13 +338,13 @@ def get_stats(ticker, headers = {'User-agent': 'Mozilla/5.0'}): "/key-statistics?p=" + ticker - tables = pd.read_html(requests.get(stats_site, headers=headers).text) + tables = pd.read_html(StringIO(requests.get(stats_site, headers=headers).text)) tables = [table for table in tables[1:] if table.shape[1] == 2] - - table = tables[0] - for elt in tables[1:]: - table = pd.concat([table, elt]) + table = pd.concat(tables, ignore_index=True) + # table = tables[0] + # for elt in tables[1:]: + # table = table.append(elt) table.columns = ["Attribute" , "Value"] From 018e8d98ef8c1966e2e14f32f83884770fe3d4e8 Mon Sep 17 00:00:00 2001 From: jayantverma2809 Date: Mon, 29 Jan 2024 01:49:15 +0530 Subject: [PATCH 3/3] update get_stats_valuation function --- yahoo_fin/stock_info.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/yahoo_fin/stock_info.py b/yahoo_fin/stock_info.py index 1f565cf..d98d169 100644 --- a/yahoo_fin/stock_info.py +++ b/yahoo_fin/stock_info.py @@ -365,7 +365,7 @@ def get_stats_valuation(ticker, headers = {'User-agent': 'Mozilla/5.0'}): "/key-statistics?p=" + ticker - tables = pd.read_html(requests.get(stats_site, headers=headers).text) + tables = pd.read_html(StringIO(requests.get(stats_site, headers=headers).text)) tables = [table for table in tables if "Trailing P/E" in table.iloc[:,0].tolist()]