aboutsummaryrefslogtreecommitdiff
path: root/python/pyspark/sql/dataframe.py
diff options
context:
space:
mode:
authorzsxwing <zsxwing@gmail.com>2015-06-29 23:44:11 -0700
committerReynold Xin <rxin@databricks.com>2015-06-29 23:44:11 -0700
commit12671dd5e468beedc2681ff2bdf95fba81f8f29c (patch)
tree17fbc6f7141b79134002b8d3bb13900d773fb6a8 /python/pyspark/sql/dataframe.py
parent6c5a6db4d53d6db8aa3464ea6713cf0d3a3bdfb5 (diff)
downloadspark-12671dd5e468beedc2681ff2bdf95fba81f8f29c.tar.gz
spark-12671dd5e468beedc2681ff2bdf95fba81f8f29c.tar.bz2
spark-12671dd5e468beedc2681ff2bdf95fba81f8f29c.zip
[SPARK-8434][SQL]Add a "pretty" parameter to the "show" method to display long strings
Sometimes the user may want to show the complete content of cells. Now `sql("set -v").show()` displays: ![screen shot 2015-06-18 at 4 34 51 pm](https://cloud.githubusercontent.com/assets/1000778/8227339/14d3c5ea-15d9-11e5-99b9-f00b7e93beef.png) The user needs to use something like `sql("set -v").collect().foreach(r => r.toSeq.mkString("\t"))` to show the complete content. This PR adds a `pretty` parameter to show. If `pretty` is false, `show` won't truncate strings or align cells right. ![screen shot 2015-06-18 at 4 21 44 pm](https://cloud.githubusercontent.com/assets/1000778/8227407/b6f8dcac-15d9-11e5-8219-8079280d76fc.png) Author: zsxwing <zsxwing@gmail.com> Closes #6877 from zsxwing/show and squashes the following commits: 22e28e9 [zsxwing] pretty -> truncate e582628 [zsxwing] Add pretty parameter to the show method in R a3cd55b [zsxwing] Fix calling showString in R 923cee4 [zsxwing] Add a "pretty" parameter to show to display long strings
Diffstat (limited to 'python/pyspark/sql/dataframe.py')
-rw-r--r--python/pyspark/sql/dataframe.py7
1 files changed, 5 insertions, 2 deletions
diff --git a/python/pyspark/sql/dataframe.py b/python/pyspark/sql/dataframe.py
index 152b87351d..4b9efa0a21 100644
--- a/python/pyspark/sql/dataframe.py
+++ b/python/pyspark/sql/dataframe.py
@@ -247,9 +247,12 @@ class DataFrame(object):
return self._jdf.isLocal()
@since(1.3)
- def show(self, n=20):
+ def show(self, n=20, truncate=True):
"""Prints the first ``n`` rows to the console.
+ :param n: Number of rows to show.
+ :param truncate: Whether truncate long strings and align cells right.
+
>>> df
DataFrame[age: int, name: string]
>>> df.show()
@@ -260,7 +263,7 @@ class DataFrame(object):
| 5| Bob|
+---+-----+
"""
- print(self._jdf.showString(n))
+ print(self._jdf.showString(n, truncate))
def __repr__(self):
return "DataFrame[%s]" % (", ".join("%s: %s" % c for c in self.dtypes))