[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 ·········· ...
随机推荐
- mysql中自动更新时间CURRENT_TIMESTAMP
timestamp的两个属性:CURRENT_TIMESTAMP 和ON UPDATE CURRENT_TIMESTAMP http://blog.163.com/qiongling007@126/b ...
- wordpress安装地址与博客地址
可千万别乱改动你的wordpress安装地址和博客地址 一月 27th, 2009 Posted in web学习, 博客建设 | 12 Comments » 我最近一个月学习数据库的一些使用,把他爱 ...
- poj3261 -- Milk Patterns
Milk Patterns Time Limit: 5000MS ...
- Keil C51 知识点
第一节 Keil C51扩展关键字 深入理解并应用C51对标准ANSIC的扩展是学习C51的关键之一.因为大多数扩展功能都是直接针对8051系列CPU硬件的.大致有以下8类: 8051存储类型 ...
- VS2010的openssl源码编译方法
http://download.csdn.net/download/soucula/9591308
- Magento How To Display Product Custom Option On list.phtml
Some time we need to display custom option of product on category list page to achive this task we o ...
- BindService总结
一.整体工程图 二.activity_bind.xml <?xml version="1.0" encoding="utf-8"?> <Lin ...
- Oracle判断语句集合(转载)
SELECT decode(sign(to_date('2008-05-01', 'yyyy-MM-dd') - to_date('2008-03-01', 'yy ...
- JavaScript面向对象之类的创建
JavaScript对象的定义: 在js中函数极为对象,对象分为二种:对象字变量产生的对象连接到Object.prototype:函数对象连接到Function.prototype 方法:当一个函数被 ...
- C#关闭显示屏,使显示屏处于待机状态
class Program { private const uint WM_SYSCOMMAND = 0x112; //系统消息 private const int SC_MONITORPOWER = ...