May-16-2024, 09:13 AM
(This post was last modified: May-16-2024, 09:13 AM by Pedroski55.)
Must be homework!
I think you will find, people will not answer because they are waiting for you to show some effort, to show what you have tried so far.
Here is a little something to get you started. You can find the other stuff you need in a very similar fashion.
I think you will find, people will not answer because they are waiting for you to show some effort, to show what you have tried so far.
Here is a little something to get you started. You can find the other stuff you need in a very similar fashion.
def myApp(): #! /usr/bin/python3 import re # where is the data? path2data = '/home/pedro/myPython/re/text_files/baseball_data1.txt' # savepath will be csv format, can open in Excel, whatever you call it savepath = '/home/pedro/myPython/re/text_files/SBSMatrix.dat' # your "box data", maybe you have more data files? baseball_data1 = 'baseball_data1.txt' # find the lines with date and game number # # example: date = 05-10-2024 07:24:29 # example: line = '05-10-2024 07:24:29 # 1 ---------------------------------------------------- ' # find the whole thing then split it is easiest pattern1 = re.compile(r'\d\d-\d\d-\d\d\d\d \d\d:\d\d:\d\d # \d+') with open(path2data) as infile, open(savepath, 'w') as output: # groups is a generator will not overtax computer memory, no matter how big the input data is. # search finds the first instance of pattern output.write('date,gamenum\n') groups = (pattern1.search(line) for line in infile) for g in groups: # g can be None when pattern is not found, don't want None lines if g: #print(g[0]) # split on space get a list # date is g[0], game number is g[-1] data = g[0].split() date = data[0] gamenum = data[-1] output.write(f'{date},{gamenum}\n')I would prefer if you used cricket data, I know nothing about baseball!