<jupyter_start><jupyter_text>Observations and Insights<jupyter_code># import dependencies
import matplotlib.pyplot as plt
import pandas as pd
import numpy as np
import scipy.stats as st

# path for csv
mouse_metadata_path = "data/Mouse_metadata.csv"
study_results_path = "data/Study_results.csv"

# read csv
mouse_metadata = pd.read_csv(mouse_metadata_path)
study_results = pd.read_csv(study_results_path)

# merge data sets
data_set = pd.merge(mouse_metadata, study_results, how = "outer", on='Mouse ID')

# done ---
# drop duplicates on mouse ID and timepoint
clean_data = data_set.drop_duplicates(subset=["Mouse ID", "Timepoint"])
clean_data

# done ---
# count of mice
num_mice = len((clean_data["Mouse ID"]).unique())

num_mice_df = pd.DataFrame({"Number of Mice" : [num_mice]})

num_mice_df

# done ---<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
summary_stats = pd.DataFrame(data_set.groupby("Drug Regimen").count())

# find: mean, med, std, var & std err vals
summary_stats["Mean Tumor Volume"] = pd.DataFrame(data_set.groupby("Drug Regimen")["Tumor Volume (mm3)"].mean())
summary_stats["Median Tumor Volume"] = pd.DataFrame(data_set.groupby("Drug Regimen")["Tumor Volume (mm3)"].median())
summary_stats["Tumor Volume Std. Dev."] = pd.DataFrame(data_set.groupby("Drug Regimen")["Tumor Volume (mm3)"].std())
summary_stats["Tumor Volume Variance"] = pd.DataFrame(data_set.groupby("Drug Regimen")["Tumor Volume (mm3)"].var())
summary_stats["Total Volume Std. Err."] = pd.DataFrame(data_set.groupby("Drug Regimen")["Tumor Volume (mm3)"].sem())

# order values in df
summary_stats = summary_stats[["Mean Tumor Volume", "Median Tumor Volume", "Tumor Volume Variance", "Tumor Volume Std. Dev.", "Total Volume Std. Err."]]

# print df
summary_stats.head(10)

# done ---
summary_stats_p2 = pd.DataFrame(data_set.groupby("Drug Regimen").count())

# find: mean, med, std, var & std err vals
summary_stats_p2["Mean"] = pd.DataFrame(data_set.groupby("Drug Regimen")["Tumor Volume (mm3)"].mean())
summary_stats_p2["Median"] = pd.DataFrame(data_set.groupby("Drug Regimen")["Tumor Volume (mm3)"].median())
summary_stats_p2["Std"] = pd.DataFrame(data_set.groupby("Drug Regimen")["Tumor Volume (mm3)"].std())
summary_stats_p2["Var"] = pd.DataFrame(data_set.groupby("Drug Regimen")["Tumor Volume (mm3)"].var())
summary_stats_p2["Sem"] = pd.DataFrame(data_set.groupby("Drug Regimen")["Tumor Volume (mm3)"].sem())

# order vals in df
summary_stats_p2 = summary_stats_p2[["Mean", "Median", "Var", "Std", "Sem"]]

# print
summary_stats_p2.head(10)

# done ---<jupyter_output><empty_output><jupyter_text>Bar Plots<jupyter_code># bar graph df
bar_graph = pd.DataFrame(clean_data.groupby("Drug Regimen").count())
bar_graph = bar_graph[["Mouse ID"]]

# df plot
bar_graph.plot(kind="bar", figsize=(7,4), color = "b", legend=False)

# label, format
plt.ylabel("Number of Data Points")
plt.show()
plt.tight_layout()

# done ---
# add x axis and ticks
x_axis = np.arange(len(bar_graph))
tick_locations = [value for value in x_axis]

# format
plt.figure(figsize=(7,4))
plt.bar(x_axis, bar_graph["Mouse ID"], color = "b", width = .5)
plt.xticks(tick_locations, bar_graph.index.values, rotation="vertical")

# add xlim and ylim
plt.xlim(-0.75, len(x_axis)-.25)
plt.ylim(0, max(bar_graph["Mouse ID"])+10)

# add xlabel and ylabel
plt.xlabel("Drug Regime")
plt.ylabel("Number of Data Points")
plt.show()

# done ---<jupyter_output><empty_output><jupyter_text>Pie Plots<jupyter_code># Generate a pie plot showing the distribution of female versus male mice using pandas
pie_plot = pd.DataFrame(clean_data.groupby("Sex").count()["Mouse ID"])
pie_plot

