Slicing by Partial Dates in Pandas – Year, Month, Quarter & Week 2026
Partial date slicing allows you to easily select data for an entire year, month, quarter, or week without specifying full start and end dates. In 2026, Pandas makes this extremely convenient and efficient when you have a sorted DatetimeIndex.
TL;DR — Partial Date Slicing Syntax
df.loc["2026"]→ entire year 2026df.loc["2026-03"]→ entire March 2026df.loc["2026Q1"]→ first quarter of 2026df.loc["2026-03-15":"2026-03-21"]→ specific week
1. Basic Partial Date Slicing
import pandas as pd
df = pd.read_csv("sales_data.csv", parse_dates=["order_date"])
df = df.set_index("order_date").sort_index()
# Slice by Year
sales_2026 = df.loc["2026"]
# Slice by Month
march_sales = df.loc["2026-03"]
# Slice by Quarter
q1_sales = df.loc["2026Q1"]
q2_sales = df.loc["2026Q2"]
2. Combining Partial Dates with Other Filters
# March 2026 sales for North region only
north_march = df.loc["2026-03"].loc[df["region"] == "North"]
# All sales in 2026 for Electronics category
electronics_2026 = df.loc["2026"].loc[df["category"] == "Electronics"]
3. Advanced Partial Date Slicing
# First half of 2026
first_half = df.loc["2026-01":"2026-06"]
# Specific week using ISO week format
week_12 = df.loc["2026-03-16":"2026-03-22"]
# Last 3 months of 2026
last_quarter = df.loc["2026-10":]
4. Best Practices in 2026
- Always set the date column as index and sort it first with
.sort_index() - Use partial string indexing like
"2026","2026-03", or"2026Q1" - Partial date slicing works only on a sorted DatetimeIndex
- Combine partial date slicing with boolean filtering for powerful queries
- Use
pd.Grouper(freq="M")orresample()when you need aggregation by time period
Conclusion
Partial date slicing is one of the most convenient features in Pandas when working with time-series data. In 2026, once you set a sorted DatetimeIndex, you can easily slice by year ("2026"), month ("2026-03"), quarter ("2026Q1"), or any custom range with simple, readable syntax. This technique greatly simplifies time-based data analysis and reporting.
Next steps:
- Set your date column as index, sort it, and practice slicing by year, month, and quarter using partial date strings