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
98 26 32 35

Python: How to get just the number out of a TR.Formula using Eikon API?

Hello everyone, I have the following short code in which I acquire local returns:

import eikon as ek #import Eikon module
ek.set_app_id('someID') #setting AppID
df = ek.get_data('B1FJ0C0','TR.TotalReturn', {'SDate': '2017-02-03'})

print(df)
print (df[0]) 

The outcome goes as follows:

What I desire is to acquire just the numeric value of the return, I don't want to know about the instrument or any other field/value, just the value of the Total Return.

Does anybody know how? I'd be happy to know.

Thanks!

eikoneikon-data-apipythonrefinitiv-dataplatform-eikonworkspaceworkspace-data-api
capturatr.jpg (15.8 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.

Upvote
Accepted
17k 80 39 63

Hi @aquilesjlp300,

To acquire just the numeric value of the return, you can do this:

First thing to note is that the call to get_data() returns a tuple containing the dataframe and error (if any).


forum.png (6.7 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.

Thanks a lot Nick. Is this a pandas dateframe, btw? The way the information is organized when I request information for a bigger list of identifiers does seem to give that appearance.

Yes, the default output is a Pandas DataFrame. For more details see the documentation for get_data method in Eikon Python API Reference Guide
https://developers.thomsonreuters.com/eikon-data-apis/docs

I have an additional question Alex, it's somehow related to the post.

Can I call TR formulas from the get_timeseries function? My guess from the reference guide you provided is "No", I can't do that. Since I'd like daily returns given a range of dates.

Show more comments
Upvotes
1 1 1 0

Due to an outage of the Thomson Reuters Developer Community email notification system from 2:30 PM CDT on November 29th until 9:00 AM CDT on November 30th we are posting to all questions updated during this timeframe in order to ensure all customers receive all relevant email updates. Please review this question, and its associated answers, in order to ensure you are aware of any possible updates that may have occurred during this outage. We apologize for the delay and any inconvenience this has caused.

Matthew Logterman, J.D.

Sr. Product Manager, Thomson Reuters Developer Community

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

I'm getting AttributeError: 'tuple' object has no attribute 'iloc'

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.

@victor.delima
If you have a question it's always best to start a new thread rather than posting an answer on an existing thread. I'm guessing, and this is only a guess, that what you did is something like

df = ek.get_data('TRI.N','TR.Revenue')
df.iloc[0],[1]

instead of correct

df, err = ek.get_data('TRI.N','TR.Revenue')
df.iloc[0],[1]

If this helps, great. If not, and you need further assistance, please start a new thread and provide detailed description of the issue you're experiencing.

Thanks man. That did the trick.

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.