Skip to main content

Tspoon

Tspoon is a Python library for time-series pre-processing, period conversion, normalization, visualization and more.

Installation

Use the package manager pip to install tspoon.

pip install tspoon

Usage

Date functions

import tspoon as tsp

# returns first and last days of a month 'M' in a year 'Y'
tsp.firstdate(2024,2)
tsp.lastdate(2024,2)

# returns the days between 'startdate' and 'enddate'
tsp.datesbetween('2024-02-01','2024-06-30')

# transform 'YYYYMMDD' to 'YYYY-MM-DD'
tsp.daytrans('20240630')

# returns a date that is 'x' days before and after a given 'basedate'
tsp.dayahead('2024-06-30',25)
tsp.dayafter('2024-06-30',25)

# returns the ISO calendar week number(YYYYWW), month(YYYYMM), and year(YYYY) of a day
tsp.day2week('2024-06-30')
tsp.day2week('20240630')
tsp.day2month('20240630')
tsp.day2year('20240630')

# returns the quarter(YYYYqX) and month(YYYYMM)
tsp.month2quarter('202406')
tsp.quarter2month('2024q2')

# returns the first day(YYYY-MM-DD) of a week(YYYYWW) and month(YYYYMM)
tsp.week2day('202420')
tsp.month2day('202406')

# generates a data frame with converted periods
df_w = tsp.GenDf_d2w(dat, aggregate='mean')
df_m = tsp.GenDf_d2m(dat, aggregate='mean')
df_wd = tsp.GenDf_w2d(df_d=None, df_w=df_w)
df_md = tsp.GenDf_m2d(df_d=None, df_m=df_m)
df_wm = tsp.GenDf_w2m(df_w, aggregate='last')
df_mw = tsp.GenDf_m2w(df_w, df_m, interpolate='linear')
df_mq = tsp.GenDf_m2q(df_m, aggregate='last')
df_qm = tsp.GenDf_q2m(df_mq, interpolate='linear')
df_my = tsp.GenDf_m2y(df_m, aggregate='last')
df_ym = tsp.GenDf_y2m(df_my, interpolate='linear')

# returns backward and central moving average of a time series
tsp.bMA(dat, lag_day=14, todf=True)
tsp.cMA(dat, lag_day=14, lead_day=14, todf=True)

# returns yoy, mom, and un-yoy transformation
tsp.yoy(dat, period=12, smooth=(1,1))
tsp.mom(dat) 		                                    # equivalent to tsp.mom(dat, period=1), tsp.yoy(dat, period=1)
tsp.unyoy(dat, dat_level, period=52, smooth=None) 		# dat_level contains the level information of the beginning day

Dummy generation

# generates dummy data frame 
tsp.GenMonthDummy(['202003','202004','202005'], MW='month')
tsp.GenMonthDummy(['2020'+str(x) for x in range(10,26)], MW='week')
tsp.GenYearDummy(['2020'])

# generates structural break dummy data frame
tsp.GenStructBreakDummy(['202001','202002','202003','202004','202005','202006'], time='202003', MW='month')
tsp.GenStructBreakDummy(['202001','202002','202003','202004','202005','202006'], time='202003', time2='202005', MW='month')

Duplicates check

# returns unique and duplicate observations
tsp.uniq(['202001','202001','202002','202003'])
tsp.dupes(['202001','202001','202002','202003'])

Transformation functions

# returns unique and duplicate observations
tsp.x13as(df, period='M', X12PATH='./x13as/')       # requires x12 ariam from us consensus
tsp.hp(df, period='M')                              # period can be 'D', 'W', 'M', 'Q', 'Y'
tsp.hptrend(df, lamb=1)
tsp.hpcycle(df, lamb=1)
tsp.norm(df)                                        # (x-mean(x))/std(x) normalization
tsp.scale(df)                                       # (x-min(x))/(max(x)-min(x)) rescale
tsp.unnorm(df, df.mean(), df.std())

# returns arima extrapolated time series
tsp.extrapolate(df, maxlags=1)

# returns proportaion, contribution, 
tsp.proportion(df)
tsp.contribution(df, period=12)
tsp.contribution_proportion(df, period=12)

Visualization functions

# Make matplotlib use Hangul
tsp.Hangul(fonthpath='C:/Windows/Fonts/NanumBarunGothic.ttf')

# Make dynamic graph
tsp.Plotly(df, theme='white')

fig = df.plot(width=800, height=600)
plotly_theme(fig, fs=19, left_unit={'text':'(YoY, %)', 'fs':17})

Contact

Release files for tspoon 0.2.22

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Built distribution (wheel)

Table of built distributions (wheels) for tspoon 0.2.22
File Interpreter ABI Platform
tspoon-0.2.22-py3-none-any.whl Python 3 none any Details

Release files / tspoon-0.2.22-py3-none-any.whl

Download URL tspoon-0.2.22-py3-none-any.whl
Size 10.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9da5f7c845e0c78db8b4646b42a963a78b59e27375a6b16308e7acb7f2b330c1
BLAKE2b-256 checksum
How to use checksums
26edd23b363f6a0dccd3aa51417e6d19ae69e684069920421a2857d77f111124
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.7.11

Release history Release notifications | RSS feed

This release

0.2.22 This release

1 release file

0.2.21

1 release file

0.2.20

1 release file

0.2.19

1 release file

0.2.18

1 release file

0.2.17

1 release file

0.2.16

1 release file

0.2.15

1 release file

0.2.14

1 release file

0.2.13

1 release file

0.2.12

1 release file

0.2.11

1 release file

0.2.10

1 release file

0.2.9

1 release file

0.2.8

1 release file

0.2.7

1 release file

0.2.6

1 release file

0.2.5

1 release file

0.2.4

1 release file

0.2.3

1 release file

0.2.2

1 release file

0.2.1

1 release file

0.2.0

1 release file

0.1.9

1 release file

0.1.8

1 release file

0.1.7

1 release file

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page