-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathalgorithm.py
36 lines (27 loc) Β· 1003 Bytes
/
algorithm.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
28
29
30
31
32
33
34
35
36
import pandas as pd
def build_dataframe(elements: list, drop=True) -> pd.DataFrame:
frames = []
for element in elements:
frames.append(pd.DataFrame(element).dropna())
df = pd.concat(frames)
df.reset_index(inplace=True, drop=True)
if drop:
df = df.loc[df.Type != "OL-Drop-In"]
return df
def group_names(df: pd.DataFrame) -> pd.DataFrame:
lectures = []
days = ["Monday", "Tuesday", "Wednesday", "Thursday", "Friday"]
for day in days:
i = df.loc[df.Day == day]
lectures.append(
i.groupby(["Day", "Start", "End", "Unit"], as_index=False).agg(
{"Names": " ".join}
)
)
lectures = pd.concat(lectures).reset_index(drop=True)
del df["Names"]
df = df.drop_duplicates(["Day", "Start", "End", "Group", "Building"])
df.Day = pd.Categorical(df.Day, categories=days, ordered=True)
df = df.sort_values("Day").reset_index(drop=True)
df = df.merge(lectures)
return df