Pandas Getting Started

Before you can use pandas, you need to install it and import it correctly into your Python scripts.

Installing Pandas

Pandas is not part of the Python standard library, so it must be installed separately using pip, Python's package manager. If you are using a distribution like Anaconda, pandas is likely already installed. Otherwise, open your terminal or command prompt and run the install command below.

Install Pandas

pip install pandas

Checking Your Installation

After installing, it is good practice to confirm pandas is available and check which version you have. Different versions can behave slightly differently, so knowing your version helps when reading documentation or debugging.

Check the Pandas Version

import pandas as pd

print(pd.__version__)
  • Use pip3 install pandas if 'pip' points to Python 2 on your system
  • Install inside a virtual environment to avoid conflicts with other projects
  • Upgrade an existing install with pip install --upgrade pandas
  • Conda users can run conda install pandas instead of pip

Importing Pandas

Once installed, pandas is imported like any other Python module. By convention, it is almost always imported with the alias pd, which keeps your code shorter and matches the convention used throughout the pandas documentation and community.

Your First Pandas Script

import pandas as pd

mydataset = {
    'cars': ["BMW", "Volvo", "Ford"],
    'passings': [3, 7, 2]
}
myvar = pd.DataFrame(mydataset)
print(myvar)
CommandPurpose
pip install pandasInstall the latest pandas release
pip install pandas==2.2.0Install a specific version
pip install --upgrade pandasUpgrade to the newest version
import pandas as pdImport pandas using the standard alias
Note: Always use the alias pd - it is a near-universal convention, and every tutorial, forum answer, and codebase you encounter will assume it.

Exercise: Pandas Getting Started

Which command installs pandas using pip?