Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8515633
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T05:12:08+00:00 2026-06-11T05:12:08+00:00

I have a csv file with a time column representing POSIX timestamps in milliseconds.

  • 0

I have a csv file with a time column representing POSIX timestamps in milliseconds. When I read it in pandas, it correctly reads it as Int64 but I would like to convert it to a DatetimeIndex. Right now I first convert it to datetime object and then cast it to a DatetimeIndex.

In [20]: df.time.head()

Out[20]: 
0    1283346000062
1    1283346000062
2    1283346000062
3    1283346000062
4    1283346000300
Name: time

In [21]: map(datetime.fromtimestamp, df.time.head()/1000.)
Out[21]: 
[datetime.datetime(2010, 9, 1, 9, 0, 0, 62000),
 datetime.datetime(2010, 9, 1, 9, 0, 0, 62000),
 datetime.datetime(2010, 9, 1, 9, 0, 0, 62000),
 datetime.datetime(2010, 9, 1, 9, 0, 0, 62000),
 datetime.datetime(2010, 9, 1, 9, 0, 0, 300000)]

In [22]: pandas.DatetimeIndex(map(datetime.fromtimestamp, df.time.head()/1000.))
Out[22]: 
<class 'pandas.tseries.index.DatetimeIndex'>
[2010-09-01 09:00:00.062000, ..., 2010-09-01 09:00:00.300000]
Length: 5, Freq: None, Timezone: None

Is there an idiomatic way of doing this? And more importantly is this the recommended way of storing non-unique timestmaps in pandas?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T05:12:09+00:00Added an answer on June 11, 2026 at 5:12 am

    You can use a converter in combination with read_csv.

    In [423]: d = """\
    timestamp data
    1283346000062 a
    1283346000062 b
    1283346000062 c
    1283346000062 d
    1283346000300 e
    """
    
    In [424]: fromtimestamp = lambda x:datetime.fromtimestamp(int(x) / 1000.)
    
    In [425]: df = pandas.read_csv(StringIO(d), sep='\s+', converters={'timestamp': fromtimestamp}).set_index('timestamp')
    
    In [426]: df.index
    Out[426]:
    <class 'pandas.tseries.index.DatetimeIndex'>
    [2010-09-01 15:00:00.062000, ..., 2010-09-01 15:00:00.300000]
    Length: 5, Freq: None, Timezone: None
    
    In [427]: df
    Out[427]:
                               data
    timestamp
    2010-09-01 15:00:00.062000    a
    2010-09-01 15:00:00.062000    b
    2010-09-01 15:00:00.062000    c
    2010-09-01 15:00:00.062000    d
    2010-09-01 15:00:00.300000    e
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a csv file like 120 column by 4500 row. I read the
I have a CSV file which has a column for time and the time
I have a comma delimited file myfile.csv where the 5th column is a date/time
I have various time-series I'd like to correlate and present as either a csv-file
i have csv files, java app and database, i read csv file from my
How to read and import .csv file in groovy on grails. I have .csv
I have a csv file, and I want to extract the each column a
I have a large 2 column csv file (data.csv) with a weeks worth of
i am generating CSV,the file is generated very fine but i have problem in
I have a csv file where one of the columns is a date/time string.

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.