How to Install Pandas
To install Pandas on your system, you have two options. Choose the one that matches your Python installation (either Pip or Anaconda):
- Pip: Run
pip install pandas
- Anaconda: Run
conda install pandas
It’s assumed you already have Python installed, either a standalone version or through an Anaconda distribution. Both will work fine, just follow the instructions for your specific case.
Continue reading for a step-by-step guide on installing Pandas for both options, both globally and inside a virtual environment.
Table of contents:
How to Install Pandas with Pip
This section will walk you through the process of installing Pandas with Pip, which is Python’s package manager. We’ll begin with a global, or system-wide installation.
Install Pandas with Pip Globally
Assuming you have Python installed on your OS, run the following line to install Pandas globally:
python3 -m pip install pandas
Note: Windows users will have to run python
instead of python3
.
Here’s what you’ll see in the Terminal window:
Once installed, run the Python shell, import Pandas, and print its version. If you don’t get an error, it means Pandas was successfully installed:
You now have Pandas available system-wide for all Python projects. If you’d rather install it for a specific project - inside a virtual environment - please reference the following section.
Install Pandas with Pip Inside a Virtual Environment
If you install Python inside a virtual environment, this means it will only be available when that environment is activated. This is the recommended way for keeping project dependencies separate and minimizing the risk of them interfering with the system ones.
First, create a new virtual environment by running the following command:
python3 -m venv /path/to/the/environment
cd /path/to/the/environment
You’re now inside the virtual environment folder, and the next step is to activate it:
source bin/activate
Once activated, run a pip
command for installing Pandas:
pip install pandas
You can check if Pandas was installed the same way as before - activate Python shell, import the library, and print its version:
That’s how you can install Pandas with Pip. Let’s cover the same topic with Anaconda next.
How to Install Pandas with Anaconda
You can think of Anaconda as a Python distribution that somewhat simplifies package and dependency management. It doesn’t matter if you have Anaconda or Miniconda installed (or some other version), the Pandas installation process will be the same.
First, let’s install Pandas globally, even though it’s not recommended.
Install Pandas with Anaconda Globally
Assuming you have Conda installed, run the following command to install Pandas:
conda install pandas
You shouldn’t install any dependency globally with Conda, especially if you opt for a slim and minimal version of the distribution. You should always create a virtual environment first.
Install Pandas with Anaconda Inside a Virtual Environment
Creating an Anaconda virtual environment boils down to specifying an environment name and Python version. The trailing -y
indicates you accept the installation of any Pandas dependency:
conda create --name pandas_env python=3.10 -y
Once the environment is created, you can activate it with the following command:
conda activate padnas_env
Unlike Pip, Anaconda doesn’t require you to remember the environment location.
Now install Pandas with a conda install
command:
conda install pandas
Pandas is now installed, and you can verify this by entering a Python shell and printing its version:
And that’s how you can install Pandas with Anaconda. Let’s make a short recap next.
Summing up How to Install Pandas
Ultimately, it doesn’t matter whether you prefer Pip or Anaconda for managing Python dependencies. Both work fine with Pandas, and you won’t run into any issues by choosing one over the other.
Today you’ve successfully installed Pandas on your system, preferably inside a virtual environment. You’re now ready to start exploring the library and learn its ins and outs. Stay tuned to Better Data Science for weekly how-to guides and reference manuals.