Question

Pandas DataFrame in Python : I have csv file which has date column with object data...

Pandas DataFrame in Python :

I have csv file which has date column with object data type which ranges from 1908 to 2018:

(Original) Date                 (My result) Date                  (I Need) Date                      

17-Sep-08                                  2008-09-17                 1908-09-17

7-Sep-09                                    2009-09-07                  1909-09-07

.    (more years)                         .   (more years)               .    

.                                                 .                                      .

8-Nov-07                                       2007-11-07                 2007-11-07

23-Sep-08                                     2008-09-23                 2008-09-23

29-Dec-18                                     2018-12-29                 2018-12-29

When I am converting it to datetime64[ns] or/and adding column as year after extracting just year values from date column, all the year values starts at 2008 and ends at 2018 instead of starting at 1908 and ending at 2018.

Can anyone answer the question

0 0
Add a comment Improve this question Transcribed image text
Answer #1

This is a case of ambiguity that arises when representation of years is done in two digits.
In [16]: Out[16]: datetime.date (2068, 7, 31) In [17]: out[17]: datetime.date(1969, 7, 31) datetine . datetine. strptime(31-

The pivot year is 1969, i.e anything with the %y year below 69 is mapped to 2000 and anything equal to or above 69 maps to 1900. This is because we are considering two centuries simultaneously by representing them with only two digits. (00-99)

It has been illustrated in the python documentation for time library: Year 2000 (Y2K) issues: Python depends on the platform’s C library, which generally doesn’t have year 2000 issues, since all dates and times are represented internally as seconds since the epoch. Function strptime() can parse 2-digit years when given %y format code. When 2-digit years are parsed, they are converted according to the POSIX and ISO C standards: values 69–99 are mapped to 1969–1999, and values 0–68 are mapped to 2000–2068.

Manual processing is preferred. The years from 1908 to 1968 can be separately processed to remove this ambiguity.

In [43]: pivotyear = 1969 ...: century int(str(pivotyear)[:2]) 100 : def convert(year) ...converted year- century year if con

Add a comment
Know the answer?
Add Answer to:
Pandas DataFrame in Python : I have csv file which has date column with object data...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Python with Pandas dataframe I have a csv file that contains a large number of columns...

    Python with Pandas dataframe I have a csv file that contains a large number of columns and rows. I need to write a script that concatenates some elements of the first row with some elements of the 2 row. Something like # if data[1][0] starts with ch then concatenate the element right below it. I have attached a picture of just a sample of my data. The booleans have to stay on there as is. But I must drop the...

  • Write a C++ program that will input data from a Comma-separated values (.csv) file and output som...

    Write a C++ program that will input data from a Comma-separated values (.csv) file and output some information about it. This program uses a csv file from Yahoo Finance (.csv) filename : SBUX.csv 1. Output the name of the ticker to the console screen (without the “.csv”) 2. Output the start date and end date that was found in the file 3. Output how many trading day(s) existed in the file 4. Prompt the use to input a number of...

  • Python Pandas, Series and DataFrame Question (NO Loops, No If Statements, No List Comprehensions) The file...

    Python Pandas, Series and DataFrame Question (NO Loops, No If Statements, No List Comprehensions) The file bank.csv contains data about bank customers. The last column ('Personal Loan') indicates whether or not the customer was approved for a personal loan or not. Write a function named loan_by_zip that accepts 3 parameters: a file name, a minimum number of records, and a percentage approval rate. The function should return a DataFrame of those zip codes for which we meet the minimum number...

  • Hello, I am having some difficulty with interpreting the data below to fill in the table...

    Hello, I am having some difficulty with interpreting the data below to fill in the table required (which is displayed below the data charts). Any help or advice would be greatly appreciated. Question: Fill in the following table based upon the data charts given Question 2005 2006 2007 2008 For each year, at what date did the water temperature first hit 1°C above expected summertime maximum? For each year, at what date did the water temperature first hit 2°C above...

  • Question 2 If you read in a csv file using read.csv() function into R, what is the resulting datastructure in which R st...

    Question 2 If you read in a csv file using read.csv() function into R, what is the resulting datastructure in which R stores the read-in data? A. numeric B. matrix    C. data.frame    D. vector    Question 3 Suppose you have 4 integers, 4 characters, and 4 logical values. Which datastructure can you use to store all 12 values? Choose one or more options. A. a vector B. a matrix C. a list D. a data frame Question 4 Suppose you have...

  • Departure Observation with Departure Times Date Departure Delay minutes WA JW, RW 136 Scheduled: 08:00; Actual:...

    Departure Observation with Departure Times Date Departure Delay minutes WA JW, RW 136 Scheduled: 08:00; Actual: 07:541 137 Scheduled: 17:10Actual: 20:301 138 Scheduled 15:45; Act 11:44 139 Schedule: 07:50; Actual: 07:43 140 Scheduled 18:45; Actual: 22:23) 141 Scheduled: 03:50: Actual:09:17 142 Scheduled 12:00; Actual: 11:561 14 Scheduled 11:00; Actual: 10:53 144 Scheduled: 19:55; Actual: 20:19 165 Scheduled 11:00; Actual: 10:56 16h a 19. al 14.20 2007-12-04 2007-12-04 2007-12-04 2007-12-04 2007-12-04 2007-12-05 2007-12-05 2007-12-05 2007-12-05 2007-12-05 2007/12-05 -6 200 3 -7...

  • I'm having trouble working with a .csv file in C Programming. I know that I need...

    I'm having trouble working with a .csv file in C Programming. I know that I need to use parallel arrays to search through the data but I am a little lost. How would I go through the data in a file, for example I created one and attached it. To find the information between two dates. So Ask the user for two dates then search the .csv file for that and give an output similar to: "Select the starting and...

  • Python programming- Download the following two files you will need for this activity: customerData.csv This file...

    Python programming- Download the following two files you will need for this activity: customerData.csv This file contains randomly generated fictitious customer data. customer_regex.py This is a Python script that imports the customer data into a list of customer details. In your personal playground in Codio, upload the two files and investigate the contents before considering the task you will pose to your peers. Assume the position of a manager of an online retailer. Pose a question to your IT expert...

  • I am using Oracle SQL and am new to it. I have seven tables, one of...

    I am using Oracle SQL and am new to it. I have seven tables, one of them is a subtable of two of the others. I need to do the following queries: 1. List all Patients and what Bed they are assigned to 2. List all patients who had Treatments and what Treatment they received 3. List all patients who had tests and what Test they had 4. List the employees (doctors, nurses, etc.) who assisted each patient. 5. List...

  • Need help with C++ assignment Assignment 1 and .txt files are provided at the bottom. PART...

    Need help with C++ assignment Assignment 1 and .txt files are provided at the bottom. PART A PART B Assignment 1 #include <iostream> #include <string> #include <fstream> #include <iomanip> #include <stdio.h> #include <ctype.h> #include <string.h> #include <algorithm> using namespace std; /** This structure is to store the date and it has three integer fields **/ struct Date{    int day;    int month;    int year; }; /** This structure is to store the size of the box and it...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT