Python Forum
How to create a dataframe from timestamp values
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
Reply
#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
Reply
#3
Can some one help on the query i have posted
Reply
#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
Reply
#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
Reply
#6
Due to the lack of this file dataset.sas7bdat, it's impossible to replicate your code.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Remove specific values from dataframe jonah88888 0 1,123 Sep-24-2021, 05:09 AM
Last Post: jonah88888
  update values in one dataframe based on another dataframe - Pandas iliasb 2 5,879 Aug-14-2021, 12:38 PM
Last Post: jefsummers
  How do I create permutations and combinations of a set of values? pythonforumuid 2 1,802 Sep-13-2020, 12:38 AM
Last Post: pythonforumuid
  Filter data based on a value from another dataframe column and create a file using lo pawanmtm 1 3,468 Jul-15-2020, 06:20 PM
Last Post: pawanmtm
  Assigning Column nunique values to another DataFrame column Pythonito 0 1,183 Jun-25-2020, 05:04 PM
Last Post: Pythonito
  Create dataframe through Dictionary in pandas ift38375 2 1,658 Aug-11-2019, 01:09 AM
Last Post: boring_accountant
  Splitting values in column in a pandas dataframe based on a condition hey_arnold 1 3,656 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 2,011 Jul-19-2018, 12:43 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020