w3resource

Pandas Series property: dt.components

Series-dt.components property

The dt.components property is used to return a Dataframe of the components of the Timedeltas.

Syntax:

Series.dt.components
Pandas Series: dt.components property

Example:

Python-Pandas Code:

import numpy as np
import pandas as pd
s = pd.Series(pd.to_timedelta(np.arange(6), unit='s'))
s

Output:

0   00:00:00
1   00:00:01
2   00:00:02
3   00:00:03
4   00:00:04
5   00:00:05
dtype: timedelta64[ns]

Python-Pandas Code:

import numpy as np
import pandas as pd
s = pd.Series(pd.to_timedelta(np.arange(6), unit='s'))
s.dt.components

Output:

  days	hours	minutes	seconds	milliseconds	microseconds	nanoseconds
0	0   	0	    0 	       0	       0	       0	            0
1	0	    0	    0	       1	       0	       0	            0
2	0	    0	    0	       2	       0	       0	            0
3	0	    0	    0	       3	       0	       0	            0
4	0	    0	    0	       4	       0	       0	            0
5	0	    0	    0	       5	       0	       0	            0

Previous: Series.dt.day_name() function
Next: Series-dt.to_pytimedelta() function



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/pandas/series/series-dt-components.php