This recipe shows how to perform complex operations such as computing difference on a column in Pandas DataFrames as well as Spark DataFrames.
To step through this recipe, you will need a running Spark cluster either in pseudo distributed mode or in one of the distributed modes, that is, standalone, YARN, or Mesos. Also, have Python and IPython installed on the Linux machine, that is, Ubuntu 14.04.
Invoke
ipython console -profile=pyspark
:In [1]: from pyspark import SparkConf, SparkContext, SQLContext In [2]: import pandas as pd In [3]: sqlcontext = SQLContext(sc)
Computing
diff
on a column in Pandas:In [4]: df = sqlCtx.createDataFrame([(1, 4), (1, 5), (2, 6), (2, 6), (3, 0)], ["A", "B"]) In [5]: pdf = df.toPandas() In [6]: pdf Out[6]: A B 0 1 4 1 1 5 2 2 6 3 2 6 4 3 0 ...