ProfessorLeVesseur
commited on
Update data_processor.py
Browse files- data_processor.py +31 -5
data_processor.py
CHANGED
@@ -55,22 +55,48 @@ class DataProcessor:
|
|
55 |
print(f"Error converting series to datetime: {e}")
|
56 |
return series
|
57 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
58 |
def replace_student_names_with_initials(self, df):
|
59 |
updated_columns = []
|
60 |
for col in df.columns:
|
61 |
-
if
|
62 |
-
|
|
|
|
|
|
|
|
|
63 |
if match:
|
64 |
-
name = match.group(1)
|
65 |
-
|
66 |
-
|
|
|
|
|
|
|
|
|
67 |
else:
|
|
|
68 |
updated_columns.append(col)
|
69 |
else:
|
70 |
updated_columns.append(col)
|
71 |
df.columns = updated_columns
|
72 |
return df
|
73 |
|
|
|
74 |
def find_intervention_column(self, df):
|
75 |
for column in self.INTERVENTION_COLUMN_OPTIONS:
|
76 |
if column in df.columns:
|
|
|
55 |
print(f"Error converting series to datetime: {e}")
|
56 |
return series
|
57 |
|
58 |
+
# def replace_student_names_with_initials(self, df):
|
59 |
+
# updated_columns = []
|
60 |
+
# for col in df.columns:
|
61 |
+
# if col.startswith('Student Attendance'):
|
62 |
+
# match = re.match(r'Student Attendance \[(.+?)\]', col)
|
63 |
+
# if match:
|
64 |
+
# name = match.group(1)
|
65 |
+
# initials = ''.join([part[0] for part in name.split()])
|
66 |
+
# updated_columns.append(f'Student Attendance [{initials}]')
|
67 |
+
# else:
|
68 |
+
# updated_columns.append(col)
|
69 |
+
# else:
|
70 |
+
# updated_columns.append(col)
|
71 |
+
# df.columns = updated_columns
|
72 |
+
# return df
|
73 |
+
|
74 |
def replace_student_names_with_initials(self, df):
|
75 |
updated_columns = []
|
76 |
for col in df.columns:
|
77 |
+
if 'Student Attendance' in col:
|
78 |
+
# Search for the last occurrence of text within square brackets at the end of the string
|
79 |
+
match = re.search(r'\[(.+?)\]$', col)
|
80 |
+
if not match:
|
81 |
+
# Handle cases where the closing bracket might be missing
|
82 |
+
match = re.search(r'\[(.+)$', col)
|
83 |
if match:
|
84 |
+
name = match.group(1).strip()
|
85 |
+
# Remove any trailing closing bracket if it wasn't matched earlier
|
86 |
+
name = name.rstrip(']')
|
87 |
+
# Get initials
|
88 |
+
initials = ''.join([part[0] for part in name.strip().split()])
|
89 |
+
updated_col = f'Student Attendance [{initials}]'
|
90 |
+
updated_columns.append(updated_col)
|
91 |
else:
|
92 |
+
# If no match is found, keep the column name as is
|
93 |
updated_columns.append(col)
|
94 |
else:
|
95 |
updated_columns.append(col)
|
96 |
df.columns = updated_columns
|
97 |
return df
|
98 |
|
99 |
+
|
100 |
def find_intervention_column(self, df):
|
101 |
for column in self.INTERVENTION_COLUMN_OPTIONS:
|
102 |
if column in df.columns:
|