<jupyter_start><jupyter_text>matplotlib-challengeThe Power of Plots April, 2020 UCF Data Analytics<jupyter_code>Overall, it is clear that Ramicane and Capomulin 
regimens both reduce tumor growth.
Ramicane and Capomulin produced similar results across this analysis and 
both had roughly the same number of mice in their trials.

A strong correlation between mouse weight and tumor volume exists, 
indicating that mouse weight may be contributing to the efficacy of 
these two drug regimens.  

The Infubinol regimen produced an outlier. While most Infubinol 
treated mice showed tumor volume increase, one mouse did
have a reduction in tumor growth. 
# Importing and setting up dependencies
import matplotlib.pyplot as plt
import pandas as pd
import scipy.stats as st

# Create a path for both csv files
mouse_metadata_path = "data/Mouse_metadata.csv"
study_results_path = "data/Study_results.csv"

# Read both csv's data
mouse_metadata = pd.read_csv(mouse_metadata_path)
study_results = pd.read_csv(study_results_path)
# Merge two datasets into dataframes based upon 
# Mouse ID-return a sample df head
Pymarceuticals_df = pd.merge(mouse_metadata, study_results, on="Mouse ID")
Pymarceuticals_df.head() 
# count the rows to see if anything is removed
Pymarceuticals_df.count()
# duplicates removed 'one row': 1893 rows to 1892
Pymarceuticals_df.drop_duplicates()
# create a summary table of mean, median, variance, standard deviation
# and SEM of the tumor volume for each drug regimen and all mice 
# outcomes included with remgimen
# Generate a summary statistics table of mean, median, 
# variance, standard deviation, and SEM of the tumor volume 
# for each regimen

means = Pymarceuticals_df.groupby('Drug Regimen').mean()['Tumor Volume (mm3)']
medians = Pymarceuticals_df.groupby('Drug Regimen').median()['Tumor Volume (mm3)']
variances = Pymarceuticals_df.groupby('Drug Regimen').var()['Tumor Volume (mm3)']
sds = Pymarceuticals_df.groupby('Drug Regimen').std()['Tumor Volume (mm3)']
sems = Pymarceuticals_df.groupby('Drug Regimen').sem()['Tumor Volume (mm3)']
summary_table = pd.DataFrame({"Tumor Volume Mean":means,
                              "Tumor Volume Median":medians,
                              "Tumor Volume Variance":variances,
                              "Tumor Volume Std. Dev.":sds,
                              "Tumor Volume Std. Err.":sems})
summary_table
# Generate a bar plot using pandas; number of data points is 
# number of mice that used that drug
counts = Pymarceuticals_df['Drug Regimen'].value_counts()
counts.plot(kind="bar")
plt.xlabel("Drug Regimens")
plt.xticks(rotation=60)
plt.ylabel("Number of Mice")
plt.show()
# Generate a bar plot using pyplot; number of data points is 
# number of mice that used that regimen
counts = Pymarceuticals_df['Drug Regimen'].value_counts()
plt.bar(counts.index.values,counts.values)
plt.xlabel("Drug Regimens")
plt.xticks(rotation=60)
plt.ylabel("Number of Mice")
plt.show()
# Generate a pie plot showing female versus male 
# distribution of mice using pandas
counts = mouse_metadata.Sex.value_counts()
counts.plot(kind="pie",autopct='%1.2f%%')
# plt.pie(counts.values,labels=counts.index.values,autopct='%1.1f%%')
plt.show()
# Generate a pie plot showing female versus male 
# distribution of mice using pyplot
counts = mouse_metadata.Sex.value_counts()
plt.pie(counts.values,labels=counts.index.values,autopct='%1.1f%%')
plt.ylabel("Sex")
plt.show()
# Prepare the data to find final tumor volume of each mouse for 4 of 
# the most promising treatment regimens: 
# Capomulin, Ramicane, Infubinol, Ceftamin

# Find the largest timepoint for each mouse
maximum_tumor = Pymarceuticals_df.groupby(["Mouse ID"]).max()
maximum_tumor = maximum_tumor.reset_index()
# Merge group dataframe with the original dataframe to retrieve tumor volume
# at the last timepoint
merged_data = maximum_tumor[['Mouse ID', 'Timepoint', ]].merge(Pymarceuticals_df,on=['Mouse ID','Timepoint'],how="left")

