hiii guys i'am new in python and pandas. i have some questions about this tutorial page from pandas
how to get a list of loc
A B C
first second
bar one 0.895717 0.410835 -1.413681
two 0.805244 0.813850 1.607920
baz one -1.206412 0.132003 1.024180
two 2.565646 -0.827317 0.569605
foo one 1.431256 -0.076467 0.875906
two 1.340309 -1.187678 -2.211372
qux one -1.170299 1.130127 0.974466
two -0.226169 -1.436737 -2.006747
In [43]: df.loc["bar"]
Out[43]:
A B C
second
one 0.895717 0.410835 -1.413681
two 0.805244 0.813850 1.607920
in that tutorial a "bar", was directly coded on that bracket
my question is how to get a list of loc like:
loc=[bar, baz, foo, qux]
some method if i call that method it print a list of loc
[bar, baz, foo, qux]
CodePudding user response:
try this
df.index.unique(level=0)
returns
Index(['bar', 'baz', 'foo', 'qux'], dtype='object', name='first')