如何显示 PySpark 数据框中每个记录的大小?

huangapple go评论52阅读模式
英文:

How to display the size of each record of a PySpark Dataframe?

问题

我们将一个parquet文件读入一个pyspark dataframe,并将其加载到Synapse中。但显然,我们的dataframe包含的记录超过了Synapse(polybase)的1MB限制。我们的databricks数据导入脚本一直抛出以下错误:

在序数'n'处的模式/行的大小超过了最大允许的行大小1000000字节。

我正在尝试找出我的dataframe中哪一行存在此问题,但我无法识别有问题的行。

我能够打印出dataframe的每列长度,但如何打印出每个记录的大小呢?

有办法可以做到这一点吗?有人能帮忙吗?

英文:

We read a parquet file into a pyspark dataframe and load it into Synapse. But apparently, our dataframe is having records that exceed the 1MB limit on Synapse (polybase). Our databricks ingestion scripts keep throwing the below error:

The size of the schema/row at ordinal 'n' exceeds the maximum allowed row size of 1000000 bytes.

I'm trying to find out which row in my dataframe has this issue but I'm unable to identify the faulty row.

I was able to print the length of each column of a dataframe but how do I print the size of each record?

Is there a way to do this? Can someone please help?

答案1

得分: 0

使用以下代码来获取每一行的大小。

import sys
rows = df.collect()
for rw in rows:
    print(str((sys.getsizeof(''.join(rw[0:])))) + " bytes")

这将为您提供以字节为单位的大小。

在获取这些数据后,检查哪个记录的大小更大。

英文:

Use below code to get size of each row.

import sys
rows = df.collect()
for rw in rows:
    print(str((sys.getsizeof(''.join(rw[0:]))))+" bytes")

This gives you size in bytes.

如何显示 PySpark 数据框中每个记录的大小?

After getting this, check which record has more size.

huangapple
  • 本文由 发表于 2023年6月8日 12:14:51
  • 转载请务必保留本文链接:https://go.coder-hub.com/76428577.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定