w3resource

Pandas: Create a whole month of dates in daily frequencies


Write a Pandas program to create a whole month of dates in daily frequencies. Also find the maximum, minimum timestamp and indexs.

Sample Solution:

Python Code :

import pandas as pd
dates = pd.Series(pd.date_range('2020-12-01',periods=31, freq='D'))
print("Month of December 2020:")
print(dates)
dates = pd.Series(pd.date_range('2020-12-01',periods=31, freq='D'))
print("\nMaximum date: ", dates.max())
print("Minimum date: ", dates.min())
print("Maximum index: ", dates.idxmax())
print("Minimum index: ", dates.idxmin())

Sample Output:

Month of December 2020:
0    2020-12-01
1    2020-12-02
2    2020-12-03
3    2020-12-04
4    2020-12-05
5    2020-12-06
6    2020-12-07
7    2020-12-08
8    2020-12-09
9    2020-12-10
10   2020-12-11
11   2020-12-12
12   2020-12-13
13   2020-12-14
14   2020-12-15
15   2020-12-16
16   2020-12-17
17   2020-12-18
18   2020-12-19
19   2020-12-20
20   2020-12-21
21   2020-12-22
22   2020-12-23
23   2020-12-24
24   2020-12-25
25   2020-12-26
26   2020-12-27
27   2020-12-28
28   2020-12-29
29   2020-12-30
30   2020-12-31
dtype: datetime64[ns]

Maximum date:  2020-12-31 00:00:00
Minimum date:  2020-12-01 00:00:00
Maximum index:  30
Minimum index:  0

Python Code Editor:

Have another way to solve this solution? Contribute your code (and comments) through Disqus.

Previous: Write a Pandas program to create a date range using a startpoint date and a number of periods.
Next: Write a Pandas program to create a time series using three months frequency.

What is the difficulty level of this exercise?

Test your Programming skills with w3resource's quiz.



Follow us on Facebook and Twitter for latest update.