I am trying to append many data frames into one empty data frame but It is not working. For this, I am using this tutorial my code is like this:
I am generating a frame inside a loop for that my code is:
def loop_single_symbol(p1):
i = 0
delayedPrice = []
symbol = []
while i<5 :
print(p1)
h = get_symbol_data(p1)
delayedPrice.append(h['delayedPrice'])
symbol.append(h['symbol'])
i+=1
df = pd.DataFrame([], columns = [])
df["delayedPrice"] = delayedPrice
df["symbol"] = symbol
df["time"] = get_nyc_time()
return df
time.sleep(4)
This code is generating a frame like this:
delayedPrice symbol time
0 30.5 BAC 6:6
1 30.5 BAC 6:6
2 30.5 BAC 6:6
3 30.5 BAC 6:6
4 30.5 BAC 6:6
And I am running a loop like this:
length = len(symbol_list())
data = ["BAC","AAPL"]
df = pd.DataFrame([], columns = [])
for j in range(length):
u = data[j]
if h:
df_of_single_symbol = loop_single_symbol(u)
print(df_of_single_symbol)
df.append(df_of_single_symbol, ignore_index = True)
print(df)
I am trying to append two or more data frame into one empty data frame but using the above code I am getting:
Empty DataFrame
Columns: []
Index: []
And I want a result like this:
delayedPrice symbol time
0 30.5 BAC 6:6
1 30.5 BAC 6:6
2 30.5 BAC 6:6
3 30.5 BAC 6:6
4 30.5 BAC 6:6
0 209.15 AAPL 6:6
1 209.15 AAPL 6:6
2 209.15 AAPL 6:6
3 209.15 AAPL 6:6
4 209.15 AAPL 6:6
How can I do this using panda and what is the best possible way to do this.
Note: Here this line
h = get_symbol_data(p1)
Is fetching some data from API