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)
這是串列的輸出:
[Int64Index([88], dtype='int64'), Int64Index([151], dtype='int64'), Int64Index([212], dtype='int64'), Int64Index([276], dtype='int64'), Int64Index([], dtype='int64')]
uj5u.com熱心網友回復:
使用extend替代append:
index_earning_value.extend(df_stock.index[df_stock['timestamp']==str(y)].tolist())
另一種方法是使用串列理解與展平:
index_earning_value = [y for y in actual_date_name
for y in df_stock.index[df_stock['timestamp']==str(y)]]
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/347959.html
上一篇:如何計算多列中的名義資料
下一篇:將一列轉換為行和列
