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 7862937
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T23:19:12+00:00 2026-06-02T23:19:12+00:00

I am parsing a file this way : for d in csvReader: print datetime.datetime.strptime(d[Date]+-+d[Time],

  • 0

I am parsing a file this way :

for d in csvReader:
    print datetime.datetime.strptime(d["Date"]+"-"+d["Time"], "%d-%b-%Y-%H:%M:%S.%f").date()

date() returns : 2000-01-08, which is correct

time() returns : 06:20:00, which is also correct

How would I go about returning informations like “date+time” or “date+hours+minutes”

EDIT

Sorry I should have been more precise, here is what I am trying to achieve :

lmb = lambda d: datetime.datetime.strptime(d["Date"]+"-"+d["Time"], "%d-%b-%Y-%H:%M:%S.%f").date()

daily_quotes = {}
for k, g in itertools.groupby(csvReader, key = lmb):
    lowBids = []
    highBids = []
    openBids = []
    closeBids = []
    for i in g:

        lowBids.append(float(i["Low Bid"]))
        highBids.append(float(i["High Bid"]))
        openBids.append(float(i["Open Bid"]))
        closeBids.append(float(i["Close Bid"]))

    dayMin = min(lowBids)
    dayMax = max(highBids)
    open = openBids[0]
    close = closeBids[-1]

    daily_quotes[k.strftime("%Y-%m-%d")] = [dayMin,dayMax,open,close]

As you can see, right now I’m grouping values by day, I would like to group them by hour ( for which I would need date + hour ) or minutes ( date + hour + minute )

thanks in advance !

  • 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-02T23:19:14+00:00Added an answer on June 2, 2026 at 11:19 pm

    Don’t use the date method of the datetime object you’re getting from strptime. Instead, apply strftime directly to the return from strptime, which gets you access to all the member fields, including year, month, day, hour, minute, seconds, etc…

    d = {"Date": "01-Jan-2000", "Time": "01:02:03.456"}
    dt = datetime.datetime.strptime(d["Date"]+"-"+d["Time"], "%d-%b-%Y-%H:%M:%S.%f")
    print dt.strftime("%Y-%m-%d-%H-%M-%S")
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I got a string from parsing a XML file which looks like this: Fri,
I know, that this way of dtd validation before parsing a xml file works:
I have student.xml file and am parsing this file using SAX Parser and now
When parsing an xml file in android, I'm doing like this: try { InputStream
I'm trying to read in an xml file which looks like this <?xml version=1.0
I have a property-file with strings inside, formatted in this way: audit.log.events.purged=The audit events
I'm parsing a big CSV file using csv.DictReader . quotes=open( "file.csv", "rb" ) csvReader=
I need help in parsing a very long text file which looks like: NAME
I'm parsing a text file made from this Wikipedia article , basically I made
I'm parsing a file that is set up like so: <blah-name name=Turkey> <blah-city name=Test/>

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.