-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
2788 lines (2285 loc) · 119 KB
/
main.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import pandas as pd
pd.options.mode.chained_assignment = None # default='warn'
import numpy as np
import matplotlib.pyplot as plt
import plotly.express as px
import plotly.io as pio
from warnings import simplefilter # suppresses warning, allows > 100 columns to be created in new dataframe
simplefilter(action="ignore", category=pd.errors.PerformanceWarning)
general_df = pd.read_excel('23-RC-Pub-Data-Set.xlsx', sheet_name='General')
finance_df = pd.read_excel('23-RC-Pub-Data-Set.xlsx', sheet_name='Finance')
ela_math_science_df = pd.read_excel('23-RC-Pub-Data-Set.xlsx',sheet_name='ELA Math Science')
iar_df = pd.read_excel('23-RC-Pub-Data-Set.xlsx', sheet_name='IAR')
iar_2_df = pd.read_excel('23-RC-Pub-Data-Set.xlsx', sheet_name='IAR (2)')
sat_df = pd.read_excel('23-RC-Pub-Data-Set.xlsx', sheet_name='SAT')
isa_df = pd.read_excel('23-RC-Pub-Data-Set.xlsx', sheet_name='ISA')
dlm_aa_df = pd.read_excel('23-RC-Pub-Data-Set.xlsx', sheet_name='DLM-AA')
dlm_aa_2_df = pd.read_excel('23-RC-Pub-Data-Set.xlsx', sheet_name='DLM-AA (2)')
cte_df = pd.read_excel('23-RC-Pub-Data-Set.xlsx', sheet_name='CTE')
teacher_out_to_field_df = pd.read_excel('23-RC-Pub-Data-Set.xlsx', sheet_name='TeacherOutofField')
discipline_df = pd.read_excel('23-RC-Pub-Data-Set.xlsx', sheet_name='Discipline')
# create condensed version of general condensed data sheet
general_condensed_df = pd.DataFrame()
rcdts = general_df.iloc[:,0]
general_condensed_df['RCDTS'] = rcdts.copy()
school_name = general_df.iloc[:,2]
general_condensed_df['School Name'] = school_name.copy() # school name
city = general_df.iloc[:,4]
general_condensed_df['City'] = city.copy() # city
school_type = general_df.iloc[:,8]
general_condensed_df['School Type'] = school_type.copy() # school type
# delete empty rows
def delete_row(df): # find all the non-missing values ONLY
try:
return df[df['School Name'].notna()]
except Exception as e:
print(f'caught {type(e)}: e \n '
f'Cannot delete rows with missing school names')
general_condensed_df = delete_row(general_condensed_df)
general_condensed_df.to_excel('general_condensed.xlsx', index=False)
# create condensed version of discipline data sheet
discipline_condensed_df = pd.DataFrame()
rcdts = discipline_df.iloc[:,0]
discipline_condensed_df['RCDTS'] = rcdts.copy()
school_name = discipline_df.iloc[:,2]
discipline_condensed_df['School Name'] = school_name.copy() # school name
city = discipline_df.iloc[:,4]
discipline_condensed_df['City'] = city.copy() # city
school_type = discipline_df.iloc[:,8]
discipline_condensed_df['School Type'] = school_type.copy() # school type
number_of_discipline_incidents = discipline_df.iloc[:,11]
discipline_condensed_df['# of Discipline Incidents'] = \
number_of_discipline_incidents.copy() # school type
# delete rows with empty cell under School Name
finance_condensed_df = delete_row(discipline_condensed_df)
# discipline condensed excel file xlsx
discipline_condensed_df.to_excel('discipline_condensed.xlsx', index=False)
# sort by alphabetical order
discipline_condensed_df = discipline_condensed_df.sort_values(
by='School Name',
ascending=True
)
discipline_condensed_df.to_excel('discipline_condensed.xlsx', index=False)
# create condensed version of finance data sheet
finance_condensed_df = pd.DataFrame()
rcdts = finance_df.iloc[:,0]
finance_condensed_df['RCDTS'] = rcdts.copy()
school_name = finance_df.iloc[:,2]
finance_condensed_df['School Name'] = school_name.copy() # school name
city = finance_df.iloc[:,4]
finance_condensed_df['City'] = city.copy() # city
school_type = finance_df.iloc[:,8]
finance_condensed_df['School Type'] = school_type.copy() # school type
total_per_pupil_expenditures_subtotal = finance_df.iloc[:,26]
finance_condensed_df['$ Total Per-Pupil Expenditures - Subtotal'] = \
total_per_pupil_expenditures_subtotal.copy() # school name
# finance condensed file
finance_condensed_df.to_excel('finance_condensed.xlsx', index=False)
# delete rows with emtpy cell under School Name
finance_condensed_df = delete_row(finance_condensed_df)
finance_condensed_df.to_excel('finance_condensed.xlsx', index=False)
# lookup name of school, name of school column, $ Total Per-Pupil Expenditures - Subtotal column, false
discipline_finance_condensed_df = pd.merge(
discipline_condensed_df,
finance_condensed_df.iloc[:,4],
left_index=True,
right_index=True,
how='outer'
)
# delete rows with emtpy cell under School Name
discipline_finance_condensed_df = delete_row(discipline_finance_condensed_df)
discipline_finance_condensed_df.to_excel('discipline_finance_condensed.xlsx', index=False)
discipline_finance_condensed_df = discipline_finance_condensed_df.sort_values(
by='$ Total Per-Pupil Expenditures - Subtotal',
ascending=True
)
discipline_finance_condensed_df.to_excel('discipline_finance_condensed.xlsx', index=False)
def incident_numbers_reported(df):
# conversion of non-numeric values to NaN and then filtering rows based on those values
numeric_mask = pd.to_numeric(df['# of Discipline Incidents'],
errors='coerce').notna()
if numeric_mask is None:
raise ValueError
return df[numeric_mask]
incident_numbers_df = incident_numbers_reported(discipline_condensed_df)
incident_numbers_df.to_excel('incident_numbers_reported.xlsx', index=False)
# pivot table - total student incident numbers of each city
total_incident_num_per_city_df = pd.pivot_table(incident_numbers_df,
values='# of Discipline Incidents',
columns='City',
aggfunc='sum'
)
total_incident_num_per_city_df.to_excel('sum_of_incidents_per_city_pivot_table.xlsx')
# pivot table - total student incident numbers per school type
total_incident_num_per_city_df = pd.pivot_table(incident_numbers_df,
values='# of Discipline Incidents',
columns='School Type',
aggfunc='sum'
)
total_incident_num_per_city_df.to_excel('sum_of_incidents_per_school_type_pivot_table.xlsx')
# highlight the lowest number of incidents
def highlight_min(data, color='#1dd7f3'):
'''
highlight the maximum in a Series or DataFrame
'''
attr = 'background-color: {}'.format(color)
if data.ndim == 1: # Series from .apply(axis=0) or axis=1
is_min = data == data.min()
return [attr if v else '' for v in is_min]
else: # from .apply(axis=None)
is_min = data == data.min().min()
return pd.DataFrame(np.where(is_min, attr, ''),
index=data.index, columns=data.columns)
incident_numbers_df = incident_numbers_df.style.apply(highlight_min, subset=['# of Discipline Incidents'])
incident_numbers_df.to_excel('incident_numbers_reported.xlsx', index=False)
# SAT Math Average Score (High Schools only and eventually calculate its averages of each county)
sat_condensed_df = pd.DataFrame()
rcdts = sat_df.iloc[:,0]
sat_condensed_df['RCDTS'] = rcdts.copy()
school_name = sat_df.iloc[:,2]
sat_condensed_df['School Name'] = school_name.copy() # school name
city = sat_df.iloc[:,4]
sat_condensed_df['City'] = city.copy()
county = sat_df.iloc[:,5]
sat_condensed_df['County'] = county.copy()
school_type = sat_df.iloc[:,8]
sat_condensed_df['School Type'] = school_type.copy() # school type
sat_reading_average_score = sat_df.iloc[:,10]
sat_condensed_df['SAT Reading Average Score'] = sat_reading_average_score.copy()
sat_math_average_score = sat_df.iloc[:,11]
sat_condensed_df['SAT Math Average Score'] = sat_math_average_score.copy()
sat_condensed_df.to_excel('sat_condensed.xlsx', index=False)
# filter data to only high schools
sat_condensed_df = sat_condensed_df.loc[(sat_condensed_df['School Type'] == 'HIGH SCHOOL')]
# delete empty rows
def empty_grade_value(df): # removes rows that have at least 1 average score null
try:
return df[df['SAT Reading Average Score'].notna() | df['SAT Math Average Score'].notna()]
except Exception as e:
print(f'caught {type(e)}: e \n '
f'Cannot delete rows with missing SAT Reading Average Score or SAT Math Average Score values')
sat_condensed_df = empty_grade_value(sat_condensed_df)
sat_condensed_df.to_excel('sat_condensed.xlsx', index=False)
# create new columns -> Total Score, Average Score (Total Score / 1600), and Percentage
sat_condensed_df['Total SAT Score'] = sat_condensed_df['SAT Reading Average Score'] + \
sat_condensed_df['SAT Math Average Score']
sat_condensed_df['SAT Score Percentage'] = sat_condensed_df['Total SAT Score'] / 1600
sat_condensed_df['SAT Score Percentage'] = sat_condensed_df['SAT Score Percentage']\
.astype(str)\
.str[2:4]\
+ '%'
sat_condensed_df['SAT Grade Status'] = [''] * len(sat_condensed_df)
sat_condensed_df.to_excel('sat_condensed.xlsx', index=False)
#sat_condensed_df.to_csv('sat_condensed.csv', index=False)
sat_condensed_df.loc[sat_condensed_df['SAT Score Percentage'] == '9%', 'SAT Score Percentage'] = '90%'
sat_condensed_df.loc[sat_condensed_df['SAT Score Percentage'] == '8%', 'SAT Score Percentage'] = '80%'
sat_condensed_df.loc[sat_condensed_df['SAT Score Percentage'] == '7%', 'SAT Score Percentage'] = '70%'
sat_condensed_df.loc[sat_condensed_df['SAT Score Percentage'] == '6%', 'SAT Score Percentage'] = '60%'
sat_condensed_df.loc[sat_condensed_df['SAT Score Percentage'] == '5%', 'SAT Score Percentage'] = '50%'
sat_condensed_df.loc[sat_condensed_df['SAT Score Percentage'] == '4%', 'SAT Score Percentage'] = '40%'
sat_condensed_df.loc[sat_condensed_df['SAT Score Percentage'] == '3%', 'SAT Score Percentage'] = '30%'
sat_condensed_df.loc[sat_condensed_df['SAT Score Percentage'] == '2%', 'SAT Score Percentage'] = '20%'
sat_condensed_df.loc[sat_condensed_df['SAT Score Percentage'] == '1%', 'SAT Score Percentage'] = '10%'
sat_condensed_df.to_excel('sat_condensed.xlsx', index=False)
# values in 'SAT Grade Status' -> Low, Mediocre, Decent, Good, Excellent
status = []
for grade in sat_condensed_df['Total SAT Score']:
try:
if grade >= 1400:
status.append('Excellent')
elif grade >= 1000 and grade < 1400:
status.append('Proficient')
elif grade >= 800 and grade < 1000:
status.append('Decent')
elif grade >= 600 and grade < 800:
status.append('Mediocre')
else:
status.append('Low')
raise ValueError
except:
status.append('Not an appropriate value')
sat_condensed_df['SAT Grade Status'] = status
sat_condensed_df.to_excel('sat_condensed.xlsx', index=False)
# top 5 total sat scores
sat_condensed_top_five_high_total_scores_df = sat_condensed_df['Total SAT Score'].\
sort_values(ascending=False).head()
sat_condensed_top_five_high_total_scores_df.to_excel('sat_condensed_top_five_total_scores.xlsx',
index=False)
# bottom 5 total sat scores
sat_condensed_bot_five_low_total_scores_df = sat_condensed_df['Total SAT Score'].\
sort_values(ascending=False).tail()
sat_condensed_bot_five_low_total_scores_df.to_excel('sat_condensed_bottom_five_total_scores.xlsx',
index=False)
# list of schools with sat grade status = 'excellent'
sat_condensed_excellent_total_scores_df = \
sat_condensed_df.loc[(sat_condensed_df['SAT Grade Status'] == 'Excellent')]
sat_condensed_excellent_total_scores_df.to_excel('sat_condensed_total_scores_excellent.xlsx',
index=False)
# list of schools with sat grade status = 'proficient'
sat_condensed_proficient_total_scores_df = \
sat_condensed_df.loc[(sat_condensed_df['SAT Grade Status'] == 'Proficient')]
sat_condensed_proficient_total_scores_df.to_excel('sat_condensed_total_scores_proficient.xlsx',
index=False)
# list of schools with sat grade status = 'decent'
sat_condensed_decent_total_scores_df = \
sat_condensed_df.loc[(sat_condensed_df['SAT Grade Status'] == 'Decent')]
sat_condensed_decent_total_scores_df.to_excel('sat_condensed_total_scores_decent.xlsx',
index=False)
# list of schools with sat grade status = 'mediocre'
sat_condensed_mediocre_total_scores_df = \
sat_condensed_df.loc[(sat_condensed_df['SAT Grade Status'] == 'Mediocre')]
sat_condensed_mediocre_total_scores_df.to_excel('sat_condensed_total_scores_mediocre.xlsx',
index=False)
# list of schools with sat grade status = 'low'
sat_condensed_low_total_scores_df = \
sat_condensed_df.loc[(sat_condensed_df['SAT Grade Status'] == 'Low')]
sat_condensed_low_total_scores_df.to_excel('sat_condensed_total_scores_low.xlsx',
index=False)
# highlight the highest Total SAT Score value
def highlight_max(data, color='green'):
'''
highlight the maximum in a Series or DataFrame
'''
attr = 'background-color: {}'.format(color)
if data.ndim == 1: # Series from .apply(axis=0) or axis=1
is_max = data == data.max()
return [attr if v else '' for v in is_max]
else: # from .apply(axis=None)
is_max = data == data.max().max()
return pd.DataFrame(np.where(is_max, attr, ''),
index=data.index, columns=data.columns)
sat_condensed_highlight_max_total_sat_score_value_df = sat_condensed_df.style.apply(
highlight_max,
subset=['Total SAT Score']
)
sat_condensed_highlight_max_total_sat_score_value_df.to_excel(
'sat_condensed_highlighted_top_total_score.xlsx',
index=False
)
# create pivot table with SAT score average per county
sat_condensed_avg_score_per_county_pivot_table = pd.pivot_table(
sat_condensed_df,
index='City',
columns='County',
values='Total SAT Score',
aggfunc='mean'
)
sat_condensed_avg_score_per_county_pivot_table.to_excel('sat_condensed_avg_score_per_county_pivot_table.xlsx')
'''
# creating a bar chart of total SAT scores per county
file = pd.read_excel('sat_condensed.xlsx')
x_axis = file['County']
y_axis = file['Total SAT Score']
plt.bar(x_axis, y_axis, width=5)
plt.xlabel("County")
plt.ylabel("Total SAT Score Per County")
plt.show()
'''
'''
# creating a pie chart of total SAT scores per county
fig = px.bar(sat_condensed_df, x='County', y='Total SAT Score', title='Total SAT Score Per County')
# set the border and background color of the chart area
fig.update_layout(
plot_bgcolor='white',
paper_bgcolor='lightgray',
width=800,
height=500,
shapes=[dict(type='rect', xref='paper',
yref='paper',
x0=0,
y0=0,
x1=1,
y1=1,
line=dict(
color='black',
width=2,
),
)
]
)
#display the graph
fig.show()
# Alternatively you can save the bar graph to an image using below line of code
pio.write_image(fig, 'bar_graph.png')
'''
# isa proficiency
isa_condensed_df = pd.DataFrame()
rcdts = isa_df.iloc[:,0]
isa_condensed_df['RCDTS'] = rcdts.copy()
school_name = isa_df.iloc[:,2]
isa_condensed_df['School Name'] = school_name.copy() # school name
city = isa_df.iloc[:,4]
isa_condensed_df['City'] = city.copy()
county = isa_df.iloc[:,5]
isa_condensed_df['County'] = county.copy()
district_size = isa_df.iloc[:,7]
isa_condensed_df['District Size'] = district_size.copy()
school_type = isa_df.iloc[:,8]
isa_condensed_df['School Type'] = school_type.copy()
isa_proficiency_total_student = isa_df.iloc[:,10]
isa_condensed_df['# ISA Proficiency Total Student'] = isa_proficiency_total_student.copy()
isa_proficiency_male = isa_df.iloc[:,11]
isa_condensed_df['# ISA Proficiency - Male'] = isa_proficiency_male.copy()
isa_proficiency_female = isa_df.iloc[:,12]
isa_condensed_df['# ISA Proficiency - Female'] = isa_proficiency_female.copy()
isa_proficiency_white = isa_df.iloc[:,13]
isa_condensed_df['# ISA Proficiency - White'] = isa_proficiency_white.copy()
isa_proficiency_black_or_african_american = isa_df.iloc[:,14]
isa_condensed_df['# ISA Proficiency - Black or African American'] = \
isa_proficiency_black_or_african_american.copy()
isa_proficiency_hispanic_or_latino = isa_df.iloc[:,15]
isa_condensed_df['# ISA Proficiency - Hispanic or Latino'] = \
isa_proficiency_hispanic_or_latino.copy()
isa_proficiency_asian = isa_df.iloc[:,16]
isa_condensed_df['# ISA Proficiency - Asian'] = isa_proficiency_asian.copy()
isa_proficiency_native_hawaiian_or_other_pacific_islander = isa_df.iloc[:,17]
isa_condensed_df['# ISA Proficiency - Native Hawaiian or Other Pacific Islander'] = \
isa_proficiency_native_hawaiian_or_other_pacific_islander.copy()
isa_proficiency_american_indian_or_alaska_native = isa_df.iloc[:,18]
isa_condensed_df['# ISA Proficiency - American Indian or Alaska Native'] = \
isa_proficiency_american_indian_or_alaska_native.copy()
isa_proficiency_two_or_more_races = isa_df.iloc[:,19]
isa_condensed_df['# ISA Proficiency - Two or More Races'] = isa_proficiency_two_or_more_races.copy()
isa_proficiency_children_with_disabilities = isa_df.iloc[:,20]
isa_condensed_df['# ISA Proficiency - Children with Disabilities'] = \
isa_proficiency_children_with_disabilities.copy()
isa_condensed_df.to_excel('isa_condensed.xlsx', index=False)
# if school name AND proficiency values for total student, male, and female are blank for each column, REMOVE row
def grab_isa_gender_data(df): # find all the non-missing values ONLY
try:
return df[df['School Name'].notna() &
df['# ISA Proficiency Total Student'].notna() &
df['# ISA Proficiency - Male'].notna() &
df['# ISA Proficiency - Female'].notna()]
except Exception as e:
print(f'caught {type(e)}: e \n '
f'Cannot delete certain rows within grab_isa_gender_data().')
# delete rows with empty cell under proficiency columns in grab_isa_gender_data()
isa_condensed_gender_df = grab_isa_gender_data(isa_condensed_df)
# create updated version of isa condensed gender (male/female) data
isa_condensed_gender_df.to_excel('isa_condensed_gender_data.xlsx', index=False)
# if the # isa proficiency values of white students is blank, remove row
def grab_isa_white_students_data(df): # find all the non-missing values ONLY
try:
return df[df['# ISA Proficiency - White'].notna()]
except Exception as e:
print(f'caught {type(e)}: e \n '
f'Cannot delete rows with missing data within grab_isa_white_students_data()')
# delete rows with empty cell under proficiency columns in grab_isa_white_students_data()
isa_condensed_white_students_data_df = grab_isa_white_students_data(isa_condensed_gender_df)
# create updated version of isa condensed white students data
isa_condensed_white_students_data_df.to_excel('isa_condensed_white_students_data.xlsx', index=False)
# drop # isa columns that are not relative to black students in the dataframe
isa_condensed_white_students_data_df = isa_condensed_white_students_data_df.\
drop(['# ISA Proficiency - Black or African American',
'# ISA Proficiency - Hispanic or Latino',
'# ISA Proficiency - Asian',
'# ISA Proficiency - Native Hawaiian or Other Pacific Islander',
'# ISA Proficiency - American Indian or Alaska Native',
'# ISA Proficiency - Two or More Races',
'# ISA Proficiency - Children with Disabilities'],
axis=1)
isa_condensed_white_students_data_df.to_excel('isa_condensed_white_students_data.xlsx', index=False)
# add percentage column to dataframe
isa_condensed_white_students_data_df['White Students %'] =\
isa_condensed_white_students_data_df['# ISA Proficiency - White'] / \
isa_condensed_white_students_data_df['# ISA Proficiency Total Student']
isa_condensed_white_students_data_df.to_excel('isa_condensed_white_students_data.xlsx', index=False)
# if the # isa proficiency values of black students is blank, remove row
def grab_isa_black_students_data(df): # find all the non-missing values ONLY
try:
return df[df['# ISA Proficiency - Black or African American'].notna()]
except Exception as e:
print(f'caught {type(e)}: e \n '
f'Cannot delete rows with missing data within grab_isa_black_students_data()')
# delete rows with empty cell under proficiency columns in grab_isa_black_students_data()
isa_condensed_black_students_data_df = grab_isa_black_students_data(isa_condensed_gender_df)
# create updated version of isa condensed black students data
isa_condensed_black_students_data_df.to_excel('isa_condensed_black_students_data.xlsx', index=False)
# drop # isa columns that are not relative to black students in the dataframe
isa_condensed_black_students_data_df = isa_condensed_black_students_data_df.\
drop(['# ISA Proficiency - White',
'# ISA Proficiency - Hispanic or Latino',
'# ISA Proficiency - Asian',
'# ISA Proficiency - Native Hawaiian or Other Pacific Islander',
'# ISA Proficiency - American Indian or Alaska Native',
'# ISA Proficiency - Two or More Races',
'# ISA Proficiency - Children with Disabilities'],
axis=1)
isa_condensed_black_students_data_df.to_excel('isa_condensed_black_students_data.xlsx', index=False)
# add percentage column to dataframe
isa_condensed_black_students_data_df['Black or African American Students %'] =\
isa_condensed_black_students_data_df['# ISA Proficiency - Black or African American'] / \
isa_condensed_black_students_data_df['# ISA Proficiency Total Student']
isa_condensed_black_students_data_df.to_excel('isa_condensed_black_students_data.xlsx', index=False)
# if the # isa proficiency values of hispanic students is blank, remove row
def grab_isa_hispanic_students_data(df): # find all the non-missing values ONLY
try:
return df[df['# ISA Proficiency - Hispanic or Latino'].notna()]
except Exception as e:
print(f'caught {type(e)}: e \n '
f'Cannot delete rows with missing data within grab_isa_hispanic_students_data()')
# delete rows with empty cell under proficiency columns in grab_isa_hispanic_students_data()
isa_condensed_hispanic_students_data_df = grab_isa_hispanic_students_data(isa_condensed_gender_df)
# create updated version of isa condensed hispanic students data
isa_condensed_hispanic_students_data_df.to_excel('isa_condensed_hispanic_students_data.xlsx',
index=False)
# drop # isa columns that are not relative to hispanic students in the dataframe
isa_condensed_hispanic_students_data_df = isa_condensed_hispanic_students_data_df.\
drop(['# ISA Proficiency - White',
'# ISA Proficiency - Black or African American',
'# ISA Proficiency - Asian',
'# ISA Proficiency - Native Hawaiian or Other Pacific Islander',
'# ISA Proficiency - American Indian or Alaska Native',
'# ISA Proficiency - Two or More Races',
'# ISA Proficiency - Children with Disabilities'],
axis=1)
isa_condensed_hispanic_students_data_df.to_excel('isa_condensed_hispanic_students_data.xlsx',
index=False)
# add percentage column to dataframe
isa_condensed_hispanic_students_data_df['Hispanic Students %'] =\
isa_condensed_hispanic_students_data_df['# ISA Proficiency - Hispanic or Latino'] / \
isa_condensed_hispanic_students_data_df['# ISA Proficiency Total Student']
isa_condensed_hispanic_students_data_df.to_excel('isa_condensed_hispanic_students_data.xlsx', index=False)
# if the # isa proficiency values of asian students is blank, remove row
def grab_isa_asian_students_data(df): # find all the non-missing values ONLY
try:
return df[df['# ISA Proficiency - Asian'].notna()]
except Exception as e:
print(f'caught {type(e)}: e \n '
f'Cannot delete rows with missing data within grab_isa_asian_students_data()')
# delete rows with empty cell under proficiency columns in grab_isa_asian_students_data()
isa_condensed_asian_students_data_df = grab_isa_asian_students_data(isa_condensed_gender_df)
# create updated version of isa condensed asian students data
isa_condensed_asian_students_data_df.to_excel('isa_condensed_asian_students_data.xlsx', index=False)
# drop # isa columns that are not relative to asian students in the dataframe
isa_condensed_asian_students_data_df = isa_condensed_asian_students_data_df.\
drop(['# ISA Proficiency - White',
'# ISA Proficiency - Black or African American',
'# ISA Proficiency - Hispanic or Latino',
'# ISA Proficiency - Native Hawaiian or Other Pacific Islander',
'# ISA Proficiency - American Indian or Alaska Native',
'# ISA Proficiency - Two or More Races',
'# ISA Proficiency - Children with Disabilities'],
axis=1)
isa_condensed_asian_students_data_df.to_excel('isa_condensed_asian_students_data.xlsx',
index=False)
# add percentage column to dataframe
isa_condensed_asian_students_data_df['Asian Students %'] =\
isa_condensed_asian_students_data_df['# ISA Proficiency - Asian'] / \
isa_condensed_asian_students_data_df['# ISA Proficiency Total Student']
isa_condensed_asian_students_data_df.to_excel('isa_condensed_asian_students_data.xlsx', index=False)
# if the # isa proficiency values of hawaiian and other pacific islander students is blank, remove row
def grab_isa_pacific_islander_students_data(df): # find all the non-missing values ONLY
try:
return df[df['# ISA Proficiency - Native Hawaiian or Other Pacific Islander'].notna()]
except Exception as e:
print(f'caught {type(e)}: e \n '
f'Cannot delete rows with missing data within grab_isa_pacific_islander_students_data()')
# delete rows with empty cell under proficiency columns in grab_isa_pacific_islander_students_data()
isa_condensed_pacific_islander_students_data_df = \
grab_isa_pacific_islander_students_data(isa_condensed_gender_df)
# create updated version of isa condensed hawaiian and other pacific islander students data
isa_condensed_pacific_islander_students_data_df.to_excel\
('isa_condensed_pacific_islander_students_data.xlsx', index=False)
# drop # isa columns that are not relative to hawaiian and other pacific islander students in the dataframe
isa_condensed_pacific_islander_students_data_df = isa_condensed_pacific_islander_students_data_df.\
drop(['# ISA Proficiency - White',
'# ISA Proficiency - Black or African American',
'# ISA Proficiency - Hispanic or Latino',
'# ISA Proficiency - Asian',
'# ISA Proficiency - American Indian or Alaska Native',
'# ISA Proficiency - Two or More Races',
'# ISA Proficiency - Children with Disabilities'],
axis=1)
isa_condensed_pacific_islander_students_data_df.to_excel('isa_condensed_pacific_islander_students_data.xlsx',
index=False)
# add percentage column to dataframe
isa_condensed_pacific_islander_students_data_df['Native Hawaiian or Other Pacific Islander Students %'] =\
isa_condensed_pacific_islander_students_data_df['# ISA Proficiency - Native Hawaiian or Other Pacific Islander'] / \
isa_condensed_pacific_islander_students_data_df['# ISA Proficiency Total Student']
isa_condensed_pacific_islander_students_data_df.to_excel('isa_condensed_pacific_islander_students_data.xlsx',
index=False)
# if the # isa proficiency values of alaska or american indian students is blank, remove row
def grab_isa_american_indian_or_alaska_native_students_data(df): # find all the non-missing values ONLY
try:
return df[df['# ISA Proficiency - American Indian or Alaska Native'].notna()]
except Exception as e:
print(f'caught {type(e)}: e \n '
f'Cannot delete rows with missing data within '
f'grab_isa_american_indian_or_alaska_native_students_data()')
# delete rows with empty cell under proficiency columns in grab_isa_american_indian_or_alaska_native_students_data()
isa_condensed_american_indian_or_alaska_native_students_data_df = \
grab_isa_american_indian_or_alaska_native_students_data(isa_condensed_gender_df)
# create updated version of isa condensed alaska or american indian students data
isa_condensed_american_indian_or_alaska_native_students_data_df.to_excel\
('isa_condensed_american_indian_or_alaska_native_students_data.xlsx', index=False)
# drop # isa columns that are not relative to american indian or alaska native students in the dataframe
isa_condensed_american_indian_or_alaska_native_students_data_df = \
isa_condensed_american_indian_or_alaska_native_students_data_df.\
drop(['# ISA Proficiency - White',
'# ISA Proficiency - Black or African American',
'# ISA Proficiency - Hispanic or Latino',
'# ISA Proficiency - Asian',
'# ISA Proficiency - Native Hawaiian or Other Pacific Islander',
'# ISA Proficiency - Two or More Races',
'# ISA Proficiency - Children with Disabilities'],
axis=1)
isa_condensed_american_indian_or_alaska_native_students_data_df.\
to_excel('isa_condensed_american_indian_or_alaska_native_students_data.xlsx', index=False)
# add percentage column to dataframe
isa_condensed_american_indian_or_alaska_native_students_data_df['American Indian or Alaska Native Students %'] =\
isa_condensed_american_indian_or_alaska_native_students_data_df['# ISA Proficiency - American Indian or Alaska Native'] / \
isa_condensed_american_indian_or_alaska_native_students_data_df['# ISA Proficiency Total Student']
isa_condensed_american_indian_or_alaska_native_students_data_df.\
to_excel('isa_condensed_american_indian_or_alaska_native_students_data.xlsx',index=False)
# if the # isa proficiency values of multiracial students is blank, remove row
def grab_isa_multiracial_students_data(df): # find all the non-missing values ONLY
try:
return df[df['# ISA Proficiency - Two or More Races'].notna()]
except Exception as e:
print(f'caught {type(e)}: e \n '
f'Cannot delete rows with missing data within grab_isa_multiracial_students_data()')
# delete rows with empty cell under proficiency columns in grab_isa_multiracial_students_data()
isa_condensed_multiracial_students_data_df = \
grab_isa_multiracial_students_data(isa_condensed_gender_df)
# create updated version of isa condensed multiracial students data
isa_condensed_multiracial_students_data_df.to_excel\
('isa_condensed_multiracial_students_data.xlsx', index=False)
# drop # isa columns that are not relative to multiracial students in the dataframe
isa_condensed_multiracial_students_data_df = \
isa_condensed_multiracial_students_data_df.\
drop(['# ISA Proficiency - White',
'# ISA Proficiency - Black or African American',
'# ISA Proficiency - Hispanic or Latino',
'# ISA Proficiency - Asian',
'# ISA Proficiency - Native Hawaiian or Other Pacific Islander',
'# ISA Proficiency - American Indian or Alaska Native',
'# ISA Proficiency - Children with Disabilities'],
axis=1)
isa_condensed_multiracial_students_data_df.\
to_excel('isa_condensed_multiracial_students_data.xlsx', index=False)
# add percentage column to dataframe
isa_condensed_multiracial_students_data_df['Two or More Races (Multiracial) Students %'] =\
isa_condensed_multiracial_students_data_df['# ISA Proficiency - Two or More Races'] / \
isa_condensed_multiracial_students_data_df['# ISA Proficiency Total Student']
isa_condensed_multiracial_students_data_df.\
to_excel('isa_condensed_multiracial_students_data.xlsx',index=False)
# if the # isa proficiency values of children with disabilities students is blank, remove row
def grab_isa_children_with_disabilities_data(df): # find all the non-missing values ONLY
try:
return df[df['# ISA Proficiency - Children with Disabilities'].notna()]
except Exception as e:
print(f'caught {type(e)}: e \n '
f'Cannot delete rows with missing data within grab_isa_children_with_disabilities_data()')
# delete rows with empty cell under proficiency columns in grab_isa_children_with_disabilities_data()
isa_condensed_children_with_disabilities_data_df = \
grab_isa_children_with_disabilities_data(isa_condensed_gender_df)
# create updated version of isa condensed children with disabilities students data
isa_condensed_children_with_disabilities_data_df.to_excel\
('isa_condensed_children_with_disabilities_data.xlsx', index=False)
# drop # isa columns that are not relative to children with disabilities students in the dataframe
isa_condensed_children_with_disabilities_data_df = \
isa_condensed_children_with_disabilities_data_df.\
drop(['# ISA Proficiency - White',
'# ISA Proficiency - Black or African American',
'# ISA Proficiency - Hispanic or Latino',
'# ISA Proficiency - Asian',
'# ISA Proficiency - Native Hawaiian or Other Pacific Islander',
'# ISA Proficiency - American Indian or Alaska Native',
'# ISA Proficiency - Two or More Races'],
axis=1)
isa_condensed_children_with_disabilities_data_df.\
to_excel('isa_condensed_children_with_disabilities_data.xlsx', index=False)
# add percentage column to dataframe
isa_condensed_children_with_disabilities_data_df['Children with Disabilities Students %'] =\
isa_condensed_children_with_disabilities_data_df['# ISA Proficiency - Children with Disabilities'] / \
isa_condensed_children_with_disabilities_data_df['# ISA Proficiency Total Student']
isa_condensed_children_with_disabilities_data_df.\
to_excel('isa_condensed_children_with_disabilities_data.xlsx',index=False)
# isa white students pivot table
isa_condensed_white_students_pivot_table = pd.pivot_table(
isa_condensed_white_students_data_df,
index='City',
columns='County',
values='# ISA Proficiency - White',
aggfunc='sum'
)
# isa white students pivot table
isa_condensed_white_students_pivot_table.\
to_excel('isa_condensed_white_student_num_pivot_table.xlsx')
# isa white students percentage pivot table
isa_condensed_white_students_school_percentage_pivot_table = pd.pivot_table(
isa_condensed_white_students_data_df,
index='School Name',
columns='City',
values='White Students %',
aggfunc='sum'
)
# isa white students percentage pivot table
isa_condensed_white_students_school_percentage_pivot_table.\
to_excel('isa_condensed_white_student_school_percentage_num_pivot_table.xlsx')
# isa black students pivot table
isa_condensed_black_students_pivot_table = pd.pivot_table(
isa_condensed_black_students_data_df,
index='City',
columns='County',
values='# ISA Proficiency - Black or African American',
aggfunc='sum'
)
# isa black students pivot table
isa_condensed_black_students_pivot_table.to_excel('isa_condensed_black_student_num_pivot_table.xlsx')
# isa black students percentage pivot table
isa_condensed_black_students_school_percentage_pivot_table = pd.pivot_table(
isa_condensed_black_students_data_df,
index='School Name',
columns='City',
values='Black or African American Students %',
aggfunc='sum'
)
# isa black students percentage pivot table
isa_condensed_black_students_school_percentage_pivot_table.\
to_excel('isa_condensed_black_student_school_percentage_num_pivot_table.xlsx')
# isa hispanic students pivot table
isa_condensed_hispanic_students_pivot_table = pd.pivot_table(
isa_condensed_hispanic_students_data_df,
index='City',
columns='County',
values='# ISA Proficiency - Hispanic or Latino',
aggfunc='sum'
)
# isa hispanic students pivot table
isa_condensed_hispanic_students_pivot_table.to_excel('isa_condensed_hispanic_student_num_pivot_table.xlsx')
# isa hispanic students pivot table
isa_condensed_hispanic_students_pivot_table = pd.pivot_table(
isa_condensed_hispanic_students_data_df,
index='City',
columns='County',
values='# ISA Proficiency - Hispanic or Latino',
aggfunc='sum'
)
# isa hispanic students pivot table
isa_condensed_hispanic_students_pivot_table.to_excel('isa_condensed_hispanic_student_num_pivot_table.xlsx')
# isa hispanic students percentage pivot table
isa_condensed_hispanic_students_school_percentage_pivot_table = pd.pivot_table(
isa_condensed_hispanic_students_data_df,
index='School Name',
columns='City',
values='Hispanic Students %',
aggfunc='sum'
)
# isa hispanic students percentage pivot table
isa_condensed_hispanic_students_school_percentage_pivot_table.\
to_excel('isa_condensed_hispanic_student_school_percentage_num_pivot_table.xlsx')
# isa asian students pivot table
isa_condensed_asian_students_pivot_table = pd.pivot_table(
isa_condensed_asian_students_data_df,
index='City',
columns='County',
values='# ISA Proficiency - Asian',
aggfunc='sum'
)
# isa asian students pivot table
isa_condensed_asian_students_pivot_table.to_excel('isa_condensed_asian_student_num_pivot_table.xlsx')
# isa asian students percentage pivot table
isa_condensed_asian_students_school_percentage_pivot_table = pd.pivot_table(
isa_condensed_asian_students_data_df,
index='School Name',
columns='City',
values='Asian Students %',
aggfunc='sum'
)
# isa asian students percentage pivot table
isa_condensed_asian_students_school_percentage_pivot_table.\
to_excel('isa_condensed_asian_student_school_percentage_num_pivot_table.xlsx')
# isa pacific islander students pivot table
isa_condensed_pacific_islander_students_pivot_table = pd.pivot_table(
isa_condensed_pacific_islander_students_data_df,
index='City',
columns='County',
values='# ISA Proficiency - Native Hawaiian or Other Pacific Islander',
aggfunc='sum'
)
# isa pacific islander students pivot table
isa_condensed_pacific_islander_students_pivot_table.\
to_excel('isa_condensed_pacific_islander_student_num_pivot_table.xlsx')
# isa pacific islander students percentage pivot table
isa_condensed_pacific_islander_students_school_percentage_pivot_table = pd.pivot_table(
isa_condensed_pacific_islander_students_data_df,
index='School Name',
columns='City',
values='Native Hawaiian or Other Pacific Islander Students %',
aggfunc='sum'
)
# isa pacific islander students percentage pivot table
isa_condensed_pacific_islander_students_school_percentage_pivot_table.\
to_excel('isa_condensed_pacific_islander_student_school_percentage_num_pivot_table.xlsx')
# isa american indian or alaska native students pivot table
isa_condensed_american_indian_or_alaska_native_students_pivot_table = pd.pivot_table(
isa_condensed_american_indian_or_alaska_native_students_data_df,
index='City',
columns='County',
values='# ISA Proficiency - American Indian or Alaska Native',
aggfunc='sum'
)
# isa american indian or alaska native students pivot table
isa_condensed_american_indian_or_alaska_native_students_pivot_table\
.to_excel('isa_condensed_american_indian_or_alaska_native_student_num_pivot_table.xlsx')
# isa american indian or alaska native students percentage pivot table
isa_condensed_american_indian_or_alaska_native_students_school_percentage_pivot_table = pd.pivot_table(
isa_condensed_american_indian_or_alaska_native_students_data_df,
index='School Name',
columns='City',
values='American Indian or Alaska Native Students %',
aggfunc='sum'
)
# isa american indian or alaska native students percentage pivot table
isa_condensed_american_indian_or_alaska_native_students_school_percentage_pivot_table.\
to_excel('isa_condensed_american_indian_or_alaska_native_student_school_percentage_num_pivot_table.xlsx')
# isa multiracial students pivot table
isa_condensed_multiracial_students_pivot_table= pd.pivot_table(
isa_condensed_multiracial_students_data_df,
index='City',
columns='County',
values='# ISA Proficiency - Two or More Races',
aggfunc='sum'
)
# isa multiracial students pivot table
isa_condensed_multiracial_students_pivot_table\
.to_excel('isa_condensed_multiracial_student_num_pivot_table.xlsx')
# isa multiracial students percentage pivot table
isa_condensed_multiracial_students_school_percentage_pivot_table = pd.pivot_table(
isa_condensed_multiracial_students_data_df,
index='School Name',
columns='City',
values='Two or More Races (Multiracial) Students %',
aggfunc='sum'
)
# isa multiracial students percentage pivot table
isa_condensed_multiracial_students_school_percentage_pivot_table.\
to_excel('isa_condensed_multiracial_student_school_percentage_num_pivot_table.xlsx')
# isa children with disabilities pivot table
isa_condensed_children_with_disabilities_pivot_table = pd.pivot_table(
isa_condensed_children_with_disabilities_data_df,
index='City',
columns='County',
values='# ISA Proficiency - Children with Disabilities',
aggfunc='sum'
)
# children with disabilities pivot table
isa_condensed_children_with_disabilities_pivot_table\
.to_excel('isa_condensed_children_with_disabilities_num_pivot_table.xlsx')
# isa students children with disabilities percentage pivot table
isa_condensed_children_with_disabilities_school_percentage_pivot_table = pd.pivot_table(
isa_condensed_children_with_disabilities_data_df,
index='School Name',
columns='City',
values='Children with Disabilities Students %',
aggfunc='sum'
)
# isa students with disabilities percentage pivot table
isa_condensed_children_with_disabilities_school_percentage_pivot_table.\
to_excel('isa_condensed_children_with_disabilities_percentage_num_pivot_table.xlsx')
# concat isa white and black student pivot tables via keys
isa_pivot_table_white_and_black_student_frames = \
[
isa_condensed_white_students_pivot_table,
isa_condensed_black_students_pivot_table
]
isa_pivot_table_white_and_black_student_concat = pd.concat(
isa_pivot_table_white_and_black_student_frames,
keys=['White Students','Black Students']
)
isa_pivot_table_white_and_black_student_concat.\
to_excel('pivot_table_white_and_black_student_concat.xlsx')
# concat all isa students (race only) pivot tables via keys
isa_pivot_table_all_races_frames = \
[
isa_condensed_white_students_pivot_table,
isa_condensed_black_students_pivot_table,
isa_condensed_hispanic_students_pivot_table,
isa_condensed_asian_students_pivot_table,
isa_condensed_pacific_islander_students_pivot_table,
isa_condensed_american_indian_or_alaska_native_students_pivot_table,
isa_condensed_multiracial_students_pivot_table,
]
isa_pivot_table_all_races_concat = pd.concat(
isa_pivot_table_all_races_frames,
keys=[
'White Students',
'Black Students',
'Hispanic or Latino Students',
'Asian Students',
'Native Hawaiian or Other Pacific Islander Students',
'American Indian or Alaska Native Students',
'Two or More Races Students'
]
)
isa_pivot_table_all_races_concat.to_excel('isa_pivot_table_all_races_concat.xlsx')
# creating a bar chart of isa proficiency pertaining to white students per school
file = pd.read_excel('isa_condensed_white_students_data.xlsx')
x_axis = file['# ISA Proficiency - White']
y_axis = file['# ISA Proficiency Total Student']
plt.bar(x_axis, y_axis, width=5)
plt.xlabel("White Students Per School")
plt.ylabel("# ISA Proficiency Total Student")
plt.show()
# creating a bar chart of isa proficiency pertaining to black students per school
file = pd.read_excel('isa_condensed_black_students_data.xlsx')
x_axis = file['# ISA Proficiency - Black or African American']
y_axis = file['# ISA Proficiency Total Student']