R Code

So we will start with some easy R Code

library(psych)
## Warning: package 'psych' was built under R version 3.5.1
library(reticulate)
## Warning: package 'reticulate' was built under R version 3.5.1
mytitanic=as.data.frame(Titanic)
describe(mytitanic)
##           vars  n  mean     sd median trimmed   mad min max range skew
## Class*       1 32  2.50   1.14    2.5    2.50  1.48   1   4     3 0.00
## Sex*         2 32  1.50   0.51    1.5    1.50  0.74   1   2     1 0.00
## Age*         3 32  1.50   0.51    1.5    1.50  0.74   1   2     1 0.00
## Survived*    4 32  1.50   0.51    1.5    1.50  0.74   1   2     1 0.00
## Freq         5 32 68.78 136.00   13.5   36.62 20.02   0 670   670 3.07
##           kurtosis    se
## Class*       -1.46  0.20
## Sex*         -2.06  0.09
## Age*         -2.06  0.09
## Survived*    -2.06  0.09
## Freq          9.93 24.04

Python code

Now for some basic Python

for x in range(1,5):
    for y in range(5):
        try: 
            x/y
        except:  
            print ("Div by Zero")
        else: 
            print ("Yay, it worked.")
## Div by Zero
## Yay, it worked.
## Yay, it worked.
## Yay, it worked.
## Yay, it worked.
## Div by Zero
## Yay, it worked.
## Yay, it worked.
## Yay, it worked.
## Yay, it worked.
## Div by Zero
## Yay, it worked.
## Yay, it worked.
## Yay, it worked.
## Yay, it worked.
## Div by Zero
## Yay, it worked.
## Yay, it worked.
## Yay, it worked.
## Yay, it worked.

Passing .csvs to Swap Info

Not the best way..

import pandas as pd
import io
import requests
mydf=pd.read_csv("C:/Users/lfult/Desktop/Python Intro Course/MDSO.csv")
print(mydf)
##           Date       Open       High    ...         Close  Adj Close    Volume
## 0   2017-10-23  77.040001  78.500000    ...     72.260002  72.260002   3900700
## 1   2017-10-30  72.550003  75.639999    ...     71.779999  71.779999   3421800
## 2   2017-11-06  71.690002  72.000000    ...     65.690002  65.690002   5218600
## 3   2017-11-13  66.260002  70.639999    ...     68.639999  68.639999   2823000
## 4   2017-11-20  68.959999  71.029999    ...     70.150002  70.150002    969600
## 5   2017-11-27  70.050003  70.089996    ...     67.349998  67.349998   3768100
## 6   2017-12-04  68.150002  68.720001    ...     66.230003  66.230003   1897600
## 7   2017-12-11  66.169998  67.320000    ...     66.639999  66.639999   3302400
## 8   2017-12-18  67.199997  67.629997    ...     65.940002  65.940002   1505000
## 9   2017-12-25  65.669998  66.169998    ...     63.369999  63.369999   1125800
## 10  2018-01-01  63.070000  66.379997    ...     64.870003  64.870003   1612300
## 11  2018-01-08  64.870003  67.019997    ...     66.900002  66.900002   2274300
## 12  2018-01-15  67.230003  68.080002    ...     66.860001  66.860001   1948700
## 13  2018-01-22  66.470001  71.820000    ...     71.739998  71.739998   3195800
## 14  2018-01-29  71.260002  71.720001    ...     68.230003  68.230003   2088200
## 15  2018-02-05  67.370003  68.199997    ...     64.970001  64.970001   6800600
## 16  2018-02-12  66.650002  69.050003    ...     67.980003  67.980003   3820000
## 17  2018-02-19  67.470001  68.930000    ...     67.330002  67.330002   1860000
## 18  2018-02-26  67.660004  68.419998    ...     66.500000  66.500000   2072200
## 19  2018-03-05  66.290001  70.290001    ...     70.059998  70.059998   2165400
## 20  2018-03-12  69.989998  70.839996    ...     66.870003  66.870003   2539100
## 21  2018-03-19  66.300003  67.379997    ...     63.759998  63.759998   2642900
## 22  2018-03-26  64.800003  65.830002    ...     62.810001  62.810001   1990600
## 23  2018-04-02  62.570000  65.129997    ...     63.740002  63.740002   2340200
## 24  2018-04-09  64.339996  67.400002    ...     66.440002  66.440002   3838500
## 25  2018-04-16  67.040001  74.760002    ...     73.139999  73.139999   5849400
## 26  2018-04-23  73.050003  73.800003    ...     71.199997  71.199997   2700600
## 27  2018-04-30  70.919998  75.919998    ...     75.110001  75.110001   3709100
## 28  2018-05-07  75.629997  79.720001    ...     77.680000  77.680000   3755000
## 29  2018-05-14  77.519997  78.580002    ...     77.540001  77.540001   3051000
## 30  2018-05-21  75.519997  78.010002    ...     75.330002  75.330002   2513900
## 31  2018-05-28  74.970001  79.800003    ...     79.099998  79.099998   2246400
## 32  2018-06-04  79.139999  81.459999    ...     80.389999  80.389999   2399900
## 33  2018-06-11  80.360001  82.160004    ...     82.129997  82.129997   2517900
## 34  2018-06-18  82.379997  85.690002    ...     82.389999  82.389999   2960300
## 35  2018-06-25  81.959999  82.129997    ...     80.559998  80.559998   3466900
## 36  2018-07-02  79.389999  84.879997    ...     84.400002  84.400002   2462800
## 37  2018-07-09  84.660004  85.860001    ...     84.750000  84.750000   2278100
## 38  2018-07-16  84.589996  88.379997    ...     87.000000  87.000000   2902800
## 39  2018-07-23  86.760002  88.870003    ...     74.529999  74.529999  10948700
## 40  2018-07-30  74.610001  76.550003    ...     76.120003  76.120003   3323900
## 41  2018-08-06  75.849998  78.669998    ...     77.629997  77.629997   2068100
## 42  2018-08-13  77.830002  80.669998    ...     78.209999  78.209999   2151200
## 43  2018-08-20  78.519997  81.870003    ...     81.669998  81.669998   1800900
## 44  2018-08-27  82.379997  85.139999    ...     84.980003  84.980003   2175500
## 45  2018-09-03  84.540001  84.949997    ...     83.370003  83.370003   1488400
## 46  2018-09-10  83.989998  84.559998    ...     80.529999  80.529999   2216200
## 47  2018-09-17  80.309998  80.919998    ...     74.070000  74.070000   3715400
## 48  2018-09-24  73.910004  74.519997    ...     73.309998  73.309998   3144200
## 49  2018-10-01  73.519997  73.730003    ...     71.019997  71.019997   3348700
## 50  2018-10-08  71.000000  71.540001    ...     66.510002  66.510002   3906800
## 51  2018-10-15  66.360001  75.000000    ...     70.059998  70.059998   6243500
## 52  2018-10-22  69.809998  71.889999    ...     71.699997  71.699997   3468600
## 53  2018-10-25  68.019997  71.870003    ...     71.699997  71.699997    871256
## 
## [54 rows x 7 columns]
mydf2=pd.DataFrame.to_csv(mydf, "test.csv")
idx = pd.date_range('2017-10-30', '2018-10-25', freq='W')
myseries=pd.Series(mydf['Adj Close'])
myseries=myseries[2:53]
myseries.index=idx

