<jupyter_start><jupyter_text>Tumor Response to Treatment<jupyter_code># Store the Mean Tumor Volume Data Grouped by Drug and Timepoint 
group_drug_mean = merged_data.groupby(['Drug', 'Timepoint']).mean()
group_drug_mean.reset_index(level = None, inplace = True)

# Convert to DataFrame
tumor_mean_df = pd.DataFrame(group_drug_mean)

# Preview DataFrame
tumor_mean_df.head(30)
# Store the Standard Error of Tumor Volume Data Grouped by Drug and Timepoint 
group_drug_sem = merged_data.groupby(['Drug', 'Timepoint']).mean()
group_drug_sem.reset_index(level = None, inplace = True)

# Convert to DataFrame
tumor_sem_df = pd.DataFrame(group_drug_sem)

# Preview DataFrame
tumor_sem_df.head(30)
# Minor Data Munging to Re-Format the Data Frames
pivot_table = tumor_mean_df.pivot(index ='Timepoint', columns = 'Drug', values = 'Tumor Volume (mm3)')
pivot_table.reset_index(level = None, inplace = True)

#Preview the formatted table
pivot_table.head()
table_fourdrugs = pivot_table[["Timepoint", "Capomulin", "Infubinol", "Ketapril", "Placebo"]]
table_fourdrugs.head()
# Generate the Plot (with Error Bars)
plt.figure(figsize = (10, 5))

plt.errorbar(x=table_fourdrugs['Timepoint'],y=table_fourdrugs['Capomulin'], color= "red", linestyle="--", marker='o', 
             label = "Capomulin")
plt.errorbar(x=table_fourdrugs['Timepoint'],y=table_fourdrugs['Infubinol'], color= "blue", linestyle="--", marker='p',
             label = "Infubinol")
plt.errorbar(x=table_fourdrugs['Timepoint'],y=table_fourdrugs['Ketapril'], color= "green", linestyle="--",marker='*',
             label = "Ketapril")
plt.errorbar(x=table_fourdrugs['Timepoint'],y=table_fourdrugs['Placebo'], color ="black", linestyle="--", marker='v',
             label = "Placebo")

plt.ylabel("Tumor Volume(mm3)")
plt.xlabel("Time (Days)")
plt.title("Tumor Response to Treatment")
plt.grid()
plt.legend(loc="best")
plt.show()

# Save the Figure

# Show the Figure
plt.show()
# Show the Figure
plt.show()<jupyter_output><empty_output><jupyter_text>![Tumor Response to Treatment](../Images/treatment.png)  Metastatic Response to Treatment<jupyter_code># Store the Mean Met. Site Data Grouped by Drug and Timepoint 
group_mean_met= merged_data.groupby(["Drug","Timepoint"]).mean()

# Convert to DataFrame
met_response_mean_df = pd.DataFrame(group_mean_met["Metastatic Sites"])

# Preview DataFrame 
met_response_mean_df.head()
# Store the Standard Error associated with Met. Sites Grouped by Drug and Timepoint 
group_met_sem = merged_data.groupby(["Drug","Timepoint"]).sem()

# Convert to DataFrame
met_response_sem_df = pd.DataFrame(group_met_sem)

# Preview DataFrame
met_response_sem_df.head()
# Minor Data Munging to Re-Format the Data Frames
met_response_mean_df.reset_index(level = None, inplace = True)
met_response_mean_df2 = pd.DataFrame(tumor_mean_df)


pivot_table_met = met_response_mean_df2.pivot(index ="Timepoint", columns = 'Drug', values = "Metastatic Sites")
pivot_table_met.reset_index(level = None, inplace = True)

#Preview the Reformatted table
pivot_table_met.head()
met_table_fourdrugs = pivot_table_met[["Timepoint", "Capomulin", "Infubinol", "Ketapril", "Placebo"]]
met_table_fourdrugs.head()

# Generate the Plot (with Error Bars)
plt.figure(figsize = (10, 5))

plt.errorbar(x=met_table_fourdrugs['Timepoint'],y=met_table_fourdrugs['Capomulin'], color = "red", linestyle="--", fmt='o',
            label = "Capomulin")
plt.errorbar(x=met_table_fourdrugs['Timepoint'],y=met_table_fourdrugs['Infubinol'], color = "blue", linestyle="--", fmt='p',
            label = "Infubinol")
plt.errorbar(x=met_table_fourdrugs['Timepoint'],y=met_table_fourdrugs['Ketapril'], color = "green", linestyle="--",fmt='*',
            label = "Ketapril")
plt.errorbar(x=met_table_fourdrugs['Timepoint'],y=met_table_fourdrugs['Placebo'], color = "black", linestyle="--", fmt='v',
            label = "Placebo")

plt.ylabel("Met Sites")
plt.xlabel('Time (Days)')
plt.title('Metastatic Response to Treatment')
plt.grid()
plt.legend()       
plt.show()

# Save the Figure
plt.savefig("../MetSiteResponse.png")

# Show the Figure<jupyter_output><empty_output><jupyter_text>![Metastatic Spread During Treatment](../Images/spread.png)  Survival Rates<jupyter_code># Store the Count of Mice Grouped by Drug and Timepoint (W can pass any metric)
micecount=merged_data.groupby(["Drug","Timepoint"]).count()

# Convert to DataFrame
micecount_df=pd.DataFrame(micecount["Mouse ID"])
micecount_df.reset_index(inplace=True)

#Preview dataframe
micecount_df.head()
# Minor Data Munging to Re-Format the Data Frames
pivot_table_mice = micecount_df.pivot(index ="Timepoint", columns = 'Drug', values = "Mouse ID")
pivot_table_mice.reset_index(level = None, inplace = True)

# Preview the Data Frame
pivot_table_mice.head()

mice_table_fourdrugs = pivot_table_mice[["Timepoint", "Capomulin", "Infubinol", "Ketapril", "Placebo"]]
mice_table_fourdrugs.head()

#Calculations for the survival rate

survival_fourdrugs_df = mice_table_fourdrugs.astype(float)
survival_fourdrugs_df["Capomulin_percent"]=survival_fourdrugs_df["Capomulin"]/survival_fourdrugs_df["Capomulin"].iloc[0] * 100
survival_fourdrugs_df["Infubinol_percent"]=survival_fourdrugs_df["Infubinol"]/survival_fourdrugs_df["Infubinol"].iloc[0] * 100
survival_fourdrugs_df["Ketapril_percent"]=survival_fourdrugs_df["Ketapril"]/survival_fourdrugs_df["Ketapril"].iloc[0] * 100
survival_fourdrugs_df["Placebo_percent"]=survival_fourdrugs_df["Placebo"]/survival_fourdrugs_df["Placebo"].iloc[0] * 100
survival_fourdrugs_df
# Generate the Plot (Accounting for percentages)
plt.figure(figsize = (10, 5))


plt.errorbar(x=survival_fourdrugs_df ['Timepoint'],y=survival_fourdrugs_df['Capomulin_percent'], color = "red", 
             linestyle="--", fmt='o', label = "Capomulin")
plt.errorbar(x=survival_fourdrugs_df['Timepoint'],y=survival_fourdrugs_df['Infubinol_percent'], color = "blue", 
             linestyle="--", fmt='p', label = "Infubinol")
plt.errorbar(x=survival_fourdrugs_df['Timepoint'],y=survival_fourdrugs_df['Ketapril_percent'], color = "green", 
             linestyle="--",fmt='*', label = "Ketapril")
plt.errorbar(x=survival_fourdrugs_df['Timepoint'],y=survival_fourdrugs_df['Placebo_percent'], color = "black", 
             linestyle="--", fmt='v', label = "Placebo")

