Python in Rstudio

Michael Taylor

2018/06/15

library(reticulate)
use_python("C:/Users/micha/Anaconda3/python.exe")
library(nycflights13)
write.csv(flights,file = "flights.csv")
import os
os.environ['QT_QPA_PLATFORM_PLUGIN_PATH']="C:/Users/micha/Anaconda3/Library/plugins/platforms"
import pandas as pd
flights = pd.read_csv("flights.csv")
print(flights.head())
##    Unnamed: 0  year         ...           minute            time_hour
## 0           1  2013         ...               15  2013-01-01 05:00:00
## 1           2  2013         ...               29  2013-01-01 05:00:00
## 2           3  2013         ...               40  2013-01-01 05:00:00
## 3           4  2013         ...               45  2013-01-01 05:00:00
## 4           5  2013         ...                0  2013-01-01 06:00:00
## 
## [5 rows x 20 columns]
flights = flights[flights["dest"]=="ORD"]
flights = flights[['carrier', 'dep_delay', 'arr_delay']]
flights = flights.dropna()
print(flights.head())
##    carrier  dep_delay  arr_delay
## 5       UA       -4.0       12.0
## 9       AA       -2.0        8.0
## 25      MQ        8.0       32.0
## 38      AA       -1.0       14.0
## 57      AA       -4.0        4.0
import matplotlib.pyplot as plt
import numpy as np
t = np.arange(0.0, 2.0, 0.01)
s = 1 + np.sin(2 * np.pi * t)
plt.plot(t, s)
plt.xlabel('time (s)')
plt.ylabel('voltage (mV)')
plt.show()