简体   繁体   English

需要澄清有关Python CSV文件格式的解析

[英]Clarification needed about Python CSV file format parsing

Format is like: 格式如下:

CHINA;2002-06-25 00:00:00.000;5,60
CHINA;2002-06-26 00:00:00.000;5,32
CHINA;2002-06-27 00:00:00.000;5,31

and I try to use Python's CSV tools to parse it but cannot understand the paragraph, source : 并且我尝试使用Python的CSV工具来解析它,但无法理解该段落source

And while the module doesn't directly support parsing strings, it can easily be done: 尽管该模块不直接支持解析字符串,但可以轻松实现:

import csv
for row in csv.reader(['one,two,three']):
    print row

Could someone clarify the line ['one,two,three'] ? 有人可以澄清这一行['one,two,three']吗? How would you use it with format A;B;C ? 您将如何使用A;B;C格式?

The docs you quote are talking about the difference between parsing csv data stored in a file, and csv data stored in a string. 您引用的文档讨论的是解析存储在文件中的csv数据与存储在字符串中的csv数据之间的区别。 It doesn't have to do with the format of the data. 它与数据的格式无关。

You should be able to read your data with something like: 您应该能够通过以下方式读取数据:

import csv
csv_reader = csv.reader(open('data.csv', 'rb'), delimiter=';')
for row in csv_reader:
    # do something with row....

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM