<jupyter_start><jupyter_text>_Lambda School Data Science_ Choose appropriate visualizationsRecreate this [example by FiveThirtyEight:](https://fivethirtyeight.com/features/al-gores-new-movie-exposes-the-big-flaw-in-online-movie-ratings/)![](https://fivethirtyeight.com/wp-content/uploads/2017/09/mehtahickey-inconvenient-0830-1.png?w=575)Using this data:https://github.com/fivethirtyeight/data/tree/master/inconvenient-sequel Stretch goalsRecreate more examples from [FiveThityEight's shared data repository](https://data.fivethirtyeight.com/).For example:- [thanksgiving-2015](https://fivethirtyeight.com/features/heres-what-your-part-of-america-eats-on-thanksgiving/) ([`altair`](https://altair-viz.github.io/gallery/index.htmlmaps))- [candy-power-ranking](https://fivethirtyeight.com/features/the-ultimate-halloween-candy-power-ranking/) ([`statsmodels`](https://www.statsmodels.org/stable/index.html))  Data Wrangling and Exploration<jupyter_code>import pandas as pd
import matplotlib.pyplot as plt

url = 'https://raw.githubusercontent.com/fivethirtyeight/data/master/inconvenient-sequel/ratings.csv'

df = pd.read_csv(url)

# df.head()

df.timestamp = pd.to_datetime(df.timestamp)

df.timestamp.describe()

df.set_index('timestamp', inplace = True)

df.head()
length, width = df.shape

print(df.shape)
print(length*width)
# Use Value Counts rather than Unique

df.category.value_counts()
df.columns<jupyter_output><empty_output><jupyter_text>Suggested Correct Version of this problem<jupyter_code>cols2 = ['1_pct','2_pct', '3_pct', '4_pct', '5_pct', 
         '6_pct', '7_pct', '8_pct', '9_pct', '10_pct']

pct_votes = df[cols2].tail(1)

pct_votes


# Why inplace = True fails is beyond me, better to make a copy

pct_votes_new = pct_votes.reset_index(drop=True)

pct_votes_new
pct_votes_new.rename(columns={"1_pct": "1",
                        "2_pct": "2",
                        "3_pct": "3",
                        "4_pct": "4",
                        "5_pct": "5",
                        "6_pct": "6",
                        "7_pct": "7",
                        "8_pct": "8",
                        "9_pct": "9",
                        "10_pct": "10",},
                        
                            inplace = True)

pct_votes_new = pct_votes_new.T

pct_votes_new
# fig, ax = plt.subplots()


plt.style.use("fivethirtyeight")

# fig = plt.figure();
# fig.patch.set_alpha(0.0)

ax = pct_votes_new.plot.bar(color = '#EC713B', width = 0.9) # All bars are the same color and width

ax.tick_params(labelrotation = 0, colors = 'gray')
y_ticks = [0,10,20,30,40]
ax.set_yticks(y_ticks)
ax.legend().set_visible(False)
ax.set_facecolor("white")

ax.set_ylabel("Percent of total votes", fontweight='bold')
ax.set_xlabel("Rating", fontweight='bold')

ax.text(-1.5,45,s="'An Inconvenient Sequel: Truth to Power' is divisive", fontsize=18, weight='bold')
ax.text(-1.5,42,s="IMDb Ratings for the film as of Aug. 29", fontsize=16)

# ax.set_title("'An Inconvenient Sequel: Truth to Power' is divisive \n IMDb Ratings for the film as of Aug. 29", loc = 'left')
# ax.spines['bottom'].set_color('white')
# ax.spines['top'].set_color('white') 
# ax.spines['right'].set_color('white')
# ax.spines['left'].set_color('white')
# ax.tick_params(axis = 'x', color = 'lightgray')
# ax.tick_params(axis = 'y', color = 'blue')
# ax.yaxis.label.set_color('black')
# ax.xaxis.label.set_color('black')
# ax.patch.set_facecolor('white')


plt.show()

# plt.savefig('538.png', transparent=True)<jupyter_output><empty_output><jupyter_text>Alternate Attempt at this problem<jupyter_code># Slicing out relevant columns

cols = ['1_votes', '2_votes', '3_votes', '4_votes', '5_votes',
       '6_votes', '7_votes', '8_votes', '9_votes', '10_votes']

df_new = df[cols]

sum_votes = pd.Series(df_new.sum())
sum_votes = 100 * sum_votes / sum_votes.sum()

sum_votes.rename(index={"1_votes": "1",
                        "2_votes": "2",
                        "3_votes": "3",
                        "4_votes": "4",
                        "5_votes": "5",
                        "6_votes": "6",
                        "7_votes": "7",
                        "8_votes": "8",
                        "9_votes": "9",
                        "10_votes": "10",}, 
                            inplace = True)

sum_votes
plt.style.use("fivethirtyeight")

ax = sum_votes.plot.bar(color = '#EC713B', width = 0.9)

ax.tick_params(labelrotation = 0, colors = 'gray')
y_ticks = [0,10,20,30,40]
ax.set_yticks(y_ticks)
ax.legend().set_visible(False)
ax.set_facecolor("white")

ax.set_ylabel("Percent of total votes", fontweight='bold')
ax.set_xlabel("Rating", fontweight='bold')

ax.text(-1.5,45,s="'An Inconvenient Sequel: Truth to Power' is divisive", fontsize=18, weight='bold')
ax.text(-1.5,42,s="IMDb Ratings for the film as of Aug. 29", fontsize=18)

# ax.set_title("'An Inconvenient Sequel: Truth to Power' is divisive \n IMDb Ratings for the film as of Aug. 29", loc = 'left')
# ax.spines['bottom'].set_color('white')
# ax.spines['top'].set_color('white') 
# ax.spines['right'].set_color('white')
# ax.spines['left'].set_color('white')
# ax.tick_params(axis = 'x', color = 'lightgray')
# ax.tick_params(axis = 'y', color = 'blue')
# ax.yaxis.label.set_color('black')
# ax.xaxis.label.set_color('black')


plt.show()<jupyter_output><empty_output><jupyter_text>STRETCH GOAL<jupyter_code># Bad Drivers - https://github.com/fivethirtyeight/data/tree/master/bad-drivers

url2 = 'https://raw.githubusercontent.com/fivethirtyeight/data/master/bad-drivers/bad-drivers.csv'

driver_df = pd.read_csv(url2)

driver_df.head()
driver_df.describe()
driver_df.columns
driver_df.rename(columns = {'Number of drivers involved in fatal collisions per billion miles' : 'no_fatal',
                           'Percentage Of Drivers Involved In Fatal Collisions Who Were Speeding' : 'pct_fatal',
                           'Percentage Of Drivers Involved In Fatal Collisions Who Were Alcohol-Impaired': 'pct_fatal_alcohol',
                           'Percentage Of Drivers Involved In Fatal Collisions Who Were Not Distracted': 'pct_fatal_nodistraction',
                           'Percentage Of Drivers Involved In Fatal Collisions Who Had Not Been Involved In Any Previous Accidents' : 'pct_fatal_noprev',
                           'Car Insurance Premiums ($)' : 'ins_premiums',
                           'Losses incurred by insurance companies for collisions per insured driver ($)' : 'ins_losses'}, inplace = True)

driver_df.head()
# import altair as alt
# from vega_datasets import data
no_fatal = driver_df.no_fatal.sort_values()

no_fatal
plt.style.use("fivethirtyeight")

# fig = plt.figure();
# fig.patch.set_alpha(0.0)

ax = no_fatal.plot.bar(width = 0.9) # All bars are the same color and width (color = '#EC713B')

ax.tick_params(labelrotation = 90, colors = 'gray')
y_ticks = [0,5,10,15,20,25]
ax.set_yticks(y_ticks)
ax.legend().set_visible(False)
ax.set_facecolor("white")

ax.set_ylabel("Drivers involved in fatal collisions", fontweight='bold')
ax.set_xlabel("State", fontweight='bold')

ax.text(-1.5,28,s="'Drivers involved in fatal collisions per billion miles by State", fontsize=18, weight='bold')


# ax.text(-1.5,42,s="IMDb Ratings for the film as of Aug. 29", fontsize=16)

# ax.set_title("'An Inconvenient Sequel: Truth to Power' is divisive \n IMDb Ratings for the film as of Aug. 29", loc = 'left')
# ax.spines['bottom'].set_color('white')
# ax.spines['top'].set_color('white') 
# ax.spines['right'].set_color('white')
# ax.spines['left'].set_color('white')
# ax.tick_params(axis = 'x', color = 'lightgray')
# ax.tick_params(axis = 'y', color = 'blue')
# ax.yaxis.label.set_color('black')
# ax.xaxis.label.set_color('black')
# ax.patch.set_facecolor('white')


plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1564826700898588, 'fraction_numerical': 0.02490372272143774, 'mean_word_length': 3.6209964412811386, 'pattern_counts': {'":': 20, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 11, 'lorem ipsum': 0, 'www.': 1, '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': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '505212', 'license': 'MIT', 'n_tokens_mistral': 2979, 'n_tokens_neox': 2807, 'n_words': 536, 'path': 'LS_DS_123_Make_explanatory_visualizations.ipynb', 'repo_name': 'aapte11/DS-Sprint-02-Storytelling-With-Data', 'size': '7790'}