I need to return a list of pairs (datetime.date (x, y, z), the number of times it appears) in a text file with 1000 entries. Function def eventfreq(year, month): takes as parameters the year and month of the previously mentioned datetime.date parameter. So far I have determined the year and month
def eventfreq(year, month): F=fieldict('DOT1000.txt') for line in F: year=F[1].year month=F[1].month
fieldict is a function that returns returns a tuple (Manufacturer, datetime.date (), year, crash, inj) for each record in the file. I only need this to extract the datetime from each record. I am very new to python, I have been working on several of these functions all night.
EDIT: Example Data:
503 958504 GENERAL ENGINES CORP. CHEVROLET LUMINA 1990 19920606 N 0 0 SERVICE BRAKES, HYDRAULIC: FOUNDATION COMPONENTS: DISC: CALIPER DRACUT MA 2G1WN14T9L9 19950110 19950110 PROBLEM CALIPERS FREQUENCY MANUFACTURER. TT EVOQ
This is 1 record 1000. I need advice on creating my list of pairs [(datetime.date (), #of occurrences in the file)]. Year and month are parameters for the function
EDIT: test cases:
>>> evlist = eventfreq(1995,1) >>> len(evlist) 17 >>> evlist[0] (datetime.date(1995, 1, 1), 5) >>> evlist[14] (datetime.date(1995, 1, 15), 1)
EDIT: Another sample entry:
1332 477660 HONDA (AMERICAN HONDA MOTOR CO.) ACURA INTEGRA 1994 19940601 N 0 0 VISIBILITY: WINDSHIELD TUSTIN CA JH4DC4359RS 19950112 19941112 1 ISSUES OF THE WINDOW. * AK VOQ
Bold is the date. I already have a datetime.date format (an imported datetime module), and it is in one place in each record. You need a list containing pairs (datetime.date (year, month, day), the number of times in the same year and month )