<jupyter_start><jupyter_text>Frequency Distribution **A teacher collected all students' grades in the final exam of a mathematics course.****The teacher would like to tabulate the data in order to extract insights and understand how the data is organized.****Create a frequency distribution to help the teacher.**<jupyter_code>import pandas as pd
studentsGrades = [92, 81, 100, 92, 71, 73, 100, 92, 84, 100, 73, 92, 73, 84, 92, 92, 92, 84, 73, 100]
len(studentsGrades)<jupyter_output><empty_output><jupyter_text>Solution with Pandas Series **Serie with grades and frequencies**<jupyter_code>pdSerie = pd.Series(studentsGrades).value_counts().reset_index().sort_values('index').reset_index(drop = True)
pdSerie.columns = ['grade', 'frequency']
pdSerie<jupyter_output><empty_output><jupyter_text>**Serie with grades and frequencies, changing the number of classes**<jupyter_code>pdSerie = pd.Series(studentsGrades).value_counts(bins = 3).reset_index().sort_values('index').reset_index(drop = True)
pdSerie.columns = ['grade', 'frequency']
pdSerie<jupyter_output><empty_output><jupyter_text>Solution with Pandas Dataframes **Simple/Absolute Frequency Distribution (fi)*****The number of occurrences for each class.***<jupyter_code>pdDataframe = pd.value_counts(studentsGrades).to_frame(name = 'fi').rename_axis('grade').sort_index()
pdDataframe<jupyter_output><empty_output><jupyter_text>**Simple Relative Frequency Distribution (fri)*****The percentage value of occurrences for each class.***<jupyter_code>pdDataframe['fri'] = pd.value_counts(studentsGrades) / len(studentsGrades)
pdDataframe<jupyter_output><empty_output><jupyter_text>**Accumulated Frequency Distribution (Fi)*****The number of occurrences for each class, plus the occurrences number of the previous classes.***<jupyter_code>pdDataframe['Fi'] = pdDataframe.fi.cumsum()
pdDataframe<jupyter_output><empty_output><jupyter_text>**Accumulated Relative Frequency Distribution (Fri)*****The percentage value of occurrences for each class, plus the percentage values of the previous classes.***<jupyter_code>pdDataframe['Fri'] = pdDataframe.fi.cumsum() / len(studentsGrades)
pdDataframe<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12373505059797608, 'fraction_numerical': 0.020699172033118676, 'mean_word_length': 9.163551401869158, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 29, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 3, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '75897', 'license': 'MIT', 'n_tokens_mistral': 742, 'n_tokens_neox': 667, 'n_words': 168, 'path': 'modules/03-data-analysis-statistics/01-frequency-distribution.ipynb', 'repo_name': 'cfascina/rtaps', 'size': '2174'}