Quantcast
Channel: Active questions tagged python - Stack Overflow
Viewing all articles
Browse latest Browse all 17303

pd.date_range with enddate included

$
0
0

Using pandas 2.2.2 and python 3.11, why doesn't this give me the daterange containing the end date:

import pandas as pdstart_date = pd.to_datetime('2023-04-05T04:01:40Z')end_date = pd.to_datetime('2024-04-15T00:00:00Z')full_date_range = pd.date_range(start=start_date, end=end_date, freq='1M', inclusive='both')for date in full_date_range.to_list():    print(date)

It gives me:

2023-04-30 04:01:40+00:002023-05-31 04:01:40+00:002023-06-30 04:01:40+00:002023-07-31 04:01:40+00:002023-08-31 04:01:40+00:002023-09-30 04:01:40+00:002023-10-31 04:01:40+00:002023-11-30 04:01:40+00:002023-12-31 04:01:40+00:002024-01-31 04:01:40+00:002024-02-29 04:01:40+00:002024-03-31 04:01:40+00:00

and it stops at the end of march. I thought inclusive would give me an added entry of

2024-04-30 04:01:40+00:00

as this would include my enddate as well (at least this is how I understand the inclusive argument)


Viewing all articles
Browse latest Browse all 17303

Latest Images

Trending Articles



Latest Images

<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>