-
Notifications
You must be signed in to change notification settings - Fork 0
/
enrollmentroster-copy.py
54 lines (43 loc) · 2.44 KB
/
enrollmentroster-copy.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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#!/usr/bin/env python3
# rearranging the 'Enrollment Roster by Program Stack' file from IE for MS Access link
import csv
import pandas as pd
import os
import glob
# Globbing the file extension
file_type = ".txt"
iuieExtract = glob.glob("*" + file_type)
# opening the original file and adding the comma separations
for file in iuieExtract:
with open(file, 'r') as enrollment:
enrollmentstk = csv.reader(enrollment, delimiter='\t')
with open('enrollmentroster.csv', 'w') as newenrollment:
enrollmentwriter = csv.writer(newenrollment, delimiter=',')
for line in enrollmentstk:
enrollmentwriter.writerow(line)
# making sure to convert data types to strings
enrollment = pd.read_csv(r'enrollmentroster.csv', dtype=str)
enrollment.to_csv('enrollmentroster.tsv', index=False, encoding='utf-8', sep='\t')
# selecting the columns from the tsv in order
#enrollment = pd.read_csv(r'enrollmentroster.tsv', dtype=str, sep='\t')
# OR ...
enrollment = pd.read_csv(r'enrollmentroster.tsv', sep='\t', converters={'University ID': lambda x: str(x)}) [['Class Number', 'Subject Area', 'Course Catalog Number', 'Course Description', 'Units Taken',
'Instructor Name', 'Official Grade', 'University ID', 'Preferred Full Name',
'Total Cumulative Units', 'Primary Program Code', 'Enrollment Status Code',
'Local Address Line 1', 'Local Address Line 2', 'Local Address City',
'Local Address State Code', 'Local Address Zip Code', 'Local Address Phone Nbr', 'Home Address Line1', 'Home Address Line2', 'Home Address City', 'Home Address State Code',
'Home Address Zip Code', 'Home Address Phone Nbr', 'Network ID', 'GDS Campus Email Address',
'FERPA Complete Restriction Indicator', 'FERPA Local Address Restriction Indicator',
'FERPA Local Phone Restriction Indicator', 'FERPA Home Address Restriction Indicator',
'FERPA Home Phone Restriction Indicator']]
# renaming the 'Preferred Full Name' to 'Primary Full Name'
enrollment.rename(columns={"Preferred Full Name":"Primary Full Name"}, inplace=True)
#regexxing the comma and adding a space
enrollment['Instructor Name'] = enrollment['Instructor Name'].str.replace(', *', ', ', regex=True)
enrollment['Primary Full Name'] = enrollment['Primary Full Name'].str.replace(', *', ', ', regex=True)
# writing the final tsv text document
enrollment.to_csv('EnrollmentRoster.txt', index=0, sep='\t')
# removing the temp files
os.remove('enrollmentroster.csv')
os.remove('enrollmentroster.tsv')
print('Enrollment Roster Text File Made')