Tag: csv

使用CSV Django模块以universal-newline模式打开文件

我正在尝试访问Django中的model.filefield以使用csv模块parsingPython中的CSV文件。 它在Windows上工作,但在Mac上它给了我这个: Exception Type: Error Exception Value: new-line character seen in unquoted field – do you need to open the file in universal-newline mode? 这是代码: myfile = customerbulk.objects.all()[0].fileup mydata = csv.reader(myfile) for email,mobile,name,civilid in mydata: print email,mobile,name,civilid

将CSV文件导入到SQL Server中

我正在寻找帮助使用BULK INSERT将.csv文件导入到SQL Server中,并且我有几个基本问​​题。 问题: CSV文件数据之间可能有(逗号)(例如:说明),那么如何使导入处理这些数据? 如果客户端从Excel创buildCSV,那么带有逗号的数据将被包含在"" (双引号)内[如下例所示],那么导入如何处理呢? 我们如何跟踪一些行是否有错误的数据,导入跳过? (导入是否跳过不可导入的行) 以下是带标题的示例CSV: Name,Class,Subject,ExamDate,Mark,Description Prabhat,4,Math,2/10/2013,25,Test data for prabhat. Murari,5,Science,2/11/2013,24,"Test data for his's test, where we can test 2nd ROW, Test." sanjay,4,Science,,25,Test Only. 和SQL语句导入: BULK INSERT SchoolsTemp FROM 'C:\CSVData\Schools.csv' WITH ( FIRSTROW = 2, FIELDTERMINATOR = ',', –CSV field delimiter ROWTERMINATOR = '\n', –Use to shift the control to […]

我应该如何逃避CSV文件中的逗号和语音标记,以便在Excel中工作?

我正在生成一个CSV文件(用逗号而不是制表符分隔)。 我的用户很可能通过双击打开Excel中的CSV文件。 我的数据可能包含逗号和语音标记,所以我按照以下方式转义。 Reference, Title, Description 1, "My little title", "My description, which may contain ""speech marks"" and commas." 2, "My other little title", "My other description, which may also contain ""speech marks"" and commas." 据我所知,一直是这样做的。 这里是我的错误:当我在Excel 2010中打开此文件时,我的转义不受尊重。 语音标记出现在表单上,​​逗号导致新的列。

有没有办法在CSV列中包含逗号而不打破格式?

我有一个名称和一个数字两列CSV。 有些人的名字使用逗号,例如Joe Blow, CFA. 这个逗号打破了CSV格式,因为它被解释为一个新的列。 我已经读了,最常见的处方似乎是用一个新的值(例如this|that|the, other )replace那个字符,或者用分隔符代替分隔符。 我真的想保留逗号分隔符(我知道Excel支持其他分隔符,但其他解释器可能不)。 我也想用这个名字来保留这个逗号,就像Joe Blow| CFA Joe Blow| CFA看起来非常愚蠢。 有没有办法在CSV列中包含逗号而不打破格式,例如通过转义格式?

在C#中,如何从string创build一个TextReader对象(不写入磁盘)

我正在使用一个快速的CSV阅读器来parsing一些粘贴的文字到一个网页。 Fast CSV阅读器需要一个TextReader对象,而我所拥有的只是一个string。 将string转换为TextReader对象的最佳方法是什么? 谢谢! 更新 – 示例代码 – 在原始示例中,新的StreamReader正在查找名为“data.csv”的文件。 我希望通过TextBox_StartData.Text来提供它。 使用下面的代码不能编译。 TextReader sr = new StringReader(TextBox_StartData.Text); using (CsvReader csv = new CsvReader(new StreamReader(sr), true)) { DetailsView1.DataSource = csv; DetailsView1.DataBind(); } new StreamReader(sr)告诉我它有一些无效的参数。 有任何想法吗? 作为一种替代方法,我试过这个: TextReader sr = new StreamReader(TextBox_StartData.Text); using (CsvReader csv = new CsvReader(sr, true)) { DetailsView1.DataSource = csv; DetailsView1.DataBind(); } 但我得到一个Illegal characters […]

使用write.csv时,防止将行名写入文件

命令: t <- data.frame(v = 5:1, v2 = 9:5) write.csv(t, "t.csv") 结果文件: # "","v","v2" # "1",5,9 # "2",4,8 # "3",3,7 # "4",2,6 # "5",1,5 如何防止将行索引的第一列写入文件?

用C#将数据写入CSV文件

我正在尝试使用C#语言逐行写入一个csv文件。 这是我的function string first = reader[0].ToString(); string second=image.ToString(); string csv = string.Format("{0},{1}\n", first, second); File.WriteAllText(filePath, csv); 整个函数在一个循环内部运行,并且每一行都应该被写入到csv文件中。 在我的情况下,下一行将覆盖现有的行,最后我只获得单个logging在最后一个csv文件。 我怎样才能在csv文件中写出所有的行。

使用Python读取Pandas中的CSV文件时的UnicodeDecodeError

我正在运行一个正在处理30,000个类似文件的程序。 随机数字正在停止并产生这个错误… File "C:\Importer\src\dfman\importer.py", line 26, in import_chr data = pd.read_csv(filepath, names=fields) File "C:\Python33\lib\site-packages\pandas\io\parsers.py", line 400, in parser_f return _read(filepath_or_buffer, kwds) File "C:\Python33\lib\site-packages\pandas\io\parsers.py", line 205, in _read return parser.read() File "C:\Python33\lib\site-packages\pandas\io\parsers.py", line 608, in read ret = self._engine.read(nrows) File "C:\Python33\lib\site-packages\pandas\io\parsers.py", line 1028, in read data = self._reader.read(nrows) File "parser.pyx", line 706, in pandas.parser.TextReader.read (pandas\parser.c:6745) File […]

_csv.Error:字段大于字段限制(131072)

我有一个脚本阅读的CSV文件非常大的领域: # example from http://docs.python.org/3.3/library/csv.html?highlight=csv%20dictreader#examples import csv with open('some.csv', newline='') as f: reader = csv.reader(f) for row in reader: print(row) 但是,这会在某些csv文件上引发以下错误: _csv.Error: field larger than field limit (131072)

将多个csv文件导入到pandas并连接成一个DataFrame

我想从一个目录中读取几个CSV文件到pandas,并将它们连接成一个大的dataframe。 我还没有弄明白。 这是我到目前为止: import glob import pandas as pd # get data file names path =r'C:\DRO\DCL_rawdata_files' filenames = glob.glob(path + "/*.csv") dfs = [] for filename in filenames: dfs.append(pd.read_csv(filename)) # Concatenate all data into one DataFrame big_frame = pd.concat(dfs, ignore_index=True) 我想我需要在for循环内的一些帮助?