The summary box for Dataset
objects shows the number of levels and elements at the bottom.
How can we get these values programmatically?
For example, "4 levels, 350 elements" in the Planets dataset:
Answer
If we are not afraid of using undocumented functions, we can get the counts the same way that the summary box gets them:
info @ Dataset[data_, type_, _] :=
{TypeSystem`TypeDepth[type], TypeSystem`AtomCount[type, data]}
info @ ExampleData[{"Dataset", "Planets"}]
(* {4, 350} *)
Or, as per @Szabolcs' suggestion:
info2 @ ds_Dataset :=
{TypeSystem`TypeDepth[#], TypeSystem`AtomCount[##]}& @@
Through[{Dataset`GetType, Dataset`GetData} @ ds]
info2 @ ExampleData[{"Dataset", "Planets"}]
(* {4, 350} *)
Comments
Post a Comment