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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T16:09:33+00:00 2026-05-26T16:09:33+00:00

I am reading data from a csv file, and there are date elements in

  • 0

I am reading data from a csv file, and there are date elements in it, but there is an inconsistency in the dates.

For example: sometimes the date element is like 1/1/2011 and sometimes it is like 01/01/2011

Since I am plotting this data later.. this causes a great deal of noise in my plots. The following is my date class. Can you help me out in where and how to modify the code in order to get the date in the form 01/01/2011

import re
class Date:
def __init__(self, input_date):
    self._input_date = input_date
    self._date = None
    self._month = None
    self._year = None
    self._hour = None
    self._min = None


def  setDate(self):
    date = self._input_date
    #date = re.findall('w+',date)
    date = self.__mySplit()
    #print"len ",len(date)
    assert (len(date) >= 3) #has atleast dd/mm/yy 
    #dateLength = len(date[0])

    self._month = int(date[0])
    self._date = int(date[1])
    self._year = int(date[2])
    if (len(date) ==5):
        self._hour = int(date[3])
        self._min = int(date[4])

def __mySplit(self): #splitting the date by delimiters..
    res = [self._input_date]
    #print res
    seps = [' ','/',':']
    for sep in seps:
        s,res = res,[]
        for seq in s:
            res += seq.split(sep)
            #print res
    return res

Thanks

  • 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-05-26T16:09:33+00:00Added an answer on May 26, 2026 at 4:09 pm

    You definitely want to be using datetime. Here’s some code that will get a datetime from either string type:

    from datetime import datetime
    
    def strToDatetime(dateStr):
        return datetime.strptime(dateStr, "%d/%m/%Y")
    

    Then, you can print a datetime out in the format you want with:

    strToDatetime("1/3/2011").strftime("%d/%m/%Y)
    >'01/03/2011'
    

    You should never need to roll your own date/time/datetime structure in python.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm reading weekly data from a .csv data file. A sample of the data
When reading data from the Input file I noticed that the ¥ symbom was
I am reading data from a file that has, unfortunately, two types of character
I'm having some trouble reading data from a file into a vector of Orders.
I'm adding data from a csv file into a database. If I open the
I'm trying to load data from an external csv file that needs to be
I had one csv file of 1 cr lines of data. From this file
I'm reading data from a table( from a MySQL Database) with Hibernate SQL Query.
I'm reading data from a device which measures distance. My sample rate is high
I am reading data from multiple serial ports. At present I am using a

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.