pandas
data manipulation
datetime
python
data analysis

Pandas: combine date and time columns into one datetime column

Codemia Knowledge Hub ·

To combine separate date and time columns in pandas, concatenate them with a space and pass the result to pd.to_datetime. If the columns hold datetime.date and datetime.time objects, convert them with .astype(str) first. Specify a format when you know it, and handle time zones deliberately.

Combining string columns

When both parts are stored as strings:

python
1import pandas as pd
2
3df = pd.DataFrame({
4    "date": ["2026-03-01", "2026-03-02"],
5    "time": ["09:15:00", "18:45:00"],
6})
7
8df["timestamp"] = pd.to_datetime(df["date"] + " " + df["time"])
9print(df)
10print(df.dtypes)

pandas parses the combined string into a single datetime64 column.

Passing an explicit format

If the input format is stable, specify it. Parsing is faster and less likely to misread values, which matters most when day and month order could be ambiguous:

python
1import pandas as pd
2
3df = pd.DataFrame({
4    "date": ["01/03/2026", "02/03/2026"],
5    "time": ["09:15", "18:45"],
6})
7
8df["timestamp"] = pd.to_datetime(
9    df["date"] + " " + df["time"],
10    format="%d/%m/%Y %H:%M"
11)
12
13print(df["timestamp"])

Combining datetime.date and datetime.time columns

When the columns are already typed, converting both to strings is acceptable and keeps the code simple, as long as you know what you are normalizing:

python
1import pandas as pd
2import datetime as dt
3
4df = pd.DataFrame({
5    "date": [dt.date(2026, 3, 1), dt.date(2026, 3, 2)],
6    "time": [dt.time(9, 15), dt.time(18, 45)],
7})
8
9df["timestamp"] = pd.to_datetime(df["date"].astype(str) + " " + df["time"].astype(str))
10print(df["timestamp"])

Adding a time zone

If the result represents a real-world timestamp, you may also need a time zone:

python
df["timestamp_utc"] = df["timestamp"].dt.tz_localize("UTC")
print(df["timestamp_utc"])

If the source values are local times from a known region, localize to that region first and convert later if needed. Don't attach a time zone after the fact without knowing what the original data meant, and don't treat naive datetimes as if they were already UTC.

What usually goes wrong

Most bugs come from hidden assumptions:

  • the date format is not what you thought
  • the time column contains missing values
  • one column already has timezone information
  • the business meaning is local time, but the pipeline treats it as UTC

That is why explicit parsing is safer in production pipelines than letting pandas infer everything.

Validating the combined column

python
print(df[["date", "time", "timestamp"]])
print(df["timestamp"].isna().sum())

If parsing produced unexpected NaT values, fix the source format, or pass errors="coerce" only if you are ready to handle bad rows explicitly.

Keep the original date and time columns until you trust the result. Having them during validation makes it much easier to inspect bad rows, confirm time zone assumptions and explain parsing issues to teammates before the final cleanup.


Free course
Beginner
7 lessons
2 hours
Tackling System Design Interview Problems

A short course that equips you with the skills to approach system design interviews methodically.

Start the free course
Basis Lab
No course covers this one yet

Basis Lab writes one for you from a sentence about what you want to be able to do, then teaches it and checks you understood. Your first course is free.

Build my course
ML System Design practice on Codemia

Design recommenders, ranking systems and training pipelines the way ML interviews actually ask for them, with worked solutions.

Practice ML system design