Skip to content

Instantly share code, notes, and snippets.

Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
# sample of checking package installed and load all.
required.pckg <-
c(
'dummies',
'tidyverse',
'glmnet'
)
not.installed <- !(required.pckg %in% installed.packages()[,'Package'])
if (any(not.installed)) {
@messefor
messefor / convert_datatype_in_df.R
Last active November 6, 2016 09:11
how to convert each column data type in data.frame
# set function with which convert data into named vector
col.type.f <- c(vane=as.factor,
prefecture=as.factor,
date=as.Date,
time=as.factor,
ts=as.POSIXct)
# convert data type
for (col in names(col.type.f)) {
f.conv <- col.type.f[col][[1]]
@messefor
messefor / excel_pandas.md
Last active December 4, 2016 11:45
Excel Bookからデータをpandasに読み込むメモ

pandas Excel Bookからデータ読み込み

anaconda が入っていれば、特に問題にならない

  • 事前に必要なモジュールをインストール

    $ pip install openpyxl xlrd xlwt
@messefor
messefor / 161204_matplotlib_jpfont.md
Last active December 4, 2016 15:21
matplotlib 日本語設定のときに使うコマンド

matplotlib 日本語フォント

日本語設定のときに使うコマンド

# 設定ファイルの場所確認
matplotlib.matplotlib_fname()
#> C:\Users\daisuke.oda\AppData\Local\Continuum\Anaconda3\lib\site-packages\matplotlib\mpl-data\matplotlibrc

# システムフォントファイル一覧
@messefor
messefor / ggplot2_multi_circle.R
Created January 11, 2017 13:58
ggplot2で同心円状に複数円を描いて、ポイントもプロットする
library(tidyverse)
library(ggrepel)
#-------------------------
# データ作成
#-------------------------
# 円のインデックスとrを指定(r^2が中心からのユークリッド距離)
dist.vec <- c(user1=1, user2=2, user3=3, user4=4)
idx.vec <- names(dist.vec)
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@messefor
messefor / subplot_with_pandas.ipynb
Created February 11, 2017 10:20
pandas.DataFrame.plotとsubplotを使って、複数グラフを柔軟にプロットする
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@messefor
messefor / hist_cum_twin.py
Created September 5, 2017 12:16
Histogram with cumulative ratio
"""Example to show how to plot histogram with accumulate ratio."""
import numpy as np
import matplotlib.pyplot as plt
import seaborn as sns
# % matplotlib inline
sns.set(style="darkgrid", palette="muted", color_codes=True)
# Toy data
np.random.seed(0)
@messefor
messefor / mpl_bar_exaple_with_ratio.py
Created September 9, 2017 02:11
Example of matplotlib barplot with accumulative ratio on 2nd axis.
"""Example of matplotlib barplot with accumulative ratio on 2nd axis."""
import matplotlib.pyplot as plt
import numpy as np
import pandas as pd
import seaborn as sns
# Plot with seaborn darkgrid style
% matplotlib inline
sns.set(style="darkgrid", palette="muted", color_codes=True)