Bottom Page

Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
 How to create a dataframe from timestamp values
#1
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
Quote
#2
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
Quote
#3
Can some one help on the query i have posted
Quote
#4
(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
Quote
#5
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
Quote
#6
Due to the lack of this file dataset.sas7bdat, it's impossible to replicate your code.
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  Create dataframe through Dictionary in pandas ift38375 2 125 Aug-11-2019, 01:09 AM
Last Post: boring_accountant
  How to find difference between two timestamp index python_newbie09 3 166 Aug-01-2019, 10:24 AM
Last Post: python_newbie09
  Splitting values in column in a pandas dataframe based on a condition hey_arnold 1 1,236 Jul-24-2018, 02:18 PM
Last Post: hey_arnold
  Improve segmentation : Create sphere brush to edit voxels values in scanners image wi LauraLaura 1 496 Jul-19-2018, 12:43 PM
Last Post: Larz60+
  Get max values based on unique values in another list - python Antonio 8 1,545 Jun-12-2018, 07:49 PM
Last Post: Mekire

Forum Jump:


Users browsing this thread: 1 Guest(s)