0

I have a DataFrame like this:

import pandas as pd
import numpy as np

index_columns = [
  ['en'] * 3 + ['fr'] * 3 + ['it'] * 3,
  ['count', 'mean', 'std'] * 3
]

df = pd.DataFrame(np.random.randn(9, 2), index=index_columns)
df

DataFrame presentation

It would be more convenient visually to somehow separate the rows corresponding to different languages. For example, draw a grid line between the botton en row and the top fr row, and another between fr and it. Or, to set a different background color for each language.

What is a good way to achieve such separation?

Lev
  • 6,487
  • 6
  • 28
  • 29
  • You can use the DataFrame `style`, see the duplicate link for a suggestion on how to do it, you can adapt the answer with `for l0 in df.index.get_level_values(0).unique(): ...` – mozway Nov 30 '22 at 10:09

0 Answers0