<jupyter_start><jupyter_text>Observations and Insights Look across all previously generated figures and tables and write at least three observations or inferences that can be made from the data.Include these observations at the top of notebook.**Observations**1. At the first timepoint (timepoint = 0), every tumor starts with a volume of 45 mm3, before being applying the selected drugs, so according toa boxplot analysis that we create by extracting the Lower Quartiles, Mid Quartiles, Upper Quartiles, IQR, Lower Bounds,	Upper Bounds and Outlinersof 4 drugs of interest (Capomulin, Ramicane, Infubinol, and Ceftamin), we can confirm that there are only to successful treatments that showed adecrease in the initial tumor volume (45 mm3), this two drugs where Capomulin and Ramicane, both start with 45 mm3 of tumor volume, and average afinal tumor volume of: Capomulin - 38.13 and Ramicane - 36.56. We are certain that the most effective drug to decrease the tumor volume is Ramicane.In the other hand Infubinol and Ceftamin, didn't reach the expected outcome, because in both of them the final average of tumor volume was above 45 mm3.- Ramicane Initial Tumor: 45 mm3- Capomulin Initial Tumor: 45 mm3- Ceftamin Initial Tumor: 45 mm3- Infubinol Initial Tumor: 45 mm3- Ramicane Average Initial Tumor: 36.56 mm3- Capomulin Average Initial Tumor: 38.13 mm3- Ceftamin Average Initial Tumor: 59.85 mm3- Infubinol Average Initial Tumor: 60.17 mm32. In Capomulin Cases, according to a Scatter Plot Graph the tumor volume of a mice is strongly correlated to the weight of it,with a r-squared of 0.903, and actually it makes sense, because the bigger the tumor is, the heavier the mouse will get.3. Making sense with the point number one, we can appreciate in a bar chart that the two drugs that are more applied to mice, are Capomulin and Ramicane, and will all justification both are the ones with the most promising results.<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_path = "data/Mouse_metadata.csv"
study_results_path = "data/Study_results.csv"

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

# Combine the data into a single dataset

# Display the data table for preview
studied_mice =  pd.merge(mouse_metadata,study_results, on = "Mouse ID", how="outer")
studied_mice["Tumor Volume (mm3)"]=round(studied_mice["Tumor Volume (mm3)"],2)
studied_mice.head()
# Checking the number of mice.
number_of_mice=len(mouse_metadata["Mouse ID"].unique())
print(f"There are {number_of_mice} mice for measures.")
# Getting the duplicate mice by ID number that shows up for Mouse ID and Timepoint. 
duplicate_df=studied_mice[studied_mice.duplicated(subset=["Mouse ID","Timepoint"])]
duplicated_mice = len(duplicate_df["Mouse ID"].unique())
duplicated_mice_serie = pd.Series(duplicate_df["Mouse ID"].unique())
print(f"Duplicate mice by ID number that shows up for Mouse ID and Timepoint: {duplicated_mice}.")
print(f"ID of duplicated mice: {duplicated_mice_serie[0]}.")

# Optional: Get all the data for the duplicate mouse ID. 
duplicate_df

# Create a clean DataFrame by dropping the duplicate mouse by its ID.
mice_df = studied_mice.loc[studied_mice["Mouse ID"] != "g989",:]
mice_df
# Checking the number of mice in the clean DataFrame.
mices = len(mice_df["Mouse ID"].unique())
print(f"There are {mices} mice for tests.")
tests = mice_df["Mouse ID"].count()
print(f"They run {tests} tests on the mice.")<jupyter_output>There are 248 mice for tests.
They run 1880 tests on the mice.<jupyter_text>Summary Statistics<jupyter_code>#Long Summary Statistics Method
drug_regimen = mice_df[["Drug Regimen","Tumor Volume (mm3)"]]

