首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 开发语言 > perl python >

python简略的数据处理

2012-09-01 
python简单的数据处理xxx主车道副车道起始时间终止时间4.0,0.0,0.0, 2012-06-14 10:27:53,2012-06-14 10:2

python简单的数据处理
xxx 主车道 副车道 起始时间 终止时间 

 4.0, 0.0, 0.0, 2012-06-14 10:27:53,2012-06-14 10:28:04
 4.0, 97.0, 102.0, 2012-06-14 10:27:53,2012-06-14 10:31:56
 4.0, 205.0, 220.0, 2012-06-14 10:27:53,2012-06-14 10:35:45

 4.0, 0.0, 0.0, 2012-06-14 10:37:41,2012-06-14 10:37:51
 4.0, 71.0, 113.0, 2012-06-14 10:37:41,2012-06-14 10:41:47
 4.0, 884.0,1185.0, 2012-06-14 10:37:41,2012-06-14 11:16:21
 4.0, 997.0,1284.0, 2012-06-14 10:37:41,2012-06-14 11:20:07
 4.0,1065.0,1376.0, 2012-06-14 10:37:41,2012-06-14 11:23:58


 4.0, 0.0, 0.0, 2012-06-14 11:26:43,2012-06-14 11:26:53
 4.0, 678.0, 893.0, 2012-06-14 11:29:25,2012-06-14 12:00:06
 4.0, 770.0,1023.0, 2012-06-14 11:29:25,2012-06-14 12:03:58
 4.0, 877.0,1132.0, 2012-06-14 11:29:25,2012-06-14 12:07:43
 4.0,1470.0,1820.0, 2012-06-14 11:29:25,2012-06-14 12:30:37

 4.0, 0.0, 0.0, 2012-06-14 12:30:54,2012-06-14 12:31:05
 4.0, 93.0, 100.0, 2012-06-14 12:30:54,2012-06-14 12:34:50
 4.0, 191.0, 216.0, 2012-06-14 12:30:54,2012-06-14 12:38:34

 4.0, 0.0, 0.0, 2012-06-14 12:40:40,2012-06-14 12:40:49
 4.0, 76.0, 113.0, 2012-06-14 12:40:40,2012-06-14 12:44:35
 4.0,1006.0,1285.0, 2012-06-14 12:40:40,2012-06-14 13:22:47
 4.0,1081.0,1416.0, 2012-06-14 12:40:40,2012-06-14 13:26:39
 4.0,1187.0,1535.0, 2012-06-14 12:40:40,2012-06-14 13:30:24


 4.0, 0.0, 0.0, 2012-06-14 14:33:48,2012-06-14 14:33:59
 4.0, 86.0, 109.0, 2012-06-14 14:33:48,2012-06-14 14:37:48
 4.0, 190.0, 229.0, 2012-06-14 14:33:48,2012-06-14 14:41:33
 4.0,1181.0,1506.0, 2012-06-14 14:33:48,2012-06-14 15:23:37
 4.0,1273.0,1614.0, 2012-06-14 14:33:48,2012-06-14 15:27:29
 4.0,1362.0,1737.0, 2012-06-14 14:33:48,2012-06-14 15:31:15
 

 4.0, 0.0, 0.0, 2012-06-14 15:32:13,2012-06-14 15:32:25

 5.0, 0.0, 0.0, 2012-06-14 15:35:26,2012-06-14 15:35:44
 5.0, 135.0, 0.0, 2012-06-14 15:35:26,2012-06-14 15:39:31
 5.0, 286.0, 0.0, 2012-06-14 15:35:26,2012-06-14 15:43:19


 4.0, 0.0, 0.0, 2012-06-14 15:47:12,2012-06-14 15:47:19
 4.0, 66.0, 100.0, 2012-06-14 15:47:12,2012-06-14 15:51:09
 4.0, 154.0, 216.0, 2012-06-14 15:47:12,2012-06-14 15:54:54
 4.0,1026.0,1231.0, 2012-06-14 15:47:12,2012-06-14 16:29:19
 4.0,1115.0,1348.0, 2012-06-14 15:47:12,2012-06-14 16:33:03


 4.0, 0.0, 0.0, 2012-06-14 16:34:09,2012-06-14 16:34:18

 5.0, 0.0, 0.0, 2012-06-14 16:36:54,2012-06-14 16:37:13
 5.0, 134.0, 0.0, 2012-06-14 16:36:54,2012-06-14 16:40:58
 5.0, 281.0, 0.0, 2012-06-14 16:36:54,2012-06-14 16:44:44

 4.0, 0.0, 0.0, 2012-06-14 16:48:35,2012-06-14 16:48:43
 4.0, 65.0, 107.0, 2012-06-14 16:48:35,2012-06-14 16:52:25
 4.0, 159.0, 229.0, 2012-06-14 16:48:35,2012-06-14 16:56:13
 4.0,1076.0,1408.0, 2012-06-14 16:48:35,2012-06-14 17:34:23

 4.0, 0.0, 0.0, 2012-06-14 17:38:02,2012-06-14 17:38:12
 4.0, 89.0, 100.0, 2012-06-14 17:38:02,2012-06-14 17:42:02
 4.0, 193.0, 223.0, 2012-06-14 17:38:02,2012-06-14 17:45:53

 4.0, 0.0, 0.0, 2012-06-14 17:47:47,2012-06-14 17:47:57
 4.0, 75.0, 104.0, 2012-06-14 17:47:47,2012-06-14 17:51:48
 4.0, 139.0, 203.0, 2012-06-14 17:47:47,2012-06-14 17:55:38
 4.0, 233.0, 337.0, 2012-06-14 17:47:47,2012-06-14 17:59:27

 4.0, 0.0, 0.0, 2012-06-14 18:00:17,2012-06-14 18:00:27
 4.0, 0.0, 0.0, 2012-06-14 18:00:17,2012-06-14 23:56:43

 4.0, 240.0, 324.0, 2012-06-14 16:48:35,2012-06-14 17:00:00
 4.0, 240.0, 324.0, 2012-06-14 16:48:35,2012-06-14 17:00:00


 4.0, 575.0, 804.0, 2012-06-14 16:48:35,2012-06-14 17:15:18

 4.0, 983.0,1287.0, 2012-06-14 16:48:35,2012-06-14 17:30:39
 4.0,1076.0,1408.0, 2012-06-14 16:48:35,2012-06-14 17:34:23
 4.0,1076.0,1408.0, 2012-06-14 16:48:35,2012-06-14 17:34:23


 4.0, 0.0, 0.0, 2012-06-14 17:38:02,2012-06-14 17:38:12
 4.0, 0.0, 0.0, 2012-06-14 17:38:02,2012-06-14 17:38:12
 4.0, 89.0, 100.0, 2012-06-14 17:38:02,2012-06-14 17:42:02
 4.0, 89.0, 100.0, 2012-06-14 17:38:02,2012-06-14 17:42:02
 4.0, 193.0, 223.0, 2012-06-14 17:38:02,2012-06-14 17:45:53
 4.0, 193.0, 223.0, 2012-06-14 17:38:02,2012-06-14 17:45:53


 4.0, 0.0, 0.0, 2012-06-14 17:47:47,2012-06-14 17:47:57
 4.0, 0.0, 0.0, 2012-06-14 17:47:47,2012-06-14 17:47:57
 4.0, 233.0, 337.0, 2012-06-14 17:47:47,2012-06-14 17:59:27
 4.0, 233.0, 337.0, 2012-06-14 17:47:47,2012-06-14 17:59:27

 4.0, 0.0, 0.0, 2012-06-14 18:00:17,2012-06-14 18:00:27
 4.0, 0.0, 0.0, 2012-06-14 18:00:17,2012-06-14 18:00:27
 4.0, 0.0, 0.0, 2012-06-14 18:00:17,2012-06-14 21:02:00

 4.0, 0.0, 0.0, 2012-06-14 18:00:17,2012-06-14 22:48:17
 4.0, 0.0, 0.0, 2012-06-14 18:00:17,2012-06-14 23:49:54
