Skip to main content

Get some usable vector representations of datetime

Project description

timevec

python versions package version codecov

Functions to create time vectors

Description

Time has a periodic nature due to the rotation of the earth and the position of the sun. This affects human behavior in various ways.

  • Seasonality ... periodicity in a year (seasonal distinction)
  • Daily periodicity ... periodicity in a day (distinction between day and night)
  • Day of the week ... periodicity in a week (distinction between weekdays and holidays)

When dealing with these, it is desirable to vectorize with periodicity in mind. That is, at 23:59 on a given day, it is desirable that the value is close to 00:00 on the next day. To achieve this, the time is represented as a combination of cos and sin. This is called a time vector.

Installation

pip install timevec

Usage

import timevec.numpy as tv
import datetime
dt = datetime.datetime(2020, 1, 1, 0, 0, 0)
vec = tv.year_vec(dt)
# array([1., 0.])

Modules

  • timevec.numpy provides functions that return numpy.ndarray.
  • timevec.numpy_datetime64 provides functions that return numpy.datetime64.
  • timevec.builtin_math provides functions that return tuple of float.

Functions

Almost same functions are provided in timevec.numpy, timevec.numpy_datetime64, and timevec.builtin_math. The difference is the return type.

year_vec

year_vec(dt: datetime.datetime)

Create a time vector for a year. This is a vector that has periodicity like seasonality. (Summer, Autumn, Winter, Spring) year_vec

month_vec

month_vec(dt: datetime.datetime)

Create a time vector for a month. This is a vector that has periodicity in a month. You can express periodicity such as the beginning of the month, the end of the month, and the salary day. month_vec

week_vec

week_vec(dt: datetime.datetime)

Create a time vector for a week. This is a vector that has periodicity in a week. You can express periodicity such as weekdays and holidays. week_vec

day_vec

day_vec(dt: datetime.datetime)

Create a time vector for a day. This is a vector that has periodicity in a day. You can express periodicity such as morning, noon, and night. day_vec

Others

  • long_time_vec ... 1 to 5001 years period
  • millennium_vec ... one millennium (1000 years) period
  • century_vec ... one century (100 years) period
  • decade_vec ... one decade (10 years) period

License

BSD 3-Clause License

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

timevec-0.3.0.tar.gz (64.5 kB view details)

Uploaded Source

Built Distribution

timevec-0.3.0-py3-none-any.whl (8.7 kB view details)

Uploaded Python 3

File details

Details for the file timevec-0.3.0.tar.gz.

File metadata

  • Download URL: timevec-0.3.0.tar.gz
  • Upload date:
  • Size: 64.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for timevec-0.3.0.tar.gz
Algorithm Hash digest
SHA256 87879791598b105cd5bfd1e8bb1f3d05d2d87e16280221e9f7ba39af26b01a17
MD5 ae539b56db61559c697b515b43292dc5
BLAKE2b-256 6de0d518b6383cef72587f3f45281fa406c72899de4a50d6e601df3e7f5d04fe

See more details on using hashes here.

File details

Details for the file timevec-0.3.0-py3-none-any.whl.

File metadata

  • Download URL: timevec-0.3.0-py3-none-any.whl
  • Upload date:
  • Size: 8.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.12.7

File hashes

Hashes for timevec-0.3.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e07693c45c361771e2a42006a48beece03eb2e8e03d65c4580c6ba3d52c645db
MD5 124c4a6e0389e3684074647bc8766d6f
BLAKE2b-256 e764c384d6e4a51eac36da31f0ea23a2097d577c522b9df0f6e399ba7d94449b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page