1
$\begingroup$

I have a dataset on which I apply a GroupBy on the rows and columns. I expected the output to be a table with the first grouping on the vertical, and the second grouping on the horizontal. However, what I get is the first grouping on the vertical, and the second grouping also on the vertical, nested inside the first.

The following screenshot from the documentation shows what I expected.

This is what I expected

The following screenshot from my notebook is what I got. enter image description here

Could someone explain to me what I am doing wrong?

$\endgroup$
7
  • $\begingroup$ Please do not post images of your work, especially when the images display at a size that make them difficult to read. Please post your actual Mathematica code in the form of text that can be copied and pasted into a Mathematica notebook. Without such, people who wan to helo you will have do a lot of work to reproduce your problem so they can experiment with possible solutions. $\endgroup$
    – m_goldberg
    Sep 2, 2020 at 21:32
  • 1
    $\begingroup$ I get what you are saying, but I find it difficult to express the problem I have without providing a picture. After all, the problem has to do with how the output looks. $\endgroup$
    – Ruben
    Sep 3, 2020 at 13:47
  • 1
    $\begingroup$ I believe this is related to the underlying Association structure of the data. If you have a look at the Normal of the Dataset, it might help give some understanding. The second example shows a dataset with at least one extra "level" to it, and so Dataset acts a little differently. But it could also just be the data structure itself - for instance, Hilversum only has one sub-table (Aug 2019) where the rest have more. $\endgroup$
    – Carl Lange
    Sep 3, 2020 at 15:02
  • 1
    $\begingroup$ There's a line in the documentation for Dataset about this: "Data without a consistent structure will not usually format in the same way as structured data". I believe this is what you are seeing here. $\endgroup$
    – Carl Lange
    Sep 3, 2020 at 15:02
  • $\begingroup$ @CarlLange The consistency of the structure seems necessary but not sufficient. The keys should also be strings. At least in my case when the structure was corrected but the keys were still DateObjects, the formatting was still not as expected. $\endgroup$
    – Ruben
    Sep 3, 2020 at 15:40

1 Answer 1

2
$\begingroup$

I found a solution. Apparently there are two things here that Wolfram doesn't like.

  1. Every cell should have a value
  2. Column names should be strings

I had to fix both for the expected result to appear. Fixing one issue, but not the other, was not enough.

If anyone has an easier method to make this work I will gladly hear it.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.