Installing & Importing
How to install pandas with pip or conda, the standard `import pandas as pd` convention, checking the version, and setting display options.
Before you can analyse a single IPL scorecard, pandas has to be installed on your computer and imported into your program. pandas is not part of Python's standard library, so a fresh Python installation does not have it.
Definition
Installing a package downloads it (and its dependencies, such as NumPy) into your Python environment once. Importing loads the installed package into the current program every time it runs, and
import pandas as pdbinds it to the short aliaspd.
- Install once, import every time — installation is a one-time setup step; the
importline goes at the top of every script or notebook. - Dependencies — pip/conda automatically install what pandas needs: NumPy, python-dateutil (date parsing) and tzdata (time zones).
- Alias
pd— a universal convention. Every tutorial, Stack Overflow answer and job codebase writespd.DataFrame,pd.read_csv, etc.
Syntax — installing
bash
# with pip (any Python installation)
pip install pandas
# upgrade to the latest version
pip install --upgrade pandas
# install a specific version
pip install pandas==3.0.2
# with conda (Anaconda / Miniconda)
conda install pandas
# inside a Jupyter / Colab notebook cell
!pip install pandas| Command part | Meaning |
|---|---|
pip install pandas | download and install the latest pandas + dependencies |
--upgrade | replace an older installed version with the newest |
pandas==3.0.2 | pin an exact version (useful to match a course or a team) |
conda install pandas | install via the conda package manager (comes with Anaconda) |
!pip ... | the ! runs a shell command from inside a notebook cell |
Tip: Anaconda and Google Colab already include pandas. On this website's playground, pandas is also pre-loaded — just write
import pandas as pd.
Optional extras pandas can use (install only when needed):
| Package | Needed for |
|---|---|
openpyxl | pd.read_excel / df.to_excel with .xlsx files |
pyarrow | fast Parquet / Feather files and Arrow-backed dtypes |
matplotlib | df.plot() charts |
sqlalchemy | pd.read_sql from databases |
Syntax — importing
python
import pandas as pd # the standard convention
import numpy as np # almost always imported alongside pandas
pd.__version__ # version string, e.g. '3.0.2'
pd.show_versions() # long report: pandas, Python, NumPy and all optional packages| Name | Meaning |
|---|---|
import pandas as pd | load pandas and refer to it as pd |
pd.__version__ | the installed pandas version as a string |
pd.show_versions() | prints versions of pandas and every dependency (great for bug reports) |
Example — check that everything works
python
import pandas as pd
import numpy as np
print("Pandas version:", pd.__version__)
print("NumPy version :", np.__version__)text
Pandas version: 3.0.2
NumPy version : 2.4.6How it works: __version__ is a special attribute that most libraries provide. Checking it is the first thing to do when code from a tutorial behaves differently on your machine — the tutorial may have used an older version.
Example — display options
When a DataFrame is large, pandas shortens the printout with ... so your screen is not flooded:
python
df = pd.DataFrame({"x": range(100)})
print(df)text
x
0 0
1 1
2 2
3 3
4 4
.. ..
95 95
96 96
97 97
98 98
99 99
[100 rows x 1 columns]You can control this with options:
python
pd.set_option("display.max_rows", 100) # show up to 100 rows before shortening
pd.set_option("display.max_columns", None) # never hide columns
pd.set_option("display.width", 120) # characters per line before wrapping
pd.set_option("display.precision", 2) # decimals shown for floats (display only!)
pd.get_option("display.max_rows") # read an option
pd.reset_option("display.max_rows") # back to default| Function | Meaning |
|---|---|
pd.set_option(name, value) | change a display/behaviour option |
pd.get_option(name) | read the current value |
pd.reset_option(name) | restore the default |
print(df.to_string()) | print everything, ignoring max_rows once |
Note: Display options only change how data is printed —
display.precisiondoes not round the actual values.
Common mistakes
- ❌
ModuleNotFoundError: No module named 'pandas'→ pandas is not installed in the Python you are running. ✅ Runpython -m pip install pandaswith the samepythonthat runs your script (virtual environments are a common cause). - ❌ Naming your own file
pandas.py. ✅ Python will import your file instead of the library. Rename it (e.g.ipl_analysis.py). - ❌
import pandasand then writingpd.DataFrame. ✅ Useimport pandas as pdso the namepdexists. - ❌
pip install panda(singular). ✅ The package ispandas.
Interview tip
Q: How do you find which pandas version a script is running with, and why does it matter?
A: pd.__version__ (or pd.show_versions() for everything). Behaviour changes between major versions — for example pandas 3 introduced a dedicated str dtype and Copy-on-Write — so the version explains why the same code can print different results on different machines.
Key points to remember
- Install once with `pip install pandas` (or `conda install pandas`); import in every script.
- The universal convention is `import pandas as pd`, usually together with `import numpy as np`.
- pip installs pandas' dependencies automatically: NumPy, python-dateutil and tzdata.
- `pd.__version__` shows the installed version; `pd.show_versions()` shows all dependencies.
- Optional packages add features: openpyxl for Excel, pyarrow for Parquet, matplotlib for plotting.
- Display options (`pd.set_option`) change only how data is printed, never the data itself.
- Never name your own file pandas.py — it shadows the real library.
Try it yourself
Import pandas and check versions
Display options: rows and precision
Practice: build and print your first DataFrame
Revision Flashcards
Tap a card to flip it and see the answer.
