How do I make a bar chart with Kandy for this Data...
# datascience
d
How do I make a bar chart with Kandy for this DataFrame:
Copy code
VERSION: String
NAMESPACE:
    dev: Int
    istio-system: Int
    loki: Int
    monitor: Int
    prod: Int
    redis: Int
More in the thread
The original table was:
Copy code
NAMESPACE: String
VERSION: String
and I did this on it:
Copy code
psVersions.pivot { NAMESPACE }.groupBy { VERSION }.count()
I tried:|
Copy code
versionStats.plot { 
    bars { 
        x(VERSION)
        y(NAMESPACE.values())
    }
}
but I got a very unclear error:
Copy code
The problem is found in one of the loaded libraries: check library renderers
java.lang.IllegalArgumentException: Can't serialize object { dev:32, istio-system:0, lokistats:0, monitor:0, prod:0, redis:0 }
org.jetbrains.kotlinx.jupyter.exceptions.ReplLibraryException: The problem is found in one of the loaded libraries: check library renderers
a
Hi! What do you expect the
y
values of bars to be?
d
the count
a
The count of what value?
d
Copy code
psVersions.pivot { NAMESPACE }.groupBy { VERSION }.count()
count()
I basically have a list of pods in all my namespaces, each pod has an istio version, I'd like to count how many pods of each version there is in each namespace
There's only two or three possible versions at a time
So X is the namespace, with a bar in each namespace for each version, and the count of pods in each of them is Y
a
Please, try (with original dataframe)
Copy code
psVersions.groupBy {NAMESPACE} plot {
  countPlot(VERSION)
}
Is that what you expect?
d
btw plot is red with
'infix' modifier is required on 'plot' in 'org. jetbrains. kotlinx. kandy. dsl'
Nope, that gives me (not using infix) the namespaces in each version, I want the versions in each namespace
]
a
Oh, got it, then
Copy code
psVersions.groupBy {VERSION} plot {
  countPlot(NAMESPACE)
}
should work for you.
👍🏼 1
Is it?😄
d
Wow so simple... I didn't really expect that Kandy could plot with all that extra data still there, I really thought I had to eliminate all the data except for Kandy's input.
I looked all over the docs, and couldn't find a hint on this one.
Now that I know it seems logical, since you actually need to specify the appropriate fields.
a
d
Yeah, that's for two dimensions... when I started with pivots I was already getting confused how to do it.
a
You can do the same with your pivoted dataframe, but more complicated - there is one problem described here (https://kotlin.github.io/kandy/series-hack-guide.html) why Kandy can’t work with columns in “pyplot style”.
So you need to gather (https://kotlin.github.io/dataframe/gather.html) NAMESPACE subcolumns into one column (“count”) with new key column (“namespace”) and write something like that:
Copy code
df.plot {
  bars {
     x(namespace)
     y(count)
     fillColor(version)
  }
}
But
countPlot
solution is a way better, of course.
d
Yeah, I guess gather is just trying to "depivot" it... It's still a bit obscure how
countPlot
uses
NAMESPACE
to count the pods in it...?
Oh... it's just the count of rows for each namespace 😅!
a
Yep 😁
d
Thanks for all the help!
👍 2