-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtask8.py
28 lines (22 loc) · 1.03 KB
/
task8.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
import pandas as pd
import seaborn as sns
data = pd.read_csv("students_data.csv")
g_df = pd.DataFrame(columns=["MG1", "MG2", "MG3", "PG1", "PG2", "PG3"])
df = data.sort_values(["Subject"]).drop(["ID", "Subject", "G1", "G2", "G3", "famrel",
"freetime", "goout", "Dalc", "Walc", "absences", "cheating", "paid"], axis=1)
scores = data[["Subject", "G1", "G2", "G3"]]
duplicates = df[df.duplicated(keep=False)].sort_values(df.columns.to_list())
inds = duplicates.index.to_list()
i = iter(inds)
for _ in range(len(inds)//2):
g_df.loc[len(g_df)] = scores.iloc[i.__next__()].tolist()[
1:] + scores.iloc[i.__next__()].tolist()[1:]
# 8.1
print(f"Оба предмета изучали {len(g_df)} учащихся")
# 8.2
sns.displot(data=g_df, x="PG1", y="MG1", aspect=1,
).figure.savefig("G1_compare")
sns.displot(data=g_df, x="PG2", y="MG2", aspect=1,
).figure.savefig("G2_compare")
sns.displot(data=g_df, x="PG3", y="MG3", aspect=1,
).figure.savefig("G3_compare")