I use the following:
from pandas.tseries.offsets import BMonthEnd
from datetime import date
d=date.today()
offset = BMonthEnd()
#Last day of current month
offset.rollforward(d)
#Last day of previous month
offset.rollback(d)
More Related Contents:
- How can I select all of the Sundays for a year using Python?
- Convert python datetime to epoch with strftime
- How to parse dates with -0400 timezone string in Python?
- Creating a range of dates in Python
- How do I calculate the date six months from the current date using the datetime Python module?
- Convert pandas timezone-aware DateTimeIndex to naive timestamp, but in certain timezone
- How to compare two dates?
- Plotting dates on the x-axis with Python’s matplotlib
- datetime dtypes in pandas read_csv
- How do I get the UTC time of “midnight” for a given timezone?
- pandas dataframe groupby datetime month
- ISO time (ISO 8601) in Python
- pytz localize vs datetime replace
- Find the end of the month of a Pandas DataFrame Series
- Generate a list of datetimes between an interval
- How to get day name from datetime
- Convert date from excel in number format to date format python [duplicate]
- Pandas: Datetime Improperly selecting day as month from date [duplicate]
- Convert String with month name to datetime
- Generate RFC 3339 timestamp in Python [duplicate]
- Pandas converting row with unix timestamp (in milliseconds) to datetime
- How to calculate difference between two dates in weeks in python
- Converting string to datetime object
- Comparing a time delta in python
- datetime: Round/trim number of digits in microseconds
- Create trading holiday calendar with Pandas
- Clean way to convert quarterly periods to datetime in pandas
- Python: Matplotlib avoid plotting gaps
- pandas extract year from datetime: df[‘year’] = df[‘date’].year is not working
- Python Pandas : pandas.to_datetime() is switching day & month when day is less than 13