python正則はCSVファイルデータを抽出して購入者単価を計算します。py

1269 ワード

"""
python    CSV           .py
     https://github.com/FGFW/FCNNIC
    4:36 2015/11/22
   python   csv           ,
                    .
    csv   http://t.cn/RU3hoB0
  csv   http://t.cn/RU3haTL
     :
      =       /    
          1 ,                
       =           ,               
  :   CSV           .
       (  )        ,             。
                    ,          。
"""
import re
rec=re.compile("\((.+)\)  .+,.+,(\d+.\d+),.*")
with open("0914    .csv") as f:
    cf=f.read()
    f.close()

dglist=re.findall(rec,cf) #     [('   ', '480.00'), ('   ', '505.00'),..]
for d,t in dglist: #  dglist, d     ,t         480.00
    rec=re.compile("%s,\d+-\d+-\d+,(\w+-\d+),"%d) #          ,            
       =len({l for l in re.findall(rec,cf)}) #          ,           ,
                                            #         ,       ,  len            
       =float(t)/    #t     ,    float   
    print("  :%s      : %s     :%3.2f     :%s" %(d,t,   ,   ))

try:
    input("    ")
except SystemError:
    pass
"""
  :
>>> 
  :         : 480.00     :26.67     :18
  :         : 505.00     :28.06     :18
...
"""