Importing Dataset in Pandas
Start your free 7-days trial now!
To import and read a CSV file as a DataFrame, use Pandas
read_csv(~) is a misnomer. Despite having
csv in its name, the method can be used to import datasets that use delimiters (separators) other than comma.
Datasets with Column Labels and Indices
Suppose we wanted to import the following file called
Note the following:
the column labels are
the row labels are
To read this file as a DataFrame:
Note that this code assumes the file to be located in the same directory.
Datasets with Only Values
Suppose our CSV dataset only consisted of values:
To import this file, we need to add the
As we can see, Pandas uses the default integer indices for its column and row labels.
Datasets with Custom Delimiters
read_csv() method can also be used to import datasets that use delimiters other than comma. We can specify the delimiter by supplying the
As an example, suppose our dataset uses a single blank space as the delimiter:
a b cA 1 2 3B 4 5 6
To read this file: