0

How can I convert timestamp column of dataframe to numeric value? The datatype of the below Time column in below dataframe 'df' is 'datetime64'.

       Time          Count
2018-05-15 00:00:00    4
2018-05-15 00:15:00    1
2018-05-15 00:30:00    5
2018-05-15 00:45:00    6
2018-05-15 01:15:00    3
2018-05-15 01:30:00    4
2018-05-15 02:30:00    5
2018-05-15 02:45:00    3
2018-05-15 03:15:00    2
2018-05-15 03:30:00    5
2
  • 3
    What kind of number do you want to represent those timestamps? Number of seconds since some date? Number of minutes since midnight? Commented May 30, 2018 at 0:32
  • If it's not obvious why the comment by @ALollz makes your question impossible to answer as written, consider that df.Time = 42 converts the column to a numeric value, which is all you've specified, but is almost certainly useless. Commented May 30, 2018 at 1:28

1 Answer 1

1

By using to_numeric

pd.to_numeric(df.Time)
Out[218]: 
0    1526342400000000000
1    1526343300000000000
2    1526344200000000000
3    1526345100000000000
4    1526346900000000000
5    1526347800000000000
6    1526351400000000000
7    1526352300000000000
8    1526354100000000000
9    1526355000000000000
Name: Time, dtype: int64
Sign up to request clarification or add additional context in comments.

1 Comment

These values get changed when I export dataframe to csv. I have same values for most columns. They are not unique

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.