Python Pandas - Display the keyword arguments applied on the given BusinessHour object

PythonServer Side ProgrammingProgramming

<p>To display the keyword arguments applied on the given BusinessHour object, use the BusinessHour.kwds property in Pandas.</p><p>At first, import the required libraries &minus;</p><pre class="just-code notranslate language-python3" data-lang="python3">import pandas as pd</pre><p>Create the BusinessHour Offset. Here, &quot;start&quot; is the start time of your custom business hour in 24h format. The &quot;end&quot; is the end time of your custom business hour in 24h format &minus;</p><pre class="just-code notranslate language-python3" data-lang="python3">bhOffset = pd.tseries.offsets.BusinessHour(start=&quot;09:30&quot;, end = &quot;18:00&quot;) </pre><p>Set the timestamp object in Pandas &minus;</p><pre class="just-code notranslate language-python3" data-lang="python3">timestamp = pd.Timestamp(&#39;2021-1-1 01:55:30&#39;)</pre><p>Display the Updated Timestamp &minus;</p><pre class="just-code notranslate language-python3" data-lang="python3">print(&quot; Updated Timestamp... &quot;,timestamp + bhOffset) </pre><p>Display the keyword arguments &minus;</p><pre class="just-code notranslate language-python3" data-lang="python3">print(&quot; Keyword arguments on the given BusinessHour Offset... &quot;,bhOffset.kwds)</pre><h2>Example</h2><p>Following is the code &minus;</p><pre class="demo-code notranslate language-python3" data-lang="python3">import pandas as pd # Set the timestamp object in Pandas timestamp = pd.Timestamp(&#39;2021-1-1 01:55:30&#39;) # Display the Timestamp print(&quot;Timestamp... &quot;,timestamp) # Create the BusinessHour Offset # BusinessHour is the DateOffset subclass # Here, &quot;start&quot; is the start time of your custom business hour in 24h format. # The &quot;end&quot; is the end time of your custom business hour in 24h format. bhOffset = pd.tseries.offsets.BusinessHour(start=&quot;09:30&quot;, end = &quot;18:00&quot;) # Display the BusinessHour Offset print(&quot; BusinessHour Offset... &quot;,bhOffset) # Display the Updated Timestamp print(&quot; Updated Timestamp... &quot;,timestamp + bhOffset) # Return frequency applied on the given BusinessHour Offset object as a string print(&quot; Frequency applied on the given BusinessHour Offset object... &quot;,bhOffset.freqstr) # Display the keyword arguments print(&quot; Keyword arguments on the given BusinessHour Offset... &quot;,bhOffset.kwds)</pre><h2>Output</h2><p>This will produce the following code &minus;</p><pre class="result notranslate">Timestamp... 2021-01-01 01:55:30 BusinessHour Offset... &lt;BusinessHour: BH=09:30-18:00&gt; Updated Timestamp... 2021-01-01 10:30:00 Frequency applied on the given BusinessHour Offset object... BH Keyword arguments on the given BusinessHour Offset... {&#39;start&#39;: (datetime.time(9, 30),), &#39;end&#39;: (datetime.time(18, 0),), &#39;offset&#39;: datetime.timedelta(0)}</pre>
raja
Updated on 21-Oct-2021 08:32:08

Advertisements