Jan-18-2021, 12:49 PM
Hi guys,
I have a dataset and the following code:
The column c includes a couple of characteristics of which I only want to select the rows with "Total".
Therefore, I have used:
Alternatively, the code works using the following:
I would be happy if someone could please help me.
Many thanks!
I have a dataset and the following code:
a = dataset.set_index('c', append=True).sort_index()This generates a table with 3 indices (a, b and c) and one column containing values.
The column c includes a couple of characteristics of which I only want to select the rows with "Total".
Therefore, I have used:
dataset.loc[('Total'), :]However, this generates a KeyError: 'Total'
Alternatively, the code works using the following:
dataset.set_index('c', append=True).sort_index().loc[(slice(None), slice(None), 'Total'), :]To me it is not clear why it works with the second alternative but not with the first one.
I would be happy if someone could please help me.
Many thanks!