Pyspark:以表格格式显示Spark数据框 [英] Pyspark: display a spark data frame in a table format
本文介绍了Pyspark:以表格格式显示Spark数据框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用pyspark读取如下所示的实木复合地板文件:
I am using pyspark to read a parquet file like below:
my_df = sqlContext.read.parquet('hdfs://myPath/myDB.db/myTable/**')
然后,当我执行my_df.take(5)
时,它将显示[Row(...)]
,而不是像我们使用熊猫数据框时那样的表格式.
Then when I do my_df.take(5)
, it will show [Row(...)]
, instead of a table format like when we use the pandas data frame.
是否可以以表格格式(如熊猫数据框)显示数据框?谢谢!
Is it possible to display the data frame in a table format like pandas data frame? Thanks!
推荐答案
The show method does what you're looking for.
例如,给定以下3行数据框,我可以只打印前两行:
For example, given the following dataframe of 3 rows, I can print just the first two rows like this:
df = sqlContext.createDataFrame([("foo", 1), ("bar", 2), ("baz", 3)], ('k', 'v'))
df.show(n=2)
产生:
+---+---+
| k| v|
+---+---+
|foo| 1|
|bar| 2|
+---+---+
only showing top 2 rows
这篇关于Pyspark:以表格格式显示Spark数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文