0

I have dataframe in following format:

    >     buyer_id   purch_id   timestamp  

    >     buyer_2    purch_2    1330767282
    >     buyer_3    purch_3    1330771685
    >     buyer_3    purch_4    1330778269
    >     buyer_4    purch_5    1330780256
    >     buyer_5    purch_6    1330813517

I want to ask for your advice how to convert timestamp column (in dataframe) into datetime and then extract only the time of the event into the new column??

Thanks!

1 Answer 1

1

assuming 'timestamp' is Unix time (seconds since the epoch), you can cast to_datetime provided the right unit ('s') and use the time part:

df['time'] = pd.to_datetime(df['timestamp'], unit='s').dt.time

df
Out[9]: 
  buyer_id purch_id   timestamp      time
0  buyer_2  purch_2  1330767282  09:34:42
1  buyer_3  purch_3  1330771685  10:48:05
2  buyer_3  purch_4  1330778269  12:37:49
3  buyer_4  purch_5  1330780256  13:10:56
4  buyer_5  purch_6  1330813517  22:25:17
Sign up to request clarification or add additional context in comments.

Comments

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.