0

The default behaviour for df.take() on Watson Studio Jupyter notebooks does not display the header for the table whereas df.show() does:

enter image description here

I would like to use df.take() because the output is much easier on the eye :) - Is it possible to get df.take() to display the header?


NOTE:

  • I don't want to use show().
  • I want to use take() and I want take() to display the header.
Chris Snow
  • 23,813
  • 35
  • 144
  • 309
  • take will return you the Array[Row] but show is the api to give you the tabular view of the dataframe. What exactly your expected output. if you want to get limited records then you can use limit api with show – Chandan Ray Aug 30 '18 at 18:19
  • In scala, `take` expects a number and outputs a number of rows. So, no, you can't use `take`. Why not just use Pandas `take` and call it a day? You will get the header. – Dr G. Aug 31 '18 at 05:17
  • @A.J.Alger thanks! The problem is that this is scala. – Chris Snow Aug 31 '18 at 05:28

2 Answers2

1

Limit can be used:

df.limit(5).show()
pasha701
  • 6,831
  • 1
  • 15
  • 22
1

No, it is not possible to let take show the headers. Header information is in the dataframe, but take returns a plain list or array, not a dataframe.

As suggested in another answer, limit would return a dataframe with header information, on which you could call show.

But since you insist on using take and on not using show, the answer is No. take is not meant to do what you want to accomplish.

Roland Weber
  • 1,865
  • 2
  • 17
  • 27