<jupyter_start><jupyter_text>Tumor Response to Treatment<jupyter_code># Store the Mean Tumor Volume Data Grouped by Drug and Timepoint 
grouped = combined.groupby(["Drug","Timepoint"])
# count how many drugs
mouse_to_drug["Drug"].value_counts()
# Convert to DataFrame
drug_mouse_ct = pd.DataFrame(grouped["Mouse ID"].count())
drug_mouse_ct = drug_mouse_ct.rename(columns={"Mouse ID":"mice_count"})

# Preview DataFrame
drug_mouse_ct.head()
drug_tumor_size = pd.DataFrame(grouped["Tumor Volume (mm3)"].mean())
drug_tumor_size = drug_tumor_size.rename(columns={"Tumor Volume (mm3)":"avg_tumor_size"})
drug_tumor_size.head()
# Store the Standard Error of Tumor Volumes Grouped by Drug and Timepoint
grouped["Tumor Volume (mm3)"].sem()

# Convert to DataFrame
drug_tumor_size_st_err = pd.DataFrame(grouped["Tumor Volume (mm3)"].sem())
drug_tumor_size_st_err = drug_tumor_size_st_err.rename(columns={"Tumor Volume (mm3)":"standard_err_of_tumor_size"})
drug_tumor_size_st_err.head()
# merge all trial data 
# drug_mouse_ct
# drug_tumor_size
# drug_tumor_size_st_err

merge1 = pd.merge(drug_mouse_ct,drug_tumor_size,left_index=True,right_index=True)
merge1.head()

merged_final = pd.merge(merge1,drug_tumor_size_st_err,left_index=True,right_index=True)
merged_final.tail()
merged_final.head()
# merged_final=merged_final.reset_index(inplace=False,drop=False)
# merged_final.head()
merge_selected = merged_final.loc[["Capomulin","Infubinol","Placebo","Ketapril"]]
print(merge_selected.shape)
merge_selected.tail(10)
merge_selected.head(10)
# Generate the Plot (with Error Bars)

# x_axis = array([ 0,  5, 10, 15, 20, 25, 30, 35, 40, 45])
x_axis = np.arange(0,50,5)

# means = avg tumor size for all four drugs
cap_means = merge_selected.loc["Capomulin","avg_tumor_size"]
inf_means = merge_selected.loc["Infubinol","avg_tumor_size"]
ket_means = merge_selected.loc["Ketapril","avg_tumor_size"]
pla_means = merge_selected.loc["Placebo","avg_tumor_size"]

# standard error for all four drugs
cap_sd_err = merge_selected.loc["Capomulin","standard_err_of_tumor_size"]
inf_sd_err = merge_selected.loc["Infubinol","standard_err_of_tumor_size"]
ket_sd_err = merge_selected.loc["Ketapril","standard_err_of_tumor_size"]
pla_sd_err = merge_selected.loc["Placebo","standard_err_of_tumor_size"]
# Save the Figure
# legend didn't work

plt.title("Avg tumor size by drug")
plt.ylabel("Tumor Volume (mm3)")
cap,a,b = plt.errorbar(x_axis,cap_means,yerr=cap_sd_err)
inf,c,d = plt.errorbar(x_axis,inf_means,yerr=inf_sd_err)
ket,e,f = plt.errorbar(x_axis,ket_means,yerr=ket_sd_err)
pla,g,h = plt.errorbar(x_axis,pla_means,yerr=pla_sd_err)
plt.legend(handles=[cap,inf,ket,pla],loc="best")
plt.savefig("../Images/avg_tumor_size_by_drug.png")
plt.show()<jupyter_output><empty_output><jupyter_text>Metastatic Response to Treatment<jupyter_code># grouped = combined.groupby(["Drug","Timepoint"])
# Store the Mean Met. Site Data Grouped by Drug and Timepoint 
# Convert to DataFrame
# Preview DataFrame

drug_mets = pd.DataFrame(grouped["Metastatic Sites"].mean())
drug_mets = drug_mets.rename(columns={"Metastatic Sites":"avg_mets_num"})
drug_mets.head()
# Store the Standard Error associated with Met. Sites Grouped by Drug and Timepoint 
# Convert to DataFrame
# Preview DataFrame

drug_mets_num_st_err = pd.DataFrame(grouped["Metastatic Sites"].sem())
drug_mets_num_st_err= drug_mets_num_st_err.rename(columns={"Metastatic Sites":"standard_err_of_mets_num"})
drug_mets_num_st_err.head()
merge3=pd.merge(drug_mets,drug_mets_num_st_err,left_index=True,right_index=True)
merge3.head()
# create final df with all columns - drug, timepoint, # of living mice, tumor size, # of mets

merged_final2=pd.merge(merged_final,merge3,left_index=True,right_index=True)
merge_selected2=merged_final2.loc[["Capomulin","Infubinol","Placebo","Ketapril"]]
merge_selected2.shape
merge_selected2.head(3)
# Generate the Plot (with Error Bars)

