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

# 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
df_merged = pd.merge(study_results, mouse_metadata, on = ['Mouse ID'], how='left')
df_merged<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

drug_mean = df_merged.groupby("Drug Regimen").mean()["Tumor Volume (mm3)"]
drug_mean
drug_median = df_merged.groupby("Drug Regimen").median()["Tumor Volume (mm3)"]
drug_median
drug_variance = df_merged.groupby("Drug Regimen").var()["Tumor Volume (mm3)"]
drug_variance
drug_stdDev = df_merged.groupby("Drug Regimen").std()["Tumor Volume (mm3)"]
drug_stdDev
drug_SEM = df_merged.groupby("Drug Regimen").sem()["Tumor Volume (mm3)"]
drug_SEM<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

drug_vCounts = df_merged["Drug Regimen"].value_counts()

drug_vCounts.plot(kind = "bar")
plt.xlabel("Drug Labels")
plt.ylabel("Number of Data points")
##plt.ticks
# Generate a bar plot showing number of data points for each treatment regimen using pyplot

plt.bar(drug_vCounts.index.values, drug_vCounts.values)
plt.xticks(rotation = 90)
plt.xlabel("Drug Labels")
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

mouse_genCounts = mouse_metadata["Sex"].value_counts()
mouse_genCounts.plot(kind = "pie", autopct='%1.1f%%')
plt.show()

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

plt.pie(mouse_genCounts.values, labels = mouse_genCounts.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. 
# max_tumor = drug_SEM.groupby(["Mouse ID"]).max()
# max_tumor =  max_tumor.reset_index();
# merged
mouse_success = df_merged.groupby("Mouse ID").max()
mouse_success = mouse_success.reset_index()
mouse_success
mouse_merge = mouse_success[["Mouse ID", "Timepoint"]].merge(df_merged, on = ["Mouse ID", "Timepoint"], how = "left")
mouse_merge
#Value 1
Capomulin = mouse_merge.loc[mouse_merge["Drug Regimen"] == "Capomulin"]["Tumor Volume (mm3)"]
Capomulin
capomulin_df = pd.DataFrame(Capomulin)
capo_Quartile_df = capomulin_df['Tumor Volume (mm3)'].quantile([.25,.5,.75])
capo_lowerq = capo_Quartile_df[.25]
capo_upperq = capo_Quartile_df[.75]
capo_iqr = capo_upperq-capo_lowerq
print(f"The lower quartile of Capomulin is: {capo_lowerq}")
print(f"The upper quartile of Capomulin is: {capo_upperq}")
print(f"The interquartile range of Capomulin is: {capo_iqr}")
#Value 2
Ramicane = mouse_merge.loc[mouse_merge["Drug Regimen"] == "Ramicane"]["Tumor Volume (mm3)"]
Ramicane
ramicane_df = pd.DataFrame(Ramicane)
rami_Quartile_df = ramicane_df['Tumor Volume (mm3)'].quantile([.25,.5,.75])
rami_lowerq = rami_Quartile_df[.25]
rami_upperq = rami_Quartile_df[.75]
rami_iqr = rami_upperq-rami_lowerq
print(f"The lower quartile of Ramicane is: {rami_lowerq}")
print(f"The upper quartile of Ramicane is: {rami_upperq}")
print(f"The interquartile range of Ramicane is: {rami_iqr}")
#val 3
Infubinol = mouse_merge.loc[mouse_merge["Drug Regimen"] == "Infubinol"]["Tumor Volume (mm3)"]
Infubinol
infubinol_df = pd.DataFrame(Infubinol)
infu_Quartile_df = infubinol_df['Tumor Volume (mm3)'].quantile([.25,.5,.75])
infu_lowerq = infu_Quartile_df[.25]
infu_upperq = infu_Quartile_df[.75]
infu_iqr = infu_upperq-infu_lowerq
print(f"The lower quartile of Infubinol is: {infu_lowerq}")
print(f"The upper quartile of Infubinol is: {infu_upperq}")
print(f"The interquartile range of Infubinol is: {infu_iqr}")
##val 4
Ceftamin = mouse_merge.loc[mouse_merge["Drug Regimen"] == "Ceftamin"]["Tumor Volume (mm3)"]
Ceftamin
ceftamin_df = pd.DataFrame(Ceftamin)
cefta_Quartile_df = ceftamin_df['Tumor Volume (mm3)'].quantile([.25,.5,.75])
cefta_lowerq = cefta_Quartile_df[.25]
cefta_upperq = cefta_Quartile_df[.75]
cefta_iqr = cefta_upperq-cefta_lowerq
print(f"The lower quartile of Ceftamin is: {cefta_lowerq}")
print(f"The upper quartile of Ceftamin is: {cefta_upperq}")
print(f"The interquartile range of Ceftamin is: {cefta_iqr}")
# Generate a box plot of the final tumor volume of each mouse across four regimens of interest
drug_data = [Capomulin, Ramicane, Infubinol, Ceftamin]
drug_data = [Capomulin, Ramicane, Infubinol, Ceftamin]
fig1, ax1 = plt.subplots()
ax1.boxplot(drug_data, showmeans = True)<jupyter_output><empty_output><jupyter_text>Line and scatter plots<jupyter_code>capo_Full_df = df_merged.loc[df_merged['Drug Regimen'] == 'Capomulin']
capo_Full_df.head()
# Generate a line plot of time point versus tumor volume for a mouse treated with Capomulin

capo_Mouse_df = capo_Full_df.groupby("Mouse ID").get_group("s185")
capo_Mouse_df
capo_Full_df.plot(kind = "line", x = "Timepoint", y = "Tumor Volume (mm3)" )

#group by mouse ID then Get_group to get one mouse
##.get
# Generate a scatter plot of mouse weight versus average tumor volume for the Capomulin regimen

capo_Full_df.plot(kind = "scatter", x = "Weight (g)", y = "Tumor Volume (mm3)" )
# Calculate the correlation coefficient and linear regression model for mouse weight and average tumor volume for the Capomulin regimen
capo_Full_wieght = capo_Full_df("Wieght (g)")
capo_Full_TvolMean = capo_Full_df(capo_Full_df("Tumor Volume (mm3)").mean()
plt.scatter(capo_Full_wieght, capo_Full_TvolMean)
plt.plot(X, Y_pred, color='red')
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11844412561772677, 'fraction_numerical': 0.01084010840108401, 'mean_word_length': 7.266139657444005, 'pattern_counts': {'":': 0, '<': 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': '184310', 'license': 'ADSL', 'n_tokens_mistral': 2425, 'n_tokens_neox': 2280, 'n_words': 561, 'path': 'Pymaceuticals/pymaceuticals_starter.ipynb', 'repo_name': 'XxTopShottaxX/Matplotlib-challenge', 'size': '6273'}