capomulin = merged_data.loc[merged_data["Drug Regimen"] == "Capomulin"]['Tumor Volume (mm3)']
ramicane = merged_data.loc[merged_data["Drug Regimen"] == "Ramicane"]['Tumor Volume (mm3)']
infubinol = merged_data.loc[merged_data["Drug Regimen"] == "Infubinol"]['Tumor Volume (mm3)']
ceftamin = merged_data.loc[merged_data["Drug Regimen"] == "Ceftamin"]['Tumor Volume (mm3)'] 
# Quantitatively find the capomulin data outliers
capomulin_quartiles = capomulin.quantile([.25,.5,.75])
capomulin_lowerq = capomulin_quartiles[0.25]
capomulin_upperq = capomulin_quartiles[0.75]
capomulin_iqr = capomulin_upperq-capomulin_lowerq
capomulin_lower_bound = capomulin_lowerq - (1.5*capomulin_iqr)
capomulin_upper_bound = capomulin_upperq + (1.5*capomulin_iqr)
print(f"Capomulin outliers: {capomulin.loc[(capomulin < capomulin_lower_bound) | (capomulin > capomulin_upper_bound)]}")
# Quantitatively find the ramicane data outliers
ramicane_quartiles = ramicane.quantile([.25,.5,.75])
ramicane_lowerq = ramicane_quartiles[0.25]
ramicane_upperq = ramicane_quartiles[0.75]
ramicane_iqr = ramicane_upperq-ramicane_lowerq
ramicane_lower_bound = ramicane_lowerq - (1.5*ramicane_iqr)
ramicane_upper_bound = ramicane_upperq + (1.5*ramicane_iqr)
print(f"Ramicane outliers: {ramicane.loc[(ramicane < ramicane_lower_bound) | (ramicane > ramicane_upper_bound)]}")
# Quantitatively find infubinol data outliers
infubinol_quartiles = infubinol.quantile([.25,.5,.75])
infubinol_lowerq = infubinol_quartiles[0.25]
infubinol_upperq = infubinol_quartiles[0.75]
infubinol_iqr = infubinol_upperq-infubinol_lowerq
infubinol_lower_bound = infubinol_lowerq - (1.5*infubinol_iqr)
infubinol_upper_bound = infubinol_upperq + (1.5*infubinol_iqr)
print(f"Infubinol outliers: {infubinol.loc[(infubinol < infubinol_lower_bound) | (infubinol > infubinol_upper_bound)]}")
# Quantitatively find the ceftamin data outliers
ceftamin_quartiles = ceftamin.quantile([.25,.5,.75])
ceftamin_lowerq = ceftamin_quartiles[0.25]
ceftamin_upperq = ceftamin_quartiles[0.75]
ceftamin_iqr = ceftamin_upperq-ceftamin_lowerq
ceftamin_lower_bound = ceftamin_lowerq - (1.5*ceftamin_iqr)
ceftamin_upper_bound = ceftamin_upperq + (1.5*ceftamin_iqr)
print(f"Ceftamin outliers: {ceftamin.loc[(ceftamin < ceftamin_lower_bound) | (ceftamin > ceftamin_upper_bound)]}")
# Generate a box and whisker plot of the final tumor volume for the four 
# treatment regimens
red_square = dict(markerfacecolor='red',markersize=14)
plt.boxplot([capomulin,ramicane,infubinol,ceftamin],labels=['Capomulin','Ramicane','Infubinol','Ceftamin'],flierprops=red_square)
plt.ylabel('Final Tumor Volume in MM3')
plt.show()
# Generate a line plot of timepoint versus tumor volume for a single 
# mouse treated with Capomulin
capomulin_table = Pymarceuticals_df.loc[Pymarceuticals_df['Drug Regimen'] == "Capomulin"]
mousedata = capomulin_table.loc[capomulin_table['Mouse ID']== 's185']
plt.plot(mousedata['Timepoint'],mousedata['Tumor Volume (mm3)'])
plt.xlabel('Timepoint in days')
plt.ylabel('Tumor Volume in MM3')
plt.title('mouse s185 Capomulin treatment results')
plt.show()
# Generate a scatter plot of mouse weight versus average tumor volume for the Capomulin regimen
capomulin_table = Pymarceuticals_df.loc[Pymarceuticals_df['Drug Regimen'] == "Capomulin"]
capomulin_average = capomulin_table.groupby(['Mouse ID']).mean()
plt.scatter(capomulin_average['Weight (g)'],capomulin_average['Tumor Volume (mm3)'])
plt.xlabel('Weight in grams')
plt.ylabel('Average Tumor Volume in MM3')
plt.show()
# Calculate the correlation coefficient and linear regression model 
# for mouse weight and average tumor volume for the Capomulin regimen
corr=round(st.pearsonr(capomulin_average['Weight (g)'],capomulin_average['Tumor Volume (mm3)'])[0],2)
print(f"Capomulin correlation: mouse weight and average tumor volume {corr}")
model = st.linregress(capomulin_average['Weight (g)'],capomulin_average['Tumor Volume (mm3)'])
y_values = capomulin_average['Weight (g)']*model[0]+model[1]
plt.scatter(capomulin_average['Weight (g)'],capomulin_average['Tumor Volume (mm3)'])
plt.plot(capomulin_average['Weight (g)'],y_values,color="yellow")
plt.xlabel('Weight in grams')
plt.ylabel('Average Tumor Volume in MM3')
plt.show()<jupyter_output>Capomulin correlation: mouse weight and average tumor volume 0.84
{'fraction_non_alphanumeric': 0.11077445158162647, 'fraction_numerical': 0.014058901951278633, 'mean_word_length': 6.440937781785392, 'pattern_counts': {'":': 5, '<': 8, '<?xml version=': 0, '>': 8, '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': '352360', 'license': 'MIT', 'n_tokens_mistral': 3052, 'n_tokens_neox': 2793, 'n_words': 696, 'path': 'Pymarceuticals/matplotlib-challenge.ipynb', 'repo_name': 'brianchristopherhenley/matplotlib-challenge', 'size': '8251'}