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
16 2 1 9

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-apipythondatapython apitime-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.

Hi @LRE42

Thank you for your participation in the forum.

Is the reply below satisfactory in answering your question?

If yes please click the 'Accept' text next to the reply.

This will guide all community members who have a similar question.

Otherwise please post again offering further insight into your question.

Thanks,

AHS

LRE42 avatar image   LRE42 chavalit-jintamalit
it is; thank you

1 Answer

· Write an Answer
Upvotes
Accepted
22.1k 59 14 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.