NOTE: All instructions in capital letters indicate code that you should fill in with the appropriate information.
reticulate package (do not include this code).reticulate library.library(reticulate)
py_config() to find the python versions you have installed on your machine.python: /usr/bin/python
libpython: /System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/config/libpython2.7.dylib
pythonhome: /System/Library/Frameworks/Python.framework/Versions/2.7:/System/Library/Frameworks/Python.framework/Versions/2.7
version: 2.7.16 (default, Oct 17 2019, 17:14:30) [GCC 4.2.1 Compatible Apple LLVM 11.0.0 (clang-1100.0.32.4) (-macos10.15-objc-s
numpy: /System/Library/Frameworks/Python.framework/Versions/2.7/Extras/lib/python/numpy
numpy_version: 1.8.0
python versions found:
/usr/bin/python
/usr/bin/python3
/usr/local/bin/python3
/Users/buchanan/anaconda3/bin/python
python on the top line is the one you want to use, you are all done./Users/buchanan/...) and tell R to talk to that python instead.use_python("PATH", required = TRUE).use_python() after running py_config(). You will get an error message:ERROR: The requested version of Python
('/Users/buchanan/anaconda3/bin/python') cannot be used, as
another version of Python ('/usr/bin/python') has already
been initialized. Please restart the R session if you need
to attach reticulate to a different version of Python.
Error in use_python("/Users/buchanan/anaconda3/bin/python", required = TRUE) :
failed to initialize requested version of Python
use_python() code.py_config() and use_python() in the same markdown. Once you know where your path is, just use use_python().py_config()
## python: C:\Users\nanl\AppData\Local\CONTIN~1\ANACON~1\python.exe
## libpython: C:/Users/nanl/AppData/Local/CONTIN~1/ANACON~1/python27.dll
## pythonhome: C:\Users\nanl\AppData\Local\CONTIN~1\ANACON~1
## version: 2.7.16 |Anaconda, Inc.| (default, Mar 14 2019, 15:42:17) [MSC v.1500 64 bit (AMD64)]
## Architecture: 64bit
## numpy: C:\Users\nanl\AppData\Local\CONTIN~1\ANACON~1\lib\site-packages\numpy
## numpy_version: 1.16.5
##
## python versions found:
## C:\Users\nanl\AppData\Local\Continuum\anaconda2\envs\r-reticulate\python.exe
## C:\PROGRA~1\Python37\python.exe
## C:\Users\nanl\AppData\Local\CONTIN~1\ANACON~1\python.exe
## C:\PROGRA~1\Python37\\python.exe
## C:\Users\nanl\AppData\Local\Continuum\anaconda2\python.exe
data(rock) to load it.head() function to print out the first six rows of the dataset.data(rock)
head(rock,6)
## area peri shape perm
## 1 4990 2791.90 0.0903296 6.3
## 2 7002 3892.60 0.1486220 6.3
## 3 7558 3930.66 0.1833120 6.3
## 4 7352 3869.32 0.1170630 6.3
## 5 7943 3948.54 0.1224170 17.1
## 6 7979 4010.15 0.1670450 17.1
numpy, nltk, spacy, seaborn and pandas for starters.py_module_available("PACKAGE").py_module_available('numpy')
## [1] TRUE
py_module_available('nltk')
## [1] TRUE
py_module_available('spacy')
## [1] FALSE
py_module_available('seaborn')
## [1] TRUE
py_module_available('pandas')
## [1] TRUE
FALSE, then install them using py_install("PACKAGE").#if they are all TRUE, leave this blank
seaborn library, it has several sample datasets. You load python packages by using import PACKAGE.dots dataset by doing: VARNAME = PACKAGENAME.load_dataset("DATASETNAME")..head() function: VARNAME.head().import seaborn
var1 = seaborn.load_dataset("dots")
var1.head()
## align choice time coherence firing_rate
## 0 dots T1 -80 0.0 33.189967
## 1 dots T1 -80 3.2 31.691726
## 2 dots T1 -80 6.4 34.279840
## 3 dots T1 -80 12.8 32.631874
## 4 dots T1 -80 25.6 35.060487
QUESTION: Look in your environment window. What do you see?
py$VARNAME.DATAFRAME$COLUMN. Try to print out the time column from your dots variable (whatever you named it above).py$var1$time
## [1] -80 -80 -80 -80 -80 -80 -60 -60 -60 -60 -60 -60 -40 -40
## [15] -40 -40 -40 -40 -20 -20 -20 -20 -20 -20 0 0 0 0
## [29] 0 0 20 20 20 20 20 20 40 40 40 40 40 40
## [43] 60 60 60 60 60 60 80 80 80 80 80 80 100 100
## [57] 100 100 100 100 120 120 120 120 120 120 140 140 140 140
## [71] 140 140 160 160 160 160 160 160 180 180 180 180 180 180
## [85] 200 200 200 200 200 200 220 220 220 220 220 220 240 240
## [99] 240 240 240 240 260 260 260 260 260 260 280 280 280 280
## [113] 280 280 300 300 300 300 300 320 320 320 320 320 340 340
## [127] 340 340 340 360 360 360 360 360 380 380 380 380 380 400
## [141] 400 400 400 400 420 420 420 420 420 440 440 440 440 460
## [155] 460 460 460 480 480 480 480 500 500 500 500 520 520 520
## [169] 520 540 540 540 540 560 560 560 560 580 580 580 600 600
## [183] 600 620 620 620 640 640 660 660 680 680 700 720 -80 -80
## [197] -80 -80 -80 -80 -60 -60 -60 -60 -60 -60 -40 -40 -40 -40
## [211] -40 -40 -20 -20 -20 -20 -20 -20 0 0 0 0 0 0
## [225] 20 20 20 20 20 20 40 40 40 40 40 40 60 60
## [239] 60 60 60 60 80 80 80 80 80 80 100 100 100 100
## [253] 100 100 120 120 120 120 120 120 140 140 140 140 140 140
## [267] 160 160 160 160 160 160 180 180 180 180 180 180 200 200
## [281] 200 200 200 200 220 220 220 220 220 220 240 240 240 240
## [295] 240 240 260 260 260 260 260 260 280 280 280 280 280 280
## [309] 300 300 300 300 300 300 320 320 320 320 320 320 340 340
## [323] 340 340 340 360 360 360 360 360 380 380 380 380 380 400
## [337] 400 400 400 400 420 420 420 420 420 440 440 440 440 440
## [351] 460 460 460 460 480 480 480 480 500 500 500 500 520 520
## [365] 520 520 540 540 540 540 560 560 560 560 580 580 580 600
## [379] 600 600 620 620 620 640 640 640 660 660 680 680 700 700
## [393] 720 720 -600 -580 -560 -560 -540 -540 -520 -520 -500 -500 -500 -480
## [407] -480 -480 -460 -460 -460 -440 -440 -440 -440 -420 -420 -420 -420 -400
## [421] -400 -400 -400 -380 -380 -380 -380 -360 -360 -360 -360 -340 -340 -340
## [435] -340 -320 -320 -320 -320 -300 -300 -300 -300 -300 -280 -280 -280 -280
## [449] -280 -260 -260 -260 -260 -260 -240 -240 -240 -240 -240 -220 -220 -220
## [463] -220 -220 -200 -200 -200 -200 -200 -180 -180 -180 -180 -180 -160 -160
## [477] -160 -160 -160 -160 -140 -140 -140 -140 -140 -140 -120 -120 -120 -120
## [491] -120 -120 -100 -100 -100 -100 -100 -100 -80 -80 -80 -80 -80 -80
## [505] -60 -60 -60 -60 -60 -60 -40 -40 -40 -40 -40 -40 -20 -20
## [519] -20 -20 -20 -20 0 0 0 0 0 0 20 20 20 20
## [533] 20 20 40 40 40 40 40 40 60 60 60 60 60 60
## [547] 80 80 80 80 80 80 100 100 100 100 100 100 120 120
## [561] 120 120 120 120 140 140 140 140 140 140 160 160 160 160
## [575] 160 160 180 180 180 180 180 180 200 200 200 200 200 200
## [589] 220 220 220 220 220 220 240 240 240 240 240 240 260 260
## [603] 260 260 260 260 280 280 280 280 280 280 300 300 300 300
## [617] 300 300 -600 -600 -580 -580 -560 -560 -540 -540 -520 -520 -520 -500
## [631] -500 -500 -480 -480 -480 -460 -460 -460 -440 -440 -440 -440 -420 -420
## [645] -420 -420 -400 -400 -400 -400 -380 -380 -380 -380 -360 -360 -360 -360
## [659] -340 -340 -340 -340 -320 -320 -320 -320 -320 -300 -300 -300 -300 -300
## [673] -280 -280 -280 -280 -280 -260 -260 -260 -260 -260 -240 -240 -240 -240
## [687] -240 -220 -220 -220 -220 -220 -200 -200 -200 -200 -200 -200 -180 -180
## [701] -180 -180 -180 -180 -160 -160 -160 -160 -160 -160 -140 -140 -140 -140
## [715] -140 -140 -120 -120 -120 -120 -120 -120 -100 -100 -100 -100 -100 -100
## [729] -80 -80 -80 -80 -80 -80 -60 -60 -60 -60 -60 -60 -40 -40
## [743] -40 -40 -40 -40 -20 -20 -20 -20 -20 -20 0 0 0 0
## [757] 0 0 20 20 20 20 20 20 40 40 40 40 40 40
## [771] 60 60 60 60 60 60 80 80 80 80 80 80 100 100
## [785] 100 100 100 100 120 120 120 120 120 120 140 140 140 140
## [799] 140 140 160 160 160 160 160 160 180 180 180 180 180 180
## [813] 200 200 200 200 200 200 220 220 220 220 220 220 240 240
## [827] 240 240 240 240 260 260 260 260 260 260 280 280 280 280
## [841] 280 280 300 300 300 300 300 300
$, we use . like this: r.VARNAME.DATAFRAME["COLUMNNAME"]. Try printing out the shape column in the rock dataset.r.rock["shape"]
## 0 0.090330
## 1 0.148622
## 2 0.183312
## 3 0.117063
## 4 0.122417
## 5 0.167045
## 6 0.189651
## 7 0.164127
## 8 0.203654
## 9 0.162394
## 10 0.150944
## 11 0.148141
## 12 0.228595
## 13 0.231623
## 14 0.172567
## 15 0.153481
## 16 0.204314
## 17 0.262727
## 18 0.200071
## 19 0.144810
## 20 0.113852
## 21 0.291029
## 22 0.240077
## 23 0.161865
## 24 0.280887
## 25 0.179455
## 26 0.191802
## 27 0.133083
## 28 0.225214
## 29 0.341273
## 30 0.311646
## 31 0.276016
## 32 0.197653
## 33 0.326635
## 34 0.154192
## 35 0.276016
## 36 0.176969
## 37 0.438712
## 38 0.163586
## 39 0.253832
## 40 0.328641
## 41 0.230081
## 42 0.464125
## 43 0.420477
## 44 0.200744
## 45 0.262651
## 46 0.182453
## 47 0.200447
## Name: shape, dtype: float64