I'm a newbie to python and I have a problem. My problem is that I have a CSV file with hundreds and hundreds of rows of data. Each row contains temperature data that has been recorded daily. What I want to do is try to extract certain rows of data from the csv file. For example I want to be able to give a function two different days.(mm/dd/yyyy) I'll call one 'initialDay' and the other 'finalDay'. Now I would like to extract the data in between these two days. My data is constructed so that's DATE is a column. Does Python offer any way of extracting just the data between my two dates?? Another quick example: let say I entered:
initialDay = 1/1/2000 and finalDay = 1/4/2000
I would want the daily temp recorded for january 1st 2000 through january 4th 2000.
So if initialDay = finalDay it should only return the temp for that single day.
stompper33
0
Newbie Poster
Recommended Answers
Jump to PostDoes Python offer any way of extracting just the data between my two dates??
Yes more than one way depends how data are organized.
post an short example off that cvs file.
Mark where 'initialDay' and 'finalDay' are.
Jump to PostIf i understood correctly:
initial_date = '9/14/1990' initial_month, initial_day, initial_year = initial_date.split('/') final_date = '9/17/1990' final_month, final_day, final_year = final_date.split('/') f_in = open('stations_temp.csv').readlines() f_out = open('filtered_stations_temp.csv', 'w') f_out.write(f_in[0]) for i in range(1, len(f_in)): station, date, max_temp, min_temp = f_in[i].split(',') month, day, year = date.split('/') if initial_month <= …
Jump to PostIf you change Bent Slayer code,to this.
It will give you a list.initial_date = '9/14/1990' initial_month, initial_day, initial_year = initial_date.split('/') final_date = '9/17/1990' final_month, final_day, final_year = final_date.split('/') f_in = open('test.csv').readlines() #f_out = open('filtered_stations_temp.csv', 'w') my_list = [] for i in range(1, len(f_in)): station, date, max_temp, …
All 9 Replies
snippsat
661
Master Poster
stompper33
0
Newbie Poster
Beat_Slayer
17
Posting Pro in Training
stompper33
0
Newbie Poster
snippsat
661
Master Poster
TrustyTony
888
pyMod
Team Colleague
Featured Poster
Beat_Slayer
17
Posting Pro in Training
TrustyTony
888
pyMod
Team Colleague
Featured Poster
Beat_Slayer
17
Posting Pro in Training
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.