Regex for slicing categorical axes #430
alexander-held
started this conversation in
Ideas
Replies: 1 comment
-
This small example allows filtering for categories matching a regex: import hist
import re
def cat_regex_slice(h, expression):
return [hist.tag.loc(name) for name in h.axes["categories"] if re.search(expression, name)]
h = hist.Hist.new.StrCat(["aa", "ab", "bb"], name="categories").Double()
print(h.axes)
print(h[cat_regex_slice(h, r"^a")].axes) output: (StrCategory(['aa', 'ab', 'bb'], name='categories', label='categories'),)
(StrCategory(['aa', 'ab'], name='categories', label='categories'),) The axis name needs to be specified in this implementation, but presumably it is possible somehow to infer which axis should be used in an automatic way? |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
StrCategory
axes are very useful for grouping many datasets together in multi-dimensional histograms. The available indexing features in UHI seem mostly targeted at numerical axes. It is possible to slice categorical axes in the same way via integers after determining which index a given category corresponds to. Are there any methods inhist
at the moment to extract them directly by matching strings? I imagine that something like a regex-based category matching could be useful.Beta Was this translation helpful? Give feedback.
All reactions