数据框索引行
Posted bravesunforever
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了数据框索引行相关的知识,希望对你有一定的参考价值。
label1=[‘apple‘,‘orange‘,‘pear‘,‘banana‘] label2=[‘one‘,‘two‘,‘three‘,‘four‘] df=pd.DataFrame(np.arange(16).reshape(4,-1),index=label1,columns=label2) print(df) print(df[[‘one‘,‘three‘]]) #虽然只传入一个字符串列表,并未指定任何东西,它是取指定的列 print(df[[‘apple‘,‘pear‘]]) #这种并不能索引出想要的行,它结果会报错, # KeyError: "None of [Index([‘apple‘, ‘pear‘], dtype=‘object‘)] are in the [columns]"
以上是关于数据框索引行的主要内容,如果未能解决你的问题,请参考以下文章