Python Dataframe操作

DataFrame获取行、列、index;

    A   B   C
a   0   1   2
b   3   4   5
c   6   7   8
d   9  10  11
e  12  13  14

其实,就是分为两部分:

上文访问:按照行 比如第0行,或者是按照第a、b行;按照列:比如第一列,或者第A列;

获取相关元素等。

行:len(df) df.shape[0]

列:df.shape[1]

选择行:

df.iloc[0] df.loc[['b']] # 按照index的具体值,选择索引为'b'的那一行

 选择列:

df[['A','B']] df.iloc[:,0]

选择行、列:

df.loc['a',['B','C']] #返回‘a’行'B'、'C'列,这种用于选取行索引列索引已知
df.iat[1,1]

你可能感兴趣的:(python)