How to print the days in a given month using Python?


Input

Assume, you have date series to find the number of days in a month.

Solution

To solve this, we will follow the steps given below −

  • Define date series

  • Set date_range value as 2020-02-10.

  • find the number of days in a month using Series.dt.daysinmonth

Example

Let us see the complete implementation to get a better understanding −

import pandas as pd
date = pd.date_range('2020-02-10',periods=1)
data = pd.Series(date)
print(data.dt.daysinmonth)

Output

0    29

Updated on: 24-Feb-2021

249 Views

Kickstart Your Career

Get certified by completing the course

Get Started
Advertisements