I am trying to put together a pandas dataframe for a school project with but to do so I am hitting an api repeatedly. I can't figure out excatly why I am returning the same dataframe over and over, sans the column title, any help much appreciated.
Code is as follows:
a.py
import json
import requests
import pandas as pd
import numpy as np
from bs4 import BeautifulSoup
tmp = []
tmp_1 = []
def fetchdata(ticker):
url = 'https://api.iextrading.com/1.0/stock/'
time = '/chart/5y'
get = url + ticker + time
data = requests.get(get).json()
length = len(data)
# i = i + 1
for j in range(0, length):
date = data[j]['date']
closing = data[j]['close']
x = tmp.append(date)
y = tmp_1.append(closing)
df = pd.DataFrame(x)
df[ticker] = tmp_1
df_1 = df.loc[1:1000]
return df_1
b.py
import pandas as pd
import numpy as np
from slizzy import fetchdata
df_appl_1 = fetchdata('aapl')
df_appl_2 = fetchdata('aapl')
df_appl_3 = fetchdata('aapl')
df_gold = fetchdata('gld')
print df_appl_1
print df_gold