np.random.seed(1)
keys = ['foo'] * 10 + ['bar'] * 10
values = np.hstack([np.random.normal(0, 1, 10), np.random.normal(10, 1, 100)])
df = sqlContext.createDataFrame([{'k': k, 'v': round(float(v), 3)} for k, v in
    zip(keys, values)])
How to use window functions in PySpark?