# pie plot
pie_plot.plot(kind="pie", labels=("Female","Male"), autopct="%1.1f%%", subplots = "Mouse ID", legend=False)

# add y label
plt.ylabel("Sex")
plt.show()

# done ---
# Generate a pie plot showing the distribution of female versus male mice using pyplot
plt.pie(pie_plot, labels=("Female","Male"), autopct="%1.1f%%")

# add y label
plt.ylabel("Sex")
plt.show()

# done ---<jupyter_output>C:\Users\GT185066\Anaconda3\lib\site-packages\ipykernel_launcher.py:2: MatplotlibDeprecationWarning: Non-1D inputs to pie() are currently squeeze()d, but this behavior is deprecated since 3.1 and will be removed in 3.3; pass a 1D array instead.<jupyter_text>Quartiles, Outliers and Boxplots<jupyter_code># calc vals for each drug
tumor_vol_cam = clean_data.loc[(clean_data["Drug Regimen"] == "Capomulin") & (clean_data["Timepoint"] == 45), ["Drug Regimen", "Tumor Volume (mm3)"]]

tumor_vol_ram = clean_data.loc[(clean_data["Drug Regimen"] == "Ramicane") & (clean_data["Timepoint"] == 45), ["Drug Regimen", "Tumor Volume (mm3)"]]

tumor_vol_inf = clean_data.loc[(clean_data["Drug Regimen"] == "Infubinol") & (clean_data["Timepoint"] == 45), ["Drug Regimen", "Tumor Volume (mm3)"]]

tumor_vol_cef = clean_data.loc[(clean_data["Drug Regimen"] == "Ceftamin") & (clean_data["Timepoint"] == 45), ["Drug Regimen", "Tumor Volume (mm3)"]]

box_plot = [tumor_vol_cam["Tumor Volume (mm3)"], tumor_vol_ram["Tumor Volume (mm3)"], tumor_vol_inf["Tumor Volume (mm3)"], tumor_vol_cef["Tumor Volume (mm3)"]]

# set fig size
fig = plt.figure(1, figsize=(8, 5))
ax = fig.add_subplot(111)

# create box plt
bp = ax.boxplot(box_plot)

# done ---<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 = clean_data.loc[(clean_data["Drug Regimen"] == "Capomulin"),:]
cam_df = capomulin.loc[capomulin["Mouse ID"] == "l509"]

# add variables for timepoint and tumor volume
timepoint = cam_df["Timepoint"]
tumor_volume = cam_df["Tumor Volume (mm3)"]

# show tumor vol for mice on capomulin
tumor_volume_line, = plt.plot(timepoint, tumor_volume)

# Show the chart, add labels
plt.xlabel('Timepoint')
plt.ylabel('Tumor Volume')
plt.title('Capomulin treatment of mouse l509')
plt.show()

# done ---
# Generate a scatter plot of mouse weight versus average tumor volume for the Capomulin regimen
mouse_weight = capomulin.groupby(capomulin["Mouse ID"])["Weight (g)"].mean()
tumor_volume = capomulin.groupby(capomulin["Mouse ID"])["Tumor Volume (mm3)"].mean()

# add vals into scatter plot
plt.scatter(mouse_weight,tumor_volume)
plt.xlabel("Weight (g)")
plt.ylabel("Average Tumor Volume (mm3)")
plt.show()

# done ---<jupyter_output><empty_output><jupyter_text>Correlation and Regression<jupyter_code># calc linear regression
slope, int, r, p, std_err = st.linregress(mouse_weight, tumor_volume)
      
# calc best fit line
fit = slope * mouse_weight + int

# add vals to scatterplot
plt.scatter(mouse_weight,tumor_volume)
plt.xlabel("Weight (g)")
plt.ylabel("Average Tumor Volume (mm3)")
plt.plot(mouse_weight,fit,"--",color="red")
plt.xticks(mouse_weight)
plt.show()

# calc correlation coef
corr = round(st.pearsonr(mouse_weight,tumor_volume)[0],2)

# prit - corr
print(f'The correlation between weight and tumor value is {corr}')

# done ---<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.15624562875926704, 'fraction_numerical': 0.012309413904042523, 'mean_word_length': 6.447916666666667, 'pattern_counts': {'":': 0, '<': 28, '<?xml version=': 0, '>': 28, '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': '319287', 'license': 'ADSL', 'n_tokens_mistral': 2727, 'n_tokens_neox': 2549, 'n_words': 611, 'path': 'pymaceuticals_starter.ipynb', 'repo_name': 'gthornburgh/Pymaceuticals', 'size': '7149'}