<p>我可以对大型数据集进行分组,并使用熊猫数据框制作多个CSV、excel文件。但是如何使用Pyspark数据框将<strong>700K</strong>记录分组到大约<strong>230</strong>组中,并在全国范围内生成<strong>230</strong>CSV文件</p>
<p><strong>使用熊猫</strong></p>
<pre><code>grouped = df.groupby("country_code")
# run this to generate separate Excel files
for country_code, group in grouped:
group.to_excel(excel_writer=f"{country_code}.xlsx", sheet_name=country_code, index=False)
</code></pre>
<p><strong>使用Pyspark数据帧</strong>,当我尝试喜欢它时-</p>
<pre><code>for country_code, df_country in df.groupBy('country_code'):
print(country_code,df_country.show(1))
</code></pre>
<p>它回来了</p>
<blockquote>
<p>TypeError: 'GroupedData' object is not iterable</p>
</blockquote>