Forum

MyDataFrame['LabelA...
 
Notifications
Clear all

MyDataFrame['LabelA'] vs MyDataFrame['LabelB': 'LabelC']  

   RSS

0

MyDataFrame['LabelA'] - refers to column 'LabelA'

MyDataFrame['LabelB': 'LabelC'] - refers to row 'LabelB' to 'LabelC'; why not refers to column 'LabelB' to 'LabelC'?

Short of memorising the difference, is there an easier way to remember the difference? Any suggestion is welcome.

This topic was modified 3 months ago by raymondsing
1 Answer
0

I recommend the following because it's more explicit.

 

For referring to a slice of rows by label:

df1.loc['row1':'row5', :]

 

For referring to a slice of columns:

df.loc[:, 'col1':'col3']

Relevant documentation here:
https://pandas.pydata.org/pandas-docs/stable/user_guide/indexing.html#selection-by-label

This post was modified 2 months ago by Yi Sheng
Share:

Delete your account