Loading data into Python
Last updated
Last updated
Pandas is a powerful library for handling tabular data in Python. It provides simple methods for loading data from CSV and Excel files into DataFrames, allowing for efficient data manipulation and analysis. We'll be using this demo file:
The required package for this section is pandas. This can be installed with the following command in the command window (Windows) / terminal (Mac).
CSV (Comma-Separated Values) files store tabular data in plain text format, making them widely used for data exchange.
An absolute path specifies the full directory structure where the file is stored. This method ensures correct file access regardless of the working directory.
A relative path specifies the file location relative to the script's execution directory. This is useful for portability across different systems.
Excel files (.xlsx
) are common in data analysis, and Pandas provides easy methods to read them.
After loading the excel data using the code above, we observe the data table:
Note that the row indices are numbered starting from 0. If our sample names are unique we can also use the Sample names as row indices:
Now we observe:
This allows us to acces for example the first row by it's Sample name: