Hole | Wins | Losses | Score | +2 |
---|---|---|---|---|
1 | 43 | 38 | +2 | (-1) |
10 | ||||
Avg | 43 | 38 | +34 |
This appears to be a text file containing the game results for Major League Baseball (MLB) games. Each line represents a single game result in the format:
[Home Team] [Score] [Away Team]
Here's a reformatted version of the data with some additional information extracted from each line, such as the date and stadium:
{
"games": [
{
"date": "June 17, 2022",
"home_team": "Cleveland Indians",
"score": "7-3",
"away_team": "Kansas City Royals"
},
...
]
}
Note that I've used some sample data to generate this example. The actual data would require more processing to extract the necessary information.
Here is a Python script using regular expressions and the pandas
library to parse and clean the text file:
import re
import pandas as pd
def parse_game_result(line):
match = re.match(r"(\w+ \w+) (\d+)-(\d+), (\w+) (\w+)", line)
if match:
return {
"date": None,
"home_team": match.group(1),
"score": f"{match.group(2)}-{match.group(3)}",
"away_team": match.group(4),
}
else:
return None
def main():
with open("game_results.txt", "r") as file:
lines = file.readlines()
data = [parse_game_result(line) for line in lines if parse_game_result(line)]
df = pd.DataFrame(data)
print(df)
if __name__ == "__main__":
main()
This script assumes that the text file is named "game_results.txt" and is located in the same directory as the script. The parse_game_result
function uses regular expressions to extract the necessary information from each line, and the main
function reads the file, parses each line, and creates a pandas DataFrame from the parsed data.
Please note that you'll need to adjust the path to the text file if it's located elsewhere. Updated: July 18, 2025 at 4:17 AM