添加新的“列” Tcl 中的 csv 数据文件
我正在处理“大”测量数据,大约 30K 键值 对。测量有迭代次数。每次迭代后 创建具有 30K 关键值对的数据文件(非 csv)。我想以某种方式 创建一个以下形式的 csv 文件:
Key1,value of iteration1,value of iteration2,...
Key2,value of iteration1,value of iteration2,...
Key2,value of iteration1,value of iteration2,...
...
现在,我想知道添加每次迭代测量的有效方法 Tcl 中将数据作为列保存到 csv 文件。到目前为止,无论哪种情况我似乎 需要将整个 csv 文件加载到某个变量(数组/列表)中并继续工作 每个元素都添加新的测量数据。这看起来效率有些低。 也许还有其他方法吗?
I am dealing with a "large" measurement data, approximately 30K key-value
pairs. The measurements have number of iterations. After each iteration a
datafile (non-csv) with 30K kay-value pairs is created. I want to somehow
creata a csv file of form:
Key1,value of iteration1,value of iteration2,...
Key2,value of iteration1,value of iteration2,...
Key2,value of iteration1,value of iteration2,...
...
Now, I was wondering about efficient way of adding each iteration mesurement
data as a columns to csv file in Tcl. So, far it seems that in either case I
will need to load whole csv file into some variable(array/list) and work on
each element by adding new measurement data. This seems somewhat inefficient.
Is there another way, perhaps?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
由于 CSV 文件本质上是文本文件,因此您必须加载所有数据并再次将其写出。由于数据基本上是行优先的,因此没有其他方法可以扩展列数。做你想做的事的最简单方法(毕竟,30k 对并没有那么多)是使用 csv 包 来完成解析工作。这段代码可能会满足您的需求……
不过,您可能最好使用数据库。 metakit 和 sqlite3 与 Tcl 配合得很好,并且可以很好地处理此类任务。
Because CSV files are fundamentally text files, you have to load all the data in and write it out again. There's no other way to expand the number of columns since the data is fundamentally row-major. The easiest way to do what you say you want (after all, 30k-pairs isn't that much) is to use the csv package to do the parsing work. This code might do what you're looking for…
You would probably be better off using a database though. Both metakit and sqlite3 work very well with Tcl, and handle this sort of task well.