Subject : Visualizing Data in Python with
Matplotlib
Topic : Exploring Data Visually with Matplotlib using
Dictionaries
Begin by reviewing the matplotlib documentation and the User Guide.
Here we will make a histogram using some data from the Loan Stats
Q1 2019 file.
(Loan Stats Q1 2019 Download File Link : - https://www.lendingclub.com/info/download-data.action)
Explore the user guide and then review this example : (
https://matplotlib.org/gallery/lines_bars_and_markers/categorical_variables.html)
Question:
#CODE
#Importing libraries
import pandas as pd
import numpy as np
#Reading csv file with skiping the first row in csv to
remove
#the line "Notes offered by Prospectus
(https://www.lendingclub.com/info/prospectus.action)"
df=pd.read_csv("LoanStats_2019Q1.csv",skiprows=1)
df.head()
#To know which columns existed in the csv file
df.columns
df['loan_status'].value_counts()
data=dict(df['loan_status'].value_counts())
import matplotlib.pyplot as plt
names = list(data.keys())
values = list(data.values())
fig, axs = plt.subplots(1, 3, figsize=(9, 3), sharey=True)
axs[0].bar(names, values)
axs[1].scatter(names, values)
axs[2].plot(names, values)
fig.suptitle('Categorical Plotting')
for ax in axs.reshape(-1):
ax.set_xticklabels(names, rotation=45,
horizontalalignment='right')
#OUTPUT
Subject : Visualizing Data in Python with Matplotlib Topic : Exploring Data Visually with Matplotlib using...