January 2019
Intermediate to advanced
390 pages
9h 16m
English
The NumPy module provides two functions for reading values from CSV files: np.loadtxt() and np.genfromtxt().
An example of np.loadtxt is as follows:
arr = np.loadtxt('temp.csv', skiprows=1, usecols=(2,3), delimiter=',')arr
The preceding code reads columns 3 and 4 from the file that we created earlier, and saves them in a 9 × 2 array as follows:
The np.loadtxt() function cannot handle CSV files with missing data. For instances where data is missing, np.genfromtxt() can be used. Both of these functions offer many more arguments; details can be found ...
Read now
Unlock full access