Python Forum
How to create a dataframe from timestamp values - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: Data Science (https://python-forum.io/forum-44.html)
+--- Thread: How to create a dataframe from timestamp values (/thread-16861.html)



How to create a dataframe from timestamp values - MohanReddy - Mar-18-2019

date_cols = ['CLOSE', 'D_MONTH', 'OPEN']
gbl = globals()
for i in date_cols:
gbl[i] = pd.to_timedelta(min(data_frame_1[i]), unit='s') + pd.datetime(1960, 1, 1)

the output looks like this:
>OPEN
Out[520]: Timestamp('1993-02-12 00:00:00')
>CLOSE
Out[522]: Timestamp('2009-04-30 00:00:00')
>D_MONTH
Out[523]: Timestamp('2018-01-01 00:00:00')

type(OPEN)
Out[518]: pandas._libs.tslib.Timestamp

The output is a time stamp but I want an output as a dataframe like below:
Attr Min_Date
CLOSE 2009-04-30 00:00:00
OPEN 1993-02-12 00:00:00
D_MONTH 2018-01-01 00:00:00


RE: How to create a dataframe from timestamp values - MohanReddy - Mar-18-2019

date_cols = ['CLOSE', 'D_MONTH', 'OPEN']
gbl = globals()
for i in date_cols:
    gbl[i] = pd.to_timedelta(min(data_frame_1[i]), unit='s') + pd.datetime(1960, 1, 1)
I am getting the output as below
Output:
>OPEN Out[520]: Timestamp('1993-02-12 00:00:00') >CLOSE Out[522]: Timestamp('2009-04-30 00:00:00') >D_MONTH Out[523]: Timestamp('2018-01-01 00:00:00')
But I want the output like below as a dataframe not as a timestamp:
Output:
Attr Min_Date CLOSE 2009-04-30 00:00:00 OPEN 1993-02-12 00:00:00 D_MONTH 2018-01-01 00:00:00



RE: How to create a dataframe from timestamp values - MohanReddy - Mar-19-2019

Can some one help on the query i have posted


RE: How to create a dataframe from timestamp values - samsonite - Mar-19-2019

(Mar-19-2019, 04:36 AM)MohanReddy Wrote: Can some one help on the query i have posted
You should inform the helper which library comes pd from, in order to replicate your test. Cheers


RE: How to create a dataframe from timestamp values - MohanReddy - Mar-19-2019

import pandas as pd
data_frame_1 = pd.read_sas("path\dataset.sas7bdat")
# When the data got loaded to a dataframe from SAS dataset, the values have been loaded as exponential values. So i have used to_timedelta function to convert the values to datetime and at the same time I am trying to find out the minimum date from each column
date_cols = ['CLOSE', 'D_MONTH', 'OPEN']
gbl = globals()
for i in date_cols:
    gbl[i] = pd.to_timedelta(min(data_frame_1[i]), unit='s') + pd.datetime(1960, 1, 1)
Below is the output I am getting after running the code. Each output is Timestamp format. But I cant append these values.
Output:
>OPEN Out[520]: Timestamp('1993-02-12 00:00:00') >CLOSE Out[522]: Timestamp('2009-04-30 00:00:00') >D_MONTH Out[523]: Timestamp('2018-01-01 00:00:00')
Below is the output I am looking for as a dataframe
Output:
Attr Min_Date CLOSE 2009-04-30 00:00:00 OPEN 1993-02-12 00:00:00 D_MONTH 2018-01-01 00:00:00



RE: How to create a dataframe from timestamp values - samsonite - Mar-20-2019

Due to the lack of this file dataset.sas7bdat, it's impossible to replicate your code.