Skip to main content
Made compliant with the Jon Skeet Decree - <https://twitter.com/PeterMortensen/status/976400000942034944>.
Source Link
Peter Mortensen
  • 31.1k
  • 22
  • 111
  • 134
df[['a', 'b']]  # selectSelect all rows of 'a' and 'b'column 
df.loc[0:10, ['a', 'b']]  # indexIndex 0 to 10 select column 'a' and 'b'
df.loc[0:10, 'a':'b']  # indexIndex 0 to 10 select column 'a' to 'b'
df.iloc[0:10, 3:5]  # indexIndex 0 to 10 and column 3 to 5
df.iloc[3, 3:5]  # indexIndex 3 of column 3 to 5
df[['a', 'b']]  # select all rows of 'a' and 'b'column 
df.loc[0:10, ['a', 'b']]  # index 0 to 10 select column 'a' and 'b'
df.loc[0:10, 'a':'b']  # index 0 to 10 select column 'a' to 'b'
df.iloc[0:10, 3:5]  # index 0 to 10 and column 3 to 5
df.iloc[3, 3:5]  # index 3 of column 3 to 5
df[['a', 'b']]  # Select all rows of 'a' and 'b'column 
df.loc[0:10, ['a', 'b']]  # Index 0 to 10 select column 'a' and 'b'
df.loc[0:10, 'a':'b']  # Index 0 to 10 select column 'a' to 'b'
df.iloc[0:10, 3:5]  # Index 0 to 10 and column 3 to 5
df.iloc[3, 3:5]  # Index 3 of column 3 to 5
df[['a','b']] # select all rows of 'a' and 'b'column 
df.loc[0:10, ['a','b']] # index 0 to 10 select column 'a' and 'b'
df.loc[0:10, ['a':'b']] # index 0 to 10 select column 'a' to 'b'
df.iloc[0:10, 3:5] # index 0 to 10 and column 3 to 5
df.iloc[3, 3:5] # index 3 of column 3 to 5
df[['a', 'b']]  # select all rows of 'a' and 'b'column 
df.loc[0:10, ['a', 'b']]  # index 0 to 10 select column 'a' and 'b'
df.loc[0:10, 'a':'b']  # index 0 to 10 select column 'a' to 'b'
df.iloc[0:10, 3:5]  # index 0 to 10 and column 3 to 5
df.iloc[3, 3:5]  # index 3 of column 3 to 5
df[['a','b']] # select all rows of 'a' and 'b'column 
df.loc[0:10, ['a','b']] # index 0 to 10 select column 'a' and 'b'
df.loc[0:10, ['a':'b']] # index 0 to 10 select column 'a' to 'b'
df.iloc[0:10, 3:5] # index 0 to 10 and column 3 to 5
df.iloc[3, 3:5] # index 3 of column 3 to 5
df[['a', 'b']]  # select all rows of 'a' and 'b'column 
df.loc[0:10, ['a', 'b']]  # index 0 to 10 select column 'a' and 'b'
df.loc[0:10, 'a':'b']  # index 0 to 10 select column 'a' to 'b'
df.iloc[0:10, 3:5]  # index 0 to 10 and column 3 to 5
df.iloc[3, 3:5]  # index 3 of column 3 to 5
Source Link
Biplob Das
  • 3.2k
  • 26
  • 15

df[['a','b']] # select all rows of 'a' and 'b'column 
df.loc[0:10, ['a','b']] # index 0 to 10 select column 'a' and 'b'
df.loc[0:10, ['a':'b']] # index 0 to 10 select column 'a' to 'b'
df.iloc[0:10, 3:5] # index 0 to 10 and column 3 to 5
df.iloc[3, 3:5] # index 3 of column 3 to 5