<jupyter_start><jupyter_text>Observations and Insights As a conclusion of the python matplotlib challenge, I can say that the capomulin treatment was the most efficient for the tumor treatments in the mice. The majority of the mice tested were males. They were no outliers. When the doses of the drug is increase, the size of the tumor is reduce.  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)

# Combine the data into a single dataset

combined_study_data=pd.merge(study_results,mouse_metadata,how='outer', on="Mouse ID")

combined_study_data.head(20)<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
#Create inital summary table with Drug Regimes and counts

tumor_data = pd.DataFrame(combined_study_data.groupby("Drug Regimen").count())

tumor_data["Mean"] = pd.DataFrame(combined_study_data.groupby("Drug Regimen")["Tumor Volume (mm3)"].mean())
tumor_data["Median"] = pd.DataFrame(combined_study_data.groupby("Drug Regimen")["Tumor Volume (mm3)"].median())
tumor_data["Standard Deviation"] = pd.DataFrame(combined_study_data.groupby("Drug Regimen")["Tumor Volume (mm3)"].std())
tumor_data["Variance"] = pd.DataFrame(combined_study_data.groupby("Drug Regimen")["Tumor Volume (mm3)"].var())
tumor_data["SEM"] = pd.DataFrame(combined_study_data.groupby("Drug Regimen")["Tumor Volume (mm3)"].sem())


tumor_data = tumor_data[[ "Mouse ID","Mean", "Median", "Standard Deviation", "Variance", "SEM"]]


tumor_data.head()<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



tumor_data = tumor_data[["Mouse ID"]]
tumor_data.plot(kind="bar", figsize=(6,4), color = "r", legend=False)

plt.title("Trials per Drug Regime")
plt.show()
plt.tight_layout()
# Generate a bar plot showing number of data points for each treatment regimen using pyplot


x_axis = np.arange(len(tumor_data))
tick_locations = [value for value in x_axis]


plt.figure(figsize=(6,4))
plt.bar(x_axis, tumor_data["Mouse ID"], color = "r", width = .5)
plt.xticks(tick_locations, tumor_data.index.values, rotation="vertical")


plt.title("Trials per Drug Regime")
plt.xlim(-0.75, len(x_axis)-.25)
plt.ylim(0, max(tumor_data["Mouse ID"])+10)<jupyter_output><empty_output><jupyter_text>Pie plots<jupyter_code>combined_study_data.head()
# Generate a pie plot showing the distribution of female versus male mice using pandas
combined_study_data.groupby("Sex")["Sex"].count()
explode=(0.01,0)

sexPie=combined_study_data.groupby("Sex")['Sex'].count().sort_index(ascending=False)
sexPie.plot(kind='pie', explode=explode, autopct="%1.1f%%", shadow=True)
plt.title("Distribution Of Female Vs male")
plt.savefig("Pandas Pie.png")

# Generate a pie plot showing the distribution of female versus male mice using pyplot
plt.pie(sexPie, explode=explode, autopct="%1.1f%%", shadow=True, labels=sexPie.index)
plt.title("Distribution Of Female Vs male")
plt.savefig("Pyplot Pie.png")<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.

tumor_number = combined_study_data.loc[(combined_study_data["Drug Regimen"]=="Capomulin") | (combined_study_data["Drug Regimen"] == "Ramicane") | (combined_study_data["Drug Regimen"] == "Infubinol") | (combined_study_data["Drug Regimen"] == "Ceftamin"), :]
tumor_number = tumor_number.sort_values("Timepoint", ascending= False)
tumor_number = tumor_number.drop_duplicates(subset="Mouse ID", keep='first')

quartiles = tumor_number['Tumor Volume (mm3)'].quantile([.25,.5,.75])
lowerq = quartiles[0.25]
upperq = quartiles[0.75]
iqr = upperq-lowerq

lower_bound = lowerq - (1.5*iqr)
upper_bound = upperq + (1.5*iqr)

tumor_data = tumor_number.loc[(tumor_number['Tumor Volume (mm3)'] > upper_bound) | (tumor_number['Tumor Volume (mm3)'] < lower_bound), :]

tumor_data.head()
# Generate a box plot of the final tumor volume of each mouse across four regimens of interest
tumor_volume= tumor_number['Tumor Volume (mm3)']
fig1, ax1 = plt.subplots()
ax1.set_title('Tumor Volume of each Mouse')
ax1.set_ylabel('Tumor Volume (mm3)')
ax1.boxplot(tumor_volume)
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


capomulin_data = combined_study_data.loc[(combined_study_data["Drug Regimen"]== "Capomulin") & (combined_study_data["Mouse ID"]== "b128"),:]

timepoint = capomulin_data["Timepoint"]
tumor_volume = capomulin_data["Tumor Volume (mm3)"]
plt.title("Generate a line plot of time point versus tumor volume for a mouse treated with Capomulin")
plt.xlabel("Tumor Volume (mm3)")
plt.ylabel("Timepoint")

tumor_value_data= plt.plot(timepoint, tumor_volume)
# Generate a scatter plot of mouse weight versus average tumor volume for the Capomulin regimen
capomulin_result = combined_study_data.loc[(combined_study_data ["Drug Regimen"] == "Capomulin"), :]
mouse_weight = capomulin_result.groupby(combined_study_data["Mouse ID"])["Weight (g)"].mean()
tumor_volume = capomulin_result.groupby(combined_study_data["Mouse ID"])["Tumor Volume (mm3)"].mean()

plt.scatter(mouse_weight,tumor_volume)
plt.xlabel("Mouse's weight(g)")
plt.ylabel("Tumor Volume (mm3)")
plt.title("Mouse weight Vs Average Tumor Volume (mm3) For The Capomulin Regimen")
plt.show()

# Calculate the correlation coefficient and linear regression model for mouse weight and average tumor volume for the Capomulin regimen
mouse_weight = capomulin_result.groupby(capomulin_result["Mouse ID"])["Weight (g)"].mean()
tumor_volume = capomulin_result.groupby(capomulin_result["Mouse ID"])["Tumor Volume (mm3)"].mean()
slope, intercept, rvalue, pvalue, stderr = st.linregress(mouse_weight, tumor_volume)

line = slope * mouse_weight + intercept

plt.scatter(mouse_weight,tumor_volume)
plt.title("Correlation Coefficient And Linear Regression Model For Mouse Weight And Average Tumor Volume For The Capomulin Regimen")
plt.xlabel("Mouse's weight (g)")
plt.ylabel("Tumor Volume (mm3)")
plt.plot(mouse_weight,line,"--")
plt.xticks(mouse_weight, rotation=90)
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.12498162034994853, 'fraction_numerical': 0.00955741802676077, 'mean_word_length': 7.407911001236094, 'pattern_counts': {'":': 0, '<': 26, '<?xml version=': 0, '>': 26, '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': '217659', 'license': 'ADSL', 'n_tokens_mistral': 2449, 'n_tokens_neox': 2206, 'n_words': 586, 'path': 'Pymaceuticals/pymaceuticals_starter.ipynb', 'repo_name': 'cathdp/Python-Matplotlib-Project', 'size': '6801'}