Article Categories
- All Categories
-
Data Structure
-
Networking
-
RDBMS
-
Operating System
-
Java
-
MS Excel
-
iOS
-
HTML
-
CSS
-
Android
-
Python
-
C Programming
-
C++
-
C#
-
MongoDB
-
MySQL
-
Javascript
-
PHP
Selected Reading
Python Pandas - Construct a naive UTC datetime from a POSIX timestamp
To construct a naive UTC datetime from a POSIX timestamp, use the timestamp.utcfromtimestamp() method. Pass the POSIX as an argument.
At first, import the required libraries −
import pandas as pd
Create a timestamp
timestamp = pd.Timestamp('2021-09-14T15:12:34.261811624')
Constructing a naive UTC datetime from a POSIX timestamp. POSIX is passed as an argument
timestamp.utcfromtimestamp(1631717502)
Example
Following is the code
import pandas as pd
# creating a timestamp
timestamp = pd.Timestamp('2021-09-14T15:12:34.261811624')
# display the Timestamp
print("Timestamp...\n", timestamp)
# constructing a naive UTC datetime from a POSIX timestamp
# POSIX is passed as an argument
print("\nConstruct UTC Datetime...\n", timestamp.utcfromtimestamp(1631717502))
Output
This will produce the following code
Timestamp... 2021-09-14 15:12:34.261811624 Construct UTC Datetime... 2021-09-15 14:51:42
Advertisements
