美文网首页
python常见数据处理方式

python常见数据处理方式

作者: xiaoguo16 | 来源:发表于2017-11-22 15:40 被阅读0次

Spyder下的块注释

ctrl+4/5

日期转为时间戳

timeArray = time.strptime(time, "%d/%b/%Y %H:%M:%S")        
timeStamp = int(time.mktime(timeArray))
#time为相应的日期的字符串,最后timeStamp为转换后的时间戳。

正则表达式匹配

import re
time='2013-04-06 11:12:04'
#匹配2013-04-06 11:09分到20分的数据
m=re.match(r'^(2013-04-06 11:){1}(09|10|11|12|13|14|15|16|17|18|19|20):([0-9])+',time)

小数点位数保留两位

a='%.2f'%3.2455
print a   #3.25

相关文章

网友评论

      本文标题:python常见数据处理方式

      本文链接:https://www.haomeiwen.com/subject/rjfspxtx.html