Python | Pandas Series.dt.nanosecond



Series.dt can be used to access series values ​​as datetimelike and return multiple properties. Series.dt.nanosecond Pandas Series.dt.nanosecond returns an empty array containing the nanosecond date and time in base data of this series object.

Syntax: Series.dt.nanosecond

Parameter: None

Returns: numpy array

Example # 1: Use the Series.dt.nanosecond attribute to return the nanosecond of the datetime in the underlying data of the given Series object.

# import pandas as pd

import pandas as pd

 
# Create series

sr = pd.Series (pd.date_range (< / code> `2012-12-12 12: 12` , periods = 5 , freq = `5N` ))

  
# Create index

idx = [ `Day 1` , ` Day 2` , `Day 3` , `Day 4` , ` Day 5` ]

 
# set index

sr.index = idx

 
# Print series

print (sr)

Output:

We will now use the Series.dt.nanosecond attribute to return the datetime nanosecond in the underlying data of this Series object.

# return nanosecond

result = sr.dt .nanosecond

 
# print result

print (result)

< strong> Output:

As we can see from the output, the Series. dt.nanosecond successfully accessed and returned the datetime nanosecond in the underlying data for this series object.

Example # 2: Use the Series.dt attribute. nanosecond to return the datetime nanosecond in the underlying data of this Series object.

# import pandas as pd

import pandas as pd

 
# Create series

sr = pd.Series (pd.date_range ( `2008-2-9 08: 20: 21`

  periods = 5 , freq = `9N` ))

 
# Create index

idx = [ ` Day 1` , `Day 2` , `Day 3` , ` Day 4` , ` Day 5` ]

 
# set index

sr.index = idx

  
# Print series

print (sr)

Output:

Now we will use the Series.dt.nanosecond attribute to return the datetime nanosecond in the underlying data of this Series object.

# return nanosecond

result = sr.dt.nanosecond

 
# print the result

print (result)

Output:

As we can see from the output, the Series.dt.nanosecond attribute was successfully accessed and returned the datetime nanosecond in the underlying data of the given series object.