[Head First Python]5. 推导数据:处理数据
读取4个文件内容,格式化数据,升序,显示每个文件前3个数据
julie.txt
2.59,2.11,2:11,2:23,3-10,2-23,3:10,3.21,3-21
james.txt
2-34,3:21,2.34,2.45,3.01,2:01,2:01,3:10,2-22
sarah.txt
2:58,2.58,2:39,2-25,2-55,2:54,2.18,2:55,2:55
mikey.txt
2:22,3.01,3:01,3.02,3:02,3.02,3:22,2.49,2:38
chapter5.py
def get_coach_data(filename):
try:
with open(filename) as f:
data = f.readline()
return ( data.strip().split(','))
except IOError as err:
print('File err:' + str(err))
return(None) def sanitize(time_string):
if '-' in time_string:
splitter = '-'
elif ':' in time_string:
splitter = ':'
else:
return(time_string) (mins, secs) = time_string.split(splitter)
return(mins + '.' + secs) try:
julie = get_coach_data('julie.txt')
james = get_coach_data('james.txt')
sarah = get_coach_data('sarah.txt')
mikey = get_coach_data('mikey.txt') print( sorted( set ([sanitize(s) for s in julie]) )[0:3] )
print( sorted( set ([sanitize(s) for s in james]) )[0:3] )
print( sorted( set ([sanitize(s) for s in sarah]) )[0:3] )
print( sorted( set ([sanitize(s) for s in mikey]) )[0:3] ) except IOError as err:
print("file error" + str(err))

[Head First Python]5. 推导数据:处理数据的更多相关文章
- 使用Python将Excel中的数据导入到MySQL
使用Python将Excel中的数据导入到MySQL 工具 Python 2.7 xlrd MySQLdb 安装 Python 对于不同的系统安装方式不同,Windows平台有exe安装包,Ubunt ...
- Python中,添加写入数据到已经存在的Excel的xls文件,即打开excel文件,写入新数据
背景 Python中,想要打开已经存在的excel的xls文件,然后在最后新的一行的数据. 折腾过程 1.找到了参考资料: writing to existing workbook using xlw ...
- Python利用pandas处理Excel数据的应用
Python利用pandas处理Excel数据的应用 最近迷上了高效处理数据的pandas,其实这个是用来做数据分析的,如果你是做大数据分析和测试的,那么这个是非常的有用的!!但是其实我们平时在做 ...
- python获取数据网页数据并创建文件夹保存(基于python3.6)
from urllib.parse import urljoin import urllib.request from bs4 import BeautifulSoup import os impor ...
- python后端将svc文件数据读入数据库具体实现
如何用python将svc文件的数据读入到MySQL数据库里,在此直接上代码了,感兴趣的朋友可以贴代码测试: import pandas as pd import os from sqlalchemy ...
- python使用xlrd读取excel数据时,整数变小数的解决办法
python使用xlrd读取excel数据时,整数变小数: 解决方法: 1.有个比较简单的就是在数字和日期的单元格内容前加上一个英文的逗号即可.如果数据比较多,也可以批量加英文逗号的前缀(网上都有方法 ...
- 用python探索和分析网络数据
Edited by Markdown Refered from: John Ladd, Jessica Otis, Christopher N. Warren, and Scott Weingart, ...
- Python Socket请求网站获取数据
Python Socket请求网站获取数据 ---阻塞 I/O ->收快递,快递如果不到,就干不了其他的活 ---非阻塞I/0 ->收快递,不断的去问,有没有送到,有没有送到,. ...
- [Python] 糗事百科文本数据的抓取
[Python] 糗事百科文本数据的抓取 源码 https://github.com/YouXianMing/QiuShiBaiKeText import sqlite3 import time im ...
- 【python-excel】Selenium+python自动化之读取Excel数据(xlrd)
Selenium2+python自动化之读取Excel数据(xlrd) 转载地址:http://www.cnblogs.com/lingzeng86/p/6793398.html ·········· ...
随机推荐
- 调查程序phpquestionnaire 2.2中文安装注意
最近找调查投票软件 找到limesurvey 和 phpquestionnaire,limesurvey 中文可以用,但是比较烦琐.phpquestionnaire有汉化过的包下载,但是安装完,发现中 ...
- 手机user agent大全下载 整理发布一批移动设备的user agent【分享】
手机user agent大全下载 整理发布一批移动设备的user agent[分享] 很多人朋友在玩浏览器的时候 或者写软件的时候需要用到 user agent 这个东西 修改这个 可以使自己的浏览器 ...
- django删除migrations
先把migrations文件夹里面的数据删除. 删除数据库中关联的表 删除django_migrations里面关联的数据(因为在migrate的时候发现django_migrations表有相关数据 ...
- JAVA单元测试Junit
1.为什么要用Junit 做了很多项目,几乎没怎么用过Java的单元测试,是因为它没有用吗?显然不是,是自己的开发方式太不规范!对于大型的软件项目,单元测试不仅有效实用,还非常有必要!它能够测试每个方 ...
- Qt编程之信号与槽-------unresolved external symbol "public: virtual struct QMetaObject const * __thiscall XX::metaObject(void)const
原因是加入Q_OBJECT这个macro的类,被编译的时候就要用到moc这个命令,所以在VS2010中,没有加入此命令的应用,当然会出错了.所以解决办法是加,或者如果你不使用信号槽可以直接删除. 当要 ...
- The end of other
The end of other For language training our Robots want to learn about suffixes. In this task, you ar ...
- Struts2源代码解读之Action调用
对于Struts2源代码的分析已经有些时日了,虽然网上有很多解读代码,不过自己还是写一个放上来,供大家参考一下. 解读过程: 直接在action类中打断点(包括构造函数和待执行方法)进行debug调试 ...
- libeXosip2(1) -- Modules
Modules Here is a list of all modules: [detail level 12] The eXtented eXosip stack LibeXosip2 Versio ...
- java链接sqlite资料整理
0.SQLite三种JDBC驱动的区别 摘自http://blog.sina.com.cn/s/blog_654337ca01016x4n.html 在DBeaver中看到SQLite有三种JDBC驱 ...
- Python 异步IO、IO多路复用
事件驱动模型 <!DOCTYPE html> <html lang="en"> <head> <meta charset="UT ...