Back to List

What is pandas β€” Series and DataFrame

Understand the core data structures of pandas, Series and DataFrame, and learn the basics of loading and manipulating data.

Beginner
|
7min
|
Verified (2026-07)
Progress0/17 (0%)

pandas Explained: Series and DataFrame

After completing this topic, you will be able to:

  • Explain what Series and DataFrame are in pandas.
  • Load a CSV file and perform basic operations.

What is pandas?

pandas is a library for working with tabular data in Python. Think of it as a way to manipulate spreadsheets like Excel, but with code.

python
import pandas as pd
# Read a CSV file – it's as simple as this
df = pd.read_csv("students.csv")
print(df)
text
Name  Age  Score
0  Kim  25     85
1  Lee  23     92
2  Park  27     78

pd is the conventional abbreviation for pandas. You'll almost always see it used in data analysis code.


Series: A One-Dimensional Data Structure

A Series is a labeled, one-dimensional array. A column in a DataFrame is a Series.

python
import pandas as pd
# Create a Series
scores = pd.Series([85, 92, 78], index=["Kim", "Lee", "Park"])
print(scores)
text
Kim     85
Lee     92
Park    78
dtype: int64
python
# Access by index
print(scores["Lee"]) # 92
# Conditional filtering
print(scores[scores >= 80])
# Kim 85
# Lee 92
# Operations
print(scores.mean()) # 85.0
print(scores.max()) # 92

It's similar to a list, but you can access elements by name, and it has built-in statistical methods.


DataFrame: The Whole Table

A DataFrame is a two-dimensional table composed of multiple Series. It has rows and columns.

python
import pandas as pd
# Create from a dictionary
data = {
"Name": ["Kim", "Lee", "Park"],
"Age": [25, 23, 27],
"Score": [85, 92, 78]
}
df = pd.DataFrame(data)
print(df)
text
Name  Age  Score
0  Kim   25     85
1  Lee   23     92
2  Park  27     78

Basic Operations

python
# Select a column
print(df["Name"]) # Returns a Series
print(df[["Name", "Score"]]) # Returns a DataFrame
# Select a row
print(df.loc[0]) # Row 0 (by label)
print(df.iloc[0]) # Row 0 (by position)
# Conditional filtering
high = df[df["Score"] >= 80]
print(high)
# Name Age Score
# 0 Kim 25 85
# 1 Lee 23 92
# Basic statistics
print(df.describe())
# Mean, standard deviation, min/max, etc., for Age and Score

Commonly Used Methods

python
df.head(3) # First 3 rows
df.tail(3) # Last 3 rows
df.shape # (Number of rows, number of columns) - e.g., (3, 3)
df.columns # List of column names
df.dtypes # Data type of each column
df.info() # Summary information (including missing values)
df.sort_values("Score", ascending=False) # Sort by Score in descending order

Adding and Deleting Columns

python
# Add a new column
df["Passed"] = df["Score"] >= 80
print(df)
# Name Age Score Passed
# 0 Kim 25 85 True
# 1 Lee 23 92 True
# 2 Park 27 78 False
# Delete a column
df = df.drop("Passed", axis=1)
# axis=0 is for rows, axis=1 is for columns

Why pandas?

TaskPure Pythonpandas
Read CSV10+ lines (open, split, loop)pd.read_csv() 1 line
Calculate meanCalculate sum()/len() directlydf.mean()
Conditional filteringfor + ifdf[df["column"] > value]
Sortingsorted() + keydf.sort_values()

Not only is the code shorter, but pandas is internally optimized with C/Cython, making it 10 to 100 times faster than pure Python.


πŸ’¬ Questions & Comments

0 comments

You can post without signing in. Guest comments cannot be edited or deleted by their author.

0/2000

Loading...