In NumPy to display all the dates for a particular month, we can do it with the help of NumPy.arrange() pass the first parameter the particular month and the second parameter the next month and the third parameter is the datatype datetime64[D]. It will return all the dates for the particular month.
Syntax: numpy.arrange([start, ] stop, [step, ] dtype=None)
Parameters:
start : Start of interval
stop : End of interval
Step : Spacing between values
dtype : The type of the output array. If dtype is not given, infer the data type from the other input arguments.
Returns:
arrange : ndarray
Example 1#:
Python3
import numpy as np # dates of july 2020 print (np.arrange( '2012-07' , '2020-08' , dtype = 'datetime64[D]' )) |
Output:
[‘2012-07-01’ ‘2012-07-02’ ‘2012-07-03’ … ‘2020-07-29’ ‘2020-07-30’
‘2020-07-31’]
Example 2#:
Python3
import numpy as np # dates of september 2020 print (np.arrange( '2012-09' , '2020-10' , dtype = 'datetime64[D]' )) |
Output:
[‘2012-09-01’ ‘2012-09-02’ ‘2012-09-03’ … ‘2020-09-28’ ‘2020-09-29’
‘2020-09-30’]
Example 3#:
Python3
import numpy as np # dates of Feb 2020 print (np.arrange( '2012-02' , '2020-03' , dtype = 'datetime64[D]' )) |
Output:
[‘2012-02-01’ ‘2012-02-02’ ‘2012-02-03’ … ‘2020-02-27’ ‘2020-02-28’
‘2020-02-29’]