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
18 2 3 10

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'},
    )
eikon-data-apipythonpython apidatatime-series
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.

1 Answer

· Write an Answer
Upvotes
Accepted
24.5k 63 15 21

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, (%)    Float64

You 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: object
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.