[python] Create a date array with arbitrary increments with np.arange

Motivated

I want to create a date array with arbitrary increments

code

#Every 3 months
np.arange('2000-01', '2002-02',np.timedelta64(3,'M'), dtype='datetime64')
# ['2000-01' '2000-04' '2000-07' '2000-10' '2001-01' '2001-04' '2001-07' '2001-10' '2002-01']

#Every 2 years
np.arange('2010', '2018',np.timedelta64(2,'Y'), dtype='datetime64')
# ['2010' '2012' '2014' '2016']

#1 minute increments
np.arange('2000-01-01 10:00:00', '2000-01-01 10:05:00',np.timedelta64(1,'m'), dtype='datetime64')
#['2000-01-01T10:00:00' '2000-01-01T10:01:00' '2000-01-01T10:02:00' '2000-01-01T10:03:00' '2000-01-01T10:04:00']

#bonus# '2010'Even if you specify only, it actually has a fine value
np.datetime64('2010')==np.datetime64('2010-01-01 00:00:00')  # True
np.datetime64('2010')==np.datetime64('2010-01-01 00:00:01')  # False

It seems easier to use if you get used to numpy's datetime

reference

https://numpy.org/devdocs/reference/arrays.datetime.html

Recommended Posts

[python] Create a date array with arbitrary increments with np.arange
Create a python numpy array
Create a directory with python
Create a virtual environment with Python!
Create a Python function decorator with Class
Build a blockchain with Python ① Create a class
Create a dummy image with Python + PIL.
[Python] Create a virtual environment with Anaconda
Let's create a free group with Python
How to create a heatmap with an arbitrary domain in Python
What I did with a Python array
Create a frame with transparent background with tkinter [Python]
Create a C array from a Python> Excel sheet
Create a LINE BOT with Minette for Python
Create a virtual environment with conda in Python
Create a page that loads infinitely with python
[Note] Create a one-line timezone class with python
You can easily create a GUI with Python
Create a python3 build environment with Sublime Text3
Create a color bar with Python + Qt (PySide)
Steps to create a Twitter bot with python
Create a decision tree from 0 with Python (1. Overview)
Create a new page in confluence with Python
Create a color-specified widget with Python + Qt (PySide)
Create a Photoshop format file (.psd) with python
Create a Python console application easily with Click
Create a Python module
Get date with python
Create a Python environment
[Python] Create structured array (store heterogeneous data with NumPy)
Simulate a good Christmas date with a Python optimized model
[Python] Create a ValueObject with a complete constructor using dataclasses
Why not create a stylish table easily with Python?
Create a random number with an arbitrary probability density
[Python] How to create a 2D histogram with Matplotlib
[Python] Create a Tkinter program distribution file with cx_Freeze
Create a fake Minecraft server in Python with Quarry
Create a company name extractor with python using JCLdic
Create a 2d CAD file ".dxf" with python [ezdxf]
Curry arbitrary functions with Python ....
Create a Wox plugin (Python)
Create a function in Python
Create 3d gif with python3
Create a homepage with django
Stumble story with Python array
Make a fortune with Python
Create a heatmap with pyqtgraph
[Python] Create a file & folder path specification screen with tkinter
Create a list in Python with all followers on twitter
How to convert an array to a dictionary with Python [Application]
Create a Mastodon bot with a function to automatically reply with Python
[Python] Create a linebot that draws any date on a photo
Create a child account for connect with Stripe in Python
Let's create a script that registers with Ideone.com in Python.
Probably the easiest way to create a pdf with Python3
[Python] Create a date and time list for a specified period
Create a Twitter BOT with the GoogleAppEngine SDK for Python
Create a simple video analysis tool with python wxpython + openCV
Create a simple Python development environment with VSCode & Docker Desktop
Create a python machine learning model relearning mechanism with mlflow
Create a pixel art of Levi Captain with Python programming!