plt.ylabel("Survival Rate (%)")
plt.xlabel('Time (Days)')
plt.title(' Survival During Treatment')
plt.grid()
plt.legend(loc="best")       

# Save the Figure
plt.savefig("../SurvivalRespnse.png")

# Show the Figure
plt.show()<jupyter_output><empty_output><jupyter_text>![Metastatic Spread During Treatment](../Images/survival.png)  Summary Bar Graph<jupyter_code># Calculate the percent changes for each drug
Capomulin_percent=(table_fourdrugs["Capomulin"].iloc[9]-table_fourdrugs["Capomulin"].iloc[0])/table_fourdrugs["Capomulin"].iloc[0]*100
Infubinol_percent=(table_fourdrugs["Infubinol"].iloc[9]-table_fourdrugs["Infubinol"].iloc[0])/table_fourdrugs["Infubinol"].iloc[0]*100
Ketapril_percent=(table_fourdrugs["Ketapril"].iloc[9]-table_fourdrugs["Ketapril"].iloc[0])/table_fourdrugs["Ketapril"].iloc[0]*100
Placebo_percent=(table_fourdrugs["Placebo"].iloc[9]-table_fourdrugs["Placebo"].iloc[0])/table_fourdrugs["Placebo"].iloc[0]*100


# Display the data to confirm
print(Capomulin_percent)
print(Infubinol_percent)
print(Ketapril_percent)
print(Placebo_percent)


# Store all Relevant Percent Changes into a Tuple
percent_tuple = {'Capomulin': Capomulin_percent, 'Infubinol': Infubinol_percent, 'Ketapril': Ketapril_percent, 'Placebo': Placebo_percent}
percentchange_tumorvolume = pd.Series(percent_tuple)
percentchange_tumorvolume

#Index the 4 drugs
testdrugs=percentchange_tumorvolume.keys()
testdrugs
# Store all Relevant Percent Changes into a Tuple
percent_tuple = {'Capomulin': Capomulin_percent, 'Infubinol': Infubinol_percent, 'Ketapril': Ketapril_percent, 'Placebo': Placebo_percent}
percentchange_tumorvolume = pd.Series(percent_tuple)
percentchange_tumorvolume

# Splice the data between passing and failing drugs
# Orient widths. Add labels, tick marks, etc. 


summary_bar = plt.subplot()
x_axis = np.arange(0, len(testdrugs))

tick_locations = []
for x in x_axis:
    tick_locations.append(x + 0.5)
plt.xticks(tick_locations, testdrugs)
colors = []
for value in percentchange_tumorvolume:
    if value >= 0 :
        colors.append('r')
    else:
        colors.append('g')
        
#Plot       
percent_change = summary_bar.bar(x_axis, percentchange_tumorvolume, color=colors, align="center")

plt.title("Tumor Change Over 45 Days Treatment")
plt.ylabel("% Tumor Volume Change")
plt.xlim(-0.25, len(testdrugs))
plt.ylim(-30, max(percentchange_tumorvolume) + 20)
plt.grid()
plt.show()<jupyter_output><empty_output><jupyter_text>![Metastatic Spread During Treatment](../Images/change.png)<jupyter_code>#Include 3 observations about the results of the study. 
#Use the visualizations you generated from the study data as the basis for your observations.

#1: According to the first scatter plot and bar graph, Capomulin is reducing the tumor size with continued treatment. 
#2: Mice had a higher survival rate while on Capomulin compared to other drugs in the survival during treatment chart.
#3: In regards to the metastasis rate, Capomulin had a slower rate than the control and other drugs.<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13732432142473983, 'fraction_numerical': 0.00804634695848085, 'mean_word_length': 6.729684908789387, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 22, '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': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '299764', 'license': 'ADSL', 'n_tokens_mistral': 3458, 'n_tokens_neox': 3210, 'n_words': 644, 'path': 'pymaceuticals_starter.ipynb', 'repo_name': 'danieljo9418/matplotlib-challenge', 'size': '9321'}