我现在已经坚持了几个小时,并通过各种不同的工具循环来完成工作.没有成功.如果有人可以帮我解决这个问题,那真是太棒了.
这是问题所在:
我有一个非常大的CSV文件(400mb +)格式不正确.现在它看起来像这样:
This is a long abstract describing something. What follows is the tile for this sentence." ,Title1 This is another sentence that is running on one line. On the next line you can find the title. ,Title2
你可能会看到标题",Title1"和",Title2"实际上应与前面的句子在同一行.然后它看起来像这样:
This is a long abstract describing something. What follows is the tile for this sentence.",Title1 This is another sentence that is running on one line. On the next line you can find the title.,Title2
请注意,句子的结尾可以包含引号.最后,他们也应该被替换.
这是我到目前为止提出的:
sed -n '1h;1!H;${;g;s/\."?.*,//g;p;}' …Run Code Online (Sandbox Code Playgroud) 考虑像这样的CSV文件
item1,"description 1"
item2,"description 2"
item3,"description 3
description 3 continues on new line"
item4,"description 4"
Run Code Online (Sandbox Code Playgroud)
哪个应该像这样解析
item1,"description 1"
item2,"description 2"
item3,"description 3 description 3 continues on new line"
item4,"description 4"
Run Code Online (Sandbox Code Playgroud)
有没有办法在PHP中解析具有多行值的CSV?
每个人.我有一个列表列表,我想把它们写在一个带有列和行的csv文件中.我已经尝试了写作者,但这不是我想要的.我的列表的例子如下:
[[1, 2], [2, 3], [4, 5]]
Run Code Online (Sandbox Code Playgroud)
谢谢你的帮助.
有了这个 :
example=csv.writer(open('test.csv', 'wb'), delimiter=' ')
example.writerows( [[1, 2], [2, 3], [4, 5]])
Run Code Online (Sandbox Code Playgroud)
我在一个细胞中获得1 2,在细胞中获得2 3等.在细胞中不是1,在下一个细胞中是2.
我应该更清楚.我需要将这个示例列表写入文件,所以当我用excel打开它时,每个元素都在它自己的单元格中.我的输出应该是这样的:
1 2
2 3
4 5
Run Code Online (Sandbox Code Playgroud)
不同细胞中的每个元素.
我有一个带有许多缺失值的.csv数据集,并且当我读取表格时,我希望R以同样的方式("正确"方式)识别它们.我一直在使用:
import = read.csv("/Users/dataset.csv",
header =T, na.strings=c(""))
Run Code Online (Sandbox Code Playgroud)
这个脚本用一些东西填充所有空单元格,但它不是一致的.当我查看数据时head(import),会填充<NA>一些丢失的单元格,并填充一些丢失的单元格NA.我担心R在开始分析数据集时会采用不同的方式来识别缺失值,因此我希望将导入统一读入这些缺失值.
最后,我的csv文件中的一些缺失值仅用句点表示.我还想在导入到R时用正确的缺失值表示法表示这些句点.
我试图导出并下载JSON对象到CSV文件,我有希腊字符的问题.我的代码有效; 它并不完美,但它确实有效.
问题是希腊字符看起来像垃圾.
这是我现有的代码:
function downloadJsonToCsv(jsonObject) {
var array = typeof jsonObject != "object" ? JSON.parse(jsonObject) : jsonObject;
if (array == null) {
return; // No data found on the jsonObject
}
var str = "";
for (var i = 0; i < array.length; i++) {
var line = "";
for (var index in array[i]) {
line += array[i][index] + ";"; // Set delimiter
}
// Here is an example where you would wrap the values …Run Code Online (Sandbox Code Playgroud) javascript csv character-encoding export-to-excel export-to-csv
I have tried the following code but getting some errors. Here I can read the input file but I am getting the following error:Deprecated: Function split() is deprecated in C:\wamp\www\aaj2\index.php on line 63. O/P: Found a total of 5124 records in this csv file.
<?php
$databasehost = "localhost";
$databasename = "test";
$databasetable = "sample";
$databaseusername="test";
$databasepassword = "";
$fieldseparator = ",";
$lineseparator = "\n";
$csvfile = "filename.csv";
$addauto = 0;
$save = 1;
$outputfile = "output.sql";
if(!file_exists($csvfile)) { echo "File …Run Code Online (Sandbox Code Playgroud) 我想在Scala中读取一个CSV字符串/文件,以便给定一个case类C和一个错误类型Error,解析器填充一个Iterable[Either[Error,C]].是否有任何库可以执行此操作或类似的操作?
例如,给定一个类和错误
case class Person(name: String, age: Int)
type Error = String
Run Code Online (Sandbox Code Playgroud)
和CSV字符串
Foo,19
Ro
Bar,24
Run Code Online (Sandbox Code Playgroud)
解析器会输出
Stream(Right(Person("Foo",1)), Left("Cannot read 'Ro'"), Right(Person("Bar", 24)))
Run Code Online (Sandbox Code Playgroud)
更新:
我认为我的问题不明确,所以让我澄清一下:有没有办法在Scala中读取CSV而不定义样板?鉴于任何案例类,有没有办法自动加载它?我想以这种方式使用它:
val iter = csvParserFor[Person].parseLines(lines)
Run Code Online (Sandbox Code Playgroud) 我有一个数据文件apples.csv,它有以下标题:
"id","str1","str2","str3","num1","num2"
Run Code Online (Sandbox Code Playgroud)
我把它读成一个带有pandas的数据框:
apples = pd.read_csv('apples.csv',delimiter=",",sep=r"\s+")
Run Code Online (Sandbox Code Playgroud)
然后我做了一些事情,但忽略了(我把它全部注释掉了,我的整体问题仍然存在,所以说这些东西在这里无关紧要).
然后我保存出来:
apples.to_csv('bananas.csv',columns=["id","str1","str2","str3","num1","num2"])
Run Code Online (Sandbox Code Playgroud)
现在,看看bananas.csv,它的标题是:
,id,str1,str2,str3,num1,num2
Run Code Online (Sandbox Code Playgroud)
没有更多的引号(我不关心它,因为它不会影响文件中的任何内容),然后是那个引导逗号.随后的行现在有一个额外的列,因此它保存了7列.但如果我这样做:
print(len(apples.columns))
Run Code Online (Sandbox Code Playgroud)
在保存之前,它显示6列...
我通常使用Java/Perl/R,而且对Python,尤其是Pandas的经验不足,所以我不确定这是"是的,只是这样做"或问题是什么 - 但我花了很长时间才想到这个,通过搜索找不到它.
我怎样才能不做逗号的前置,也许同样重要 - 它为什么要这样做?
我有一个数据表,其中包含从数据库中检索的数据.当我在搜索文本框中输入一些关键字时(搜索文本框由数据表生成),表格的结果将会发生变化.这很好.但是当我单击导出到csv或pdf时,将从数据库而不是数据表中检索csv或pdf中的结果.
如何使用laravel基于datatables插件导出到csv/pdf?
//数据表插件
<link href="plugins/datatables/dataTables.bootstrap.css" rel="stylesheet" type="text/css" />
<script src="plugins/datatables/jquery.dataTables.min.js" type="text/javascript"></script>
<script src="plugins/datatables/dataTables.bootstrap.min.js" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)
// PHP
public function sales_csv(){
// columns
$arrSelectFields = array(
-- columns --
);
// query
-- sql queries --
// passing the columns which I want from the result set. Useful when we have not selected required fields
$arrColumns = $arrSelectFields;
// define the first row which will come as the first row in the csv
$arrFirstRow = $arrSelectFields;
// building the options array
$options …Run Code Online (Sandbox Code Playgroud) 假设我有一个临时表,如下所示:
+----+------+
| Id | Value|
+----+------+
| 1 | 1 |
| 1 | 2 |
| 1 | 3 |
| 2 | 1 |
| 2 | 2 |
+----+------+
Run Code Online (Sandbox Code Playgroud)
我希望我的桌子像这样:
+----+----------+
| Id | ValueList|
+----+----------+
| 1 | 1,2,3 |
| 2 | 1,2 |
+----+----------+
Run Code Online (Sandbox Code Playgroud)
所以基本上我需要将我的值分组为逗号分隔列表.我已经尝试过以下方法:
SELECT Id, STUFF((SELECT ',' + CAST(VALUE AS varchar) FROM @MyTable FOR XML PATH('')), 1 ,1, '') AS ValueList
FROM @MyTable
GROUP BY Id
Run Code Online (Sandbox Code Playgroud)
但我得到的结论是:
+----+---------------------+
| Id | …Run Code Online (Sandbox Code Playgroud)