<jupyter_start><jupyter_text>Data Science Unit 1 Sprint Challenge 2 Storytelling with DataIn this sprint challenge you'll work with a dataset from **FiveThirtyEight's article, [Every Guest <NAME> Ever Had On ‘The Daily Show’](https://fivethirtyeight.com/features/every-guest-jon-stewart-ever-had-on-the-daily-show/)**!  Part 0 — Run this starter codeYou don't need to add or change anything here. Just run this cell and it loads the data for you, into a dataframe named `df`.(You can explore the data if you want, but it's not required to pass the Sprint Challenge.)<jupyter_code>%matplotlib inline
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd

df = pd.read_csv('https://raw.githubusercontent.com/fivethirtyeight/data/master/daily-show-guests/daily_show_guests.csv')
df.rename(columns={'YEAR': 'Year', 'Raw_Guest_List': 'Guest'}, inplace=True)

def get_occupation(group):
    if group in ['Acting', 'Comedy', 'Musician']:
        return 'Acting, Comedy & Music'
    elif group in ['Media', 'media']:
        return 'Media'
    elif group in ['Government', 'Politician', 'Political Aide']:
        return 'Government and Politics'
    else:
        return 'Other'
      
df['Occupation'] = df['Group'].apply(get_occupation)<jupyter_output><empty_output><jupyter_text>Part 1 — What's the breakdown of guests’ occupations per year?For example, in 1999, what percentage of guests were actors, comedians, or musicians? What percentage were in the media? What percentage were in politics? What percentage were from another occupation?Then, what about in 2000? In 2001? And so on, up through 2015.So, **for each year of _The Daily Show_, calculate the percentage of guests from each occupation:**- Acting, Comedy & Music- Government and Politics- Media- Other Hints:1. Use pandas to make a **crosstab** of **`Year`** & **`Occupation`**. ([This documentation](http://pandas.pydata.org/pandas-docs/stable/reshaping.htmlcross-tabulations) has examples and explanation.)2. To get percentages instead of counts, use crosstab's **`normalize`** parameter to normalize over each _row._ ([This documentation](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.crosstab.html) describes the parameter and its options.)3. You'll know you've calculated the crosstab correctly when the percentage of "Acting, Comedy & Music" guests is 90.36% in 1999, and 45% in 2015.<jupyter_code>df.describe()
df.describe(exclude=[np.number])
crosstabdf = pd.crosstab(df['Year'],df['Occupation'],normalize='index')
print(crosstabdf)<jupyter_output>Occupation  Acting, Comedy & Music  Government and Politics     Media  \
Year                                                                    
1999                      0.903614                 0.012048  0.066265   
2000                      0.739645                 0.082840  0.124260   
2001                      0.726115                 0.038217  0.197452   
2002                      0.622642                 0.069182  0.264151   
2003                      0.560241                 0.102410  0.246988   
2004                      0.384146                 0.225610  0.274390   
2005                      0.370370                 0.160494  0.333333   
2006                      0.360248                 0.192547  0.291925   
2007                      0.255319                 0.170213  0.333333   
2008                      0.207317                 0.201220  0.469512   
2009                      0.208589                 0.208589  0.361963   
2010                      0.351515                 [...]<jupyter_text>Part 2 — Recreate this explanatory visualization:<jupyter_code>from IPython.display import display, Image
url = 'https://fivethirtyeight.com/wp-content/uploads/2015/08/hickey-datalab-dailyshow.png'
example = Image(url, width=500)
display(example)<jupyter_output><empty_output><jupyter_text>**Hint:** use the crosstab you calculated in part 1!**Expectations:** Your plot should include:- 3 lines visualizing "occupation of guests, by year." The shapes of the lines should look roughly identical to 538's example. Each line should be a different color. (But you don't need to use the _same_ colors as 538.)- Legend or labels for the lines. (But you don't need each label positioned next to its line or colored like 538.)- Title in the upper left: _"Who Got To Be On 'The Daily Show'?"_ with more visual emphasis than the subtitle. (Bolder and/or larger font.)- Subtitle underneath the title: _"Occupation of guests, by year"_Any visual element not specifically mentioned in the expectations is an optional bonus, but it's _not_ required to pass the Sprint Challenge.<jupyter_code>labels = {'Acting, Comedy & Music':'act',
          'Government and Politics':'gov',
          'Media':'media',
          'Other':'other'}

crosstabdf.rename(columns=labels, inplace=True)
plt.style.use('fivethirtyeight')

fig, ax = plt.subplots()

dfact = crosstabdf['act']*100
dfact.plot(color='deepskyblue', linewidth=2)
dfgov = crosstabdf['gov']*100
dfgov.plot(color='red', linewidth=2)
dfmedia = crosstabdf['media']*100
dfmedia.plot(color='purple', linewidth=2)

# Setting title and sub-title
ax.text(x=1997.8, y=115, 
        s="Who Got To Be On 'The Daily Show'?",
        fontsize=15, fontweight='bold')
ax.text(x=1997.8, y=108, 
        s="Occupation of guests, by year",
        fontsize=12)

# Setting labels
ax.text(x=2001, y=80, 
        s="Acting, Comedy & Music",
        fontsize=12, color='deepskyblue')
ax.text(x=2009, y=7, 
        s="Government and Politics",
        fontsize=12, color='red')
ax.text(x=2007.5, y=50, 
        s="Media",
        fontsize=12, color='purple')

ax.set_xlim(1999, 2015)
ax.set_ylim(0, 100)
ax.set_ylim(0, 100)
ax.set_xlabel("");
ax.set_xticks([x for x in range(2000,2016,4)])
ax.set_xticklabels(['2000',"'04","'08","'12"])
ax.set_yticks([x for x in range(0,125,25)])
ax.set_yticklabels(['0',"25","50","75","100%"])

plt.show()<jupyter_output><empty_output><jupyter_text>Part 3 — Who were the top 10 guests on _The Daily Show_?**Make a plot** that shows their names and number of appearances.**Hint:** you can use the pandas `value_counts` method.**Expectations:** This can be a simple, quick plot: exploratory, not explanatory. If you want, you can add titles and change aesthetics, but it's _not_ required to pass the Sprint Challenge.<jupyter_code>import seaborn as sns

top10guests = df['Guest'].value_counts()[:10,]

plt.figure(figsize=(10,5))
ax = sns.barplot(top10guests.values, top10guests.index, orient='h')
plt.title("Top 10 Guests in 'The Daily Show'")
plt.ylabel('Names', fontsize=12)
plt.xlabel('Number of appearances', fontsize=12)

ax.set_xticks([x for x in range(0,21,2)])
plt.show()<jupyter_output><empty_output>
StarcoderdataJupyterStructuredCleanDedup