I could find some answer which should have work but strangely it did not. Any help would be appreciated.
I have the following dataframe:
vendor currency value 2 CKE 3 PWW 2 LPS 1 5 PWO 4
On this df I try to take only the following desired output with the code:
vendor currency value 2 CKE 3 LPS 1
fiat = ['CKE','LPS','ZZZ'] df = df.loc[(2, fiat)]
KeyError: "None of [Index(['CKE','LPS','ZZZ'], dtype='object')] are in the [columns]"
You can add
: for select all columns, without it pandas incorrectly parse it like second value of tuple are not existing columns names, so error is raised:
fiat = ['CKE','LPS','ZZZ'] df = df.loc[(2, fiat), :] print (df) value vendor currency 2 CKE 3 LPS 1