<jupyter_start><jupyter_text>Visualizing Loans Awarded by KivaIn this project you'll visualize insights using a dataset from Kaggle. The dataset contains information about loans awarded by the non-profit Kiva.<jupyter_code>from matplotlib import pyplot as plt
import pandas as pd
import seaborn as sns
df = pd.read_csv('kiva_data.csv')
print(df.head())
print(df.head(25))
# Creates the figure, you're only using this syntax to modify the y-axis ticks later
f, ax = plt.subplots(figsize=(15, 10))

sns.barplot(data=df, x="country", y="loan_amount")
plt.show()
import matplotlib.ticker as mtick

# Creates the figure, you're only using this syntax to modify the y-axis ticks below
f, ax = plt.subplots(figsize=(15, 10))
fmt = '${x:,.0f}'
tick = mtick.StrMethodFormatter(fmt)
ax.yaxis.set_major_formatter(tick) 

sns.barplot(data=df, x="country", y = "loan_amount")
plt.show()

f, ax = plt.subplots(figsize=(15, 10))

fmt = '${x:,.0f}'
tick = mtick.StrMethodFormatter(fmt)
ax.yaxis.set_major_formatter(tick)

sns.barplot(data=df, x="country", y = "loan_amount", hue="gender")
plt.show()<jupyter_output><empty_output><jupyter_text>Reflection Questions<jupyter_code># On average, male recepient receive larger loans from Kiva.
# El Salvador appears to have the least disparity in loan amounts (by gender).
# Kiva should work to decrease the gender loan gap.
# Some actions could be:

# Kiva could hold workshops focused on women-led projects (to see more women-led project)
# Kiva could require that an equal amount of loans be given to male and female-driven projects
# Set color palette
sns.set_palette("Accent")

# Set style
sns.set_style("whitegrid")

# Create figure and axes (no need to use the previous syntax, as the y-label ticks aren't going to be formatted)
plt.figure(figsize=(25, 15))

# Add a title
plt.title("Average Loan Amounts Given by Kiva, by country, by gender (in $ USD)")

# Use Seaborn to create the bar plot
sns.barplot(data=df, x="country", y="loan_amount", hue="gender")
plt.show()<jupyter_output><empty_output><jupyter_text>Lets make a box plot to compare the distribution of loans by country.<jupyter_code>plt.figure(figsize=(16, 10))
sns.boxplot(data=df, x="country", y="loan_amount")
plt.show()
Kenya is the country with the widest distribution
Cambodia is most likely to receive the largest loan amount<jupyter_output><empty_output><jupyter_text>Box Plot by Activity<jupyter_code>plt.figure(figsize=(16, 10))

sns.boxplot(data=df, x="activity", y="loan_amount")
plt.show()
# It shows you the loan amounts by activity, rather than country. 
# On average, "Farming" receives the largest loan amount and also has the widest distribution.
plt.figure(figsize=(16, 10))

sns.violinplot(data=df, x="activity", y = "loan_amount")
plt.show()<jupyter_output><empty_output><jupyter_text>Creating a violin plot that visualizes the distribution of loan amount by country.<jupyter_code>plt.figure(figsize=(16, 10))

sns.violinplot(data=df, x="country", y = "loan_amount")
plt.show()
sns.set_palette("Spectral")
plt.figure(figsize=(18, 12))

sns.violinplot(data=df, x="country", y = "loan_amount", hue="gender", split=True)
plt.show()<jupyter_output><empty_output><jupyter_text>Reflection Questions What does this visualization reveal about the distribution of loan amounts within countries by gender?<jupyter_code># In Pakistan, the average loan amount received by women is much less than the average loan amount received by men.
# The same can be said for Cambodia (more or less).
# In El Salvador, there is a fairly equal distribution of loans (total number of loans) between genders, as well as
# similar median loan amounts (on average).<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.11183496199782844, 'fraction_numerical': 0.010857763300760043, 'mean_word_length': 6.10019267822736, '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': '632685', 'license': 'MIT', 'n_tokens_mistral': 1264, 'n_tokens_neox': 1181, 'n_words': 408, 'path': 'kiva_project_solution.ipynb', 'repo_name': 'Yumelhernandez/Kiva-Nonprofit-Analytics', 'size': '3684'}