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

  • Home
  • SEARCH
  • 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 8282549
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T10:24:28+00:00 2026-06-08T10:24:28+00:00

I have a simple question related with csv files and parsing datetime. I have

  • 0

I have a simple question related with csv files and parsing datetime.

I have a csv file that look like this:

YYYYMMDD, HH,    X
20110101,  1,   10
20110101,  2,   20
20110101,  3,   30

I would like to read it using pandas (read_csv) and have it in a dataframe indexed by the datetime. So far I’ve tried to implement the following:

import pandas as pnd
pnd.read_csv("..\\file.csv",  parse_dates = True, index_col = [0,1])

and the result I get is:

                         X
YYYYMMDD    HH            
2011-01-01 2012-07-01   10
           2012-07-02   20
           2012-07-03   30

As you see the parse_dates in converting the HH into a different date.

Is there a simple and efficient way to combine properly the column “YYYYMMDD” with the column “HH” in order to have something like this? :

                      X
Datetime              
2011-01-01 01:00:00  10
2011-01-01 02:00:00  20
2011-01-01 03:00:00  30

Thanks in advance for the help.

  • 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-08T10:24:32+00:00Added an answer on June 8, 2026 at 10:24 am

    If you pass a list to index_col, it means you want to create a hierarchical index out of the columns in the list.

    In addition, the parse_dates keyword can be set to either True or a list/dict. If True, then it tries to parse individual columns as dates, otherwise it combines columns to parse a single date column.

    In summary, what you want to do is:

    from datetime import datetime
    import pandas as pd
    parse = lambda x: datetime.strptime(x, '%Y%m%d %H')
    pd.read_csv("..\\file.csv",  parse_dates = [['YYYYMMDD', 'HH']], 
                index_col = 0, 
                date_parser=parse)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a simple question. I have a model that looks like this: public
this time i have a simple question: I have one table, related with himself
Simple question, but I couldn't find any related topics that match this exact scenario.
i have a simple question: i have this var: $v = 24000,1500,1500,1500,1500,1500,; i would
i have a simple question, there is a function with parameter emp_id that opens
I have a simple question and that is how do you check if an
I have a simple question related to database schema, how can I check whether
I have a simple question related to viewport.. I have a page which has
I have a simple question related to the jquery Uploadify plugin because I am
I'm starting with programming actionscript and have a simple flow question related to flash.

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.