Se7enSquared
10/29/2019 - 7:13 PM

Pandas: Slicing dataframes

Select by integer positionExplicit SyntaxShorthand Convention
Single column from dataframedf.iloc[:,3]
List of columns from dataframedf.iloc[:,[3,5,6]]
Slice of columns from dataframedf.iloc[:,3:7]
Single row from dataframedf.iloc[20]
List of rows from dataframedf.iloc[[0,3,8]]
Slice of rows from dataframedf.iloc[3:5]df[3:5]
Single items from seriess.iloc[8]s[8]
List of item from seriess.iloc[[2,8,1]]s[[2,8,1]]
Slice of items from seriess.iloc[5:10]s[5:10]