Change format of date output in Eikon API

LRE42
Newcomer
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: object0
Categories
- All Categories
- 3 Polls
- 6 AHS
- 36 Alpha
- 166 App Studio
- 6 Block Chain
- 4 Bot Platform
- 18 Connected Risk APIs
- 47 Data Fusion
- 34 Data Model Discovery
- 685 Datastream
- 1.4K DSS
- 615 Eikon COM
- 5.2K Eikon Data APIs
- 10 Electronic Trading
- Generic FIX
- 7 Local Bank Node API
- 3 Trading API
- 2.9K Elektron
- 1.4K EMA
- 252 ETA
- 556 WebSocket API
- 38 FX Venues
- 14 FX Market Data
- 1 FX Post Trade
- 1 FX Trading - Matching
- 12 FX Trading – RFQ Maker
- 5 Intelligent Tagging
- 2 Legal One
- 23 Messenger Bot
- 3 Messenger Side by Side
- 9 ONESOURCE
- 7 Indirect Tax
- 60 Open Calais
- 275 Open PermID
- 44 Entity Search
- 2 Org ID
- 1 PAM
- PAM - Logging
- 6 Product Insight
- Project Tracking
- ProView
- ProView Internal
- 22 RDMS
- 1.9K Refinitiv Data Platform
- 652 Refinitiv Data Platform Libraries
- 4 LSEG Due Diligence
- LSEG Due Diligence Portal API
- 4 Refinitiv Due Dilligence Centre
- Rose's Space
- 1.2K Screening
- 18 Qual-ID API
- 13 Screening Deployed
- 23 Screening Online
- 12 World-Check Customer Risk Screener
- 1K World-Check One
- 46 World-Check One Zero Footprint
- 45 Side by Side Integration API
- 2 Test Space
- 3 Thomson One Smart
- 10 TR Knowledge Graph
- 151 Transactions
- 143 REDI API
- 1.8K TREP APIs
- 4 CAT
- 27 DACS Station
- 121 Open DACS
- 1.1K RFA
- 104 UPA
- 193 TREP Infrastructure
- 228 TRKD
- 917 TRTH
- 5 Velocity Analytics
- 9 Wealth Management Web Services
- 90 Workspace SDK
- 11 Element Framework
- 5 Grid
- 18 World-Check Data File
- 1 Yield Book Analytics
- 46 中文论坛