Installing Pandas
Installing pandas adds the library to Python. The pip tool does the installing.
The version check
This code imports pandas and prints the first part of the version number. It works only after the install.
import pandas as pd
print(pd.__version__.split(".")[0])Save the version first
The first part of the version number can sit in a variable first. The print then shows the same number.
import pandas as pd
version = pd.__version__.split(".")[0]
print(version)Example
import pandas as pd
version = pd.__version__.split(".")[0]
print(version)
print(pd.__name__)Key points
- Use pip install pandas to install pandas.
- Run the pip command in a terminal, not in a Python file.
- A terminal is a window for typing commands to the computer.
- Check the install with the line import pandas as pd in Python.
- Print pd.__version__ to see the installed version number.
- A version number has three parts, like 3.0.6.
In this example, pandas is imported first. The first part of the version number goes into a variable named version. The first print shows the first part of the version, 3. The second print shows the library name.
Note
If the import fails, pandas is not installed yet, so run the pip command again.
Try it Yourself
Edit the code, then press Run.
Running is simulated · Python Playground
Exercise
Which command installs pandas?