<jupyter_start><jupyter_text>Lecture 8   Categorical Distribution<jupyter_code>top = Table.read_table('top_movies_2017.csv')
top
studios = top.select('Studio')
studios
studio_distribution = studios.group('Studio')
studio_distribution
sum(studio_distribution.column(1))<jupyter_output><empty_output><jupyter_text>Bar Charts<jupyter_code>studio_distribution.barh('Studio')
studio_distribution.sort(1, descending=True).barh(0)<jupyter_output><empty_output><jupyter_text>Numerical Distribution<jupyter_code>ages = 2018 - top.column('Year')
top = top.with_column('Age', ages)
top<jupyter_output><empty_output><jupyter_text>Binning<jupyter_code>[min(ages), max(ages)]
my_bins = make_array(0, 5, 10, 15, 25, 40, 65, 100)
top.bin('Age', bins = my_bins)
sum(top.bin('Age', bins = my_bins).column(1))
top.bin('Age', bins = np.arange(0, 101, 25))
top.bin('Age', bins = np.arange(0, 60, 25))
top.where('Age', 50)<jupyter_output><empty_output><jupyter_text>Histograms<jupyter_code>my_bins
top.bin('Age', bins = my_bins)
top.hist('Age', bins = my_bins, unit = 'Year')
# What *not* to do:
top.hist('Age', bins = my_bins, unit = 'Year', normed = False)
top.hist('Age', bins = my_bins, unit = 'Year')
top.hist('Age', bins = np.arange(0, 110, 10), unit = 'Year')
top.hist('Age', unit='Year')
top.hist('Age', bins = my_bins, unit = 'Year')
distribution = top.bin('Age', bins = my_bins)
distribution
# 52 out of 200 movies in the [40, 65) bin

percent = (52/200) * 100
percent
width = 65 - 40
width
height = percent / width
height
survey = Table.read_table('welcome_survey.csv')
survey.show(5)
survey.hist('Hours of sleep', bins=np.arange(4, 12))
texters = survey.column('Number of texters')
[min(texters), max(texters)]
survey.hist('Number of texters', bins=np.arange(0, 101, 5))
survey.hist('Number of texters', bins=np.arange(0, 41, 2))
survey.hist('Number of texters', bins=np.arange(0, 41, 1))
survey.hist('Extroversion', bins=np.arange(0, 11))
hand_distribution = survey.group('Handedness')
hand_distribution.barh('Handedness')
galton = Table.read_table('galton.csv')

galton
heights = galton.select(3, 7).relabeled(0, 'MidParent').relabeled(1, 'Child')

heights
my_bins = np.arange(55, 80, 2)
heights.hist('Child', bins = my_bins, unit='Inch')
heights.where('Child', are.between(65, 67)).num_rows / heights.num_rows
heights.hist('MidParent', bins=my_bins, unit='inch')
heights.hist(bins=my_bins, unit='inch')<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.17608247422680412, 'fraction_numerical': 0.04164948453608248, 'mean_word_length': 7.452961672473868, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '366116', 'license': 'CC0-1.0', 'n_tokens_mistral': 1077, 'n_tokens_neox': 929, 'n_words': 180, 'path': 'lec/lec08/lec08.ipynb', 'repo_name': 'schoend/tu-fa21', 'size': '2425'}