pandas练习(二)------ 数据过滤与排序
数据过滤与排序------探索2012欧洲杯数据
相关数据见(github)
步骤1 - 导入pandas库
import pandas as pd
步骤2 - 数据集
path2 = "./data/Euro2012.csv" # Euro2012.csv
步骤3 - 将数据集命名为euro12
euro12 = pd.read_csv(path2)
euro12.tail()
输出:
步骤4 选取 Goals
这一列
euro12.Goals # euro12['Goals']
输出:
步骤5 有多少球队参与了2012欧洲杯?
euro12.shape[0]
输出:
16
步骤6 该数据集中一共有多少列(columns)?
euro12.info()
输出:
<class 'pandas.core.frame.DataFrame'>
RangeIndex: 16 entries, 0 to 15
Data columns (total 35 columns):
Team 16 non-null object
Goals 16 non-null int64
Shots on target 16 non-null int64
Shots off target 16 non-null int64
Shooting Accuracy 16 non-null object
% Goals-to-shots 16 non-null object
Total shots (inc. Blocked) 16 non-null int64
Hit Woodwork 16 non-null int64
Penalty goals 16 non-null int64
Penalties not scored 16 non-null int64
Headed goals 16 non-null int64
Passes 16 non-null int64
Passes completed 16 non-null int64
Passing Accuracy 16 non-null object
Touches 16 non-null int64
Crosses 16 non-null int64
Dribbles 16 non-null int64
Corners Taken 16 non-null int64
Tackles 16 non-null int64
Clearances 16 non-null int64
Interceptions 16 non-null int64
Clearances off line 15 non-null float64
Clean Sheets 16 non-null int64
Blocks 16 non-null int64
Goals conceded 16 non-null int64
Saves made 16 non-null int64
Saves-to-shots ratio 16 non-null object
Fouls Won 16 non-null int64
Fouls Conceded 16 non-null int64
Offsides 16 non-null int64
Yellow Cards 16 non-null int64
Red Cards 16 non-null int64
Subs on 16 non-null int64
Subs off 16 non-null int64
Players Used 16 non-null int64
dtypes: float64(1), int64(29), object(5)
memory usage: 4.5+ KB
步骤7 将数据集中的列Team, Yellow Cards和Red Cards单独存为一个名叫discipline的数据框
discipline = euro12[['Team', 'Yellow Cards', 'Red Cards']]
discipline
输出:
步骤8 对数据框discipline按照先Red Cards再Yellow Cards进行排序
discipline.sort_values(['Red Cards', 'Yellow Cards'], ascending = False)
输出:
步骤9 计算每个球队拿到的黄牌数的平均值
round(discipline['Yellow Cards'].mean())
输出:
7.0
步骤10 找到进球数Goals超过6的球队数据
euro12[euro12.Goals > 6]
输出:
步骤11 选取以字母G开头或以e结尾的球队数据
# euro12[euro12.Team.str.startswith('G')]
euro12[euro12.Team.str.endswith('e')] # 以字母e结束的球队
输出:
步骤12 选取前7列
euro12.iloc[: , 0:7]
输出:
步骤13 选取除了最后3列之外的全部列
euro12.iloc[: , :-3]
输出:
步骤14 找到英格兰(England)、意大利(Italy)和俄罗斯(Russia)的命中率(Shooting Accuracy)
euro12.loc[euro12.Team.isin(['England', 'Italy', 'Russia']), ['Team','Shooting Accuracy']]
输出:
参考链接:
1、http://pandas.pydata.org/pandas-docs/stable/cookbook.html#cookbook
2、https://www.analyticsvidhya.com/blog/2016/01/12-pandas-techniques-python-data-manipulation/
3、https://github.com/guipsamora/pandas_exercises
pandas练习(二)------ 数据过滤与排序的更多相关文章
- Vue 基本列表 && 数据过滤与排序
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="UTF-8" /> 5 & ...
- pandas之DateFrame 数据过滤+遍历行+读写csv-txt-excel
# XLS转CSV df = pd.read_excel(r'列表.xls') df2 = pd.DataFrame()df2 = df2.append(list(df['列名']), ignore_ ...
- Oracle学习(二):过滤和排序
1.知识点:能够对比以下的录屏进行阅读 SQL> --字符串大写和小写敏感 SQL> --查询名叫KING的员工信息 SQL> select * 2 from emp 3 where ...
- python 数据清洗之数据合并、转换、过滤、排序
前面我们用pandas做了一些基本的操作,接下来进一步了解数据的操作, 数据清洗一直是数据分析中极为重要的一个环节. 数据合并 在pandas中可以通过merge对数据进行合并操作. import n ...
- [数据清洗]- Pandas 清洗“脏”数据(二)
概要 了解数据 分析数据问题 清洗数据 整合代码 了解数据 在处理任何数据之前,我们的第一任务是理解数据以及数据是干什么用的.我们尝试去理解数据的列/行.记录.数据格式.语义错误.缺失的条目以及错误的 ...
- mysql必知必会(四、检索数据,五、排序检索数据,六、过滤数据,七、数据过滤)
四.select语句 1.检索单个列 select prod_name from products; 2.检索多个列 select prod_name, prod_price from product ...
- [数据清洗]-使用 Pandas 清洗“脏”数据
概要 准备工作 检查数据 处理缺失数据 添加默认值 删除不完整的行 删除不完整的列 规范化数据类型 必要的转换 重命名列名 保存结果 更多资源 Pandas 是 Python 中很流行的类库,使用它可 ...
- [数据清洗]- Pandas 清洗“脏”数据(三)
预览数据 这次我们使用 Artworks.csv ,我们选取 100 行数据来完成本次内容.具体步骤: 导入 Pandas 读取 csv 数据到 DataFrame(要确保数据已经下载到指定路径) D ...
- Oracle01——基本查询、过滤和排序、单行函数、多行函数和多表查询
作者: kent鹏 转载请注明出处: http://www.cnblogs.com/xieyupeng/p/7272236.html Oracle的集群 Oracle的体系结构 SQL> --当 ...
随机推荐
- java.lang.instrument 中的premain 实现类的个性化加载(附源代码)
背景 想调用ASM API (用于字节码处理的开源API)对字节码进行处理,目标是实现对java程序运行时各种对象的动态跟踪,并进一步分析各个对象之间的关系(研究前提是目前的UML锁阐释的whole- ...
- AndroidStudio 使用Release签名进行Debug
extends:http://blog.csdn.net/h3c4lenovo/article/details/42011887 , http://www.linuxidc.com/Linux/201 ...
- iOS - 利用 iTunes 接口检查 App 版本更新
iOS 想要检查 App 当前版本是否为最新,一般的方案大概都是服务器自己提供一个接口来获取 App 最新版本是多少,然后再做出相应提示是否需要更新,但是接口需要手动维护,应用要审核,还得等审核通过以 ...
- ftok函数
ftok函数 系统建立IPC通讯(消息队列.信号量和共享内存)时必须指定一个ID值.通常情况下,该id值通过ftok函数得到. ftok原型 头文件: #include <sys/types.h ...
- vue--双向数据绑定
<template> <div id="app"> <p>{{msg}}</p> <input v-model="m ...
- Spark2 DataSet 创建新行之flatMap
val dfList = List(("Hadoop", "Java,SQL,Hive,HBase,MySQL"), ("Spark", & ...
- Win7去掉桌面图标小箭头
去掉win7的快捷方式的小箭头: 每当我们装完一个软件,在桌面生成快捷方式的时候总会有个小箭头,有些朋友看到觉得很烦,如何去掉这个小箭头呢? 点击开始图标 - 附件 - 命令提示符(有情提示,请右击用 ...
- C++虚函数virtual,纯虚函数pure virtual和Java抽象函数abstract,接口interface与抽象类abstract class的比较
由于C++和Java都是面向对象的编程语言,它们的多态性就分别靠虚函数和抽象函数来实现. C++的虚函数可以在子类中重写,调用是根据实际的对象来判别的,而不是通过指针类型(普通函数的调用是根据当前指针 ...
- Kendo UI使用小小记
之所以说小小记,是因为我根本没有好好用它,只是正好前些日子接触了一下,觉得还不错,随手记记~ 契机 我从加入现在这个公司以来,半专业的承担了很多前端相关的事情,用过不少前端框架,也为框架和原生的页面写 ...
- Java编程思想第四版随书源码官方下载方法
见不少人在找net.mindview.util.Print,CSDN上有下载,收积分,以下是官网的下载方法,免费: 官网链接:http://mindview.net/ 电子书下载地址:http://w ...