• python读取CSV数据


                       CSV (逗号分隔值(Comma-Separated Values,CSV)文件)(简称为 CSV)是指将数据列用逗号分隔的文件。文件的扩展名是 .csv。另一种数据类型,叫作制表符分隔值(tab-separated values,TSV)数据,   有时也与 CSV归为一类。TSV 与 CSV 唯一的不同之处在于,数据列之间的分隔符是制表符(tab), 而不是逗号。文件的扩展名通常是 .tsv,但有时也用 .csv 作为扩展名。从本质上来看,  .tsv 文件与 .csv 文件在 Python 中的作用是相同的。

    在文本编辑器中打开 CSV 文件,你看到的数据应该与其类似:
    "Year","Country","Sex","Display Value","Numeric"
    "1990","Andorra","Both sexes","77","77.00000"
    "2000","Andorra","Both sexes","80","80.00000"
    "2012","Andorra","Female","28","28.00000"
    "2000","Andorra","Both sexes","23","23.00000"
    "2012","United Arab Emirates","Female","78","78.00000"
    "2000","Antigua and Barbuda","Male","72","72.00000"
    "1990","Antigua and Barbuda","Male","17","17.00000"
    "2012","Antigua and Barbuda","Both sexes","22","22.00000"
    "2012","Australia","Male","81","81.00000"

    下面用 Python (运行环境python2.7)打开这个文件,并将数据转换成
    Python 可以理解的格式。这只要几行代码:

    1 import csv
    2 csvfile = open('/home/lwk/python_test_data/data_processing/scores.csv', 'rb')
    3 reader = csv.reader(csvfile)
    4 for row in reader:
    5 print row

  • 相关阅读:
    多选下拉框带搜索(aps.net)
    asp.net无刷新上传(带预览)
    http免费升级https 攻略(超简单)
    用JS获取地址栏参数的方法
    C#生成二维码
    update更新另一个字段
    自适应瀑布型布局(手机,PC全兼容)
    微信扫码支付.net版本
    常用css3技巧
    Repeater 嵌套,子级Repeater获取 父级Repeater 中的值
  • 原文地址:https://www.cnblogs.com/liweikuan/p/13907541.html
Copyright © 2020-2023  润新知