Skip to content

Instantly share code, notes, and snippets.

View XianglongTan's full-sized avatar

Xianglong Tan XianglongTan

View GitHub Profile
@XianglongTan
XianglongTan / faster_toPandas.py
Created May 31, 2019 02:25 — forked from joshlk/faster_toPandas.py
PySpark faster toPandas using mapPartitions
import pandas as pd
def _map_to_pandas(rdds):
""" Needs to be here due to pickling issues """
return [pd.DataFrame(list(rdds))]
def toPandas(df, n_partitions=None):
"""
Returns the contents of `df` as a local `pandas.DataFrame` in a speedy fashion. The DataFrame is
repartitioned if `n_partitions` is passed.