Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Is there a way to extract the specific integer value and add it to a list from python, so in this case 88, 151, 212 and 276?

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')]

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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)]]
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading