<jupyter_start><jupyter_text>Dependencies and starter code<jupyter_code># Dependencies and Setup
import matplotlib.pyplot as plt
import pandas as pd
import scipy.stats as st
import numpy as np

# Study data files
mouse_metadata = "data/Mouse_metadata.csv"
study_results = "data/Study_results.csv"

# Read the mouse data and the study results
mouse_metadata = pd.read_csv(mouse_metadata)
study_results = pd.read_csv(study_results)

mouse_metadata.head ()
# Combine the data into a single dataset
Study_results_complete = pd.merge (study_results, mouse_metadata, how="left", on=["Mouse ID", "Mouse ID"])

#Display the data table for preview
Study_results_complete.head ()<jupyter_output><empty_output><jupyter_text>Summary statistics<jupyter_code># Generate a summary statistics table of mean, median, variance, standard deviation, and SEM of the tumor volume for each regimen

#https://www.tutorialspoint.com/python_pandas/python_pandas_descriptive_statistics.htm
#https://www.dataquest.io/blog/basic-statistics-with-python-descriptive-statistics/
#https://docs.python.org/3/library/statistics.html

tumor_volume_mean = Study_results_complete.groupby(["Drug Regimen"]).mean()["Tumor Volume (mm3)"]
tumor_volume_median = Study_results_complete.groupby(["Drug Regimen"]).median()["Tumor Volume (mm3)"]
tumor_volume_variance = Study_results_complete.groupby(["Drug Regimen"]).var()["Tumor Volume (mm3)"]
tumor_volume_std = Study_results_complete.groupby(["Drug Regimen"]).std()["Tumor Volume (mm3)"]
tumor_volume_sem = Study_results_complete.groupby(["Drug Regimen"]).sem()["Tumor Volume (mm3)"]

summary_statistics = pd.DataFrame ({
    "Mean":tumor_volume_mean, 
    "Median":tumor_volume_median, 
    "Variance":tumor_volume_variance, 
    "Std Dev":tumor_volume_std, 
    "SEM":tumor_volume_sem})

summary_statistics
Study_results_complete.describe()
#Groupby drug regimen with .count and mouse id to determine the datapoints
regimen_data_points = Study_results_complete.groupby(["Drug Regimen"]).count()["Mouse ID"]
regimen_data_points<jupyter_output><empty_output><jupyter_text>Bar plots<jupyter_code># Generate a bar p# Generate a bar plot showing number of data points for each treatment regimen using pandas
regimen_data_points.plot(kind="bar", figsize=(10,5))

#set chart title
plt.title("Data Points Visual")
plt.xlabel("Drug Regimen")
plt.ylabel("Data Points")

#show chart and set layout
plt.show()
plt.tight_layout()
# Generate a bar plot showing number of data points for each treatment regimen using pyplot

#Create an arraw with the datapoints
users = [230, 178, 178, 188, 186, 181, 161, 228, 181, 182]

#Set the x_axis to be the amount of the Data Regimen
x_axis = np.arange(len(regimen_data_points))

plt.bar(x_axis, users, color='b', alpha=0.75, align='center')

tick_locations = [value for value in x_axis]
plt.xticks(tick_locations, ['Capomulin', 'Ceftamin', 'Infubinol', 'Ketapril', 'Naftisol', 'Placebo', 'Propriva', 'Ramicane', 'Stelasyn', 'Zoniferol'],  rotation='vertical')

plt.xlim(-0.75, len(x_axis)-0.25)

plt.ylim(0, max(users)+10)

plt.title("Data Points Visual")
plt.xlabel("Drug Regimen")
plt.ylabel("Data Points")<jupyter_output><empty_output><jupyter_text>Pie plots<jupyter_code>#Group by "Mouse ID" and "Sex" to find the unique number of male vs female
groupby_gender = Study_results_complete.groupby(["Mouse ID","Sex"])
groupby_gender

mouse_gender_df = pd.DataFrame(groupby_gender.size())

