English 中文(简体)
csvrows into separate txt file?
原标题:csv rows into separate txt files?

http://www.ohchr.org。 每一行从一只剪辑中读到一只rate子。

http://www.hchr.org。 反之,在一栏中,从每个轴心文档中读出案文,一行一行。 因此,将所有txt案卷改为一只Csv案。

你们如何这样做? 贾瓦或沙里是否善于迅速完成这项任务?

Update: For Java, there are already some quite useful libraries you can use, for example opencsv or javacsv. But better have a look at wikipedia about csv if no knowledge on csv. And this post tells you all the possibilities in Java.


<<>strong>:由于问题简单明了,有些事前即是家事。 兹宣布。

更多背景: 我正在自己进行机器学习实验,建立大型测试组。 作为试验的基本用途,我需要进行拖网、报废和档案类型的转让。 我本人现在做很多事情,由于最近的一些发现,突然想学到沙里夫,而感受则比 Java更简明,因为许多教区和档案处理情况。 因此,这个问题就是如此。

我只想为你们和我节省时间,在不说明与外界无关的背景的情况下,去掉头脑。 我的问题更多地涉及第二个问题“Java诉Sharma”。 因为我用一些雕像的图书馆跑到很少几条路面(?) 这并不是我所问的,只是不知道如何使用沙尔。 这是我提出这一问题的原因。 感谢。

最佳回答

从你写的文字来看,很少需要使用特别安全委员会档案中的具体内容。 尤其是任务1,这是关于文本档案的纯数据I/O操作。 例如:

for i,l in enumerate(open(the_file)):
   f = open( new_file_%i.csv  % i,  w )
   f.write(l)
   f.close()

就任务2而言,如果你能够保证每个档案都有相同的结构(每行的田地数目相同),它就再次是一种纯粹的数据I/O操作:

# glob files
files = glob( file_*.csv )
target = open( combined.csv ,  w )
for f in files:
   target.write(open(f).read())
   target.write(new_line_speparator_for_your_platform)
target.close()

是否在贾瓦或沙勒这样做取决于目标制度的有无和你个人偏好。

问题回答

In python, Task 1:

import csv
with open( file.csv ,  rb ) as df:
    reader = csv.reader(df)
    for rownumber, row in enumerate(reader):
        with open(  .join(str(rownumber), .txt ) as f:
            f.write(row)

任务2:

from glob import glob
with open( output.csv ,  wb ) as output:
    for f in glob( *.txt ):
        with open(f) as myFile:
            rows = myFile.readlines()
            output.write(rows)

你们需要加以调整,以备你们使用。





相关问题
Spring Properties File

Hi have this j2ee web application developed using spring framework. I have a problem with rendering mnessages in nihongo characters from the properties file. I tried converting the file to ascii using ...

Logging a global ID in multiple components

I have a system which contains multiple applications connected together using JMS and Spring Integration. Messages get sent along a chain of applications. [App A] -> [App B] -> [App C] We set a ...

Java Library Size

If I m given two Java Libraries in Jar format, 1 having no bells and whistles, and the other having lots of them that will mostly go unused.... my question is: How will the larger, mostly unused ...

How to get the Array Class for a given Class in Java?

I have a Class variable that holds a certain type and I need to get a variable that holds the corresponding array class. The best I could come up with is this: Class arrayOfFooClass = java.lang....

SQLite , Derby vs file system

I m working on a Java desktop application that reads and writes from/to different files. I think a better solution would be to replace the file system by a SQLite database. How hard is it to migrate ...

热门标签