drug_regimen_capomulin = drug_regimen.loc[drug_regimen["Drug Regimen"]=="Capomulin"]
drug_regimen_ceftamin = drug_regimen.loc[drug_regimen["Drug Regimen"]=="Ceftamin"]
drug_regimen_infubinol = drug_regimen.loc[drug_regimen["Drug Regimen"]=="Infubinol"]
drug_regimen_ketapril = drug_regimen.loc[drug_regimen["Drug Regimen"]=="Ketapril"]
drug_regimen_naftisol = drug_regimen.loc[drug_regimen["Drug Regimen"]=="Naftisol"]
drug_regimen_placebo = drug_regimen.loc[drug_regimen["Drug Regimen"]=="Placebo"]
drug_regimen_propriva = drug_regimen.loc[drug_regimen["Drug Regimen"]=="Propriva"]
drug_regimen_ramicane = drug_regimen.loc[drug_regimen["Drug Regimen"]=="Ramicane"]
drug_regimen_stelasyn = drug_regimen.loc[drug_regimen["Drug Regimen"]=="Stelasyn"]
drug_regimen_zoniferol = drug_regimen.loc[drug_regimen["Drug Regimen"]=="Zoniferol"]

#Capomulin
capomulin_mean = np.mean(drug_regimen_capomulin["Tumor Volume (mm3)"])
capomulin_median = np.median(drug_regimen_capomulin["Tumor Volume (mm3)"])
capomulin_mode = st.mode(drug_regimen_capomulin["Tumor Volume (mm3)"])
capomulin_variance = np.var(drug_regimen_capomulin["Tumor Volume (mm3)"],ddof=0)
capomulin_std = np.std(drug_regimen_capomulin["Tumor Volume (mm3)"],ddof=0)
capomulin_sem = drug_regimen_capomulin["Tumor Volume (mm3)"].sem()

#Ceftamin
ceftamin_mean = np.mean(drug_regimen_ceftamin["Tumor Volume (mm3)"])
ceftamin_median = np.median(drug_regimen_ceftamin["Tumor Volume (mm3)"])
ceftamin_mode = st.mode(drug_regimen_ceftamin["Tumor Volume (mm3)"])
ceftamin_variance = np.var(drug_regimen_ceftamin["Tumor Volume (mm3)"],ddof=0)
ceftamin_std = np.std(drug_regimen_ceftamin["Tumor Volume (mm3)"],ddof=0)
ceftamin_sem = drug_regimen_ceftamin["Tumor Volume (mm3)"].sem()

#Infubinol
infubinol_mean = np.mean(drug_regimen_infubinol["Tumor Volume (mm3)"])
infubinol_median = np.median(drug_regimen_infubinol["Tumor Volume (mm3)"])
infubinol_mode = st.mode(drug_regimen_infubinol["Tumor Volume (mm3)"])
infubinol_variance = np.var(drug_regimen_infubinol["Tumor Volume (mm3)"],ddof=0)
infubinol_std = np.std(drug_regimen_infubinol["Tumor Volume (mm3)"],ddof=0)
infubinol_sem = drug_regimen_infubinol["Tumor Volume (mm3)"].sem()

#Ketapril
ketapril_mean = np.mean(drug_regimen_ketapril["Tumor Volume (mm3)"])
ketapril_median = np.median(drug_regimen_ketapril["Tumor Volume (mm3)"])
ketapril_mode = st.mode(drug_regimen_ketapril["Tumor Volume (mm3)"])
ketapril_variance = np.var(drug_regimen_ketapril["Tumor Volume (mm3)"],ddof=0)
ketapril_std = np.std(drug_regimen_ketapril["Tumor Volume (mm3)"],ddof=0)
ketapril_sem = drug_regimen_ketapril["Tumor Volume (mm3)"].sem()

#Naftisol
naftisol_mean = np.mean(drug_regimen_naftisol["Tumor Volume (mm3)"])
naftisol_median = np.median(drug_regimen_naftisol["Tumor Volume (mm3)"])
naftisol_mode = st.mode(drug_regimen_naftisol["Tumor Volume (mm3)"])
naftisol_variance = np.var(drug_regimen_naftisol["Tumor Volume (mm3)"],ddof=0)
naftisol_std = np.std(drug_regimen_naftisol["Tumor Volume (mm3)"],ddof=0)
naftisol_sem = drug_regimen_naftisol["Tumor Volume (mm3)"].sem()

