<jupyter_start><jupyter_text>Preview the whole dataframe<jupyter_code># Preview data

workshops
def workshops_by_year(data, year): 
    """Takes a dataframe and a year, returns dataframe filtered by year"""
    df = pd.read_csv(data)
    df = df[df['year'] == year]
    return df<jupyter_output><empty_output><jupyter_text>Select a year to see a dataframe of all workshops (across Carpentries) that year<jupyter_code># The interact function takes as arguments the function and that function's arguments separately
interact(workshops_by_year, data = 'workshops.csv', year = range(2011, 2019)) 
def workshops_by_carpentry(data, carpentry): 
    """Takes a dataframe and a carpentry, returns dataframe filtered by that carpentry"""
    df = pd.read_csv(data)
    df = df[df['tag_name'].str.contains(carpentry)]
    return df<jupyter_output><empty_output><jupyter_text>Select a Carpentry to see a dataframe of all workshops for that Carpentry (across all years)<jupyter_code>interact(workshops_by_carpentry, data = 'workshops.csv', carpentry = ['SWC', 'DC', 'LC']) 
def attendance_by_carpentry_and_year(data, carpentry): 
    """Takes a dataframe and a carpentry, returns attendance total by year for that carpentry as pandas series and bar plot"""
    df = pd.read_csv(data)
    df = df[df['tag_name'].str.contains(carpentry)]
    attendance_by_year = df.groupby('year')['attendance'].sum()
   
    attendance_list = attendance_by_year.tolist()
    
    offset = max(attendance_list) * .025
    ax = attendance_by_year.plot(x = 'year', y = 'attendance', kind = 'bar')
    for i in range(len(attendance_list)):
        ax.text(i, attendance_list[i] + offset, str(int(attendance_list[i])))
    plt.show()
    
    return attendance_by_year<jupyter_output><empty_output><jupyter_text>Select a Carpentry to see a bar chart of attendance by year for that CarpentryThis does not account for workshops missing attendance<jupyter_code>interact(attendance_by_carpentry_and_year, data = 'workshops.csv', carpentry = ['SWC', 'DC', 'LC']) 
def workshops_by_carpentry_and_year(data, carpentry="All", yr="All", stacked = True, agg="workshop count"): 
    """Takes a dataframe and a carpentry, returns dataframe filtered by that carpentry"""
    df = pd.read_csv(data)
    df.loc[df.administrator_name != 'self-organized', 'administrator_name'] = 'centrally'
    df.loc[df.administrator_name == 'self-organized', 'administrator_name'] = 'self'
    
    df.loc[df["tag_name"].str.contains("SWC"), 'tag_name'] = "SWC"
    df.loc[df["tag_name"].str.contains("DC"), 'tag_name'] = "DC"
    df.loc[df["tag_name"].str.contains("LC"), 'tag_name'] = "LC"
    df.loc[df["tag_name"].str.contains("TTT"), 'tag_name'] = "TTT"

    if carpentry != "All":
        df = df[df['tag_name'].str.contains(carpentry)]
    if yr != "All":
        df = df[df['year'] == year]
    
    if agg == "workshop count":
        attendance_by_year = df.groupby(['year', 'tag_name', 'administrator_name'])['slug'].count()
    elif agg == "attendance sum":
        attendance_by_year = df.groupby(['year', 'tag_name', 'administrator_name'])['attendance'].sum()

    attendance_by_year = attendance_by_year.to_frame()
    attendance_by_year.unstack().plot(kind='bar', stacked=stacked)

    return attendance_by_year<jupyter_output><empty_output><jupyter_text>Select a Carpentry and year to see a bar chart of workshop count OR attendance total for that Carpentry/year and that bar chart's source dataframe by self organized and centrally organized workshops.  Select "stacked" to toggle stacked view or side by side view.This does not account for workshops missing attendance.  See here on how to fill na with means: https://chrisalbon.com/python/data_wrangling/pandas_missing_data/Need to figure out how to make the legends and labels more human readable.This is not currently accurate - we need to fix some data behind the scenes about whether workshops were self organized or centrally organized.<jupyter_code>interact(workshops_by_carpentry_and_year, data = 'workshops.csv', stacked = [True, False], carpentry = ['All', 'SWC', 'DC', 'LC', 'TTT'], yr = ["All"] + list(range(2011, 2019)), agg=["attendance sum", "workshop count"])<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12707838479809977, 'fraction_numerical': 0.004513064133016627, 'mean_word_length': 5.1384839650145775, 'pattern_counts': {'":': 4, '<': 21, '<?xml version=': 0, '>': 21, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '535720', 'license': 'CC-BY-4.0', 'n_tokens_mistral': 1397, 'n_tokens_neox': 1353, 'n_words': 369, 'path': 'programmatic-assessment/workshops/archived_notebooks/workshops_interactive.ipynb', 'repo_name': 'ErinBecker/assessment', 'size': '4210'}