forked from python-organizers/conferences
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplit.py
27 lines (22 loc) · 770 Bytes
/
split.py
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
from collections import defaultdict
from pathlib import Path
import pandas as pd
def strip_safely(x):
try:
x = x.rstrip('/')
except AttributeError:
pass
return x
repository_folder = Path(__file__).parents[1]
t = pd.read_csv(repository_folder / 'conferences.csv')
t.dropna(subset=['Subject'], inplace=True)
events_by_year = defaultdict(list)
for i, r in t.iterrows():
year = r['Start Date'].split('-')[0]
events_by_year[year].append(r)
column_names = t.columns
for year, rows in events_by_year.items():
t = pd.DataFrame(rows, columns=column_names)
t = t.applymap(strip_safely)
t.sort_values(['Start Date', 'End Date', 'Subject'], inplace=True)
t.to_csv((repository_folder / year).with_suffix('.csv'), index=False)