码迷,mamicode.com
首页 > 其他好文 > 详细

数据框索引行

时间:2020-04-24 01:53:43      阅读:109      评论:0      收藏:0      [点我收藏+]

标签:orange   none   The   frame   结果   数据   err   div   指定   

 

 

 

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]"

 

数据框索引行

标签:orange   none   The   frame   结果   数据   err   div   指定   

原文地址:https://www.cnblogs.com/bravesunforever/p/12764676.html

踩
(0)
赞
(0)
   
举报
评论 一句话评论(0)
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!