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

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
7 1 0 0

Python and PowerBI Date

I'm new to Python, but have successfully pulled Eikon data and used in PowerBI. I'm attempting to pull data changes between two periods, and I'm able to do so in Python via diff, but when loading in Python lose the Timestamp (I get the difference in days, as diff seems to give change in the data I care about and the days):


from datetime import date, timedelta

import pandas as pd

import eikon as ek


ek.set_app_key('MY APP KEY')


stocks = ek.get_timeseries('DST-STK-T-EIA',

fields=['Close','Timestamp'],

start_date=(date.today()-timedelta(days=(13*365))).strftime("%Y-%m-%d"),

end_date=(date.today()+timedelta(days=(5*365))).strftime("%Y-%m-%d"),interval="weekly"

)

stocks['Timestamp'] = stocks.index


stocks_change = stocks.diff()

eikoneikon-data-apiworkspaceworkspace-data-apirefinitiv-dataplatform-eikon
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.

Upvote
Accepted
39.2k 75 11 27

@Corey.Stewart

Pandas diff method calculates the difference of a Dataframe element compared with another element in the Dataframe (default is element in previous row). It does not modify the index of the Dataframe, so the result of stocks.diff() in your example still has the timestamp in the Dataframe index. But it does modify all the columns including the column named 'Timestamp' that you create from the Dataframe index. If you would like to have the column containing the timestamp of the timeseries, you can simply create it from Dataframe index after executing the diff method. I.e. delete the line

stocks['Timestamp'] = stocks.index 

and at the end of your code snippet (after stocks_change = stocks.diff()) add

stocks_change['Timestamp'] = stocks_change.index
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.

Upvote
1.4k 6 2 2

Hi @Corey.Stewart,


There are many ways to do this. I would keep the data in one data-frame to keep things simple:


stocks = ek.get_timeseries(rics = 'DST-STK-T-EIA',
                           fields = ['Close','Timestamp'],
                           start_date = (date.today()-timedelta(days=(13*365))).strftime("%Y-%m-%d"),
                           end_date = (date.today()+timedelta(days=(5*365))).strftime("%Y-%m-%d"),interval="weekly")
stocks['CLOSE1d'] = stocks.diff()["CLOSE"]


Does this resolve your issue?

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