#Placebo
placebo_mean = np.mean(drug_regimen_placebo["Tumor Volume (mm3)"])
placebo_median = np.median(drug_regimen_placebo["Tumor Volume (mm3)"])
placebo_mode = st.mode(drug_regimen_placebo["Tumor Volume (mm3)"])
placebo_variance = np.var(drug_regimen_placebo["Tumor Volume (mm3)"],ddof=0)
placebo_std = np.std(drug_regimen_placebo["Tumor Volume (mm3)"],ddof=0)
placebo_sem = drug_regimen_placebo["Tumor Volume (mm3)"].sem()

#Propriva
propriva_mean = np.mean(drug_regimen_propriva["Tumor Volume (mm3)"])
propriva_median = np.median(drug_regimen_propriva["Tumor Volume (mm3)"])
propriva_mode = st.mode(drug_regimen_propriva["Tumor Volume (mm3)"])
propriva_variance = np.var(drug_regimen_propriva["Tumor Volume (mm3)"],ddof=0)
propriva_std = np.std(drug_regimen_propriva["Tumor Volume (mm3)"],ddof=0)
propriva_sem = drug_regimen_propriva["Tumor Volume (mm3)"].sem()

#Ramicane
ramicane_mean = np.mean(drug_regimen_ramicane["Tumor Volume (mm3)"])
ramicane_median = np.median(drug_regimen_ramicane["Tumor Volume (mm3)"])
ramicane_mode = st.mode(drug_regimen_ramicane["Tumor Volume (mm3)"])
ramicane_variance = np.var(drug_regimen_ramicane["Tumor Volume (mm3)"],ddof=0)
ramicane_std = np.std(drug_regimen_ramicane["Tumor Volume (mm3)"],ddof=0)
ramicane_sem = drug_regimen_ramicane["Tumor Volume (mm3)"].sem()

#Stelasyn
stelasyn_mean = np.mean(drug_regimen_stelasyn["Tumor Volume (mm3)"])
stelasyn_median = np.median(drug_regimen_stelasyn["Tumor Volume (mm3)"])
stelasyn_mode = st.mode(drug_regimen_stelasyn["Tumor Volume (mm3)"])
stelasyn_variance = np.var(drug_regimen_stelasyn["Tumor Volume (mm3)"],ddof=0)
stelasyn_std = np.std(drug_regimen_stelasyn["Tumor Volume (mm3)"],ddof=0)
stelasyn_sem = drug_regimen_stelasyn["Tumor Volume (mm3)"].sem()

#Zoniferol
zoniferol_mean = np.mean(drug_regimen_zoniferol["Tumor Volume (mm3)"])
zoniferol_median = np.median(drug_regimen_zoniferol["Tumor Volume (mm3)"])
zoniferol_mode = st.mode(drug_regimen_zoniferol["Tumor Volume (mm3)"])
zoniferol_variance = np.var(drug_regimen_zoniferol["Tumor Volume (mm3)"],ddof=0)
zoniferol_std = np.std(drug_regimen_zoniferol["Tumor Volume (mm3)"],ddof=0)
zoniferol_sem = drug_regimen_zoniferol["Tumor Volume (mm3)"].sem()

drug_regimen_df = pd.DataFrame({"Mean":[capomulin_mean,ceftamin_mean,infubinol_mean,ketapril_mean,naftisol_mean,
                                       placebo_mean,propriva_mean,ramicane_mean,stelasyn_mean,zoniferol_mean],
                               "Median":[capomulin_median,ceftamin_median,infubinol_median,ketapril_median,naftisol_median,
                                       placebo_median,propriva_median,ramicane_median,stelasyn_median,zoniferol_median],
                               "Variance":[capomulin_variance,ceftamin_variance,infubinol_variance,ketapril_variance,naftisol_variance,
                                       placebo_variance,propriva_variance,ramicane_variance,stelasyn_variance,zoniferol_variance],
                               "Standard Deviation":[capomulin_std,ceftamin_std,infubinol_std,ketapril_std,naftisol_std,
                                       placebo_std,propriva_std,ramicane_std,stelasyn_std,zoniferol_std],
                               "SEM":[capomulin_sem,ceftamin_sem,infubinol_sem,ketapril_sem,naftisol_sem,placebo_sem,
                                     propriva_sem,ramicane_sem,stelasyn_sem,zoniferol_sem]})

