# Selecting rows and columns in pandas DataFrames
import pandas as pd
data = {
    'A': [0, 1, 22, 21, 12, 23],
    'B': [2, 3, 2,  2,  12, 22],
    'C': [2, 3, 44,  2,  52, 52],
}

table = pd.DataFrame(data)
table
A B C
0 0 2 2
1 1 3 3
2 22 2 44
3 21 2 2
4 12 12 52
5 23 22 52

Selecting columns#

table[['B', 'C']]
B C
0 2 2
1 3 3
2 2 44
3 2 2
4 12 52
5 22 52

Selecting rows#

mask = table['A'] > 20
table[mask]
A B C
2 22 2 44
3 21 2 2
5 23 22 52
table[table['A'] < 20]
A B C
0 0 2 2
1 1 3 3
4 12 12 52