pigeon/data_processing.py
def facility_proportions(data, fac_type_colname, student_amount_colname, fac_proportions=True):
    """
    Calculate proportions of:
     - facility type in all facilities
     - total students of facility type in all students

     If fac_proportions = True, sort by proportions of facility in all facilities,
     else sort by student proportions.

     """
    all_data = len(data)

    total_students = data[student_amount_colname].sum()

    facilities_type_list = data[fac_type_colname].unique()
    facilities_stats = []

    for facility in facilities_type_list:
        df_filtered = data[data[fac_type_colname] == facility]

        fac_students = df_filtered[student_amount_colname].sum()
        facilities_stats.append(
            {'facility': facility,
             'total': len(df_filtered),
             'proportions': len(df_filtered) / all_data,
             'students': fac_students,
             'students/total_students': fac_students / total_students
             })

    proportions_df = pd.DataFrame.from_dict(facilities_stats)
    proportions_df_sorted = proportions_df.sort_values(
        by=['proportions' if fac_proportions else 'students/total_students'])
    return proportions_df_sorted

    Calculate proportions of:
     - facility type in all facilities
     - total students of facility type in all students

     If fac_proportions = True, sort by proportions of facility in all facilities,
     else sort by student proportions.

     
Calculate proportions of:
facility type in all facilities
total students of facility type in all students

If fac_proportions = True, sort by proportions of facility in all facilities,
else sort by student proportions.
Calculate proportions of : facility type in all facilities total students of facility type in all students If fac_proportions = True sort by proportions of facility in all facilities else sort by student proportions .
def facility_proportions(data, fac_type_colname, student_amount_colname, fac_proportions=True):
    all_data = len(data)
    total_students = data[student_amount_colname].sum()
    facilities_type_list = data[fac_type_colname].unique()
    facilities_stats = []
    for facility in facilities_type_list:
        df_filtered = data[data[fac_type_colname] == facility]
        fac_students = df_filtered[student_amount_colname].sum()
        facilities_stats.append(
            {'facility': facility,
             'total': len(df_filtered),
             'proportions': len(df_filtered) / all_data,
             'students': fac_students,
             'students/total_students': fac_students / total_students
             })
    proportions_df = pd.DataFrame.from_dict(facilities_stats)
    proportions_df_sorted = proportions_df.sort_values(
        by=['proportions' if fac_proportions else 'students/total_students'])
    return proportions_df_sorted
def facility_proportions ( data , fac_type_colname , student_amount_colname , fac_proportions = True ) : all_data = len ( data ) total_students = data [ student_amount_colname ] . sum ( ) facilities_type_list = data [ fac_type_colname ] . unique ( ) facilities_stats = [ ] for facility in facilities_type_list : df_filtered = data [ data [ fac_type_colname ] == facility ] fac_students = df_filtered [ student_amount_colname ] . sum ( ) facilities_stats . append ( { 'facility' : facility , 'total' : len ( df_filtered ) , 'proportions' : len ( df_filtered ) / all_data , 'students' : fac_students , 'students/total_students' : fac_students / total_students } ) proportions_df = pd . DataFrame . from_dict ( facilities_stats ) proportions_df_sorted = proportions_df . sort_values ( by = [ 'proportions' if fac_proportions else 'students/total_students' ] ) return proportions_df_sorted
Calculate proportions of:
 facility type in all facilities
 total students of facility type in all students
Calculate proportions of : facility type in all facilities total students of facility type in all students
"""
    Calculate proportions of:
     - facility type in all facilities
     - total students of facility type in all students

     If fac_proportions = True, sort by proportions of facility in all facilities,
     else sort by student proportions.

     """
data
fac_type_colname
student_amount_colname
fac_proportions