drug_regimen_df.rename(index={0:"Capomulin",1:"Ceftamin",2:"Infubinol",3:"Ketapril",4:"Naftisol",
                              5:"Placebo",6:"Propriva",7:"Ramicane",8:"Stelasyn",9:"Zoniferol"}, inplace=True)

drug_regimen_df["Mean"] = drug_regimen_df["Mean"].map("{:.2f}".format)
drug_regimen_df["Median"] = drug_regimen_df["Median"].map("{:.2f}".format)
drug_regimen_df["Variance"] = drug_regimen_df["Variance"].map("{:.2f}".format)
drug_regimen_df["Standard Deviation"] = drug_regimen_df["Standard Deviation"].map("{:.2f}".format)
drug_regimen_df["SEM"] = drug_regimen_df["SEM"].map("{:.2f}".format)

drug_regimen_df = drug_regimen_df.style.set_caption("Summary Statistics Of The Tumor Volume For Each Regimen")

drug_regimen_df
# Generate a summary statistics table of mean, median, variance, standard deviation, and SEM of the tumor volume for each regimen
# Use groupby and summary statistical methods to calculate the following properties of each drug regimen: 
# mean, median, variance, standard deviation, and SEM of the tumor volume. 
# Assemble the resulting series into a single summary dataframe.
grouped_by_drug_regimen = mice_df.groupby("Drug Regimen")
drug_regimen_tumor_volume = pd.DataFrame({"Mean":grouped_by_drug_regimen["Tumor Volume (mm3)"].mean(),
                            "Median":grouped_by_drug_regimen["Tumor Volume (mm3)"].median(),
                            "Variance":grouped_by_drug_regimen["Tumor Volume (mm3)"].var(),
                            "Standard Deviation":grouped_by_drug_regimen["Tumor Volume (mm3)"].std(),
                            "SEM":grouped_by_drug_regimen["Tumor Volume (mm3)"].sem()})

drug_regimen_tumor_volume["Mean"] = drug_regimen_tumor_volume["Mean"].map("{:.2f}".format)
drug_regimen_tumor_volume["Median"] = drug_regimen_tumor_volume["Median"].map("{:.2f}".format)
drug_regimen_tumor_volume["Variance"] = drug_regimen_tumor_volume["Variance"].map("{:.2f}".format)
drug_regimen_tumor_volume["Standard Deviation"] = drug_regimen_tumor_volume["Standard Deviation"].map("{:.2f}".format)
drug_regimen_tumor_volume["SEM"] = drug_regimen_tumor_volume["SEM"].map("{:.2f}".format)

drug_regimen_tumor_volume

# Generate a summary statistics table of mean, median, variance, standard deviation, and SEM of the tumor volume for each regimen
# Using the aggregation method, produce the same summary statistics in a single line
# Generate a summary statistics table of mean, median, variance, standard deviation, and SEM of the tumor volume for each regimen
drug_regimen = mice_df[["Drug Regimen","Tumor Volume (mm3)"]]
drug_regimen_agg = drug_regimen.groupby(['Drug Regimen'])["Tumor Volume (mm3)"].agg([np.mean,np.median,np.var,np.std,st.sem])

drug_regimen_agg = drug_regimen_agg.rename(columns={"mean":"Mean","median":"Median","var":"Variance","std":"Standard Deviation","sem":"SEM"})

drug_regimen_agg["Mean"] = drug_regimen_agg["Mean"].map("{:.2f}".format)
drug_regimen_agg["Median"] = drug_regimen_agg["Median"].map("{:.2f}".format)
drug_regimen_agg["Variance"] = drug_regimen_agg["Variance"].map("{:.2f}".format)
drug_regimen_agg["Standard Deviation"] = drug_regimen_agg["Standard Deviation"].map("{:.2f}".format)
drug_regimen_agg["SEM"] = drug_regimen_agg["SEM"].map("{:.2f}".format)

