Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
Use R from Python
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
airspace_nobo
July 27, 2019
Technology
370
1
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Use R from Python
airspace_nobo
July 27, 2019
More Decks by airspace_nobo
See All by airspace_nobo
Try using dbtplyr
airspace_nobo
0
39
Other Decks in Technology
See All in Technology
FOSS4Gを活用した自治体業務DXの試み
470715
0
130
Essential architectural thinking (revised edition)
ufried
0
110
脆弱性診断って、何をしているの? 〜弱点を見つけて、会社の改善につなげるまで〜
keeg
0
690
あなたの知らないAmazon VPC Route Server/Amazon VPC Route Server you don't know about
masakiokuda
2
240
「事実」を「計測」して、「解釈」する 〜AWS Lambdaのメモリ最適解の見つけ方〜
maimyyym
0
120
2026-10-01_MagicPod_QAハーネスエンジニアリングとQA組織の未来像
ynisqa1988
1
560
転んだ話が背中を預ける理由になる / A_story_about_falling_down_gives_you_a_reason_to_watch_each_other_s_backs.pdf
pauli
3
330
プロダクト価値を、 チームが使える判断軸に変える
vivion
0
140
今さら理解するウェブフォントver.2026
takanorip
3
420
並行性の問題を防げ!実践トランザクション入門
occhi
0
280
自主式軟體工廠
philipz
0
240
[AWS 秋のクラウドオペレーション祭り 2026]AWS DevOps Agentで変わるリリースと運用対応 ~リリース管理機能と Directed actions のご紹介~
furuton
4
1.1k
Featured
See All Featured
Agile Actions for Facilitating Distributed Teams - ADO2019
mkilby
0
300
New Earth Scene 8
popppiees
4
2.7k
Evolution of real-time – Irina Nazarova, EuRuKo, 2024
irinanazarova
9
1.6k
ReactJS: Keep Simple. Everything can be a component!
pedronauck
666
130k
Documentation Writing (for coders)
carmenintech
77
5.6k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
162
16k
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
620
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
2
470
Six Lessons from altMBA
skipperchong
29
4.5k
"I'm Feeling Lucky" - Building Great Search Experiences for Today's Users (#IAC19)
danielanewman
230
23k
A brief & incomplete history of UX Design for the World Wide Web: 1989–2019
jct
2
530
Leading Effective Engineering Teams in the AI Era
addyosmani
9
2.7k
Transcript
6TF3GSPN1ZUIPO 5PLZP3 !BJSTQBDF@OPCP
ࣗݾհ w ໊લখ௶ୖਓ,PUTVCP5BLVUP w 5XJUUFS!BJSTQBDF@OPCP w ݱࡏम࢜ ༛༧िؒ w
ະདྷσʔλαΠΤϯςΟετ w ݚڀγϦϯυϦΧϧλΠϜγϦʔζ w ༻3 1ZUIPO ࡱӨऀ!LVSDLZ@Z
ࢲͱ3ͱ1ZUIPO w 3σʔλϋϯυϦϯά HHQMPU ౷ܭղੳؔ࿈ ٸ͍ͰΔ࣌ w 1ZUIPOػցֶश LFSBT εΫϥον͢Δ࣌
͓ۚՔ͙࣌ ͓ޓ͍ͷྑ͍ͱ͜ΖΛ͏·͘Ҿ͖ग़͍ͨ͠
QZQFSࣄ࢝Ί w QJQͰΠϯετʔϧ w SQZQFS3 Λ࣮ߦ͠ SΠϯελϯεʹ SίʔυΛ จࣈྻͱͯ͠༩͑Δ w
݁ՌΛදࣔ͢Δ࣌ʹ QSJOUΛ͏ r = pyper.R() r("a <- 5") print(r("a")) # ݁Ռ # try({a}) # [1] 5 r("b <- 10") print(r("a + b")) # ݁Ռ # try({a + b}) # [1] 15 pip install pyper
w Sͱಉ༷ʹ ಡΈࠐΜͰ͍ͳ͍ QBDLBHFͷؔ͑ͳ͍ w ؔΛಡΈࠐΊ ύΠϓԋࢉࢠ ͑Δʂ r =
pyper.R() print(r("glimpse(iris)")) # not find function "glimpse" r = pyper.R() r("library(tidyverse)") print(r("glimpse(iris)")) # try({glimpse(iris)}) print(r("iris %>% glimpse")) # try({iris %>% glimpse}) QZQFSؔಡΈࠐΈ
QZQFS QZUIPOS w SQZQFS3 VTF@QBOEBTb5SVF` Ͱ QBOEBT%BUB'SBNF͕͑Δ w SBTTJHOؔͰ
EG QZUIPO Λ Q@EG S ʹׂΓͯΔ n = 300 x = np.random.poisson(10, n) y = np.random.normal(0, 5, n) # dataFrame df = pd.DataFrame({"X":x, "Y":y}) r = pyper.R(use_pandas='True') r.assign("p_df", df) print(r("summary(p_df)"))
QZQFS SQZUIPO w SHFUؔ SͷσʔλΛQZUIPOଆͰ ༻Ͱ͖ΔΑ͏ʹ͢Δ w σʔλͷܕҎԼʹͳΔ ϕΫτϧOVNQZBSSBZ
σʔλϑϨʔϜQBOEBT%BUB'SBNF r = pyper.R() r("rx <- rexp(300,1)") r("rdf <- data.frame(x = 1:200, y = rnorm(200))") px = r.get(“rx") pdf = r.get("rdf") plt.hist(px, bins=20) plt.ylabel("freq") plt.show()
QZQFS SQZUIPO w σʔλϑϨʔϜܕΛQZUIPOʹ࣋ͬͯ͘Δͱ ΧϥϜ໊ʹεϖʔε͕ೖΔͷ Ͱ औΓআ͘ඞཁ͋Δʂʂ print(pdf.columns) pdf.columns
= pdf.columns.str.replace(' ', '') print(pdf.columns) Index(['x', 'y'], dtype='object')
Ϣʔβࣗ࡞ؔ w σʔλͷߦྻΛදࣔ͢Δؔ TIBQF@EBUB Λఆٛͨ͠εΫϦϓτϑΝ ΠϧΛ SͰಡΈࠐΉΑ͏ʹQZUIPOΛ௨ͯ͡ಡΈࠐΊΔ shape_data <- function(data){
sprintf("σʔλ%dߦ, %dྻͰ͢!!",NROW(data), NCOL(data)) } r = pyper.R(use_pandas='True') r("source('~/Desktop/TokyoR/script/function.R', echo=FALSE)") print(r("shape_data(iris)"))
Ϣʔβࣗ࡞ؔ w ͪΖΜQZUIPOଆ͔Β༩͑ͨσʔλʹରͯࣗ͠࡞ؔΛద༻Մೳ σʔλ͕গ͠ҟͳΔͷͰ ྻʹͳΔ w ΠϯελϯεΛॳظԽ͠ͳ͚Ε ؔอ࣋͞ΕΔʂ from
sklearn.datasets import load_iris iris = load_iris() iris = pd.DataFrame(data=iris.data, columns=iris.feature_names) r.assign("p_iris", iris) print(r("shape_data(p_iris)"))
ศརͳ͍ํΛߟ͑Δ w SͰ͜Μͳؔ࡞ͬͯʜ w QZUIPOͰ͜Μͳؔ࡞Εʜ library(tidyverse); library(skimr) view_data <- function(data){
print("use skim function"); skim(data) %>% kable print("use glimpse function"); glimpse(data) } def view_data(data): r = pyper.R(use_pandas='True') r("source('~/Desktop/TokyoR/script/function.R', echo=FALSE)") r.assign("p_data", data) print(r(“view_data(p_data)”)) view_data(iris)
ศརͳ͍ํΛߟ͑Δ w ͜Μͳ݁Ռ͕ಘΒΕΔ
ศརͳ͍ํΛߟ͑Δ w ͬͺΓSͰHHQMPUΛॻ͖͍ͨ࣌ ͦͦTUBU@DPOUPVS͍͍ͨ࣌ UIFNF@NJOBNBM ͡Όͳ͍ͱݏͩʂͱ͍͏࣌ w QZUIPOͰΞϧΰϦζϜΛεΫϥονͯ͠ ࣮ߦ݁ՌΛHHQMPUͰඒ͘͠ඳ͖ ͍ͨ࣌
େ͖ͳ w దͳσʔλϑϨʔϜΛ࡞ ͢ΔؔΛ࡞Δ w 3ͰͷEBUBGSBNF࡞࣌ؒ 1ZUIPOͷσʔλҠߦ࣌ؒ w LBHHMFͱ͔Ͱ
લॲཧ3Ͱॻ ͍ͯ σʔλͦͷ··ࣸͯ͠ ػցֶशʹҠߦ͢ΔΈ͍ͨͳ ͜ͱ͕Ͱ͖ͳ͍ fun <- function(len){ df1 <- tibble(aaa = 1:len, bbb = 10000:10000+len, ccc = 1000000:1000000+len, ddd = rbinom(len,1,0.5), eee = rnorm(len, 0, 100000), fff = rlnorm(len, 0, 100), ggg = stri_rand_strings(n=len, length=10), hhh = seq(as.Date("2018-03-07"), by="day", length.out=len)) return(df1) } MFO 3 1ZUIPO TFD TFD TFD TFD TFD ແཧ
·ͱΊ w ԿΒ͔ͷཧ༝͕͋ͬͯ QZUIPOSΘͳ͍ͱ͍͚ͳ͍࣌ SͰ࡞ͨ͠ ؔΛ͑Δͷ࣌ؒతʹ อकతʹศར w ࣗͰ͏ʹͳͦ͞͏͕ͩ
ਓʹ࡞ͨ͠ίʔυΛ͢ͳͲͷ࣌ ҙ͕ඞཁ w ձࣾͰ1ZUIPO͔͑͠ͳ͍ਓ͕ͨͪ ͬͦ͜Γ͑Δ w SFUJDVMBUFQBDLBHFͷํ͕ศར ݸਓͷײ
3PS1ZUIPO 8IZOPU#PUI &OKPZ