Eikon API - how to handle "NA" values in Python

Hi, I have a large dataset of ISINs and am using the Eikon API in Python to retrieve some information on the issuer, maturity, etc. Here is a small example of the types of queries that I'm running:

df,err = ek.get_data(['DE000DFK0NP7', 'XS2317069685', 'XS2412141769'],['TR.UltimateParentId','TR.FIIssuerName','TR.CommonName'])

df

As you can see, my query returns the '<NA>' value for some of these attributes, for example the Ultimate Parent Id for ISIN code XS2412141769.

I cannot understand how to filter out this information. I don't want to filter it out from my initial query to Eikon, i.e. via a parameter in the ek.get_data() function. Rather, I just want to be able to filter out these missing values after the Eikon API returns the output. The standard checks in Python for identifying NaN values do not seem to work here.

For example,

import math
math.isnan(df.loc[df['Instrument']=='DE000DFK0NP7','Ultimate Parent Id'])
math.isnan(df.loc[df['Instrument']=='XS2412141769','Ultimate Parent Id'])

df.loc[df['Instrument']=='DE000DFK0NP7','Company Common Name']!=''
df.loc[df['Instrument']=='XS2412141769','Company Common Name']!=''

The above will correctly identify that the Ultimate Parent Id for ISIN code DE000DFK0NP7 is not missing, i.e. I can establish a True/False statement using the first math.isnan() command.

However, performing the same for ISIN code XS2412141769 will throw a TypeError message :

TypeError: must be real number, not NAType

Similarly, when checking whether an expected string variable has returned information, I also get a nonsensical result: for ISIN code DE000DFK0NP7 I can establish a True/False statement when checking whether the Company Common Name is not missing. But running the same check for ISIN code XS2412141769 simply gives me the output "<NA>" rather than a True/False statement.

I have been searching around various Python forums (e.g. StackOverflow), but this issue seems to be specific to how the Eikon API returns missing or erroneous information.

Can you please indicate how I can check for NAType or NaN values when the returned information is "<NA>"?

Many thanks in advance

Best Answer

Answers

  • Hi Umer, thanks, that's exactly what I was looking for (not sure how I missed that on StackOverflow..).

    Thanks again

  • You are welcome - StackOverflow can be a bit of pot luck :)

    I searched for 'pandas._libs.missing.NAType' and the above link was the 1st one that came up..