Upgrade from Eikon -> Workspace. Learn about programming differences.

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

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
1 0 0 1

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-apipythonrefinitiv-dataplatform-eikonworkspaceworkspace-data-api
icon clock
10 |1500

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

@alberto.spagnoli

Hi,

Thank you for your participation in the forum.

Is the reply below satisfactory in answering your question?

If yes please click the 'Accept' text next to the reply. This will guide all community members who have a similar question. Otherwise please post again offering further insight into your question.


Thanks,

AHS

Please be informed that a reply has been verified as correct in answering the question, and has been marked as such.

Thanks,


AHS

1 Answer

· Write an Answer
Upvotes
Accepted
39.4k 77 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 512.0 KiB each and 1.0 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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