READING-NOTE

View on GitHub

Data Analysis

Data Analysis with Python

Lists Of Lists for CSV Data

. In the below code, we:

With the file open, create a new csv.reader object. Pass in the keyword argument delimiter=”;” to make sure that the records are split up on the semicolon character instead of the default comma character.

import csv
with open('winequality-red.csv', 'r') as f:
    wines = list(csv.reader(f, delimiter=';'))

# Once we’ve read in the data, we can print out the first 3 rows:

print(wines[:3])

[['fixed acidity', 'volatile acidity', 'citric acid', 'residual sugar', 'chlorides', 'free sulfur dioxide', 'total sulfur dioxide', 'density', 'pH', 'sulphates', 'alcohol', 'quality'], ['7.4', '0.7', '0', '1.9', '0.076', '11', '34', '0.9978', '3.51', '0.56', '9.4', '5'], ['7.8', '0.88', '0', '2.6', '0.098', '25', '67', '0.9968', '3.2', '0.68', '9.8', '5']]

Numpy 2-Dimensional Arrays

Creating A NumPy Array

Alternative NumPy Array Creation Methods

It’s useful to create an array with all zero elements in cases when you need an array of fixed size, but don’t have any values for it yet. Creating arrays full of random numbers can be useful when you want to quickly test your code with sample arrays.

Using NumPy To Read In Files

In the below code, we: