Skip to content
Level of Access to Microfinance operations (A case study of Saminaka LGA)
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import seaborn as snsDataFrameas
df
variable
SELECT * FROM 'Form Responses 1'df.head()df.info()df.columns = list(i.strip() for i in df.columns)df['Access'] = df['Access'].replace({
'Not sure': 'No'
})df.Age.value_counts()plt.figure(figsize=(10,9))
# Create the count plot
ax = sns.countplot(data = df, x = 'Age')
plt.title('Distribution of age of respondents')
plt.ylabel('')
# Add frequency and percentage on top of bars
total = len(df)
for p in ax.patches:
height = p.get_height()
ax.annotate(f'{height}\n({height/total:.1%})',
(p.get_x() + p.get_width() / 2., height),
ha = 'center', va = 'center',
xytext = (0, 10),
textcoords = 'offset points')
plt.show()def p_crosstab(df, col1, col2):
c = pd.crosstab(index = df[col1], columns = df[col2])
return round(c/c.sum().sum()*100, 1).astype(str) + '%'
p_crosstab(df, 'Access', 'Age')sns.countplot(data = df, x = 'Age', hue = 'Access')
plt.title('Distribution of age of respondents by Level of access to Microfinance operations')
plt.ylabel('')import plotly.express as px
fig = px.bar(df, x='Age', color='Access', title='Distribution of age of respondents by Level of access to Microfinance operations')
fig.update_layout(height=600) # Increase the height of the plot
fig.update_traces(marker_line_width=0) # Make the colors solid rather than lines
fig.show()fig = px.bar(df, x='Age', color='farmland', title='Distribution of age of respondents by size of farmland')
fig.update_layout(height=600) # Increase the height of the plot
fig.update_traces(marker_line_width=0) # Make the colors solid rather than lines
fig.show()df.Access.value_counts()df.Gender.value_counts().plot.pie(explode=(0, 0.1), autopct='%.2f%%', labeldistance = 0.4, textprops = {'color': 'white'})
plt.title('Gender Distribution of respondents')
plt.ylabel('')
plt.show()