![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python Pandas - Convert given Timestamp to Period with minutely frequency
To convert given Timestamp to Period, use the timestamp.to_period() method. Within that, set the frequency using the freq parameter. For minutely frequency, set freq as T.
At first, import the required libraries −
import pandas as pd
Create a timestamp object
timestamp = pd.Timestamp(2021, 9, 6, 11, 50, 20, 33)
Convert timestamp to Period. We have set the frequency as minutely using the "freq" parameter with value 'T'
timestamp.to_period(freq='T')
Example
Following is the code
import pandas as pd # set the timestamp object in Pandas timestamp = pd.Timestamp(2021, 9, 6, 11, 50, 20, 33) # display the Timestamp print("Timestamp...\n", timestamp) # convert timestamp to Period # we have set the frequency as minutely using the "freq" parameter with value 'T' print("\nTimestamp to Period...\n", timestamp.to_period(freq='T'))
Output
This will produce the following code
Timestamp... 2021-09-06 11:50:20.000033 Timestamp to Period... 2021-09-06 11:50
Advertisements