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
-
Hi @AAMZ
Is the following what you are after?
pd.isna(df.loc[df['Instrument']=='XS2412141769','Ultimate Parent Id'])
2 True
Name: Ultimate Parent Id, dtype: boolI found the answer on StackOverflow - python - How to map NA values of the type pandas._libs.missing.NAType - Stack Overflow
The same works for Company name:
0
Answers
-
Hi Umer, thanks, that's exactly what I was looking for (not sure how I missed that on StackOverflow..).
Thanks again
0 -
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..
0
Categories
- All Categories
- 6 AHS
- 39 Alpha
- 161 App Studio
- 4 Block Chain
- 4 Bot Platform
- 16 Connected Risk APIs
- 47 Data Fusion
- 30 Data Model Discovery
- 608 Datastream
- 1.3K DSS
- 577 Eikon COM
- 4.9K Eikon Data APIs
- 7 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- Trading API
- 2.7K Elektron
- 1.3K EMA
- 236 ETA
- 519 WebSocket API
- 33 FX Venues
- 10 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 20 Messenger Bot
- 2 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 59 Open Calais
- 264 Open PermID
- 39 Entity Search
- 2 Org ID
- PAM
- PAM - Logging
- 8.4K Private Comments
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 20 RDMS
- 1.4K Refinitiv Data Platform
- 367 Refinitiv Data Platform Libraries
- 3 Refinitiv Due Diligence
- LSEG Due Diligence Portal API
- 3 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.1K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 10 World-Check Customer Risk Screener
- 990 World-Check One
- 44 World-Check One Zero Footprint
- 45 Side by Side Integration API
- Test Space
- 3 Thomson One Smart
- 1.2K TR Internal
- Global Hackathon 2015
- 2 Specialists Who Code
- 10 TR Knowledge Graph
- 150 Transactions
- 142 REDI API
- 1.7K TREP APIs
- 4 CAT
- 21 DACS Station
- 117 Open DACS
- 1.1K RFA
- 103 UPA
- 172 TREP Infrastructure
- 224 TRKD
- 886 TRTH
- 5 Velocity Analytics
- 5 Wealth Management Web Services
- 60 Workspace SDK
- 9 Element Framework
- 5 Grid
- 13 World-Check Data File
- Yield Book Analytics
- 46 中文论坛