Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Hi! I\'ve been at this for awhile and I\'m lost and this is my first posted ques

ID: 3906726 • Letter: H

Question

Hi! I've been at this for awhile and I'm lost and this is my first posted question. Using the latest version of Python, I'm looking to normalize a data column in a .csv file. The date format is all over the place, ranging from:

I'm looking to get it formatted as MM/DD/YYYY.

The column name is Member Date

The starting code that I have is:

import csv
import re
data = []

with open('customerdata.csv') as csvfile:
reader = csv.DictReader(csvfile)
for row in reader:
data.append(row)

newFile=open("CCrewards.csv","w")
newFile.write("Name,Email,Credit Card,Member Date, ")

for d in data:
newFile.write(d["Name"]+","+d["Email"]+","+d["Credit Card"]+","+d["Member Date"]+", ")
print(d["Name"],d["Email"],d["Credit Card"],d["Member Date"])
newFile.close()

Also, not sure how to provide you with the .csv file that contains the data. Any insight would be grateful. Thanks.

Fri Jun 03 2016 01:34:30 GMT-0400 (Eastern Daylight Time) to 30/10/2010

Explanation / Answer

Hi, I would recommend you to use Pandas dataframe to solve this.

#to read csv file
df1 = pd.read_csv('CCrewards.csv.csv', index_col=0)

df1

#to convert the date format to MM/DD/YYYY

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote