7

I found library that allows me to get data from yahoo finance very efficiently. It's a wonderful library.

The problem is, I can't save the data into a csv file.

I've tried converting the data to a Panda Dataframe but I think I'm doing it incorrectly and I'm getting a bunch of 'NaN's.

I tried using Numpy to save directly into a csv file and that's not working either.

import yfinance as yf
import csv
import numpy as np

urls=[
'voo',
'msft'
    ]

for url in urls:
    tickerTag = yf.Ticker(url)

    print(tickerTag.actions)
    np.savetxt('DivGrabberTest.csv', tickerTag.actions, delimiter = '|')

I can print the data on console and it's fine. Please help me save it into a csv. Thank you!

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
Peter
  • 91
  • 1
  • 5
  • Does this answer your question? [How to read in the multi-index columns from csv and return the yfinance dataframe to the correct form?](https://stackoverflow.com/questions/63107594/how-to-read-in-the-multi-index-columns-from-csv-and-return-the-yfinance-datafram) – Trenton McKinney Aug 03 '20 at 23:28

1 Answers1

5

If you want to store the ticker results for each url in different csv files you can do:

for url in urls:
    tickerTag = yf.Ticker(url)
    tickerTag.actions.to_csv("tickertag{}.csv".format(url))

if you want them all to be in the same csv file you can do

import pandas as pd
tickerlist = [yf.Ticker.url for url in urls]
pd.concat(tickerlist).to_csv("tickersconcat.csv")
Juan Carlos Ramirez
  • 2,054
  • 1
  • 7
  • 22
  • If you found the answer useful, please consider upvoting and accepting the answer (to accept answer, click on check mark symbol). – Juan Carlos Ramirez Jun 27 '19 at 00:25
  • I tried. It says I have less than 15 reputations but won't post publicly until I reached 15 reputations. Thank you though. – Peter Jun 27 '19 at 22:02