4

たとえば、「2,881,423」、「、」を削除する方法があります。何百万ものデータを実行する必要があります。バッチアクションを実行することは可能ですか?つまり、PCforMacで使用できるツールはどれでもかまいません。

"Position","Value",
"1","1",
"2","1",
"3","1",
"4","2",
"5","2",

..。

"2,881,423","19",
"2,881,424","22",
"2,881,425","23",
"2,881,426","23",
"2,881,427","25",
"2,881,428","25",
"2,881,429","25",

..。

上記のように、csvからのいくつかの部分があります。

4

3 に答える 3

2

次のコードはジョブを実行します - フォルダーにある特定のマスクを持つすべてのファイルをループします。

Sub RemoveCommas()

Dim RegX_Comma As Object
'
Dim FileStream As Object
Dim FileContent As String
Dim SourceFolder As String
Dim FileName As String
'
Set RegX_Comma = CreateObject("VBScript.RegExp")
RegX_Comma.Pattern = "(?<=\d),(?=\d)" 'Comma between any digits
RegX_Comma.IgnoreCase = True
RegX_Comma.Global = True

Set FileStream = CreateObject("ADODB.Stream")
SourceFolder = "D:\DOCUMENTS\" 'Must be specified with trailing "\"

FileName = Dir(InputFolder & "*.txt") 'Specify ANY mask using wildcards, e.g. "*.csv*
Do While FileName <> ""

    FileStream.Open
    FileStream.Charset = "ASCII" 'Change encoding as required
    FileStream.LoadFromFile (SourceFolder & FileName)
    FileContent = RegX_Comma.Replace(FileStream.ReadText, "")
    FileStream.Position = 0
    FileStream.WriteText FileContent
    FileStream.SetEOS
    FileStream.SaveToFile SourceFolder & FileName, 2 'Will overwrite the existing file
    FileStream.Close

FileName = Dir
Loop

End Sub

インライン コメントに従って、コードに必要な変更を加えます。

幸運を!)

于 2013-01-20T08:01:46.013 に答える
2

Python の場合:

import csv
with open("myfile.csv", "rb") as infile, open("output.csv", "wb") as outfile:
    reader = csv.reader(infile)
    writer = csv.writer(outfile)
    for row in reader:
        writer.writerow(item.replace(",", "") for item in row)
于 2013-01-20T08:25:16.477 に答える