3. Introduction to NumPy, Pandas, and Matplotlib
Activity 3.01: Generating Statistics from a CSV File
Solution:
These are the steps to complete this activity:
- Load the necessary libraries:
import numpy as np import pandas as pd import matplotlib.pyplot as plt
- Read in the Boston Housing dataset (given as a
.csv
file) from the local directory:df=pd.read_csv("../datasets/Boston_housing.csv")
Note
Don't forget to change the path of the dataset (highlighted) based on where it is saved on your system.
- Check the first 10 records:
df.head(10)
The output is as follows:
- Find the total number of records:
df.shape
The output is as follows:
(506, 14)
- Create a smaller DataFrame with columns that do not include
CHAS
,NOX
,B
, andLSTAT
:df1=df[['CRIM','ZN','INDUS',\ Â Â Â Â Â Â Â Â 'RM','AGE','DIS','RAD',\...