I'm using pandas style in a jupyter notebook to emphasize the borders between subgroups in this dataframe:
(technically speaking: to draw borders at every changed multiindex but disregarding the lowest level)
# some sample df with multiindex
res = np.repeat(["response1","response2","response3","response4"], 4)
mod = ["model1", "model2","model3","model4"]*len(res)
data = np.random.randint(0,50,size=len(mod))
df = pd.DataFrame(zip(res,mod,data), columns=["res","mod","data"])
df.set_index(["res","mod"], inplace=True)
# set borders at individual frequency
indices_with_borders = range(0,len(df), len(np.unique(mod)))
df.style.set_properties(subset=(df.index[indices_with_borders], df.columns), **{
'border-width': '1px', "border-top-style":"solid"})
Result:
Now it looks a bit silly, that the borders are only drawn across the columns but not continue all the way through the multiindex. This would be a more pleasing style:
Does anybody know how / if it can be achieved? Thanks in advance!