<jupyter_start><jupyter_text>Observations and Insights<jupyter_code>#observations
#while Capomulin and ramicane had large variations in final tumor volume, they also had the smallest final volume during the tests
#from the random sample line graph of Capomulin drug tests, we can see that the drug didn't take effect right away, but once processed, had immediate results
#from the scatter plot of capomulin drug tests, we can see a direct coorelation between the weight of the mouse and the avg tumor volume (nearly a 1:1 coorelation)
# 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
full_mouse = pd.merge(study_results, mouse_metadata, how='left', on='Mouse ID')

full_mouse.head()
# Checking the number of mice in the DataFrame.
len(full_mouse['Mouse ID'].unique())
# Getting the duplicate mice by ID number that shows up for Mouse ID and Timepoint. 
# https://thispointer.com/pandas-find-duplicate-rows-in-a-dataframe-based-on-all-or-selected-columns-using-dataframe-duplicated-in-python/

dup_mice = full_mouse.loc[full_mouse.duplicated(subset=['Mouse ID', 'Timepoint']), 'Mouse ID'].unique()
dup_mice
# Optional: Get all the data for the duplicate mouse ID. 

# Create a clean DataFrame by dropping the duplicate mouse by its ID.
# https://www.w3resource.com/pandas/dataframe/dataframe-isin.php
full_mouse_clean = full_mouse[full_mouse['Mouse ID'].isin(dup_mice)==False]
full_mouse_clean
# Checking the number of mice in the clean DataFrame.
len(full_mouse_clean['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

mean = full_mouse_clean.groupby('Drug Regimen').mean()['Tumor Volume (mm3)']
#print(mean)
median = full_mouse_clean.groupby('Drug Regimen').median()['Tumor Volume (mm3)']
#print(median)
variance = full_mouse_clean.groupby('Drug Regimen').var()['Tumor Volume (mm3)']
#print(variance)
std_dev = full_mouse_clean.groupby('Drug Regimen').std()['Tumor Volume (mm3)']
#print(std_dev)
sem = full_mouse_clean.groupby('Drug Regimen').sem()['Tumor Volume (mm3)']
#print(sem)
# This method is the most straightforward, creating multiple series and putting them all together at the end.

drug_tumor_summary = pd.DataFrame({
    'Mean Tumor Volume': mean,
    'Median Tumor Volume': median,
    'Tumor Variance': variance,
    'Tumor Volume Std Dev': std_dev,
    'Tumor Volume Std Err': sem
})

drug_tumor_summary
# 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.<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.

counter = full_mouse_clean['Drug Regimen'].value_counts()

counter.plot(kind='bar')

#clean chart

plt.xlabel('Drug Regimen')
plt.ylabel('Number of Mice per Time Point')


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.

counter = full_mouse_clean['Drug Regimen'].value_counts()

plt.bar(counter.index.values, counter.values)

plt.xlabel('Drug Regimen')
plt.xticks(rotation=90)
plt.ylabel('Number of Mice per Time Point')

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

counter = full_mouse_clean['Sex'].value_counts()

counter.plot(kind='pie', autopct='%1.1f%%')


plt.show


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

counter = full_mouse_clean['Sex'].value_counts()

plt.pie(counter.values, labels=counter.index.values, autopct='%1.1f%%')

#add graph label

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. 

# thank you Carrie for the help with the code for finding drug effectivness!
#drugs taken from smallest tumor volume mean

#get only final tumor volumes for timepoints greater than or equal to 45
mmerge_df=full_mouse_clean.loc[full_mouse_clean['Timepoint']>=45]

#separate them out by drug regimen

cap_df = mmerge_df.loc[mmerge_df['Drug Regimen'] == 'Capomulin']['Tumor Volume (mm3)']
ram_df = mmerge_df.loc[mmerge_df['Drug Regimen'] == 'Ramicane']['Tumor Volume (mm3)']
pro_df = mmerge_df.loc[mmerge_df['Drug Regimen'] == 'Propriva']['Tumor Volume (mm3)']
ceft_df = mmerge_df.loc[mmerge_df['Drug Regimen'] == 'Ceftamin']['Tumor Volume (mm3)']

#wait, can't i just use .isin like before to find dups and instead find these 4 drugs???
"""best_drugs = mmerge_df.loc[mmerge_df['Drug Regimen'].isin(['Capomulin', 'Ramicane', 'Propriva', 'Ceftamin'])]
best_drugs_data = best_drugs[['Drug Regimen', 'Mouse ID', 'Timepoint', 'Tumor Volume (mm3)']]
best_drugs_data"""

mmerge_df

# Generate a box plot of the final tumor volume of each mouse across four regimens of interest

drug_list = ['Capomulin', 'Ramicane', 'Propriva', 'Ceftamin']

green_diamond = dict(markerfacecolor='g', marker='D')
plt.boxplot([cap_df,ram_df,pro_df,ceft_df],labels=drug_list, flierprops=green_diamond)
plt.ylabel('Final Tumor Volume (mm3)')
plt.show
# https://matplotlib.org/gallery/pyplots/boxplot_demo_pyplot.html#sphx-glr-gallery-pyplots-boxplot-demo-pyplot-py<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 = full_mouse_clean.loc[full_mouse_clean['Drug Regimen'] == 'Capomulin']

#check data
#capomulin_data

cap_mouse_data = capomulin_data.loc[capomulin_data['Mouse ID'] == 'r944']

#check data
#cap_mouse_data

plt.plot(cap_mouse_data['Timepoint'], cap_mouse_data['Tumor Volume (mm3)'])

#add details
plt.ylabel('Tumor Volume (mm3)')
plt.xlabel('Timepoint')
plt.title('Capomulin Treatment of Mouse r944')

plt.show
# Generate a scatter plot of mouse weight versus average tumor volume for the Capomulin regimen

capomulin_data = full_mouse_clean.loc[full_mouse_clean['Drug Regimen'] == 'Capomulin']

#check data
#capomulin_data

cap_mouse_avg = capomulin_data.groupby(['Mouse ID']).mean()

#check data
#cap_mouse_data

plt.scatter(cap_mouse_avg['Weight (g)'], cap_mouse_avg['Tumor Volume (mm3)'])

#add details
plt.ylabel('Tumor Volume (mm3)')
plt.xlabel('Weight (g)')

plt.show<jupyter_output><empty_output><jupyter_text>Correlation and Regression<jupyter_code># Calculate the correlation coefficient and linear regression model

mouse_weight_slope, mouse_weight_int, mouse_weight_r, mouse_weight_p, mouse_weight_std_err = st.linregress(cap_mouse_avg['Weight (g)'], cap_mouse_avg['Tumor Volume (mm3)'])

mouse_weight = cap_mouse_avg['Weight (g)']

mouse_weight_fit = mouse_weight_slope * mouse_weight + mouse_weight_int



# for mouse weight and average tumor volume for the Capomulin regimen

plt.scatter(cap_mouse_avg['Weight (g)'], cap_mouse_avg['Tumor Volume (mm3)'])
plt.plot(mouse_weight,mouse_weight_fit,color='red')
plt.ylabel('Tumor Volume (mm3)')
plt.xlabel('Weight (g)')
plt.show()
mouse_weight_slope<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.10966257668711657, 'fraction_numerical': 0.0048568507157464216, 'mean_word_length': 6.589718719689622, 'pattern_counts': {'":': 0, '<': 29, '<?xml version=': 0, '>': 30, 'https://': 3, 'lorem ipsum': 0, 'www.': 1, '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': '643639', 'license': 'ADSL', 'n_tokens_mistral': 2701, 'n_tokens_neox': 2545, 'n_words': 744, 'path': 'Pymaceuticals/pymaceuticals_starter.ipynb', 'repo_name': 'Al-Faust/matplotlib-challenge', 'size': '7824'}