《python》学习笔记(Day3),数据处理:转换、清洗、排序
来源:互联网 发布:达内java培训视频 2016 编辑:程序博客网 时间:2024/04/30 00:35
一、读入文本数据,存为列表。然后统一数据格式,升序排列输出到屏幕。
(1)
import os
import processos.chdir('c:\\python27\\dataprocess')
with open('james.txt') as jaf: #读入文本数据
data=jaf.readline()
james=data.strip().split(',') #删除空格,以逗号为分割,存为列表
with open('julie.txt') as juf:
data=juf.readline()
julie=data.strip().split(',')
with open('mikey.txt') as mif:
data=mif.readline()
mikey=data.strip().split(',')
with open('sarah.txt') as saf:
data=saf.readline()
sarah=data.strip().split(',')
clean_james=[process.sanitize(each_string) for each_string in james] #统一数据格式,分钟和秒均以点号分割
clean_julie=[process.sanitize(each_string) for each_string in julie]
clean_sarah=[process.sanitize(each_string) for each_string in sarah]
clean_mikey=[process.sanitize(each_string) for each_string in mikey]
print sorted(clean_james) #升序排列,输出到屏幕
print sorted(clean_julie)
print sorted(clean_mikey)
print sorted(clean_sarah)
(2)process模块为自编程序,包含函数sanitize,用于处理不一致的数据格式。
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)
二、推导列表。
new_line=[funtion(t) for t in line]
0 0
- 《python》学习笔记(Day3),数据处理:转换、清洗、排序
- python 数据处理清洗
- Python学习笔记DAY3---函数
- Python爬虫学习笔记Day3
- python机器学习/数据处理学习[一]csv数据清洗
- pandas 学习笔记-- 数据清洗和转换
- 丹的Python学习笔记Day3
- python 数据清洗之数据合并、转换、过滤、排序
- Python笔记Day3
- Python学习day3作业
- Python学习,Day3
- python学习日志--day3
- Python学习Day3
- python 空值清洗排序
- python数据分析与挖掘学习笔记(2)-淘宝商品数据清洗及预处理
- Java学习(回顾)笔记之day3
- Data Analysis学习笔记 --- Python数据清洗处理时间数据
- Data Analysis学习笔记 --- Python数据清洗对数据分组
- 面试笔试 ----- YY Java/Android(未通过)
- 关于Web界面查看日志的权限问题
- OpenSSL的安装与配置
- u-boot Overview
- jquery跳出each循环
- 《python》学习笔记(Day3),数据处理:转换、清洗、排序
- 配置putty自动登陆服务器
- ScaleGestureDetector SimpleOnScaleGestureListener缩放手势识别器
- ListView Item侧滑菜单
- 【高效server实践】--memcached网络框架剥离实践
- 泛型
- [Deeplearning]5监测学习过程(from A practical guide to training restricted boltzmann machine)
- c++11 你需要知道这些就够了
- MySQL定时备份