Python Forum
Yahoo_fin question: how does one export all stock tickers to a csv file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Yahoo_fin question: how does one export all stock tickers to a csv file
#1
I noticed that the yahoo_fin script below from DustinKlent returns an error if a stock ticker is in the stock_list that is not in the yahoo_fin stock_info. To avoid error messages I would like to compare the list of stocks in yahoo_fin stock_info with my stock list in Excel before I run the below script. To be able to do this I need to export to csv all stock tickers in the yahoo_fin stock_info. Is that possible with Yahoo_fin? If yes, how? Please post the script.

import pandas as pd
from yahoo_fin import stock_info as si
import glob
  
stock_list = "ABEO", "ABUS"
 
stats = {}
  
for ticker in stock_list:
  data2 = si.get_stats(ticker)
  data2 = data2.iloc[:,:2]
  data2.columns = ["Attribute", "Recent"]
  stats[ticker] = data2
  
combined2 = pd.concat(stats)
combined2 = combined2.reset_index()
del combined2["level_1"]
combined2.columns = ["Ticker", "Attribute", "Recent"]
  
df = pd.DataFrame(combined2)
df2 = df.drop_duplicates(subset=None, keep="first", inplace=False)
df2.to_csv(r'stats.csv')
Reply


Messages In This Thread
Yahoo_fin question: how does one export all stock tickers to a csv file - by detlefschmitt - Feb-11-2021, 11:24 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Exporting Stock Fundamental Data to a CSV file with yahoo_fin DustinKlent 2 4,767 Aug-01-2022, 06:08 PM
Last Post: paulyan
  How to keep columns header on excel without change after export data to excel file? ahmedbarbary 0 1,194 May-03-2022, 05:46 PM
Last Post: ahmedbarbary
  Yahoo_fin, Pandas: how to convert data table structure in csv file detlefschmitt 14 7,874 Feb-15-2021, 12:58 PM
Last Post: detlefschmitt
  Skeleton file export error Python Code pepapoha 4 3,560 Nov-17-2020, 02:06 AM
Last Post: pepapoha
  Python Export Question Below samlee916 1 1,590 Jul-07-2020, 12:22 PM
Last Post: Larz60+
  export file and display cmd prompt same time jacklee26 1 2,058 Jul-24-2019, 05:15 AM
Last Post: Larz60+
  [PYTHON EXPORT SQL TO .txt file] PYTHONDUDE 9 24,395 Feb-21-2018, 08:54 PM
Last Post: nilamo
  Need help to open PDF file and Export to text file ratna_ain 3 7,092 Oct-10-2017, 01:44 AM
Last Post: ratna_ain

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020