<jupyter_start><jupyter_text>UMSI Office Hours Preference (In-person vs Remote)This notebook of faux vote counts provides a gentle introduction to both the Pandas and Altair libraries.  1.0 Module imports<jupyter_code>import pandas as pd
import altair as alt<jupyter_output><empty_output><jupyter_text>2.0 Create a DataFrame<jupyter_code># Poll result tallies
df = pd.DataFrame(
    {
        'Option': pd.Categorical(['In-person', 'Remote', 'No preference']),
        'Votes': pd.Series([150, 75, 25])
    }
)

# df = pd.DataFrame(
#     {
#         'Option': ['In-person', 'Remote', 'No preference'],
#         'Votes': [150, 75, 25]
#     }
# )<jupyter_output><empty_output><jupyter_text>3.0 Check first five rows<jupyter_code>df.head()<jupyter_output><empty_output><jupyter_text>3.1 Generate descriptive statisticsSee: [API: pandas.DataFrame.describe](https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.describe.html)<jupyter_code>df.describe()<jupyter_output><empty_output><jupyter_text>4.0 Generate a bar chart<jupyter_code>alt.Chart(df).mark_bar().encode(
    x='Option:N',
    y='Votes:Q'
)<jupyter_output><empty_output><jupyter_text>4.1 Add color and a legend<jupyter_code>alt.Chart(df).mark_bar().encode(
    x='Option:N',
    y='Votes:Q',
    color='Option'
)<jupyter_output><empty_output><jupyter_text>4.2 Add title; change chart height/width<jupyter_code>alt.Chart(df).mark_bar().encode(
    x='Option:N',
    y='Votes:Q',
    color='Option'
).properties(
    title='Office Hours Preferences (In-Person vs Remote)',
    width=200,
    height=200
)<jupyter_output><empty_output><jupyter_text>4.3 Change bar order (sort by vote count)<jupyter_code>alt.Chart(df).mark_bar().encode(
    x=alt.X(
        "Option:N",
        title="Preferences",
        sort=alt.EncodingSortField(
            field='Votes',
            order='descending'
        )
    ),
    y=alt.Y('Votes:Q'),
    color='Option'
).properties(
    title='Office Hours Preferences (In-Person vs Remote)',
    width=200,
    height=200
)<jupyter_output><empty_output><jupyter_text>4.4 Remove redundant x-axis label<jupyter_code>alt.Chart(df).mark_bar().encode(
    x=alt.X(
        "Option:N",
        axis=alt.Axis(labels=False),
        title='Preferences',
        sort=alt.EncodingSortField(
            field='Votes',
            order='descending'
        )
    ), 
    y=alt.Y(
        'Votes:Q',
        title='Student votes'
    ),
    color='Option'
).properties(
    title='Office Hours Preferences (In-Person vs Remote)',
    width=200,
    height=200
)<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14949651432997677, 'fraction_numerical': 0.019364833462432222, 'mean_word_length': 3.901328273244782, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 1, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '9', 'dir': 'jupyter-structured-clean-dedup', 'id': '88564', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 959, 'n_tokens_neox': 913, 'n_words': 156, 'path': 'talks/pandas_altair/office_hours_survey.ipynb', 'repo_name': 'svilag/umpy-1', 'size': '2582'}