drug_regimen_agg<jupyter_output><empty_output><jupyter_text>Bar and Pie Charts<jupyter_code># Generate a bar plot showing the total number of measurements taken on each drug regimen using pandas.
drug_regimen_panda_plot = pd.DataFrame(mice_df["Drug Regimen"].value_counts())
drug_regimen_panda_plot.plot(kind="bar", figsize=(11,6),width = 0.5,align="center", facecolor = "red",rot=90, legend = None)

plt.title("Total Number of Measurements (Pandas)")
plt.xlabel("Drug Regimen")
plt.ylabel("Number of Tests")

plt.xlim(-0.75, len(drug_regimen_panda_plot)-0.25)
plt.ylim(0, max(mice_df["Drug Regimen"].value_counts())+20)
plt.show()

# Generate a bar plot showing the total number of measurements taken on each drug regimen using pyplot.
plt.figure(figsize=(11,6))

number_of_tests_df=mice_df.groupby("Drug Regimen") 
test_number = number_of_tests_df["Mouse ID"].count()

test_number = test_number.sort_values(ascending=False)
available_drugs = test_number.index.values.tolist()
available_drugs

tick_locations = []

x_axis = np.arange(0,len(available_drugs))
number_of_tests_df = grouped_by_drug_regimen.count()

for x in x_axis:
    tick_locations.append(x)

plt.title("Total Number of Measurements (PyPlot)")
plt.xlabel("Drug Regimen")
plt.ylabel("Number of Tests")

plt.xlim(-0.75, len(available_drugs)-0.25)
plt.ylim(0, max(test_number)+20)

plt.bar(available_drugs,test_number,facecolor = "gold",alpha=0.75,align ="center",width=0.5)
plt.xticks(tick_locations,available_drugs,rotation=90)

plt.show()

# Generate a pie plot showing the distribution of female versus male mice using pandas
sex_of_mice = mice_df["Sex"].value_counts()
explode = (0.1,0)
mice_sex = pd.DataFrame(sex_of_mice)
mice_sex_plot = mice_sex.plot(kind = "pie", y ="Sex", title ="Male vs Female (Pandas)",autopct = "%.2f%%",
                              colors = ['skyblue', 'violet'],shadow=True,startangle = 90, explode = explode)
plt.axis("equal")
plt.show()

# Generate a pie plot showing the distribution of female versus male mice using pyplot
unique_sexs = mice_df["Sex"].unique()
sex_list = []
genders =[]
sex_of_mice = mice_df["Sex"].value_counts()
mice_sex_df = pd.DataFrame(sex_of_mice)
colors = ["springgreen","hotpink"]
explode = (0.1,0)

for x in sex_of_mice:
    sex_list.append(x)

for y in unique_sexs:
    genders.append(y)
    
plt.title("Male vs Female (PyPlot)")
plt.ylabel("Sex")

plt.pie(sex_list, explode=explode, labels = genders, colors = colors, autopct="%.2f%%",shadow=True,startangle = 90)
plt.legend(loc='upper right')
plt.axis("equal")
plt.show()<jupyter_output><empty_output><jupyter_text>Quartiles, Outliers and Boxplots<jupyter_code># Calculate the final tumor volume of each mouse across four of the treatment regimens:  
# Capomulin, Ramicane, Infubinol, and Ceftamin

# Start by getting the last (greatest) timepoint for each mouse


# Merge this group df with the original dataframe to get the tumor volume at the last timepoint
mice_df.head()
last_timepoint_list = []
last_tp_volume_list = []
four_treatments_df = mice_df.loc[(mice_df["Drug Regimen"]=="Capomulin")|(mice_df["Drug Regimen"]=="Ramicane")|(mice_df["Drug Regimen"]=="Infubinol")|(mice_df["Drug Regimen"]=="Ceftamin"),:]
mice_treatment = four_treatments_df.groupby("Mouse ID")

