import pandas as pd
import numpy as np
df = np.array([['a', 23],
['b', 13],
['c', 15]])
table = pd.DataFrame(df, index=['A','B','C'], columns=['left', 'right'])
print(table)
#输出结果:
left right
A a 23
B b 13
C c 15
1、loc:
loc[n]表示索引的是第n行(index是整数)
import pandas as pd
import numpy as np
df = pd.DataFrame(np.arange(12).reshape(3,4))
print(df)
print(df.loc[[2]])
0 1 2 3
0 0 1 2 3
1 4 5 6 7
2 8 9 10 11
0 1 2 3
2 8 9 10 11
loc['A']表示索引的是第‘A’行(index是字符)
print(table.loc[['A']])
left right
A a 23
2、iloc:通过行号获取行数据,不能是字符
print(table.iloc[[1]])
left right
B b 13
3、ix:结合前两种的混合索引