九、pandas的索引index
2022-08-27 本文已影响0人
minningl
一、创建数据
df = pd.DataFrame(np.arange(12).reshape(3,4), columns=['A','B','C','D'])

二、设置索引列
df.set_index('A', inplace=True, drop=False)

三、使用索引列获取元素
df.loc[4]
df[df['A']==4]

df = pd.DataFrame(np.arange(12).reshape(3,4), columns=['A','B','C','D'])
df.set_index('A', inplace=True, drop=False)
df.loc[4]
df[df['A']==4]