如何在 PySpark 中找到 DataFrame 的大小或形状? [英] How to find the size or shape of a DataFrame in PySpark?

查看:49
本文介绍了如何在 PySpark 中找到 DataFrame 的大小或形状?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图找出 PySpark 中 DataFrame 的大小/形状.我看不到一个函数可以做到这一点.

I am trying to find out the size/shape of a DataFrame in PySpark. I do not see a single function that can do this.

在 Python 中我可以做到

In Python I can do

data.shape()

PySpark 中有没有类似的功能.这是我目前的解决方案,但我正在寻找一个元素

Is there a similar function in PySpark. This is my current solution, but I am looking for an element one

row_number = data.count()
column_number = len(data.dtypes)

列数的计算不理想...

The computation of the number of columns is not ideal...

推荐答案

您可以通过以下方式获取shape:

You can get its shape with:

print((df.count(), len(df.columns)))

这篇关于如何在 PySpark 中找到 DataFrame 的大小或形状?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