<jupyter_start><jupyter_text>Tumor Response to Treatment<jupyter_code># Store the Mean Tumor Volume Data Grouped by Drug and Timepoint 
mean_tumor_vol_data = combined_df.groupby(['Drug','Timepoint'])['Tumor Volume (mm3)'].mean()
# Convert to DataFrame
mean_tumor_vol_data_df = pd.DataFrame({"Tumor Volume (mm3)" : mean_tumor_vol_data})
# Preview DataFrame
mean_tumor_vol_data_df.head(20)
mean_tumor_vol_data_df.reset_index()
# Store the Standard Error of Tumor Volumes Grouped by Drug and Timepoint
sem_tumor_vol_data = combined_df.groupby(['Drug','Timepoint'])['Tumor Volume (mm3)'].sem()
# Convert to DataFrame
sem_tumor_vol_data_df = pd.DataFrame({"Tumor Volume (mm3)" : sem_tumor_vol_data})
# Preview DataFrame

sem_tumor_vol_data_df.reset_index()
# Minor Data Munging to Re-Format the Data Frames
#reformat_combined_df = combined_df.pivot(index='Timepoint', columns='Drug', values='Tumor Volume (mm3)')
reformat_mean_combined_df = mean_tumor_vol_data_df.pivot_table('Tumor Volume (mm3)', 'Timepoint', 'Drug')
reformat_sem_combined_df = sem_tumor_vol_data_df.pivot_table('Tumor Volume (mm3)', 'Timepoint', 'Drug')

# Preview that Reformatting worked
#reformat_mean_combined_df.head()
reformat_mean_combined_df
# Generate the Plot (with Error Bars)
fig, ax = plt.subplots()

ax.errorbar(reformat_sem_combined_df.index, reformat_mean_combined_df['Capomulin'], yerr=reformat_sem_combined_df['Capomulin'], fmt="-", 
            color="r",marker="o",linewidth=0.25, label="Capomulin")
ax.errorbar(reformat_sem_combined_df.index, reformat_mean_combined_df['Infubinol'], yerr=reformat_sem_combined_df['Infubinol'], fmt="-", 
            color="b",marker="o",linewidth=0.25, label="Infubinol")
ax.errorbar(reformat_sem_combined_df.index, reformat_mean_combined_df['Ketapril'], yerr=reformat_sem_combined_df['Ketapril'], fmt="-", 
            color="g",marker="o",linewidth=0.25, label="Ketapril")
ax.errorbar(reformat_sem_combined_df.index, reformat_mean_combined_df['Placebo'], yerr=reformat_sem_combined_df['Placebo'], fmt="-", 
            color="k",marker="o",linewidth=0.25, label="Placebo")
# Save the Figure

ax.set_ylabel("Tumor Volume (mm3)")
ax.set_xlabel("Time (days)")
ax.legend(loc="upperleft")
plt.title("Tumor Response to Treatment")
plt.grid()
plt.show()
plt.savefig("tumor-response.png")<jupyter_output><empty_output><jupyter_text>Metastatic Response to Treatment<jupyter_code># Store the Mean Met. Site Data Grouped by Drug and Timepoint 
mean_met_site_data = combined_df.groupby(['Drug','Timepoint'])['Metastatic Sites'].mean()
# Convert to DataFrame
mean_met_site_data_df = pd.DataFrame(mean_met_site_data)
# Preview DataFrame
mean_met_site_data_df.head()
# Store the Standard Error associated with Met. Sites Grouped by Drug and Timepoint 
sem_met_site_data = combined_df.groupby(['Drug','Timepoint'])['Metastatic Sites'].sem()
# Convert to DataFrame
sem_met_site_data_df = pd.DataFrame(sem_met_site_data)
# Preview DataFrame
sem_met_site_data_df.head()

# Minor Data Munging to Re-Format the Data Frames
reformat_met_mean_combined_df = mean_met_site_data_df.pivot_table('Metastatic Sites', 'Timepoint', 'Drug')
reformat_met_sem_combined_df = sem_met_site_data_df.pivot_table('Metastatic Sites', 'Timepoint', 'Drug')
# Preview that Reformatting worked
reformat_met_mean_combined_df.head()
# Generate the Plot (with Error Bars)
fig, ax = plt.subplots()

ax.errorbar(reformat_met_mean_combined_df.index, reformat_met_mean_combined_df['Capomulin'], yerr=reformat_met_sem_combined_df['Capomulin'], fmt="-", 
            color="r",marker="o",linewidth=0.25, label="Capomulin")
ax.errorbar(reformat_met_mean_combined_df.index, reformat_met_mean_combined_df['Infubinol'], yerr=reformat_met_sem_combined_df['Infubinol'], fmt="-", 
            color="b",marker="s",linewidth=0.25, label="Infubinol")
ax.errorbar(reformat_met_mean_combined_df.index, reformat_met_mean_combined_df['Ketapril'], yerr=reformat_met_sem_combined_df['Ketapril'], fmt="-", 
            color="g",marker="^",linewidth=0.25, label="Ketapril")
ax.errorbar(reformat_met_mean_combined_df.index, reformat_met_mean_combined_df['Placebo'], yerr=reformat_met_sem_combined_df['Placebo'], fmt="-", 
            color="k",marker="D",linewidth=0.25, label="Placebo")
# Save the Figure

# Show the Figure
ax.set_ylabel("Met. Sites")
ax.set_xlabel("Time (days)")
ax.legend(loc="upperleft")
plt.title("Metastic Spread During Treament")
plt.grid()
plt.show()
plt.savefig("metastic-spread.png")<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)
mice_count = combined_df.groupby(['Drug','Timepoint'])['Mouse ID'].count()

# Convert to DataFrame
mice_count_df = pd.DataFrame({"Mice Count" : mice_count}).reset_index()
# Preview DataFrame
mice_count_df.head()
# Minor Data Munging to Re-Format the Data Frames
reformat_mice_cout_df = mice_count_df.pivot_table('Mice Count', 'Timepoint', 'Drug')
# Preview that Reformatting worked
reformat_mice_cout_df.head()
# Generate the Plot (Accounting for percentages)
plt.plot(reformat_mice_cout_df['Capomulin'],color="r",marker="o",linewidth=0.25, label="Capomulin")
plt.plot(reformat_mice_cout_df['Infubinol'],color="b",marker="s",linewidth=0.25, label="Infubinol")
plt.plot(reformat_mice_cout_df['Ketapril'],color="g",marker="^",linewidth=0.25, label="Ketapril")
plt.plot(reformat_mice_cout_df['Placebo'],color="k",marker="D",linewidth=0.25, label="Placebo")

plt.legend(loc="lowerleft")
plt.title("Survival During Treatment")
plt.grid()
plt.xlabel("Time (days)")
plt.ylabel("Survival Rate (%)")
 
# Save the Figure
plt.savefig("survival.png")
# Show the Figure
plt.show()<jupyter_output><empty_output><jupyter_text>Summary Bar Graph<jupyter_code># Calculate the percent changes for each drug
first_record = reformat_mean_combined_df.iloc[0]
last_record = reformat_mean_combined_df.iloc[-1]

perc_change_tumor = (((last_record-first_record)/ first_record)*100)

# Display the data to confirm
#print(f"{first_record} and {last_record} and {perc_change_tumor}")
perc_change_tumor
# Store all Relevant Percent Changes into a Tuple

pct_tuple = (perc_change_tumor['Capomulin'],
             perc_change_tumor['Infubinol'],
             perc_change_tumor['Ketapril'],
             perc_change_tumor['Placebo'])
# Splice the data between passing and failing drugs

fig, ax = plt.subplots()
ind = np.arange(len(pct_tuple))
width = 1
rectsPass = ax.bar(ind[0], pct_tuple[0], width, color='green')
rectsFail = ax.bar(ind[1:], pct_tuple[1:], width, color='red')

# Orient widths. Add labels, tick marks, etc. 

ax.set_ylabel('% Tumor Volume Change')
ax.set_title('Tumor Change Over 45 Day Treatment')
ax.set_xticks(ind + 0.5)
ax.set_xticklabels(('Capomulin', 'Infubinol', 'Ketapril', 'Placebo'))
ax.set_autoscaley_on(False)
ax.set_ylim([-30,70])
ax.grid(True)

# Use functions to label the percentages of changes

def autolabelFail(rects):
    for rect in rects:
        height = rect.get_height()
        ax.text(rect.get_x() + rect.get_width()/2., 3,
                '%d%%' % int(height),
                ha='center', va='bottom', color="white")
def autolabelPass(rects):
    for rect in rects:
        height = rect.get_height()
        ax.text(rect.get_x() + rect.get_width()/2., -8,
                '-%d%% ' % int(height),
                ha='center', va='bottom', color="white")

# Call functions to implement the function calls

autolabelFail(rectsFail)
autolabelPass(rectsPass)

# Save the Figure

plt.savefig("summary.png")

# Show the Figure
fig.show()
#Include 3 observations about the results of the study. Use the visualizations you generated from the study data as the basis for your observations

# observation01:
# Capomulin is the only Drug that effectively reduced the Tumor Volume (-19%)

# observation02:
# After 45 days of treatment over 80% of mices undergoing Capumolin surviced while mices undergoing
# other drugs had less then 45% survival rate

# observation03:
#Keptapril in as ineffective as placebo<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13459150732555253, 'fraction_numerical': 0.010305438291532158, 'mean_word_length': 6.620624408703879, 'pattern_counts': {'":': 0, '<': 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': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '4', 'dir': 'jupyter-structured-clean-dedup', 'id': '244126', 'license': 'ADSL', 'n_tokens_mistral': 2986, 'n_tokens_neox': 2814, 'n_words': 556, 'path': 'pymaceuticals_starter.ipynb', 'repo_name': 'dominguesluciano/matplotlib-challenge', 'size': '8054'}