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.
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.
Signed-in readers can open the original source through BestHub's protected redirect.
This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactand we will review it promptly.
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!
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.
