Message Boards Message Boards

0
|
2090 Views
|
4 Replies
|
4 Total Likes
View groups...
Share
Share this post:

How can I display a dataset that has only 1 row horizontally?

I have noticed that if one has a Dataset with multiple rows, the dataset is displayes with the keys horizontally at the top and the rows are displayed one under the other vertically. However, if the dataset only has 1 row, the keys are displayed vertically to the left, in column fashion with the values to the right of the keys. Is there any way to have a single row Dataset to be shown horizontally?

POSTED BY: Henrick Jeanty
4 Replies

Thank you Rohit. I will go back and reread that part of the documentation.

POSTED BY: Henrick Jeanty

This behavior is documented, see "Dataset Structure" under "Details and Options". A single Association is treated as a table with named rows.

POSTED BY: Rohit Namjoshi

Eric, you are right. I went back to my code and found that depending on whether your dataset is created from a list of associations (as in your example) or from an association you get different representations. I've attached a notebook to illustrate the point that Dataset[<| "a"->1, "b"->2 ....|>] built from a single association displays vertically, while Dataset[{<| "a"->1, "b"->2 ....|>}] built from a list made of of a single association displays horizontally

I also learned that those two datasets are not === as it is shown at the bottom of the notebook. And since they don't conform in their dimensions you can't even compare them with == (see notebook again)

So, the solution to my problem is to find those places where I create my Dataset from a single Association and make sure I put the Association inside a List.

What I have also found is that a Dataset made of multiple Associations put inside a List display all associations in vertical rows. But if you try to put all the association pairs inside a single set of <| |>, then you will lose some of the pairs since the last Key->Value pair replaces any previous ones with the same Key. So, you end up with a Dataset with a single set of keys, which makes sense.

Well, I learned a lot from this little exercise. Eric, I will mark your response as an answer since it made me realize that you can display since row Datasets horizontally depending on how the Dataset was constructed,

Another insidious thing is that in both cases of construction of a single row dataset, one as a List of 1 Association and the other built directly from an association, you usually refer to fields by their keys and the results are the same! This can lead to some interesting head scratching later when you try to compare rows from two differently constructed Datasets. Questions like "Why can't I compare these two rows?" Well, I could continue on this subject, but living in Dade City, Florida, I have a major hurricane named "Ian" to keep an "eye" out for and am waiting for the inevitable loss of power and internet. Please keep my little family and pretty much all of Florida's people in your prayers.

Thanks, Henrick

POSTED BY: Henrick Jeanty
Posted 1 year ago

This isn't generally true. Dataset[{<|"a" -> 1, "b" -> "x", "c" -> {1}|>}] displays in the horizontal orientation, and it's a dataset with one row.

Please provide code that displays the behavior you want to discuss and then ask a specific question about what you want to achieve.

POSTED BY: Eric Rimbey
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract