For a deeper look into our Eikon Data API, look into:

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
1 0 0 0

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-apiworkspaceworkspace-data-apirefinitiv-dataplatform-eikonpythonapi
current-format.jpg (30.1 KiB)
icon clock
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 5.0 MiB each and 10.0 MiB total.

Upvotes
Accepted
39.2k 75 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 5.0 MiB each and 10.0 MiB total.

Upvotes
1 0 0 0

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 5.0 MiB each and 10.0 MiB total.

Upvotes
39.2k 75 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 5.0 MiB each and 10.0 MiB total.

Click below to post an Idea Post Idea