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

PythonPandasServer Side ProgrammingProgramming

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
raja
Published on 10-Feb-2021 13:23:34

Advertisements