for x in mice_treatment["Timepoint"].max():
    last_timepoint_list.append(x)

max_tp=mice_treatment[["Timepoint"]].max()
all_merge_timepoint = pd.merge(max_tp,four_treatments_df,on="Mouse ID")
clean_merge = all_merge_timepoint.loc[all_merge_timepoint["Timepoint_x"]==all_merge_timepoint["Timepoint_y"],:]  
clean_merge = clean_merge[["Mouse ID","Drug Regimen","Sex","Age_months","Weight (g)","Timepoint_y",
                           "Tumor Volume (mm3)","Metastatic Sites"]]
clean_merge

for y in clean_merge["Tumor Volume (mm3)"]:
    last_tp_volume_list.append(f"{y:.2f}")


clean_merge = clean_merge.rename(columns={"Timepoint_y":"Last Timepoint","Tumor Volume (mm3)":"Last Tumor Volume (mm3) Behavior"})
clean_merge.head(20)
# Put treatments into a list for for loop (and later for plot labels)
# Create empty list to fill with tumor vol data (for plotting)
# Calculate the IQR and quantitatively determine if there are any potential outliers. 
    # Locate the rows which contain mice on each drug and get the tumor volumes
    # add subset 
    # Determine outliers using upper and lower bounds
list_of_treatments = ["Capomulin", "Ramicane", "Infubinol","Ceftamin"]
lower_quartiles = []
mid_quartiles = []
upper_quartiles = []
iqrs = []
lower_bounds = []
upper_bounds =[]
tumor_volumes_per_drug = []
outliners =[]

for drug in list_of_treatments:
    specific_drug = clean_merge.loc[clean_merge["Drug Regimen"]==drug,:]
    specific_drug_tumor_volume = specific_drug["Last Tumor Volume (mm3) Behavior"]
    tumor_volumes_per_drug.append(specific_drug_tumor_volume)
    quartiles = specific_drug_tumor_volume.quantile([0.25,0.5,0.75])
    
    lower_quartile=quartiles[0.25]
    mid_quartile =quartiles[0.5]
    upper_quartile=quartiles[0.75]
    iqr = upper_quartile - lower_quartile
    lower_bound = lower_quartile - (1.5 * iqr)
    upper_bound = upper_quartile + (1.5 * iqr)
    
    lower_quartiles.append(lower_quartile)
    mid_quartiles.append(mid_quartile)
    upper_quartiles.append(upper_quartile)
    iqrs.append(iqr)
    lower_bounds.append(lower_bound)
    upper_bounds.append(upper_bound)
    
    print("")
    print(f"Drug Name: {drug}.")
    print("-----------------------")
    print(f"{drug} lower quartile: {lower_quartile}")
    print(f"{drug} mean or mid_quartile: {mid_quartile}")
    print(f"{drug} upper quartile: {upper_quartile}")
    print(f"{drug} IQR: {round(iqr,2)}")
    print(f"{drug} lower bound: {round(lower_bound,2)}")
    print(f"{drug} upper bound: {round(upper_bound,2)}")

    counter = 0
    activator = False

    for mice in specific_drug_tumor_volume:
        if mice > upper_bound or mice < lower_bound:
            print(f"Outliners detected in {drug}: {mice}")
            outliners.append(mice)
            activator = True
        counter = counter + 1
        if counter == 25 and activator == False:
            print(f"No outliners detected in {drug}")
            outliners.append("None")
    
summary_statistics_df = pd.DataFrame({"Drug Regimen":list_of_treatments,"Lower Quartiles":lower_quartiles,
                                     "Mid Quartiles":mid_quartiles,"Upper Quartiles":upper_quartiles,"IQR":iqrs,
                                     "Lower Bounds":lower_bounds,"Upper Bounds":upper_bounds,"Outliners":outliners})
summary_statistics_df.set_index(["Drug Regimen"])
    
# Generate a box plot of the final tumor volume of each mouse across four regimens of interest
x_axis = list_of_treatments
ticks_locs =[]
fig1, ax1 = plt.subplots(figsize=(12,6))
boxprops = dict(linestyle='-', linewidth=1.5, color='skyblue')
flierprops = dict(marker='o', markerfacecolor='red', markersize=12,
                  markeredgecolor='none')