# x_axis = array([ 0,  5, 10, 15, 20, 25, 30, 35, 40, 45])
x_axis = np.arange(0,50,5)

# means = avg mets num for all four drugs
cap_mets = merge_selected2.loc["Capomulin","avg_mets_num"]
inf_mets = merge_selected2.loc["Infubinol","avg_mets_num"]
ket_mets = merge_selected2.loc["Ketapril","avg_mets_num"]
pla_mets = merge_selected2.loc["Placebo","avg_mets_num"]

# standard error for all four drugs
cap_mets_sd_err = merge_selected2.loc["Capomulin","standard_err_of_mets_num"]
inf_mets_sd_err = merge_selected2.loc["Infubinol","standard_err_of_mets_num"]
ket_mets_sd_err = merge_selected2.loc["Ketapril","standard_err_of_mets_num"]
pla_mets_sd_err = merge_selected2.loc["Placebo","standard_err_of_mets_num"]
plt.title("Avg number of met sites by drug")
plt.ylabel("Met Sites")
plt.errorbar(x_axis,cap_mets,yerr=cap_mets_sd_err)
plt.errorbar(x_axis,inf_mets,yerr=inf_mets_sd_err)
plt.errorbar(x_axis,ket_mets,yerr=ket_mets_sd_err)
plt.errorbar(x_axis,pla_mets,yerr=pla_mets_sd_err)
plt.grid()
plt.savefig("../Images/avg_num_of_met_sites_by_drug.png")
plt.show()<jupyter_output><empty_output><jupyter_text>Survival Rates<jupyter_code># Store the Count of Mice Grouped by Drug and Timepoint (W can pass any metric)
# Convert to DataFrame
# Preview DataFrame
merge_selected2["percent_mice_alive_%"] = merge_selected2["mice_count"]/25*100
merge_selected2.head()
# Generate the Plot (Accounting for percentages)

# x_axis = array([ 0,  5, 10, 15, 20, 25, 30, 35, 40, 45])
x_axis = np.arange(0,50,5)

# means = avg mets num for all four drugs
cap_rates = merge_selected2.loc["Capomulin","percent_mice_alive_%"]
inf_rates = merge_selected2.loc["Infubinol","percent_mice_alive_%"]
ket_rates = merge_selected2.loc["Ketapril","percent_mice_alive_%"]
pla_rates = merge_selected2.loc["Placebo","percent_mice_alive_%"]
plt.title("Survival During TRx")
plt.ylabel("Survival Rate")
plt.plot(x_axis,cap_rates)
plt.plot(x_axis,inf_rates)
plt.plot(x_axis,ket_rates)
plt.plot(x_axis,pla_rates)
plt.grid()
plt.savefig("../Images/survival_rate_by_drug.png")
plt.show()<jupyter_output><empty_output><jupyter_text>Summary Bar Graph<jupyter_code>merge_selected2.head()
# Calculate the percent changes for each drug
df = merge_selected2

cap_change = (df.loc["Capomulin",45]["avg_tumor_size"] - df.loc["Capomulin",0]["avg_tumor_size"])/df.loc["Capomulin",0]["avg_tumor_size"]
inf_change = (df.loc["Infubinol",45]["avg_tumor_size"] - df.loc["Infubinol",0]["avg_tumor_size"])/df.loc["Infubinol",0]["avg_tumor_size"]
ket_change = (df.loc["Ketapril",45]["avg_tumor_size"] - df.loc["Ketapril",0]["avg_tumor_size"])/df.loc["Ketapril",0]["avg_tumor_size"]
pla_change = (df.loc["Placebo",45]["avg_tumor_size"] - df.loc["Placebo",0]["avg_tumor_size"])/df.loc["Placebo",0]["avg_tumor_size"]


cap_change = cap_change * 100
inf_change = inf_change *100
ket_change = ket_change*100
pla_change = pla_change* 100

# Display the data to confirm
print(cap_change,inf_change,ket_change,pla_change)
bar = (cap_change,inf_change,ket_change,pla_change)
x_axis = ("Capomulin","Infubinol","Ketapril","Placebo")
plt.bar(x_axis,bar,color=["g","r","r","r"],align="center")
plt.grid()
plt.title("Tumor size change over 45 days")
plt.ylabel("% tumor size change")
plt.savefig("../Images/Tumor_size_change_over_45_days_by_drug.png")
plt.show()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.14232209737827714, 'fraction_numerical': 0.01969760022194479, 'mean_word_length': 9.18361581920904, 'pattern_counts': {'":': 5, '<': 17, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '367793', 'license': 'ADSL', 'n_tokens_mistral': 3059, 'n_tokens_neox': 2785, 'n_words': 436, 'path': 'Pymaceuticals/pymaceuticals_elle.ipynb', 'repo_name': 'bestelle6256/plt_challenge', 'size': '7209'}