1

I have the following dataframe:

df=pd.DataFrame(index=[0])
df['timestamp'] = 1642104862000
df:
    timestamp
0   1642104862000

I am applying the following code:

df['timestamp'] = pd.to_datetime(df['timestamp'], infer_datetime_format=True)

But the date I am getting is 1970-01-01 00:27:22.104862 which is wrong. The right date is 2022-01-13 20:14:22.

How can I get the right date? Thank you

2
  • 4
    milliseconds so unit='ms' Commented Jan 27, 2022 at 17:04
  • 1
    Thanks for the quick answer. It worked Commented Jan 27, 2022 at 17:06

1 Answer 1

2

Make sure you're using the right unit. Try this code:

df['timestamp'] = pd.to_datetime(df['timestamp'], infer_datetime_format=True, unit="ms")
Sign up to request clarification or add additional context in comments.

1 Comment

infer_datetime_format=True is not needed if you specify a unit.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.