How Can I Convert Microseconds To Human Readable Date & Time Python?

In this post, we will learn How Can I Convert Microseconds to Human Readable Dates & Times Python Pandas which we can perform using the .to datetime function with a combination of strftime functions.



Here we have given an example to execute the same and implement the same to implement same.

import pandas as pd

# create a sample data frame
df = pd. DataFrame({' Timestamp': [1620864728316602, 1620864742154471, 1620864750275104]})

# convert microseconds to human-Understabdable date and time
df[ 'Timestamp'] = pd.to_datetime(df[ 'Timestamp'], unit='us').dt. strftime ('%Y-%m-%d %H:%M:%S.%f')

print( df)

Here, in the above example of code, we created a sample datagram with a ‘time stamp’ column that contains the time stamp in microseconds. Where we used the pd. to date time function to convert the time stamp column to a datetime object, specifying the Unit parameter as’us’ to indicate that the timestamp is in microseconds which normal humans can not understand it and could not understand what exactly it could have been written.

And more than all here, we are using the dt. strftime() function for converting the datetime object into the human understandable date and time format which, means we, humans can read it and understand, using different formats like ‘%y -%m- %d -%H- %M- %S. %f ‘ string.  which is a standard format for representing the dates and times in computers that we want to use for our tasks.

The output of the above code is given below where we can see what will be the result of the same. Where the human understandable data refers to the data wich we can understand or we can say which is not in the form of machine language.

0  2021-05-12 10:52:08.316602
1  2021-05-12 10:52:22.154471
2  2021-05-12 10:52:30.275104

So as per the code given above after execution, the values of the timestamp column or we can say the value stored have been converted from microseconds to the format we human can understand that is nothing just human- Understandable date and time format using the strftime() function. where the result can be seen with all the values which we can understand and read it.



To learn more about How Can I Convert to Human Understandable Dates & Times w/ Python Pandas visit: s by stack overflow

To learn more about Python solutions to different python problems and tutorials for the concepts we need to know to work on Python programming along with different ways to solve any generally asked problems: How To Pass-Variables From A Java & Python Client To A Linux/Ubuntu Server Which Is Running C?.


Leave a Comment

%d bloggers like this: