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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T05:36:39+00:00 2026-06-06T05:36:39+00:00

I have a csv file with data looking like (see below). I need help

  • 0

I have a csv file with data looking like (see below). I need help parsing datetime and fill missing date_time and assigning missing data as “M”(missing):

Datetime, Data

19920101 00:00,2
19920101 01:00,3
19920101 23:00,5
19920505 12:00,5
  • 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-06T05:36:41+00:00Added an answer on June 6, 2026 at 5:36 am

    Not a complete answer but just tried to parse the date time string

    >>> s="19920101 00:00"
    >>> format = "%Y%m%d %H:%M"
    >>> d = datetime.datetime.strptime(s, format)
    >>> print d
    1992-01-01 00:00:00
    

    Will this help in finding out the missing dates and times for you.

    I could not understand what 3 is in the string 3 19920101 23:00.

    [Edit: based on your comment]

    >>> expected = d + datetime.timedelta(days=1)
    >>> print expected
    1992-01-02 00:00:00
    

    So in your code, you could try something like this (You will need to work and refine this)

    [Edit: Code replaced]

    import csv
    import sys
    import datetime
    import pprint
    
    
    all_data_points = {}
    all_dates = []
    expected = ''
    format = "%Y%m%d %H:%M"
    
    with open('datafile', 'rt') as f:
        reader = csv.reader(f)
        for row in reader:
            if row and 'Datetime' not in row:
                day_str = row[0]
                rain_str = row[1]
                if not expected:
                    all_data_points[day_str] = rain_str
                    all_dates.append(day_str)
                    d = datetime.datetime.strptime(day_str, format)
                    expected = d + datetime.timedelta(days=1)
                else:
                    d = datetime.datetime.strptime(day_str, format)
                    gap_in_days = d - expected 
                    start_day = expected
                    if gap_in_days.days > 1:
                        for i in xrange(gap_in_days.days):
                            next_day = start_day + datetime.timedelta(days=1+i)
                            day_str = next_day.strftime(format)
                            all_data_points[day_str] = 'M'
                            all_dates.append(day_str)
                    all_data_points[day_str] = rain_str
                    expected = d
    
        pprint.pprint(all_data_points)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a file called test.csv, Data in the file is looking like this:
I have a .csv file containing 3 columns of data. I need to create
I have a data table I've loaded from a CSV file. I need to
I have a single csv file with data about schools: their locations, their names
I have a .csv file that contains data for only certain columns in a
I have a number of images and a CSV data file that I want
I have a static csv file. I want to covert all the data in
I have to write huge data in text[csv] file. I used BufferedWriter to write
I have a System.Data.DataTable which is populated by reading a CSV file which sets
I have made a java application that stores data from a .csv file to

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.