Building your own image
Now, we will customize our own container images for running a simple data processing job and an API service.
Batch processing job
Here is a simple Python code for a batch processing job:
run.py
import pandas as pd url = 'https://raw.githubusercontent.com/jbrownlee/Datasets/master/pima-indians-diabetes.data.csv' df = pd.read_csv(url, header=None) df["newcolumn"] = df[5].apply(lambda x: x*2) print(df.columns) print(df.head()) print(df.shape)
This Python code loads a CSV dataset from a URL into a pandas DataFrame, adding a new column by multiplying an existing column by 2 and then printing out some information about the DataFrame (column names, first five rows, and size of the DataFrame). Type this code using your favorite code editor and save the file with the name run.py
.
Normally, we test our code locally (whenever possible) to be sure it is working. To do that, first, you need to install the pandas
library:
pip3 install...