Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

creating an array from a pd.date_range()

I got error while trying to get this array (passed days by beginning each month of the year)

array([  1,  32,  60,  91, 121, 152, 182, 213, 244, 274, 305, 335])

How can I get the desired array from the code below or other code suggestions?

xticks = (pd.date_range('1/1/2015','31/12/2015', freq = 'M') - 1 + pd.Timedelta('1D')).strftime('%-j').astype(int)


TypeError: Addition/subtraction of integers and integer-arrays with DatetimeArray is no longer supported.  Instead of adding/subtracting `n`, use `n * obj.freq`

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

Create a date range by specifying the frequency as MS (Month-Start)

pd.date_range('1/1/2015', '31/12/2015', freq='MS').dayofyear.to_numpy()

array([  1,  32,  60,  91, 121, 152, 182, 213, 244, 274, 305, 335],
      dtype=int32)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading