Причудливый индекс Python
import numpy as np
import pandas as pd
m = np.random.randint(1,30, size = (10,3))
df = pd.DataFrame(m, columns = ["var1", "var2", "var3"])
var1 var2 var3
0 9 9 25
1 29 9 7
2 24 27 25
3 24 29 14
4 1 1 11
5 12 12 26
6 7 24 20
7 15 8 15
8 6 19 9
9 15 28 12
df[0:2][["var1","var3"]] ## pay attention to the second square brackets
output:
var1 var3
0 9 25
1 29 7
Tired Tarantula