Are you planning to work with data in Python? In that case, it’s possible you might have heard about the Pandas module but you haven’t used it yet.
If you want to use the Pandas module in your Python programs you have to install it first. Let’s see how to do it in this tutorial.
To verify if the Pandas module is available in your Python installation you can import it using the following command under the Python shell:
$ python3 Python 3.8.2 (default, Dec 21 2020, 15:06:03) [Clang 12.0.0 (clang-122.214.171.124)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import pandas Traceback (most recent call last): File "<stdin>", line 1, in <module> ModuleNotFoundError: No module named 'pandas'
If you receive the ModuleNotFoundError exception above it means that the Pandas module is not installed.
To install the Pandas module you can use the following command:
pip install pandas
Below you can see the output of the “pip install” command on my machine:
$ pip install pandas Collecting pandas Downloading pandas-1.4.3-cp38-cp38-macosx_11_0_arm64.whl (10.3 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 10.3/10.3 MB 973.5 kB/s eta 0:00:00 Collecting python-dateutil>=2.8.1 Using cached python_dateutil-2.8.2-py2.py3-none-any.whl (247 kB) Collecting pytz>=2020.1 Downloading pytz-2022.2.1-py2.py3-none-any.whl (500 kB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 500.6/500.6 kB 1.2 MB/s eta 0:00:00 Collecting numpy>=1.20.0 Downloading numpy-1.23.2-cp38-cp38-macosx_11_0_arm64.whl (13.3 MB) ━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 13.3/13.3 MB 2.6 MB/s eta 0:00:00 Requirement already satisfied: six>=1.5 in ./python-env/lib/python3.8/site-packages (from python-dateutil>=2.8.1->pandas) (1.16.0) Installing collected packages: pytz, python-dateutil, numpy, pandas Successfully installed numpy-1.23.2 pandas-1.4.3 python-dateutil-2.8.2 pytz-2022.2.1
As you can see when installing pandas the Python interpreter also requires other modules like NumPy, python-dateutil, and pytz.
Now, let’s try to import the Pandas module again using the Python shell:
$ python3 Python 3.8.2 (default, Dec 21 2020, 15:06:03) [Clang 12.0.0 (clang-1126.96.36.199)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import pandas >>>
This time I was able to import Pandas successfully. This means the module is ready to be used.
Another way to make Pandas available on your computer is by installing the Anaconda Data Science platform but this would require a lot more resources on your system.
So, if the only library you need is Pandas it’s easier to install it using PIP as we have seen above.
In this tutorial, we have seen how to install the Pandas module so you can use it in your Python programs.
The process we have used to install the Pandas module using PIP is the same to follow to install any other Python modules.
Now that you have installed Pandas you are ready to use it!
Bonus read: Go through a tutorial I have created to read CSV files using Pandas. It will give you an initial understanding of what you can do with the Pandas library.
I’m a Software Engineer and Programming Coach. I want to help you in your journey to become a Super Developer!