Login using Social Account
     Continue with GoogleLogin using your credentials
Although Pandas provides better ways and constructs to load a dataset from various sources like files, databases, etc. we should also know the NumPy constructs for the same.
There are two ways (constructs) in NumPy to load data from a text file:
(1) using loadtxt()
function
(2) using genfromtxt()
function
loadtxt()
function provides less flexibility, whereas genfromtxt()
function provides more flexibility.
For example, genfromtxt()
function also handles the missing values kind of scenarios in the loaded dataset, whereas loadtxt()
function doesn't.
import numpy as np
name_arr, address_arr, zipcode_arr = np.loadtxt('my_file.txt', skiprows=2, unpack=True)
The above piece of code will load the data from my_file.txt
text file.
skiprows=2
means, skip the first two rows of the my_file.txt
file while loading the data.
unpack=True
means, unpack the columns of the dataset being loaded and return the data of each column separately in separate arrays ( name column data in name_arr
array, address column data in address_arr
array, zipcode column data in zipcode_arr
array).
unpack=False
means, return only a single array as output from the loadtxt()
function.
Taking you to the next exercise in seconds...
Want to create exercises like this yourself? Click here.
No hints are availble for this assesment
Answer is not availble for this assesment
Loading comments...