- 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 - Display the end time of the period for each element in the given PeriodIndex object
To display the end time of the period for each element in the given PeriodIndex object, use the PeriodIndex.end_time property.
At first, import the required libraries −
import pandas as pd
Create a PeriodIndex object. PeriodIndex is an immutable ndarray holding ordinal values indicating regular periods in time. We have set the frequency using the "freq" parameter −
periodIndex = pd.PeriodIndex(['2018-07-25', '2019-10-30', '2020-11-20', '2021-09-15', '2022-03-12', '2023-06-18'], freq="D")
Display PeriodIndex object −
print("PeriodIndex...\n", periodIndex)
Display the end time −
print("\nEnd Time...\n", periodIndex.end_time)
Example
Following is the code −
import pandas as pd # Create a PeriodIndex object # PeriodIndex is an immutable ndarray holding ordinal values indicating regular periods in time # We have set the frequency using the "freq" parameter periodIndex = pd.PeriodIndex(['2018-07-25', '2019-10-30', '2020-11-20', '2021-09-15', '2022-03-12', '2023-06-18'], freq="D") # Display PeriodIndex object print("PeriodIndex...\n", periodIndex) # Display PeriodIndex frequency print("\nPeriodIndex frequency...\n", periodIndex.freq) # Display the end time print("\nEnd Time...\n", periodIndex.end_time)
Output
This will produce the following code −
PeriodIndex... PeriodIndex(['2018-07-25', '2019-10-30', '2020-11-20', '2021-09-15', '2022-03-12', '2023-06-18'], dtype='period[D]') PeriodIndex frequency... <Day> End Time... DatetimeIndex(['2018-07-25 23:59:59.999999999', '2019-10-30 23:59:59.999999999', '2020-11-20 23:59:59.999999999', '2021-09-15 23:59:59.999999999', '2022-03-12 23:59:59.999999999', '2023-06-18 23:59:59.999999999'], dtype='datetime64[ns]', freq=None)
Advertisements
To Continue Learning Please Login
Login with Google