Click here to Skip to main content
14,921,143 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I'm trying to pull multiple stocks information from alpha vantage and then put just one column of each stock into an excel sheet.

I put the list of tickers I want pulled in a .txt file

The problem I am having is getting the columns to save in a new column in excel rather than just below the data in the first column.

I am trying to get the '1. open' Column from each ticker saved over into one excel sheet, each ticker in it's own column.

What I have tried:

import pandas as pd
import matplotlib.pyplot as plt
from alpha_vantage.timeseries import TimeSeries
from alpha_vantage.techindicators import TechIndicators


sbs = []
newsbs = []
df1 = pd.DataFrame()

# Get tickers from file
file = open("test1.txt", "r")
for x in file:
    sbs.append(x)
    print(sbs)
    
#Remove spaces from ticker symbols
for y in sbs:
    newsbs.append(y.strip())

    
#print(newsbs)
for s in newsbs:
    print(s)
    API_key = 'HX.........VJ2'
    ts = TimeSeries(key= API_key, output_format='pandas')
    data_ts, meta_data_ts = ts.get_daily_adjusted(symbol=s)
    open_list = data_ts['1. open'].to_list()
    #df1 = data_ts
    #print(df1)
    df1[s] = open_list
    print(df1)
    #df2 = df1
    #print(df2)
    df1.to_csv(r'C:\Users\....\out.csv', index = False, header=True, mode ='a')
Posted
Updated 27-Mar-21 6:26am
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900