I am trying to learn and UNDERSTAND the logic behind pandas LOC and I can not come around with an explanation for the following issue. If I want to slice the dataframe with LOC I can do it in the following way
dates=pd.date_range('20130101',periods=6)
df=pd.DataFrame(np.random.rand(6,4),index=dates,columns=list('ABCD'))
print(df.loc['20130102':'20130104',['A','B']]) (*)
All fine. What I don't understand is that if in the second part of LOC I can entry a list of columns headers ['A','B'] why can't I do the same for the rows? i.e. the following would not work
print(df.loc[['20130102','20130104'],['A','B']])
What is the logic behind? I am giving LOC two row indexes, and two columns headers, but it would not work. For the columns part a list is fine, for the rows part it's not. Moreover, in the first part of the LOC (see *) the indexes of the rows can be accessed with ":" i.e. from index1 to index2 = 'index1':'index2' but I can not do the same in part 2 of the LOC function: this would not work:
print(df.loc['20130102':'20130104',['A':'C']])
I would be glad to understand why those two showed lines of codes are not working.
Thanks.