zoukankan      html  css  js  c++  java
  • python数据分析

    利用pandas查询数据

    这里的查询数据相当于R语言里的subset功能,可以通过布尔索引有针对的选取原数据的子集、指定行、指定列等。我们先导入一个student数据集:

    student=pd.io.parsers.read_csv('C:\Users\admin\Desktop\student.csv')

    查询数据的前5行或末尾5行

    student.head()

    student.tail()

    查询指定的行

    student.ix[[0,2,4,5,7]]#这里的ix索引标签函数必须是中括号[]

    查询指定的列

    student[['Name','Height','Weight']].head()#如果多个列的话,必须使用双重中括号

    也可以通过ix索引标签查询指定的列

    student.ix[:,['Name','Height','Weight']].head()

    查询指定的行和列

    student.ix[[0,2,4,5,7],['Name','Height','Weight']].head()

    以上是从行或列的角度查询数据的子集,现在我们来看看如何通过布尔索引实现数据的子集查询。

    查询所有女生的信息

    student[student['Sex']=='F']

    查询出所有12岁以上的女生信息

    student[(student['Sex']=='F')&(student['Age']>12)]

    查询出所有12岁以上的女生姓名、身高和体重

    student[(student['Sex']=='F')&(student['Age']>12)][['Name','Height','Weight']]

    上面的查询逻辑其实非常的简单,需要注意的是,如果是多个条件的查询,必须在&(且)或者|(或)的两端条件用括号括起来

  • 相关阅读:
    django第八天总结
    获取文件名的基本信息
    单个文件上传与多个文件上传
    return .php
    upload.php
    string.php
    upload.php
    upload.html
    获取上传文件
    那些年被我坑过的Python——牵一发动全身 第十一章MySQL、ORM
  • 原文地址:https://www.cnblogs.com/chenyuchun/p/12506176.html
Copyright © 2011-2022 走看看