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

Overview |  Quickstart |  Documentation |  Downloads |  Tutorials |  Articles

question

Upvotes
Accepted
1 0 1 3

Python Time Series - Convert Date Index to Pandas Column

Hi All,


In a simple time series, how do you convert the timestamp, which is in an index to a pandas column formated in dateimte?

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

1 Answer

Upvotes
Accepted
39.2k 75 11 27

If you have a dataframe named 'df' with DatetimeIndex, the following command will add a column labeled 'Timestamp' and the values corresponding to the values of the index:

df['Timestamp'] = df.index

E.g.

df = ek.get_timeseries('EUR=','CLOSE')
df['Timestamp'] = df.index
df.info()

This returns:

<class 'pandas.core.frame.DataFrame'>
DatetimeIndex: 71 entries, 2020-09-28 to 2021-01-04
Data columns (total 2 columns):
 #   Column     Non-Null Count  Dtype         
---  ------     --------------  -----         
 0   CLOSE      71 non-null     float64       
 1   Timestamp  71 non-null     datetime64[ns]
dtypes: datetime64[ns](1), float64(1)
memory usage: 1.7 KB
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