I need to do CSV parsing and I was wondering if this is possible with python and where I should go to learn how to code this script or get help.


Let's say I have a CSV file with 20 rows and 4 columns. I need to:
-Strip out the first five rows
-Strip out the last three rows
-Strip out the 2nd and 4th columns
-Convert the dates in the 3rd column from format DD-MM-YYYY to MMM-DD (so for example, a 14-05-1999 gets converted to May-14)

In the end, I'll have a CSV file with 12 rows and 2 columns, with one of the columns in a different date format.

If this is in fact possible, can someone please point me to some tutorials that would help me achieve this in the least time possible? THANKS SO MUCH!

strip out == do not write back again, when you write changed file with old name (maybe destroying the content in case of program bug) or new name with open('myoutfile.txt','w').write(my_changed_text)

Formatting time/date strings is easy with Python module time ...

# convert 14-05-1999 to May-14
# see Python manual for module time format specifiers

import time

date_old = "14-05-1999"

# use strptime(time_str, format_str) to form a time tuple
time_tuple = time.strptime(date_old, "%d-%m-%Y")

#print(time_tuple)  # test

# use time.strftime(format_str, time_tuple) to create new format
date_new = time.strftime("%b-%d", time_tuple)

print(date_old)  # 14-05-1999
print(date_new)  # May-14
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.