<jupyter_start><jupyter_text>Observations and Insights<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"

# Read the mouse data
mouse_metadata = pd.read_csv(mouse_metadata_path)
mouse_metadata
# Study data files
study_results_path = "data/Study_results.csv"

# Read the study results
study_results = pd.read_csv(study_results_path)
study_results
study_results['Mouse ID'].loc[study_results.duplicated(['Mouse ID', 'Timepoint'])]
study_results.drop_duplicates(subset=['Mouse ID', 'Timepoint'])
# Combine the data into a single dataset
mouse_study = pd.merge(mouse_metadata, study_results, on="Mouse ID", how="left")
mouse_study
# Create a clean DataFrame by dropping the duplicate mouse by its ID. 
clean_df = study_results.loc[study_results['Mouse ID'] !='g989']
clean_df
# Display the data table for preview
mouse_study.head()
# Checking the number of mice.
len(mouse_study['Mouse ID'].unique()) 
# Getting the duplicate mice by ID number that shows up for Mouse ID and Timepoint. 

duplicated_ID = mouse_study.loc[mouse_study.duplicated(subset=["Mouse ID", "Timepoint"]), "Mouse ID"].unique()
duplicated_ID                                
# Optional: Get all the data for the duplicate mouse ID. 
duplicated_data = mouse_study.loc[mouse_study["Mouse ID"]=="g989"]
duplicated_data
# Create a clean DataFrame by dropping the duplicate mouse by its ID.
cleandata_df = mouse_study[mouse_study["Mouse ID"]==False]
cleandata_df
# Checking the number of mice in the clean DataFrame.
len(clean_df["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
# 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. 

Mean = mouse_study.groupby(['Drug Regimen']).mean(), (['Tumor Volume(mm3)'])
Median = mouse_study.groupby(['Drug Regimen']).median(), (['Tumor Volume(mm3)'])
Variance = mouse_study.groupby(['Drug Regimen']).var(), (['Tumor Volume(mm3)'])
Standard_deviation = mouse_study.groupby(['Drug Regimen']).std(), (['Tumor Volume(mm3)'])
SEM = mouse_study.groupby(['Drug Regimen']).sem(), (['Tumor Volume(mm3)'])
stat_table = pd.DataFrame({'Mean:Mean', 'Median:Median', 'Variance:Variance', 'Standard_deviation:Standard_deviation', 'SEM:SEM'})
stat_table

# Assemble the resulting series into a single summary dataframe.
mouse_study = pd.merge(mouse_metadata, study_results, on="Mouse ID", how="left")
mouse_study.head()

# 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
summary_table=mouse_study.groupby(["Drug Regimen"]).agg({"Tumor Volume (mm3)":["mean", "median", "var", "std", "sem"]})
summary_table<jupyter_output><empty_output><jupyter_text>Bar and Pie Charts<jupyter_code># Generate a bar plot showing the total number of unique mice tested on each drug regimen using pandas.

mousestudy_per_treat = mouse_study.groupby(["Drug Regimen"]).count()["Mouse ID"] 
plot_pandas = mousestudy_per_treat.plot.bar(figsize=(15,10), color='b',fontsize = 14)
mousestudy_per_treat

plt.xlabel("Drug Regimen",fontsize = 14)
plt.ylabel("Number of Mice",fontsize = 14)
plt.title("Number of Mice per Treatment",fontsize = 20)

plt.savefig("../Images/Pan_mice_per_treat.png", bbox_inches = "tight")
plt.tight_layout()
plt.show()

mousestudy_per_treat

# Generate a bar plot showing the total number of unique mice tested on each drug regimen using pyplot.

labels = ["Female","Male"]

sizes = [49.799197,50.200803]

colors = ['orange', 'blue']

explode = (0.1, 0)

#Create the pie chart based upon the values 
fig1, ax1 = plt.subplots(figsize=(15, 10))
plt.pie(sizes, explode=explode,labels=labels, colors=colors, autopct="%1.1f%%", shadow=True, startangle=140,)
plt.title('Male vs Female Mouse Population',fontsize = 20)
plt.ylabel('Sex',fontsize = 14)
#Set equal axis
plt.axis("equal",fontsize = 14)

plt.savefig("../Images/pi_plot.png", bbox_inches = "tight")
plt.show()



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

#Group by "Mouse ID" and "Sex" to find the unique number of male vs female
groupby_gender = mouse_study.groupby(["Mouse ID","Sex"])
groupby_gender

mouse_study_df = pd.DataFrame(groupby_gender.size())

#Create the dataframe with total count of Female and Male mice
mouse_study = pd.DataFrame(mouse_study_df.groupby(["Sex"]).count())
mouse_study.columns = ["Total Count"]

#create and format the percentage of female vs male
mouse_study["Percentage of Sex"] = (100*(mouse_study["Total Count"]/mouse_study["Total Count"].sum()))

#format the "Percentage of Sex" column
mouse_study["Percentage of Sex"] = mouse_study["Percentage of Sex"].astype(float).map('{:,.2f}%'.format)

#gender_df
mouse_study

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

labels = ["Female","Male"]

sizes = [49.799197,50.200803]

colors = ['orange', 'blue']

#Determoine which section of the circle to detach
explode = (0.1, 0)

#Create the pie chart based upon the values 
fig1, ax1 = plt.subplots(figsize=(15, 10))
plt.pie(sizes, explode=explode,labels=labels, colors=colors, autopct="%1.1f%%", shadow=True, startangle=140,)
plt.title('Male vs Female Mouse Population',fontsize = 20)
plt.ylabel('Sex',fontsize = 14)
#Set equal axis
plt.axis("equal",fontsize = 14)

plt.savefig("../Images/pi_plot.png", bbox_inches = "tight")
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




# 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
    
# Generate a box plot of the final tumor volume of each mouse across four regimens of interest<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

# Generate a scatter plot of average tumor volume vs. mouse weight for the Capomulin regimen<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

import matplotlib.pyplot as plt<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11080408952749378, 'fraction_numerical': 0.013815971262779773, 'mean_word_length': 5.81638418079096, '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': '623088', 'license': 'ADSL', 'n_tokens_mistral': 2463, 'n_tokens_neox': 2222, 'n_words': 737, 'path': 'Pymaceuticals/pymaceuticals_starter.ipynb', 'repo_name': 'bernabecia/MatPlotLibChallenge-HW', 'size': '7238'}