Skip to content

Instantly share code, notes, and snippets.

View albert-liangd's full-sized avatar
🎯
Focusing

Derek liang albert-liangd

🎯
Focusing
View GitHub Profile
@albert-liangd
albert-liangd / faster_toPandas.py
Created June 11, 2019 03:38 — 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.