-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathconvert_excel_to_csv.py
More file actions
47 lines (38 loc) · 1.26 KB
/
Copy pathconvert_excel_to_csv.py
File metadata and controls
47 lines (38 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/usr/bin/env python3
"""
@Filename: convert_excel_to_csv.py
@Author: dulanj
@Time: 02/04/2022 11:24
"""
import os
import pandas as pd
excel_filepath = "/home/dulanj/Documents/LSR Annotations Clean.xlsx"
total_events = {
"scrum": 0,
"ruck": 0,
"lineout": 0
}
output_dir = "match_csv_files"
def main():
if not os.path.exists(output_dir):
os.makedirs(output_dir)
for match_id in range(1, 60):
try:
df = pd.read_excel(excel_filepath, sheet_name=f"M{match_id}")
except ValueError:
print("No sheet named {}".format(match_id))
continue
output_csv = f"{output_dir}/match#{match_id}.csv"
try:
for event in ["scrum", "ruck", "lineout"]:
_count = df[df["Activity"] == event].count()["Activity"]
print(f"{event}: {_count}")
total_events[event] += _count
except KeyError:
print(f"Match {match_id} has no events")
break
df.to_csv(output_csv, index=False, header=False)
print("Converted match#{} to csv - {}\n".format(match_id, output_csv))
print(f"Total events: {' '.join([f'{key} - {val}' for key, val in total_events.items()])}")
if __name__ == '__main__':
main()