Micah P. Dombrowski / Jun 10 2018

Python Template

This article can act as a starting point for any basic Python article. It has cells to accomplish some basic setup and programming tasks, as well as a few more complex ones. Just Remix and go!

For explanations of what's going on, see this article on Bash setup and this one on Python setup and coding.

1.
System Setup

apt-get update >> /dev/null
apt-get install -y fortune cowsay make g++
/usr/games/fortune | /usr/games/cowsay












































































































































































































































































pwd
ls -al
mkdir -p ~/.keras
echo '{
    "epsilon": 1e-07, 
    "image_data_format": "channels_last", 
    "backend": "cntk", 
    "floatx": "float32" 
}' > ~/.keras/keras.json




























# curl -O https://nextjournal.com/images/logo.svg
wget https://nextjournal.com/images/logo.svg

cp ~/.keras/keras.json /results/
cp logo.svg /results/











keras.json

2.
Installing Python Packages

conda install -y seaborn sympy
pip install xgboost






























































































Remember to Review & Save the Setup environment before continuing!

3.
Data intake

cubic.csv
import pandas as pd

data = pd.read_csv(cubic.csv)
with open(keras.jsonfile download &  manipulation, "r") as f:
  str = f.read()

str
print(str)







4.
Calculations

from sympy import primerange

[i for i in primerange(1,1000)]
split_data = [float(x[0])*(-1)**(i+1) for (i,x) in enumerate(data.values)]

# Return data for use by Javascript cell
split_data

4.1.
Plotting

import matplotlib.pyplot as plt

plt.figure()
plt.plot(data)
plt.title("Cubic Function")
plt.ylabel("f(x)")
plt.xlabel("x")
plt.savefig("/results/blah.png")
import plotly.plotly as plt
from plotly.graph_objs import Scatter,Layout,Figure

Figure(
  data = [
    Scatter(y=data.values[:,0])
  ],
  layout = Layout(
    title = "Cubic Function",
    yaxis = dict(title="f(x)"),
    xaxis = dict(title="x")
  )
)
var data = nilmodify file data

plottypes = ['lines','markers']

var traces = plottypes.map(function(ptype) {
  return { type: 'scatter', mode: ptype,
    name: ptype,
    x: [...Array(401).keys()],
    y: data
  }
})

var layout = { title: 'Split Cubic Function',
  xaxis: { title: 'Year' },
  yaxis: { title: 'Temperature [C]' }
}

Nextjournal.plot(traces, layout)