Fundamentals 5 min read

How to Preserve Original Date Formats When Reading Excel with Pandas

This article explains why pandas adds a time component when reading dates from Excel or CSV files and provides three practical methods—specifying column formats, using datetime.strptime, and setting a date parser for Excel—to keep dates unchanged while still enabling further datetime operations.

Python Crawling & Data Mining
Python Crawling & Data Mining
Python Crawling & Data Mining
How to Preserve Original Date Formats When Reading Excel with Pandas

The author encountered a pandas issue where dates read from Excel or CSV files were automatically converted to full datetime values (e.g., "2023-01-01 00:00:00").

Solution Overview

Specify column format : Use pandas.read_csv with the parse_dates parameter and treat the date column as a string.

Use datetime.strptime : Convert the column with pd.to_datetime and an explicit format to avoid the default time part.

Specify format when reading Excel : Use pandas.read_excel with the date_parser argument to define the desired date format.

When saving data back to Excel, pandas writes full datetime values; to keep only the date part, format the column with strftime('%Y-%m-%d') before exporting.

These approaches let you read dates without the unwanted time component while still allowing later datetime calculations if needed.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

PythondatetimeExceldate handling
Python Crawling & Data Mining
Written by

Python Crawling & Data Mining

Life's short, I code in Python. This channel shares Python web crawling, data mining, analysis, processing, visualization, automated testing, DevOps, big data, AI, cloud computing, machine learning tools, resources, news, technical articles, tutorial videos and learning materials. Join us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.