2 回答

TA貢獻1831條經(jīng)驗 獲得超4個贊
你可以通過使用將 spark df 轉(zhuǎn)換為 pandastoPandas()
unique_df = df.select('ID').distinct()
unique_pandas_df = unique_df.toPandas()

TA貢獻1812條經(jīng)驗 獲得超5個贊
以下是您正在尋找的內(nèi)容,df.select("ID").distinct().rdd.flatMap(lambda x: x).collect()為您提供了一個獨特的列表ID,您可以使用它來創(chuàng)建filterspark 數(shù)據(jù)框,toPandas()并可用于將 spark 數(shù)據(jù)框轉(zhuǎn)換為 pandas 數(shù)據(jù)框。
for i in df.select("ID").distinct().rdd.flatMap(lambda x: x).collect():
tmp_df = df.filter(df.ID == i)
user_pd_df = tmp_df.toPandas()
更新:由于問題已被編輯
toPandas()導(dǎo)致將 DataFrame 中的所有記錄收集到驅(qū)動程序,并且應(yīng)該在數(shù)據(jù)的一小部分上完成。如果您嘗試將巨大的 DataFrame 轉(zhuǎn)換為 pandas,則需要花費大量時間。
添加回答
舉報