使用包含逗号作为一个字段的字符串读取大型csv文件 [英] Reading large csv files with strings containing commas as one field

查看:520
本文介绍了使用包含逗号作为一个字段的字符串读取大型csv文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 .csv文件(〜26000行)。我想要能够读入matlab。另一个问题是,它在一个字段中包含由逗号分隔的字符串的集合。



m阅读它有麻烦。我试过像tdfread的东西,这将不工作在这里。

解决方案



有什么办法吗? / div>

我不确定是什么产生您的CSV文件,但这是你的问题。



CSV文件的点是文件本身指定字段的分隔。如果CSV的文本包含逗号,那么您无法做的任何事情都会帮助您。如果ANY程序知道单个字段中的文本是否包含逗号,或者该逗号是字段分隔符,则该如何知道?



正确的CSV将具有文本限定符。一些发电机/读卡器给您选择使用一个。标准文本限定符是一个(引号),它的变化很大,因为你的文本也可以包含这些。




I have a large .csv file (~26000 rows). I want to be able to read it into matlab. Another problem is that it contains a collection of strings delimited by commas in one of the fields.

I'm having trouble reading it. I tried stuff like tdfread, which won't work here. Any tricks with textscan i should be aware about?

Is there any other way?

解决方案

I'm not sure what is generating your CSV file but that is your problem.

The point of a CSV file, is that the file itself designates separation of fields. If the text of the CSV contains commas, then nothing you can do will help you. How would ANY program know when the text in a single field contains commas, or when that comma is a field delimiter?

Proper CSV would have a text qualifier. Some generators/readers gives you the option to use one. The standard text qualifier is a " (quote). Its changeable, though, because your text may contain those, too.

Again, its all about generating proper CSV content.

这篇关于使用包含逗号作为一个字段的字符串读取大型csv文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