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
1 2 5 5

Get the data by Date wise

Hi!
I want to get the data for PE for say 4 tickers, for the field = TR.PE for the dates 15 to 17 Feb 2021. I am using the commands

ticker_list1 = ['CHMB.NS', 'GNFC.NS', 'KVRI.NS', 'NGFR.NS']
param_list = {'SDate':'2021-02-15', 'EDate':'2021-02-17','FRQ': 'D'}
data,err = ek.get_data(ticker_list1,['TR.PE.calcdate','TR.PE'],parameters= param_list)
data = data.set_index('Instrument')
data

The output is 10 rows as shown in the image.

I want to fetch it in a format such that the tickers are aligned as the column headers and dates as the index, ie 3 rows and 4 columns.

What do you suggest, how can we achieve this.


eikoneikon-data-apipythonrefinitiv-dataplatform-eikonworkspaceworkspace-data-apiapi
current-format.jpg (30.1 KiB)
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.

Thank you for your participation in the forum.
Is the reply below satisfactory in resolving your query?
If yes, please click the 'Accept' text next to the appropriate reply. This will guide all community members who have a similar question. Otherwise please post again offering further insight into your question.
Thanks,
-AHS

@anshulmlhtr

Hi,

Please be informed that a reply has been verified as correct in answering the question, and has been marked as such.

Thanks,

AHS

Upvotes
Accepted
39.4k 77 11 27

Create a pivot table indexed on date and instrument. Then unstack the instrument from the index. In your code example replace

data = data.set_index('Instrument')

with

data = data.pivot_table(values='P/E (Daily Time Series Ratio)', 
                        index=['Calc Date', 'Instrument'])
data = data.unstack('Instrument')
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.

Upvotes
1 2 5 5

Thanks @Alex Putkov.

Though there are 2 conerns. Implementing this, has dropped ~38% of my tickers. What could be a possible reason for this, and how can we correct this.

Also, it seems that the order amongst the tickers has changed. How can we do it such that the order of tickers as column headers remains the same as in the list of tickers which I had sent as input.

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.

Upvotes
39.4k 77 11 27

One reason a ticker would be dropped is if there's no data for it. If the dataframe returned by get_data method does not include Calc Date for a given ticker, then when you set the index on Calc Date that ticker will be dropped. Using the list of tickers in your original example, NGFR.NS will be dropped. If you need to preserve it, then you need to pad the data returned by get_data method by replacing blank values in Calc Date column with something (and perhaps adding some rows depending on what you want to have for these tickers in the resulting dataframe).
I do not reproduce the order of the tickers changing. If you have an example, please share.

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.