medianprops = dict(linestyle='--', linewidth=1.5, color='mediumslateblue')

for x in range(1,len(x_axis)+1):
    ticks_locs.append(x)


ax1.set_title('Final Tumor Volume vs Drug Regimen')
ax1.set_ylabel("Tumor Volume")
ax1.set_xlabel("Interest Drug Regimen")
ax1.boxplot(tumor_volumes_per_drug, boxprops=boxprops,flierprops=flierprops,medianprops=medianprops)
plt.xticks(ticks_locs, x_axis)
plt.hlines(45,0,len(x_axis)+1,color="red")
plt.annotate("Starting Tumor Volume: 45 mm3",(1.25,48),fontsize=12, color = "blue")
plt.show()<jupyter_output><empty_output><jupyter_text>Line and Scatter Plots<jupyter_code># Generate a line plot of tumor volume vs. time point for a mouse treated with Capomulin
capomulin_df = mice_df.loc[mice_df["Drug Regimen"]=="Capomulin"]
capomulin_groupby = capomulin_df.groupby("Timepoint")
campomulin_behavior = capomulin_groupby["Tumor Volume (mm3)"].mean()
campomulin_list_index = campomulin_behavior.index.values.tolist()

plt.figure(figsize=(12,6))
plt.plot(campomulin_list_index,campomulin_behavior, color="chartreuse",label="Tumor's Behavior")
plt.title("Capomulin: Tumor Volume vs Time Point")
plt.ylabel("Tumor Volume")
plt.xlabel("Timepoint")
plt.xlim(-5,50)
plt.ylim(36,45.25)
plt.legend(loc="best")
plt.grid()

plt.show()
# Generate a scatter plot of average tumor volume vs. mouse weight for the Capomulin regimen
plt.figure(figsize=(12,6))
capomulin_gb_weight = capomulin_df.groupby("Weight (g)")
capomulin_weight_vs_volume = capomulin_gb_weight["Tumor Volume (mm3)"].mean()
capomulin_weight_vs_volume_index = capomulin_weight_vs_volume.index.values.tolist()
capomulin_weight_vs_volume_index= [float(i) for i in capomulin_weight_vs_volume_index]
capomulin_weight_vs_volume_serie = pd.Series(capomulin_weight_vs_volume_index)
x_values = capomulin_weight_vs_volume_serie
y_values = capomulin_weight_vs_volume
(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, color="red")
plt.plot(x_values,regress_values,color="orange")

plt.title("Capomulin Scatter Plot: Average Tumor Volume vs Mouse Weight")
plt.xlabel("Weight")
plt.ylabel("Tumor Volume")
plt.annotate(line_eq,(20,40),fontsize=15, color="red")
plt.ylim(35.5,46)
plt.xlim(14.5,25.5)
plt.grid()
plt.show()<jupyter_output><empty_output><jupyter_text>Correlation and Regression<jupyter_code># Calculate the correlation coefficient and linear regression model 
# for mouse weight and average tumor volume for the Capomulin regimen
print(f"The linear regression model is: {line_eq}")
print(f"The r-squared is: {rvalue**2}")<jupyter_output>The linear regression model is: y = 0.89x + 22.76
The r-squared is: 0.90355017059501
{'fraction_non_alphanumeric': 0.12619732829345817, 'fraction_numerical': 0.015506206778059362, 'mean_word_length': 6.15268817204301, 'pattern_counts': {'":': 25, '<': 24, '<?xml version=': 0, '>': 24, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 8, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '6', 'dir': 'jupyter-structured-clean-dedup', 'id': '479860', 'license': 'ADSL', 'n_tokens_mistral': 8884, 'n_tokens_neox': 8105, 'n_words': 1690, 'path': 'Pymaceuticals/pymaceuticals_challenge.ipynb', 'repo_name': 'RaulMaya/Matplotlib-Challenge', 'size': '23281'}