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 math | |
| import numpy as np | |
| import pandas as pd | |
| import time | |
| from tqdm.notebook import tqdm | |
| ## Imports for plotting | |
| import matplotlib.pyplot as plt | |
| %matplotlib inline |
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
| julia> using RCall | |
| julia> using Statistics | |
| julia> @rlibrary ggplot2 | |
| julia> crim_med = median(df[:CRIM]) | |
| julia> df[!, Symbol("CRIM_RATE")] .= ifelse.( | |
| df.CRIM .> crim_med, "HIGH", "LOW") |
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
| julia> using PyCall | |
| julia> using DataFrames | |
| # Load sklearn's Boston housing price dataset | |
| julia> sk_datasets = pyimport("sklearn.datasets") | |
| julia> boston = sk_datasets.load_boston() | |
| julia> df = boston["data"] |> DataFrame | |
| julia> cols = boston["feature_names"] | |
| julia> names!(df, Symbol.(cols)) |
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
| julia> using PyCall | |
| julia> pushfirst!(PyVector( | |
| pyimport("sys")."path"), @__DIR__) | |
| julia> mm = pyimport("mymodule.mymodule") | |
| julia> mm.hello_world("Julia") | |
| "Hello Julia" |
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
| mkdir mymodule; touch mymodule/__init__.py | |
| echo 'def hello_world(name: str) -> str: | |
| return f"Hello {name}"' > mymodule/mymodule.py |
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
| julia> using PyCall | |
| julia> pushfirst!(PyVector( | |
| pyimport("sys")."path"),@__DIR__) | |
| julia> py""" | |
| def hello_from_module(name: str) -> str: | |
| import mymodule.mymodule as mm | |
| return mm.hello_world(name) | |
| """ |
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
| julia> x = 2.0 | |
| # pass x to python | |
| julia> py"$x**2" | |
| 4.0 | |
| # pass x to R | |
| julia> rcopy(R"$x^2") | |
| 4.0 |
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
| julia> typeof(r_says_hi) | |
| RObject{StrSxp} | |
| julia> r_says_hi = rcopy(r_says_hi) | |
| julia> typeof(r_says_hi) | |
| String |
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
| # Install and import Rcall | |
| julia> using Pkg | |
| julia> Pkg.add("RCall") | |
| julia> using RCall | |
| # One liners | |
| julia> R"print('Hello Julia')" | |
| [1] "Hello Julia" | |
| RObject{StrSxp} |
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
| # Install and import PyCall | |
| julia> using Pkg | |
| julia> Pkg.add("PyCall") | |
| julia> using Pycall | |
| # One liners | |
| julia> py"print('Hello Julia')" | |
| Hello Julia | |
| # Multi-line |
NewerOlder