For a deeper look into our Eikon Data API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
1 0 0 0

Getting nan when iterating eikon.get_data

This is the function and iteration:

(Tickers.xlsx is a list with 450 RICs)

However when I do this, it works:

When I try to put it in a loop, it doesn't want to work. I need to do the above for 457 RICs, really wouldn't want to do it manually one by one. Sorry if the question may be dumb, I am a beginner! Thank you in advance for the responses.

eikoneikon-data-apiworkspaceworkspace-data-apirefinitiv-dataplatform-eikonpython
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

1 Answer

Upvotes
Accepted
39.2k 75 11 27

I think the easiest way to get what you want is to retrieve all the fields for all the stocks in one call:

rics = ['SINCH.ST','INVEb.ST','ADDTb.ST','AAK.ST']
ek.get_data(rics,
            ['TR.CompanyName','TR.HeadquartersCountry','TR.ICBIndustry',
             'TR.ICBSuperSector','TR.ICBSubSector','TR.TotalAssets',
             'TR.TotalLiabilities','TR.CompanyMarketCap'],
            {'CURN':'EUR'})

But if for whatever reason you need to retrieve the data in a loop (one or several stocks at a time), then you need to correctly concatenate the results, which is where the problem is in your code. E.g.

def get_main_data(ric):
    df, err = ek.get_data(ric,
                          ['TR.CompanyName','TR.HeadquartersCountry',
                           'TR.ICBIndustry','TR.ICBSuperSector',
                           'TR.ICBSubSector','TR.TotalAssets',
                           'TR.TotalLiabilities','TR.CompanyMarketCap'],
                         {'CURN':'EUR'})
    df.set_index('Instrument', inplace=True)
    return df

df = pd.DataFrame()
for ric in ['SINCH.ST','INVEb.ST','ADDTb.ST','AAK.ST']:
    df = df.append(get_main_data(ric))
df

Finally, if you'd like the resulting dataframe to have field names as rows and stock RICs as columns, use pandas transpose method:

df.transpose()
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Click below to post an Idea Post Idea