<jupyter_start><jupyter_text>Quiz 3  <NAME> and <NAME>  Q.1 Read in the dataframe “gss_cat.csv”.<jupyter_code>#import dataset and tools
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
df = pd.read_csv("../dataFiles/gss_cat.csv")
df.rename(columns={'Unnamed: 0':'numbers'}, inplace=True)
df.head()
# (a) create a bar plot for “marital”. It should look like this:

df['marital'].value_counts().plot.bar()
# (b) Create a histogram for “age” on the left, then a histogram for “tvhours” on the right. Set the figsize = (10,5)

plt.figure(figsize=(10,5))
df.hist(column=["age", "tvhours"])
plt.show()

# (c) You will create a line plot to see how the proportions of people identified as Democrat, Republican, and Independent 
# change over time. 
# (i)	first, recode the variable “partyid”

other = ["No answer", "Don't know", "Other party"]
rep = ["Strong republican", "Not str republican"]
ind = ["Ind,near rep", "Independent", "Ind,near dem"]
dem = ["Not str democrat", "Strong democrat"]

# (ii)	then, create a table which shows the proportions of people identified 
# as Democrat, Republican, Independent and Other for each year.

data = {
    other = "No answer", "Don't know", "Other party",
    rep = "Strong republican", "Not str republican",
    ind = "Ind,near rep", "Independent", "Ind,near dem",
    dem = "Not str democrat", "Strong democrat"}

df = pd.DataFrame(data, columns=['partyid', 'year'])

df = df.assign(relative_frequency=1).groupby(['partyid', 'year']).count().unstack()
df.div(df.sum(1), axis=0)
          
# (iii) (iii)	Create a line plot to see how the proportions of people identified
# as Democrat, Republican, and Independent changed over time.<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14498567335243553, 'fraction_numerical': 0.006876790830945559, 'mean_word_length': 4.839464882943144, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 0, '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': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '478989', 'license': 'Apache-2.0', 'n_tokens_mistral': 595, 'n_tokens_neox': 569, 'n_words': 206, 'path': 'quizzes/.ipynb_checkpoints/quiz-3-checkpoint.ipynb', 'repo_name': 'RealDogDad/ad450-data-science', 'size': '1755'}