MSK Institute LogoMSK.Institute
HomeCourses
Book Free Demo➔Sign In
Free Demo➔
MSK Institute LogoMSK.Institute

Leading computer training academy in Shikohabad for software engineering, Python, web development, and digital literacy.

ISO 9001:2015 Certified Center
Follow & Connect
4.9

Programs & Admissions

  • All CoursesCatalog
  • Learning PathsRoadmaps
  • Student ProjectsShowcase
  • Live Classes & ScheduleLive
  • Upcoming Batches
  • Campuses & LocationsHub
  • Verify Certificates
  • Book Free Demo Class

Resources & Tools

  • Free Online Mock TestsAll Tests
  • NIELIT CCC Mock TestFree
  • Course & Career FinderQuiz
  • Study Material Hub
  • All MSK ToolsHub
  • Keyboard ShortcutsNew
  • TypeQuest Speed LabTyping
  • MSK Code PlaygroundCode
  • Interactive Tutorials
  • Quick Cheatsheets

Institute & Contact

  • About MSK Institute
  • Careers & InternshipsHiring
  • Publications & Blogs
  • Gali No. 3, Near Gyan Jyoti Public School,
    Adarsh Nagar, Shikohabad, Uttar Pradesh 283135
  • +91 83930 42166
  • mskshikohabad@gmail.com
  • Hours:Mon – Sat: 8:00 AM – 7:00 PM | Sun: 10:00 AM – 2:00 PM
  • 4.9 ★(38 Google Reviews)
© 2026 MSK Institute. All rights reserved.•Privacy Policy•Terms of Service•Disclaimer•Contact Us

Shikohabad's Leading Computer & Coding Academy

Home
Courses
Live
Material
DateTime Parsing, Indexing & .dt Accessor0%
Study MaterialsCheatsheet
PandasProgress 0%
1.1What is Pandas & Core Architecture1.2Pandas Installation & Environment Setup1.3Creating Series & DataFrames from Scratch
8.1DateTime Parsing, Indexing & .dt Accessor8.2Resampling, Rolling Windows & Shifting8.3End-to-End Exploratory Data Analysis (EDA) Project
HomeTutorialsPandasDateTime Parsing, Indexing & .dt Accessor
Resampling, Rolling Windows & Shifting

DateTime Parsing, Indexing & .dt Accessor

Intermediate6 min read•Updated: 2026-11-18•By Er. Sumit Kumar (MSK Institute)
Study MaterialsCheatsheet

1. Working with Time in Pandas

In real-world business analytics (sales trends, stock prices, churn tracking, server logs), dates are central. Pandas provides the native datetime64[ns] dtype and DatetimeIndex for high-performance temporal computations.


2. Converting Strings to Datetime (pd.to_datetime)

1import pandas as pd
2 
3date_strings = ['2026-01-15', '2026-02-20', '2026-03-25']
4dt_series = pd.to_datetime(date_strings)
5print(dt_series)

Parsing Non-Standard Date Formats:

1# Indian date format: DD/MM/YYYY
2raw_dates = pd.Series(['15/08/2026', '26/01/2026', '02/10/2026'])
3 
4# Pass exact strptime format
5clean_dates = pd.to_datetime(raw_dates, format='%d/%m/%Y')
6print(clean_dates)

3. The .dt Accessor (Extracting Date Components)

Just as strings have the .str accessor, dates have the .dt accessor for extracting year, month, day, weekday, quarter, etc.:

1df = pd.DataFrame({'Timestamp': clean_dates})
2 
3df['Year'] = df['Timestamp'].dt.year
4df['Month'] = df['Timestamp'].dt.month
5df['Month_Name'] = df['Timestamp'].dt.month_name()
6df['Day'] = df['Timestamp'].dt.day
7df['Day_of_Week'] = df['Timestamp'].dt.day_name()
8df['Is_Weekend'] = df['Timestamp'].dt.dayofweek >= 5
9 
10print(df)

4. The DatetimeIndex & Date Slicing

Promoting a Datetime column to the DataFrame Index unlocks powerful partial-string date slicing:

1df_sales = pd.DataFrame({
2 'Revenue': [15000, 22000, 31000]
3}, index=pd.to_datetime(['2026-01-05', '2026-01-20', '2026-02-14']))
4 
5# Slice all transactions from January 2026 using simple string notation!
6jan_sales = df_sales.loc['2026-01']
7print(jan_sales)

Interactive Quiz• Knowledge Check

Practice Quiz

Question 1
Which function converts strings or Unix epoch integers into Pandas DateTime objects?
Question 2
What accessor is used to extract date properties (such as year, month, and day_name) from a DateTime Series?
Question 3
How do you extract the name of the day of the week (e.g. 'Monday', 'Tuesday') from a DateTime column?
Question 4
What format string parses a date formatted as "25-Dec-2026"?
Question 5
What unique capability is enabled when setting a DatetimeIndex as the DataFrame's index?

Next Lesson

Resampling, Rolling Windows & Shifting

Continue learning with hands-on practice, examples, and exercises in the upcoming topic.

Related Lessons

Previous LessonNext Lesson
Reshaping Data: Melt, Stack & UnstackResampling, Rolling Windows & Shifting

Practice Quiz

Test your understanding of this lesson with 5 questions. Each question has one correct answer.

12-Month Data Analysis Mastery Program

Master Full-Stack Data Analytics (Excel, SQL, Python, Power BI & Tableau)

Combine 15 complete courses, 150 chapters, 541 topics, live SQL/Power BI/Tableau dashboards, and Scikit-Learn capstones at MSK Institute Shikohabad or Live Online.

View Full CourseBook Free Demo
PreviousNext
PreviousPrevNext