0
av_link = 'https://www.alphavantage.co/query?function=TIME_SERIES_DAILY&symbol=' + 
ticker + '&outputsize=full&apikey=test&datatype=csv'

df_stock = pd.read_csv(av_link)

print(df_stock)
index_earning_value = []
print(actual_date_name)
for y in actual_date_name:
    index_earning_value.append(df_stock.index[df_stock['timestamp']==str(y)])

print(index_earning_value)

This is the ouput of the list:

[Int64Index([88], dtype='int64'), Int64Index([151], dtype='int64'), Int64Index([212], dtype='int64'), Int64Index([276], dtype='int64'), Int64Index([], dtype='int64')]
buran
  • 13,682
  • 10
  • 36
  • 61
aryan
  • 21
  • 6

1 Answers1

0

Use extend instead append:

index_earning_value.extend(df_stock.index[df_stock['timestamp']==str(y)].tolist())

Alternative is use list comprehension with flattening:

index_earning_value = [y for y in actual_date_name 
                         for y in df_stock.index[df_stock['timestamp']==str(y)]]
jezrael
  • 822,522
  • 95
  • 1,334
  • 1,252
  • Thank you, why does append not work? – aryan Nov 04 '21 at 06:48
  • 1
    @aryan - because append add list to end, check [this](https://stackoverflow.com/questions/252703/what-is-the-difference-between-pythons-list-methods-append-and-extend) – jezrael Nov 04 '21 at 06:50