1

I have a list of ticker values

ticker = ["AAPL","MSFT","GOOG"]

and I want to create a DF with "high" values of prices for all the stocks in the ticker list.

Creating an empty DF:

high_df = pd.DataFrame(columns = ticker) 

Filling the DF:

import pandas_datareader as web
import datetime

start = datetime.datetime(2010,1,1)
end = datetime.datetime(2010,2,1)

for each_column in high_df.columns:
   high_df[each_column] = web.DataReader(each_column, "yahoo",start,end)["High"]

This works but takes a long time if the ticker list is huge. Any other suggestions for approaches to speed up? Speed up with the way the DF is filled.

data_person
  • 3,024
  • 7
  • 28
  • 52

1 Answers1

0

Seems like just need parallel computing.

from joblib import Parallel, delayed

def yourfunc(tic):
    start = datetime.datetime(2010, 1, 1)
    end = datetime.datetime(2010, 2, 1)
    result=web.DataReader(tic, "yahoo", start, end)["High"]
    return result

results = Parallel(n_jobs=-1, verbose=verbosity_level, backend="threading")(
             map(delayed(yourfunc), ticker ))

About the conversion , you can using pd.DataFrame(results,columns=ticker)

BENY
  • 258,262
  • 17
  • 121
  • 165