<jupyter_start><jupyter_text>Observations and Insights  - Capomulin is a viable drug regimen to reduce tumor growth.- Capomulin had the most number of mice complete the study, with the exception of Remicane, all other regimens observed a number of mice deaths across the duration of the study.- There is a strong correlation between mouse weight and tumor volume, indicating that mouse weight may be contributing to the effectiveness of any drug regimen.- There was one potential outlier within the Infubinol regimen. While most mice showed tumor volume increase, there was one mouse that had a reduction in tumor growth in the study.<jupyter_code># Dependencies and Setup
import matplotlib.pyplot as plt
import pandas as pd
import scipy.stats as st

# 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

study_merged = pd.merge(study_results, mouse_metadata, how='left', on="Mouse ID")

#Displat the data table for preview

study_merged.head()



# Checking the number of mice in the DataFrame.

len(study_merged["Mouse ID"].unique())

# Getting the duplicate mice by ID number that shows up for Mouse ID and Timepoint. 
duplicate_mouse_ids = study_merged.loc[study_merged.duplicated(subset=['Mouse ID', 'Timepoint']), 'Mouse ID'].unique()

duplicate_mouse_ids

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

duplicate_mouse_data = study_merged.loc[study_merged["Mouse ID"] == "g989"]
duplicate_mouse_data

# Create a clean DataFrame by dropping the duplicate mouse by its ID. I use the ISIn method to filter out duplicated mouse ID= False
clean_study_merged = study_merged[study_merged['Mouse ID'].isin(duplicate_mouse_ids)==False]
clean_study_merged.head()


# Checking the number of mice in the clean DataFrame.

len(clean_study_merged["Mouse ID"].unique())<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

# This method is the most straightforward, creating multiple series and putting them all together at the end. Somehow Sem did not work. ADD FEEDBACK TO BOOTHCAMP

means = clean_study_merged.groupby('Drug Regimen').mean()['Tumor Volume (mm3)']
medians = clean_study_merged.groupby('Drug Regimen').median()['Tumor Volume (mm3)']
variances = clean_study_merged.groupby('Drug Regimen').var()['Tumor Volume (mm3)']
sds = clean_study_merged.groupby('Drug Regimen').std()['Tumor Volume (mm3)']
summary_table = pd.DataFrame({"Mean Tumor Volume":means,
                              "Median Tumor Volume":medians,
                              "Tumor Volume Variance":variances,
                              "Tumor Volume Std. Dev.":sds})
summary_table



clean_study_merged.groupby("Drug Regimen").describe()['Tumor Volume (mm3)']
# Generate a summary statistics table of mean, median, variance, standard deviation, and SEM of the tumor volume for each regimen



# This method produces everything in a single groupby function.
summary_table = clean_study_merged.groupby("Drug Regimen").agg({
    "Tumor Volume (mm3)": ['count', "mean","median","var","std","sem", 'max']
})
summary_table<jupyter_output><empty_output><jupyter_text>Bar Plots<jupyter_code># Generate a bar plot showing the number of mice per time point for each treatment throughout the course of the study using pandas.Check day 1 session 02:55 

counts = clean_study_merged['Drug Regimen'].value_counts()
counts.plot(kind="bar")
plt.xlabel("Drug Regimen")
plt.xticks(rotation=90)
plt.ylabel("Number of Data Points")
plt.show()


# Generate a bar plot showing the number of mice per time point for each treatment throughout the course of the study using pyplot.
# use method value_counts() to return unique Drug regimes

counts = clean_study_merged['Drug Regimen'].value_counts()
plt.bar(counts.index.values,counts.values)
plt.xlabel("Drug Regimen")
plt.xticks(rotation=90)
plt.ylabel("Number of Data Points")
plt.show()<jupyter_output><empty_output><jupyter_text>Pie Plots<jupyter_code># Generate a pie plot showing the distribution of female versus male mice using pandas
counts = mouse_metadata.Sex.value_counts()
counts.plot(kind="pie",autopct='%1.1f%%')
# plt.pie(counts.values,labels=counts.index.values,autopct='%1.1f%%')
plt.show()

counts
# Generate a pie plot showing the distribution of female versus male mice using pyplot

counts = mouse_metadata.Sex.value_counts()
counts
plt.pie(counts.values,labels=counts.index.values,autopct='%1.1f%%')
plt.ylabel("Sex")
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 most promising treatment regimens. Calculate the IQR and quantitatively determine if there are any potential outliers. 

# Start by getting the last (greatest) timepoint for each mouse
max_tumor = clean_study_merged.groupby(["Mouse ID"]).max()
max_tumor = max_tumor.reset_index()
# Merge this group df with the original dataframe to get the tumor volume at the last timepoint
merged_data = max_tumor[['Mouse ID','Timepoint']].merge(clean_study_merged,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 determine capomulin outliers
cap_quartiles = capomulin.quantile([.25,.5,.75])
cap_lowerq = cap_quartiles[0.25]
cap_upperq = cap_quartiles[0.75]
cap_iqr = cap_upperq-cap_lowerq
cap_lower_bound = cap_lowerq - (1.5*cap_iqr)
cap_upper_bound = cap_upperq + (1.5*cap_iqr)
print(f"Capomulin potential outliers: {capomulin.loc[(capomulin < cap_lower_bound) | (capomulin > cap_upper_bound)]}")



# Generate a box plot of the final tumor volume of each mouse across four regimens of interest
orange_out = dict(markerfacecolor='red',markersize=12)
plt.boxplot([capomulin,ramicane,infubinol,ceftamin],labels=['Capomulin','Ramicane','Infubinol','Ceftamin'],flierprops=orange_out)
plt.ylabel('Final Tumor Volume (mm3)')
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_table = clean_study_merged.loc[clean_study_merged['Drug Regimen'] == "Capomulin"]
mousedata = capomulin_table.loc[capomulin_table['Mouse ID']== 'l509']
plt.plot(mousedata['Timepoint'],mousedata['Tumor Volume (mm3)'])
plt.xlabel('Timepoint (days)')
plt.ylabel('Tumor Volume (mm3)')
plt.title('Capomulin treatment of mouse l509')
plt.show()

# Generate a scatter plot of mouse weight versus average tumor volume for the Capomulin regimen
capomulin_table = clean_study_merged.loc[clean_study_merged['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 (g)')
plt.ylabel('Average Tumor Volume (mm3)')
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<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10608222020490209, 'fraction_numerical': 0.00726235248346518, 'mean_word_length': 6.2961210974456, 'pattern_counts': {'":': 5, '<': 30, '<?xml version=': 0, '>': 30, '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': '7', 'dir': 'jupyter-structured-clean-dedup', 'id': '54302', 'license': 'Apache-2.0', 'n_tokens_mistral': 2602, 'n_tokens_neox': 2366, 'n_words': 723, 'path': 'pymaceuticals_starter.ipynb', 'repo_name': 'Egallego77/Matplotlib', 'size': '7711'}