Wednesday, July 3, 2024
HomeLanguagesPythonDisplay all the dates for a particular month using NumPy

Display all the dates for a particular month using NumPy

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’] 
 

Calisto Chipfumbu
Calisto Chipfumbuhttp://cchipfumbu@gmail.com
I have 5 years' worth of experience in the IT industry, primarily focused on Linux and Database administration. In those years, apart from learning significant technical knowledge, I also became comfortable working in a professional team and adapting to my environment, as I switched through 3 roles in that time.
RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments