pandas-datafram-索引-2020-01-08
2020-01-08 本文已影响0人
爬山小虎
参考:https://www.cnblogs.com/hhh5460/p/5595616.html
df = pd.DataFrame(np.random.randn(6,4), index=list('abcdef'), columns=list('ABCD'))
按行/列索引:
df[:3]
df['a':'c']
按区域索引:
1. 标签名称:df.loc[]
df.loc[['a','b','c'], :]
df.loc[df.loc[:,'A']>0, :]
df.loc[lambda_df: _df.A > 0, :]
2. index:df.iloc[]
精确定位:df.at['a','A']