Question

Subject : Visualizing Data in Python with Matplotlib Topic : Exploring Data Visually with Matplotlib using...

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:

  • Submit code demonstrating the following:
    • Using the Loan Stats file, construct a dictionary containing the number of each loan for each loan_status.
      For example: { “Current”: 123, “Fully Paid”: 1234, … }
      Follow the example for plotting categorical variables to produce a histogram of loan stats by loan_status
0 0
Add a comment Improve this question Transcribed image text
Answer #1

#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

Add a comment
Know the answer?
Add Answer to:
Subject : Visualizing Data in Python with Matplotlib Topic : Exploring Data Visually with Matplotlib using...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT