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
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
40
Other Decks in Technology
See All in Technology
自律的なチームを作るためにTechPMがやらないこと
ny7760
0
160
(swiftc) NonCopyableとライフタイム修飾子
teamhimeh
0
160
OneLakeをデータソースにした AI Search(Foundry IQ)の ライフサイクル管理
ryuseiiida
0
200
AIエージェントに 権限と鍵をどこまで渡すか
nrinetcom
PRO
2
160
Content Mapper APIの応用例~CSS Modules、言語ファイル~
uhyo
2
320
構造で守らせる データ・法務・セキュリティ・開発チームとつくる AI時代のデータガバナンスとデータ基盤のリアル
legalontechnologies
PRO
2
690
AI時代のエンジニアの情報発信〜個人の発信を組織の力に変える〜
ryo_kawamata
0
2.1k
Patterns in AI Driven Software Development
akosma
PRO
0
370
AIで選択肢が広がった組織設計の理想と現実
konifar
17
7.1k
アクセラレーターで実現するServiceNow活用の高速化 / ServiceNow World Forum 2026
visional_engineering_and_design
0
100
データマネジメント × 法務で作りあげる、 freeeの新しいデータガバナンスへの軌跡
freee
PRO
2
570
増え続けるプロダクトの品質をどう担保するか。ProductSpecとTypeScriptによる取り組み
joere
2
230
Featured
See All Featured
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
410
Paper Plane (Part 1)
katiecoart
PRO
2
12k
Bridging the Design Gap: How Collaborative Modelling removes blockers to flow between stakeholders and teams @FastFlow conf
baasie
0
750
The agentic SEO stack - context over prompts
schlessera
0
990
Principles of Awesome APIs and How to Build Them.
keavy
128
18k
職位にかかわらず全員がリーダーシップを発揮するチーム作り / Building a team where everyone can demonstrate leadership regardless of position
madoxten
70
68k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
Navigating the moral maze — ethical principles for Al-driven product design
skipperchong
2
660
Odyssey Design
rkendrick25
PRO
2
900
Breaking role norms: Why Content Design is so much more than writing copy - Taylor Woolridge
uxyall
1
470
The Power of CSS Pseudo Elements
geoffreycrofte
82
6.6k
[Rails World 2026] Durable orchestration on Rails: from continuation to workflow
palkan
2
970
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