<jupyter_start><jupyter_text>Observations and Insights  Dependencies and starter code<jupyter_code># Dependencies and Setup
import matplotlib.pyplot as plt
import pandas as pd
import scipy.stats as st
from scipy.stats import linregress
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)

# Combine the data into a single dataset
mergedData = pd.merge(mouse_metadata,study_results, on=["Mouse ID"], how="outer").groupby('Drug Regimen')<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
mean = mergedData['Tumor Volume (mm3)'].mean()
median = mergedData['Tumor Volume (mm3)'].median()
variance = mergedData['Tumor Volume (mm3)'].var()
stdDev = mergedData['Tumor Volume (mm3)'].std()
sem = mergedData['Tumor Volume (mm3)'].sem()

sumStat = pd.DataFrame ({"Mean": mean, 
                             "Median" : median,
                             "Variance" : variance,
                             "Standard Deviation" : stdDev,
                             "SEM" : sem})
sumStat<jupyter_output><empty_output><jupyter_text>Bar plots<jupyter_code># Generate a bar plot showing number of data points for each treatment regimen using pandas

# Generate a bar plot showing number of data points for each treatment regimen using pyplot
y = mergedData["Mouse ID"].count()
x = np.arange(len(y))

plt.bar(x, y, color='b', align="center")
labels = mergedData["Drug Regimen"].unique()

ticks = [value for value in x]
plt.xticks(ticks, labels, rotation = "vertical")
plt.xlim(-0.75, len(x)-0.25)

plt.title("Drug Regimen Trials")
plt.xlabel("Drug Regimen")<jupyter_output><empty_output><jupyter_text>Pie plots<jupyter_code># Generate a pie plot showing the distribution of female versus male mice using pandas
sexes = mouse_metadata.groupby('Sex')
sexCount = sexes["Mouse ID"].count()

mouse_metadata.plot.pie(y=sexCount)
# Generate a pie plot showing the distribution of female versus male mice using pyplot
sexes = mouse_metadata.groupby('Sex')
sexCount = sexes["Mouse ID"].count()

labels = sexCount.keys()

plt.pie(sexCount,labels=labels,autopct="%1.1f%%")<jupyter_output><empty_output><jupyter_text>Quartiles, outliers and boxplots<jupyter_code># Calculate the final tumor volume of each mouse across four of the most promising treatment regimens. 
#Calculate the IQR and quantitatively determine if there are any potential outliers.<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
mergedData = pd.merge(mouse_metadata,study_results, on=["Mouse ID"], how="outer")
drugValues = mergedData.loc[mergedData['Drug Regimen'] == 'Capomulin']
mouse = mergedData.loc[mergedData['Mouse ID'] == 'r157']

graph = mouse.plot.line(x='Timepoint',y='Tumor Volume (mm3)',grid=True,figsize=(10,10))
# Set the x-axis label
graph.set_xlabel("Timepoint")

# Set the y-axis label
graph.set_ylabel("Tumor Volume")
# Generate a scatter plot of mouse weight versus average tumor volume for the Capomulin 
mergedData = pd.merge(mouse_metadata,study_results, on=["Mouse ID"], how="outer")
drugValues = mergedData.loc[mergedData['Drug Regimen'] == 'Capomulin']

drugValues = drugValues[["Weight (g)","Tumor Volume (mm3)"]]
drugValues = drugValues.groupby("Weight (g)").mean()
drugValues = drugValues.reset_index()

drugValues.plot.scatter(x="Weight (g)",y="Tumor Volume (mm3)")
# Calculate the correlation coefficient and linear regression model for mouse weight 
#and average tumor volume for the Capomulin regimen

weight = drugValues['Weight (g)']
tumor = drugValues['Tumor Volume (mm3)']
correlation = st.pearsonr(weight,tumor)
print(f"Weight and tumor volume correlation is {round(correlation[0],2)}")
x_values = drugValues['Weight (g)']
y_values = drugValues['Tumor Volume (mm3)']
(slope, intercept, rvalue, pvalue, stderr) = linregress(x_values, y_values)
regress_values = x_values * slope + intercept
line_eq = "y = " + str(round(slope,2)) + "x + " + str(round(intercept,2))
plt.scatter(x_values,y_values)
plt.plot(x_values,regress_values,"r-")
plt.annotate(line_eq,(6,10),fontsize=15,color="red")
plt.xlabel('Weight (g)')
plt.ylabel('Tumor Volume (mm3)')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12472551602986386, 'fraction_numerical': 0.007685551163812033, 'mean_word_length': 5.818862275449102, 'pattern_counts': {'":': 1, '<': 25, '<?xml version=': 0, '>': 25, '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': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '522361', 'license': 'ADSL', 'n_tokens_mistral': 1544, 'n_tokens_neox': 1434, 'n_words': 402, 'path': 'Pymaceuticals/pymaceuticals_starter.ipynb', 'repo_name': 'ScriptMigo/matplotlib-challenge', 'size': '4554'}