1# Selecting Datafrmae Information:
2# iloc
3
4# selecting a single row:
5df.iloc[3]
6
7# selecting a range of rows:
8df.iloc[0:3]
9
10# selecting all rows, with columns within an index range:
11# all rows, 1st- 3rd columns, sliced at second index:
12df.iloc[:, 0:3]
13
14# selecting a range of rows and a range of columns:
15# 1st to 3rd rows, 5th & 6th columns:
16df.iloc[0:3, 4:6]
17
18# by multiple noconsecutive rows and columns:
19# selecting rows 1, 4, 6 with columns 2, 3, 5:
20df.iloc[[0, 3, 5], [1, 2, 4]]
21
22
23# a) .loc label-based indexing- selecting columns based on index:
24# all rows:
25df.loc[:, 'column_name']
26
27# or:
28df['column_name']
29
30# selected rows:
31df.loc[0:5, 'column_name']
32
33# b) boolean indexing using .loc:
34df.loc[df['column_name'] < 5]
35
36#boolean indexing fro one column:
37df.loc[df['column_condition'] < 12, ['column_desired']]
38
39
40
41
1>>> s = pd.Series(list("abcdef"), index=[49, 48, 47, 0, 1, 2])
249 a
348 b
447 c
50 d
61 e
72 f
8
9>>> s.loc[0] # value at index label 0
10'd'
11
12>>> s.iloc[0] # value at index location 0
13'a'
14
15>>> s.loc[0:1] # rows at index labels between 0 and 1 (inclusive)
160 d
171 e
18
19>>> s.iloc[0:1] # rows at index location between 0 and 1 (exclusive)
2049 a
21
1iloc - default indexes (system generated)
2loc - table indexes or we manually given indexes