

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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 - Return the frequency applied on the given DateOffset object
<p>To return the frequency applied on the given DateOffset object, use the offset.freqstr in Pandas. At first, import the required libraries −</p><pre class="just-code notranslate language-python3" data-lang="python3">from pandas.tseries.frequencies import to_offset import pandas as pd</pre><p>Set the timestamp object in Pandas −</p><pre class="just-code notranslate language-python3" data-lang="python3">timestamp = pd.Timestamp('2021-09-26 03:25:02.000045') </pre><p>Create the DateOffset. We are incrementing the days here using the "D" frequency −</p><pre class="just-code notranslate language-python3" data-lang="python3">offset = to_offset("5D")</pre><p>Display the Updated Timestamp −</p><pre class="just-code notranslate language-python3" data-lang="python3">print(" Updated Timestamp... ",timestamp + offset) </pre><p>Return the frequency applied on the given DateOffset object −</p><pre class="just-code notranslate language-python3" data-lang="python3">print(" The frequency on the DateOffset object.. ", offset.freqstr)</pre><h2>Example</h2><p>Following is the code −</p><pre class="demo-code notranslate language-python3" data-lang="python3">from pandas.tseries.frequencies import to_offset import pandas as pd # Set the timestamp object in Pandas timestamp = pd.Timestamp('2021-09-26 03:25:02.000045') # Display the Timestamp print("Timestamp... ",timestamp) # Create the DateOffset # We are incrementing the days here using the "D" frequency offset = to_offset("5D") # Display the DateOffset print(" DateOffset... ",offset) # Display the Updated Timestamp print(" Updated Timestamp... ",timestamp + offset) # return the frequency applied on the given DateOffset object print(" The frequency on the DateOffset object.. ", offset.freqstr)</pre><h2>Output</h2><p>This will produce the following code −</p><pre class="result notranslate">Timestamp... 2021-09-26 03:25:02.000045 DateOffset... <5 * Days> Updated Timestamp... 2021-10-01 03:25:02.000045 The frequency on the DateOffset object.. 5D</pre>
- Related Questions & Answers
- Python Pandas - Return frequency applied on the given DateOffset object as a string
- Python Pandas - Return the rule code applied on the given DateOffset object
- Python Pandas - Return the count of increments applied on the given DateOffset object
- Python Pandas - Return the name of the frequency applied on the given BusinessDay offset object
- Python Pandas - Return the name of the frequency applied on the given BusinessHour offset object
- Python Pandas - Return the name of the frequency applied on the given CustomBusinessDay offset object
- Python Pandas - Return the name of the frequency applied on the given CustomBusinessHour offset object
- Python Pandas - Return frequency applied on the given BusinessDay Offset object as a string
- Python Pandas - Return frequency applied on the given BusinessHour Offset object as a string
- Python Pandas - Return frequency applied on the given CustomBusinessDay Offset object as a string
- Python Pandas - Return frequency applied on the given CustomBusinessHour Offset object as a string
- Python Pandas - Return the string alias of the Time series frequency applied on the given Period object
- Python Pandas - Return the rule code applied on the given BusinessDay object
- Python Pandas - Return the rule code applied on the given BusinessHour object
- Python Pandas - Return the rule code applied on the given CustomBusinessDay object
Advertisements