This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(tidyr) | |
iris %>% | |
as_data_frame(.) %>% | |
select(matches("Petal")) %>% | |
summarise_all(.funs = c("01:sum" = "sum", | |
"02:min" = "min", | |
"03:q25" = "quantile(., 0.25)", | |
"04:median" = "median", |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import glob | |
# アスタリスクが必要 | |
files = glob.glob('/home/dir1/*.zip') | |
for file in files: | |
print(file) | |
print('/home/dir2/' + os.path.basename(file)) | |
# /home/dir1/subset3.zip | |
# /home/dir2/subset3.zip |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from sklearn import datasets | |
iris = datasets.load_iris() | |
iris_df = pd.DataFrame(iris.data, columns=iris.feature_names) | |
iris_df['species'] = iris.target | |
mapping = {0 : 'setosa', 1: 'versicolor', 2: 'virginica'} | |
iris_df = iris_df.replace({'species': mapping}) | |
def freq(data, var): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
df1 = pd.DataFrame({'id': [1, 2, 3]}) | |
df2 = pd.DataFrame({'id': [2, 3, 4]}) | |
set(df1.id).intersection(set(df2.id)) | |
# Out[73]: {2, 3} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
from sklearn import datasets | |
iris = datasets.load_iris() | |
iris_df = pd.DataFrame(iris.data, columns=iris.feature_names) | |
iris_df['species'] = iris.target | |
mapping = {0 : 'setosa', 1: 'versicolor', 2: 'virginica'} | |
iris_df = iris_df.replace({'species': mapping}) | |
iris_df['sepal length (bins)'] = pd.cut(iris_df['sepal length (cm)'], bins=[0, 3, 6, 9], include_lowest=False, right=True) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(stringr) | |
add_backquotes <- function(x) paste0("`", x, "`") | |
add_doublequotes <- function(x) paste0("\"", x, "\"") | |
generate_c_code <- function(x){ | |
vec <- paste0(add_doublequotes(x), sep=",\n") | |
vec_tail <- str_replace(tail(vec, 1), ",\n", "\n") | |
vec_head <- head(vec, length(vec) - 1) | |
vec <- c(vec_head, vec_tail) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(broom) | |
library(lazyeval) | |
df <- data_frame( | |
group = rep(letters[1:2], each = 50), | |
cat1 = letters[round(runif(100) * 5) + 1], | |
cat2 = letters[round(runif(100) * 3) + 1] | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(dplyr) | |
library(purrr) | |
library(broom) | |
df <- data_frame( | |
group = rep(letters[1:2], each = 50), | |
cat1 = letters[round(runif(100) * 5) + 1], | |
cat2 = letters[round(runif(100) * 3) + 1] | |
) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# compress/decompress zip file. | |
zip file.csv.zip file.csv | |
unzip file.csv.zip | |
# compress/decompress gz file. | |
gzip file.csv | |
gzip -d file.csv.gz | |
# compress/decompress bz2 file. | |
bzip2 file.csv |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
library(gplots) | |
library(dplyr) | |
library(magrittr) | |
check_id_sets <- function(ids){ | |
ids_venn <- gplots::venn(ids, show.plot=FALSE) | |
ids_list <- unlist(as.list(ids_venn)) | |
mat_dim <- c((length(ids_list) / (length(ids)+1)), length(ids)+1) | |
id_sets <- ids_list %>% | |
matrix(., mat_dim) %>% |