Pandas Installation and Environment Setup
Set up Python, install Pandas, configure your development environment, and run your first Pandas program.
1. Learning Objectives
After completing this lesson, you will be able to:
- Check whether Python is installed.
- Check the installed Python and pip versions.
- Install Pandas using pip.
- Understand how a Python virtual environment works.
- Prepare VS Code or Jupyter Notebook for Pandas.
- Import Pandas and run a basic DataFrame program.
- Recognize and troubleshoot common installation errors.
2. Requirements for Pandas
Before using Pandas at CIIT Training Institute, make sure Python is installed and that you can run Python commands in your terminal or development environment.
| Requirement | Purpose |
|---|---|
| Python | Runs Python programs and libraries. |
| pip | Installs Python packages. |
| Pandas | Provides data analysis functionality. |
| VS Code or Jupyter | Lets you write and execute Python code. |
3. Check Python Installation
Open Command Prompt or the VS Code terminal on Windows. Run the following command to check your Python installation.
python --version
On some Windows installations, this command may be used instead:
py --version
Example output:
Python 3.12.0
Your version number may differ. The output above is only an example; it is not a claim about your computer's installed version.
Check pip
python -m pip --version
Example output:
pip 24.0 from ... (python 3.12)
The exact path and version depend on your Python installation.
4. Install Pandas Using pip
Once Python is available, install Pandas using Python's package installer. Run this command in the terminal, not inside a normal Python script.
python -m pip install pandas
If your Windows setup uses the py launcher,
you can also try:
py -m pip install pandas
pip downloads Pandas and the required dependencies for the selected Python environment.
Verify the Installation
python -c "import pandas as pd; print(pd.__version__)"
Example output:
2.2.3
The version shown is an example only. Your installed version may be different.
python -m pip instead of just
pip when you want to make it clearer which
Python installation is receiving the package.
5. Create a Virtual Environment
A virtual environment keeps the packages for one project separate from packages used by other projects. This is helpful when students at CIIT Training Institute work on multiple Python projects with different requirements.
Step 1: Create a Project Folder
mkdir CIITPandasPractice cd CIITPandasPractice
Step 2: Create the Environment
python -m venv .venv
Step 3: Activate It on Windows
.venv\Scripts\activate
After activation, the terminal prompt often shows
(.venv).
Step 4: Install Pandas Inside the Environment
python -m pip install pandas
Step 5: Verify the Environment
python -c "import pandas as pd; print(pd.__version__)"
Virtual environment workflow: create, activate, install, and verify.
6. Set Up Pandas in VS Code
Visual Studio Code is a code editor that can run Python programs when the Python extension and a suitable Python interpreter are configured.
Setup Steps
- Install Python if it is not already installed.
- Open VS Code.
- Install the Python extension from Microsoft.
- Open your
CIITPandasPracticefolder. - Create a file named
first_pandas.py. - Choose the correct Python interpreter.
- If using a virtual environment, select its Python interpreter.
- Write and run the example program.
First VS Code Program
import pandas as pd
students = pd.DataFrame({
"Name": ["Samadhan", "Pradnya", "Samiksha"],
"Course": ["Python", "Pandas", "Data Analysis"]
})
print(students)
Expected Output:
Name Course 0 Samadhan Python 1 Pradnya Pandas 2 Samiksha Data Analysis
The example uses student names for a hypothetical classroom dataset. The course values are sample data.
7. Set Up Pandas in Jupyter Notebook
Jupyter Notebook allows you to run code in individual cells and see results immediately. It is useful for experimenting with datasets and explaining results during classroom demonstrations.
Install Jupyter
python -m pip install notebook
Start Jupyter Notebook
jupyter notebook
Your browser should open the Jupyter interface. If it does not, check the terminal output for the local address supplied by Jupyter.
Run a Notebook Cell
import pandas as pd
marks = pd.DataFrame({
"Student": ["Samadhan", "Pradnya", "Samiksha"],
"Marks": [78, 91, 85]
})
marks
In a notebook, putting the DataFrame variable at the end of a cell displays its table representation.
8. Verify Your Python Environment
Use this short checklist whenever Pandas fails to import.
| Check | Command or Action | Expected Result |
|---|---|---|
| Python | python --version |
Python version is displayed. |
| pip | python -m pip --version |
pip version and location are displayed. |
| Pandas | python -c "import pandas as pd; print(pd.__version__)" |
Pandas version is displayed. |
| Editor interpreter | Check the selected interpreter in VS Code. | It matches the environment where Pandas is installed. |
9. Common Installation Problems
Problem 1: No Module Named pandas
Possible cause: Pandas is not installed in the active Python environment.
python -m pip install pandas
Also verify that VS Code or Jupyter is using the environment in which you installed Pandas.
Problem 2: Python Is Not Recognized
Check whether Python is installed and available on PATH.
On Windows, try py --version as well.
Problem 3: Permission Error
A virtual environment is often a good solution because it keeps project packages separate from system-wide packages.
Problem 4: Installation Seems Successful but Import Fails
Check the Python executable and pip location. They may refer to different installations. Re-select the correct interpreter and repeat the verification command.
10. Practice Exercise
CIIT Training Institute: Student Records
Create a DataFrame containing the names Samadhan, Pradnya, and Samiksha. Add a Marks column with any three sample scores.
Complete these tasks:
- Print the DataFrame.
- Display the Pandas version.
- Calculate the average marks.
- Display the student with the highest marks.
- Run the same program in your selected environment.
Starter Code
import pandas as pd
students = pd.DataFrame({
"Name": ["Samadhan", "Pradnya", "Samiksha"],
"Marks": [80, 92, 86]
})
print("Pandas version:", pd.__version__)
print(students)
print("Average marks:", students["Marks"].mean())
top_student = students.loc[students["Marks"].idxmax()]
print("Top student:", top_student["Name"])
Expected Output:
Pandas version: [your installed version]
Name Marks
0 Samadhan 80
1 Pradnya 92
2 Samiksha 86
Average marks: 86.0
Top student: Pradnya
The version placeholder will be replaced by the version installed on your computer. The sample marks produce the displayed average and top student.
Summary
You learned how to check Python and pip, install Pandas, create and activate a virtual environment, configure VS Code or Jupyter Notebook, and verify that Pandas is working.
You also created a DataFrame with student names and practiced basic analysis. You are now ready to explore Pandas Series, DataFrames, indexes, rows, columns, and dimensions in detail.