Giter Club home page Giter Club logo

japandas's Introduction

japandas

image

Latest Docs

image

image

Overview

pandas Japanese extension.

pandas の日本語拡張。以下の機能を提供する。

  • 日本語の日付のパース
  • 日本の祝日カレンダーと、それを利用した営業日計算
  • 文字列の全角/半角変換
  • e-Stat からのデータの取得
  • ローソク足チャート

補足 このパッケージでは、"日本固有の機能であり本流に実装される可能性が低いもの", もしくは"それらに関係し本流に実装される可能性が低いもの" を実装 / メンテナンスする。

インストール

pip install japandas

ドキュメント

機能概要

日本語の日付のパース

>>> import japandas as jpd
>>> jpd.to_datetime('2014年11月30日')
Timestamp('2014-11-30 00:00:00')

>>> jpd.to_datetime(['2014年11月30日13時25分', '2014年11月30日14時38分'])
<class 'pandas.tseries.index.DatetimeIndex'>
[2014-11-30 13:25:00, 2014-11-30 14:38:00]
Length: 2, Freq: None, Timezone: None

>>> jpd.date_range(start=u'2013年12月01日', end=u'2014年12月01日', freq='D')
<class 'pandas.tseries.index.DatetimeIndex'>
[2013-12-01, ..., 2014-12-01]
Length: 366, Freq: D, Timezone: None

日本の祝日カレンダーと、それを利用した営業日計算

>>> import pandas as pd
>>> import datetime

>>> calendar = jpd.JapaneseHolidayCalendar()
>>> cday = pd.offsets.CDay(calendar=calendar)

>>> datetime.datetime(2014, 4, 28) + cday
# 4/29は祝日(昭和の日)
Timestamp('2014-04-30 00:00:00')

>>> datetime.datetime(2014, 4, 28) - cday
# 4/26は土曜日, 4/27は日曜日
Timestamp('2014-04-25 00:00:00')

>>> datetime.datetime(2014, 5, 3) + cday
# 5/4は日曜日, 5/5は祝日(こどもの日), 5/6は祝日(みどりの日/振替休日)
Timestamp('2014-05-07 00:00:00')

>>> datetime.datetime(2014, 5, 3) - cday
# 5/3は土曜日
Timestamp('2014-05-02 00:00:00')

# 適当なデータを作成
>>> df = pd.DataFrame(np.random.randn(10, 3),
...                   index=jpd.date_range(u'2014年5月1日', u'2014年5月10日', freq='D'))
>>> df
                   0         1         2
2014-05-01  0.762453 -1.418762 -0.150073
2014-05-02  0.966500 -0.473888  0.272871
2014-05-03  0.473370 -1.282504  0.380449
2014-05-04  0.215411  0.220587 -1.088699
2014-05-05  0.286348 -1.069165 -1.471871
2014-05-06 -0.665438 -0.402046 -1.008051
2014-05-07  1.173935  2.080087 -2.279285
2014-05-08 -0.957195  0.746798  0.092214
2014-05-09 -0.259276 -0.775489  0.572525
2014-05-10 -0.910188  0.294136  0.020730

>>> cday = pd.offsets.CDay(calendar=calendar)
>>> indexer = jpd.date_range(u'2014年5月1日', u'2014年5月10日', freq=cday)

# カレンダー上 営業日のレコードを抽出
>>> df.ix[indexer]
                   0         1         2
2014-05-01  0.762453 -1.418762 -0.150073
2014-05-02  0.966500 -0.473888  0.272871
2014-05-07  1.173935  2.080087 -2.279285
2014-05-08 -0.957195  0.746798  0.092214
2014-05-09 -0.259276 -0.775489  0.572525

全角/半角変換

>>> s = pd.Series([u'アイウエオ', u'ABC01', u'DE345'])
>>> z = s.str.h2z()
>>> z
0    アイウエオ
1    ABC01
2    DE345
dtype: object

>>> z.str.z2h()
0    アイウエオ
1    ABC01
2    DE345
dtype: object

e-Stat からの統計情報取得

>>> key = "your application id"
>>> df = jpd.DataReader("0000030001", 'estat', appid=key)
>>> df.head()
             value 全国都道府県030001 全域集中の別030002 年齢5歳階級A030002 男女A030001
時間軸(年次)
1980    117060396           全国            全域            総数      男女総数
1980     89187409         全国市部            全域            総数      男女総数
1980     27872987         全国郡部            全域            総数      男女総数
1980      5575989          北海道            全域            総数      男女総数
1980      1523907          青森県            全域            総数      男女総数

ローソク足チャート

>>> df.plot(kind='ohlc')
チャート省略

License

BSD.

日本の祝日データソースとして以下を利用。

japandas's People

Contributors

lupinthe14th avatar sinhrks avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.