Change format of date output in Eikon API
Hello, using Eikon API in Python, trying to pull data on WACC, and the date is output as datetime (eg, 2019-04-30T00:00:00Z). Is it possible to output it only as a date? I am sure I could change it with Pandas, but Pandas didn't seem to recognise it as datetime -- any idea why that may be? thank you for your help
#import refinitiv.data as rd
#rd.open_session()
import eikon as rd
rd.set_app_key('8_______1')
startdate = "2019-01-01"
enddate = "2022-07-14"
syntax = "SCREEN(U(IN(Equity(active,public,primary)))," \
"IN(TR.HQCountryCode,AT;BE;BM;CA;CH;KY;DE;DK;ES;FI;FR;FO;GB;GG;GI;GR;GL;IM;IE;IS;IT;JE;LI;LU;MC;NL;NO;PR;PT;SE;US;VG)," \
"IN(TR.TRBCEconSectorCode,52,53,4,57),CURN=USD)"
WACCfields = ['TR.WACC.date', 'TR.WACC']
df3, err = rd.get_data(syntax, WACCfields,
{'SDate': startdate,'EDate': enddate, 'FRQ': 'M'},
)
Tagged:
0
Best Answer
-
Hello @LRE42,
Some of the entries have null, so it didn't automatically convert the datatype to Datetime. If you check the type, it shows as string:
>> df3.dtypes
Instrument string
Date string
Weighted Average Cost of Capital, (%) Float64You can use a pandas convert function to change it into datetime format:
>> pd.to_datetime(df3['Date'])
0 2019-01-31 00:00:00+00:00
1 2019-02-28 00:00:00+00:00
2 2019-03-31 00:00:00+00:00
3 2019-04-30 00:00:00+00:00
4 2019-05-31 00:00:00+00:00
...
252979 NaT
252980 NaT
252981 NaT
252982 NaT
252983 NaT
Name: Date, Length: 252984, dtype: datetime64[ns, UTC]or just keep the date if you wish:
>> pd.to_datetime(df3['Date']).dt.date
0 2019-01-31
1 2019-02-28
2 2019-03-31
3 2019-04-30
4 2019-05-31
...
252979 NaT
252980 NaT
252981 NaT
252982 NaT
252983 NaT
Name: Date, Length: 252984, dtype: object2
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 中文论坛