MadiisAttendance
Pandas Fundamentals — Getting Started 4 min read 613 words 52 sentences uni

Pandas Day 1 — Installation, Series, DataFrames & Data Inspection

M Usman May 26, 2026
13 0 0 score
0%
Your Progress
0/26 sections
Reading Speed
0
words/min
Time Spent
00:00

📌 Day 1 Goal Breakdown

  1. Install pandas and verify version

  2. Create Series from list and dictionary

  3. Build DataFrame from CSV / dict with custom index

  4. Explore shape, columns, dtypes attributes

  5. Use head(), tail(), sample() to inspect data


1️⃣ Install pandas and verify version

How to install

Open your terminal (Command Prompt, PowerShell, or terminal in VS Code/PyCharm).

bash
pip install pandas

If you use Jupyter or Anaconda:

bash
conda install pandas

Verify installation & version

python
import pandas as pd
print(pd.__version__)

Example output:
2.0.3 (yours may be newer)

pd is the standard alias for pandas — almost everyone uses it.


2️⃣ Create Series from list and dictionary

What is a Series?

A Series is like a single column of data — it has index (labels) and values.
Think of it as a Python dictionary + list combined.

From a list

python
import pandas as pd

# List → Series (default index 0,1,2,...)
s1 = pd.Series([10, 20, 30, 40])
print(s1)

Output:

text
0    10
1    20
2    30
3    40
dtype: int64

From a dictionary (keys become index)

python
s2 = pd.Series({'a': 100, 'b': 200, 'c': 300})
print(s2)

Output:

text
a    100
b    200
c    300
dtype: int64

How it works

  • pandas automatically aligns data with index.

  • If index is not provided, it uses 0-based integers.

  • Dictionary keys become the index.


3️⃣ Build DataFrame from CSV/dict with custom index

DataFrame = multiple Series sharing the same index (like a spreadsheet)

From dictionary

python
data_dict = {
    'Name': ['Alice', 'Bob', 'Charlie'],
    'Age': [25, 30, 35],
    'City': ['NYC', 'LA', 'Chicago']
}

df = pd.DataFrame(data_dict)
print(df)

Output:

text
      Name  Age     City
0    Alice   25      NYC
1      Bob   30       LA
2  Charlie   35  Chicago

Add custom index

python
df = pd.DataFrame(data_dict, index=['row1', 'row2', 'row3'])
print(df)

Output:

text
        Name  Age     City
row1   Alice   25      NYC
row2     Bob   30       LA
row3 Charlie   35  Chicago

From CSV file

Suppose you have data.csv:

csv
Name,Age,City
Alice,25,NYC
Bob,30,LA
Charlie,35,Chicago
python
df_csv = pd.read_csv('data.csv')
print(df_csv)

⚠️ Make sure the CSV file is in the same folder as your Python script, or provide full path.

Set custom index while loading CSV

python
df_csv = pd.read_csv('data.csv', index_col=0)  # first column becomes index

4️⃣ Explore shape, columns, dtypes attributes

Using the DataFrame we created:

python
df = pd.DataFrame(data_dict)

# Number of rows and columns
print(df.shape)   # Output: (3, 3)

# Column names
print(df.columns) # Output: Index(['Name', 'Age', 'City'], dtype='object')

# Data type of each column
print(df.dtypes)

Output for dtypes:

text
Name     object
Age       int64
City     object
dtype: object
  • object = string/text

  • int64 = integer numbers

Why this matters

  • shape tells you dataset size

  • columns lets you access column names

  • dtypes helps detect if numeric column is wrongly read as string


5️⃣ Use head(), tail(), sample() to inspect data

Let’s make a bigger DataFrame for demonstration:

python
import numpy as np

# Create 20 rows of dummy data
big_data = {
    'ID': range(1, 21),
    'Score': np.random.randint(50, 100, 20)
}
df_big = pd.DataFrame(big_data)

head() — first 5 rows (default)

python
print(df_big.head())

Output (example):

text
   ID  Score
0   1     78
1   2     92
2   3     65
3   4     88
4   5     73

head(10) — first 10 rows

python
print(df_big.head(10))

tail() — last 5 rows

python
print(df_big.tail())

sample() — random rows

python
print(df_big.sample(3))   # 3 random rows
print(df_big.sample(frac=0.1))  # 10% of rows (2 rows here)

Why these are useful

  • head(): quick sanity check

  • tail(): check recent/last entries

  • sample(): random inspection (good for large datasets)


🧪 Practice Exercises (try these)

  1. Create a Series from [5, 10, 15, 20] with custom index ['a','b','c','d'].

  2. Build a DataFrame from this dictionary:
    {'Product': ['A','B'], 'Price': [100, 200], 'Stock': [10, 20]}
    Set index to ['item1', 'item2'].

  3. For that DataFrame, print:

    • shape

    • column names

    • data types

  4. Load any small CSV (or create one) and use .head(3), .tail(2), .sample(2).


❌ Common mistakes & how to avoid

MistakeFix
Forgetting import pandas as pdAlways write it first
Using wrong file path for CSVUse r'C:\data\file.csv' or os.path.join()
Assuming default index is usefulExplicitly set index if needed
Confusing Series vs DataFrameSeries = 1D, DataFrame = 2D

✅ Summary of Day 1

You now know:

  • Install pandas & check version

  • Create Series from list/dict

  • Create DataFrame from dict/CSV with custom index

  • Inspect DataFrame using .shape, .columns, .dtypes

  • View data with .head(), .tail(), .sample()

Discussion (1)
Login to comment
M Usman May 27, 2026

thnks

Dictionary

Add New Word

Dictionary Words
My Notes
Highlights
Select text and click highlight to save
My Vocabulary
Quick Quiz
Settings
Reading Analytics
Today's reading: 0 min
Total read time: 0 min
Words learned: 0
Streak: 0 days
AI Summary

Generating summary...