#Create the dataframe with total count of Female and Male mice
mouse_gender = pd.DataFrame(mouse_gender_df.groupby(["Sex"]).count())
mouse_gender.columns = ["Total Count"]

#create and format the percentage of female vs male
mouse_gender["Percentage of Sex"] = (100*(mouse_gender["Total Count"]/mouse_gender["Total Count"].sum()))

#format the "Percentage of Sex" column
mouse_gender["Percentage of Sex"] = mouse_gender["Percentage of Sex"]

#gender_df
mouse_gender
# Generate a pie plot showing the distribution of female versus male mice using pandas

#plot = name of the data frame .plot.pie (sumplots true)
colors = ['blue', 'green']
explode = (0.1, 0)
plot = mouse_gender.plot.pie(y='Total Count',figsize=(5,5), colors = colors, startangle=140, explode = explode, shadow = False, autopct="%1.1f%%")
# Generate a pie plot showing the distribution of female versus male mice using pyplot

# Create Labels for the sections of the pie
labels = ["Female","Male"]

#List the values of each section of the pie chart
sizes = [49.799197,50.200803]

#Set colors for each section of the pie
colors = ['blue', 'green']

#Determoine which section of the circle to detach
explode = (0.1, 0)

#Create the pie chart based upon the values 
plt.pie(sizes, explode=explode, labels=labels, colors=colors, autopct="%1.1f%%", shadow=False, startangle=140)

#Set equal axis
plt.axis("equal")<jupyter_output><empty_output><jupyter_text>Quartiles, outliers and boxplots<jupyter_code>#Group data by Drug Regimen and Mouse ID to capture Last Tumor Measurement
Study_results_complete_sort = Study_results_complete.groupby(['Drug Regimen', 'Mouse ID']).last()['Tumor Volume (mm3)']
Study_results_complete.head()

# Turn retrieved data into dataframe to easily manipulate
Study_results_df = Study_results_complete
Study_results_df

#Create a list to use as labels and dataframe
top_4 = ['Capomulin', 'Ramicane', 'Infubinol','Ceftamin']

# Generate a box plot of the final tumor volume of each mouse across four regimens of interest
final_df = Study_results_df.reset_index()
tumor_lists = final_df.groupby('Drug Regimen')['Tumor Volume (mm3)'].apply(list)
tumor_list_df = pd.DataFrame(tumor_lists)
tumor_list_df = tumor_list_df.reindex(top_4)
tumor_vols = [vol for vol in tumor_list_df['Tumor Volume (mm3)']]
plt.boxplot(tumor_vols, labels=top_4)
plt.ylim(10, 80)
plt.show()<jupyter_output><empty_output><jupyter_text>Line and scatter plots<jupyter_code># Generate a line plot of time point versus tumor volume for a mouse treated with Capomulin
time_vs_tumor = Study_results_complete["Mouse ID"].isin(["j119"])
time_vs_tumor

time_vs_tumor_data = Study_results_complete[["Mouse ID", "Timepoint", "Tumor Volume (mm3)"]]
time_vs_tumor_data

line_plot_df = time_vs_tumor_data.reset_index()
line_plot_df

line_plot_final = line_plot_df[["Mouse ID", "Timepoint", "Tumor Volume (mm3)"]]
line_plot_final

lines = line_plot_final.plot.line()
# Generate a scatter plot of mouse weight versus average tumor volume for the Capomulin regimen
# Calculate the correlation coefficient and linear regression model for mouse weight and average tumor volume for the Capomulin regimen<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.1132504548211037, 'fraction_numerical': 0.0156155245603396, 'mean_word_length': 6.872315035799523, 'pattern_counts': {'":': 5, '<': 25, '<?xml version=': 0, '>': 25, 'https://': 3, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 1, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '496937', 'license': 'ADSL', 'n_tokens_mistral': 2341, 'n_tokens_neox': 2131, 'n_words': 610, 'path': 'Pymaceuticals/pymaceuticals_starter.ipynb', 'repo_name': 'Harmonylm/Matplotlib-Challenge', 'size': '6596'}