Why not Use the Tools?

Here, we use reticulate.

mypandas=import("pandas")
mydf2=read.csv("test.csv")
mydf3=read.csv("test.csv")
describe(mydf2)# R describe
##           vars  n       mean         sd    median    trimmed        mad
## X            1 54      26.50      15.73 2.650e+01      26.50      20.02
## Date*        2 54      27.50      15.73 2.750e+01      27.50      20.02
## Open         3 54      72.68       6.66 7.113e+01      72.28       7.03
## High         4 54      74.93       6.71 7.377e+01      74.58       8.09
## Low          5 54      69.93       6.56 6.772e+01      69.57       6.36
## Close        6 54      72.65       6.69 7.170e+01      72.28       7.70
## Adj.Close    7 54      72.65       6.69 7.170e+01      72.28       7.70
## Volume       8 54 3014941.78 1630812.52 2.591e+06 2767863.64 1041378.24
##                 min         max       range skew kurtosis        se
## X              0.00       53.00       53.00 0.00    -1.27      2.14
## Date*          1.00       54.00       53.00 0.00    -1.27      2.14
## Open          62.57       86.76       24.19 0.45    -1.05      0.91
## High          65.13       88.87       23.74 0.40    -1.11      0.91
## Low           59.60       83.59       23.99 0.44    -1.12      0.89
## Close         62.81       87.00       24.19 0.44    -1.03      0.91
## Adj.Close     62.81       87.00       24.19 0.44    -1.03      0.91
## Volume    871256.00 10948700.00 10077444.00 2.46     8.64 221925.47
mypandas$DataFrame$describe(mydf3) #Python describe
##              X     Open      High       Low     Close Adj.Close   Volume
## count 54.00000 54.00000 54.000000 54.000000 54.000000 54.000000       54
## mean  26.50000 72.67815 74.928333 69.931296 72.652593 72.652593  3014942
## std   15.73213  6.65523  6.711973  6.563521  6.692131  6.692131  1630813
## min    0.00000 62.57000 65.129997 59.599998 62.810001 62.810001   871256
## 25%   13.25000 67.08000 68.960001 64.727499 66.862501 66.862501  2103950
## 50%   26.50000 71.13000 73.765003 67.715000 71.699997 71.699997  2591000
## 75%   39.75000 77.75250 80.452499 75.057503 77.667499 77.667499  3468175
## max   53.00000 86.76000 88.870003 83.589996 87.000000 87.000000 10948700