Read CSV files Using built-in Python csv module
csv.reader() function reads each line of the CSV file. We read data line by line and then convert each line to a list of items.
Syntax: csv.reader(x)
Parameters:
- x : TextIOWrapper of the CSV file.
Example: Loading CSV data using csv reader
Python3
import numpy as np # Importing csv module import csv with open ( "sample_data.csv" , 'r' ) as x: sample_data = list (csv.reader(x, delimiter = "," )) sample_data = np.array(sample_data) display(sample_data) |
Output:
How to Read CSV Files with NumPy?
In this article, we will discuss how to read CSV files with Numpy in Python. Reading CSV files using Python NumPy library helps in loading large amount of data quicker. Due to performance reason, NumPy is preferred while reading huge amount of data from CSV files.
Dataset in use: