-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathweek.py
More file actions
29 lines (21 loc) · 724 Bytes
/
week.py
File metadata and controls
29 lines (21 loc) · 724 Bytes
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
import csv
import time
import os
from datetime import *
def CSV_split_by_week(path: str) -> None:
"""Split dstaset.csv in n files ( 1 file = 1 week)
Args:
path (str): path to file to cut
"""
with open(path, "r", encoding="utf-8", newline="") as file:
reader = csv.reader(file)
for row in reader:
d = datetime.strptime(row[0], "%Y-%m-%d")
with open(os.path.join("3", f"{d.year}-{d.isocalendar().week}.csv"), "a", encoding="utf-8", newline="") as file_N:
writer = csv.writer(file_N)
writer.writerow(row)
print("end")
def main():
CSV_split_by_week(os.path.join("dataset.csv"))
if __name__ == '__main__':
main()