这样一群文本数据
如何可以用什么软件进行方便的做一些定制的处理与数据获取,程序正在写,太繁杂。。。

[解决办法]
文件a.txt包含上面的内容,下面代码中 fields 包含解析后的结果:

Python code
with open('a.txt') as fd:    for line in fd:        line = line.strip()        if line:            fields = line.split(',')            print fields
[解决办法]
貌似可以用字典方式,key = 时间,value = 统计数据
[解决办法]
Python code
#!/usr/bin/python# encoding: utf-8import reimport codecspatt = re.compile(r'''\s+?    (?P<id>[\d\.]+),\s?    (?P<mchannel>[\d\.]+),\s?    (?P<schannel>[\d\.]+),\s?    (?P<bgntime>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2}),\s?    (?P<endtime>\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}:\d{2})    (?P<other>.*)    ''', re.X | re.U | re.I)handle = codecs.open(r'/home/tim/Documents/test.txt', 'r', 'utf-8')with handle:    for m in filter(lambda x: x, map(patt.match, handle)):        print m.groupdict()
[解决办法]
Python code
#!/usr/bin/env pythonimport reaDict = {}with open('a.txt') as fd:    for line in fd:        line = line.strip()        if line:            fields = line.split(',')            aDate = re.sub(':.*', '', fields[3])            if aDate in aDict:                aDict[aDate] += 1            else:                aDict[aDate] = 1for key in sorted(aDict):    print key, ' => ', aDict[key] 

热点排行