这个问题是我之前的问题How to transform a CSV into multiple lists (applescript)?
我有一个大约 4000 行的 csv 文件。我导入它并将每一行变成列表的一个项目,然后我将每一行变成它自己的项目列表。
例如:(我使用的是数字,但我拥有的数据也包含文本,并且大多数条目都超过 1 个字符,有些条目也是空白的)
1,2,3,4,5,6
6,5,4,3,2,1
7,8,9,0,7,6
3,4,4,5,3,1
变成
{"1,2,3,4,5,6","6,5,4,3,2,1","7,8,9,0,7,6","3,4,4,5,3,1"}
变成
{{"1","2","3","4","5","6"}{"6","5","4","3","2","1"}{"7","8","9","0","7","6"}{"3","4","4","5","3","1"}}
现在我想做的是以下几点:
从每个列表中删除某些项目,例如我想从每个列表中删除第二个项目,即“2”、“5”、“8”和“4”
对某些项目运行计算,例如我想将项目 5 乘以 2
此外,我的数据中的一些数字在它们的末尾有 +11 或 + 17,我想知道如何用匹配数量的零替换它,例如,如果我有 5002+6 我想把它变成5002000000
当前代码是:
-- Choosing your file
set csvDevices to "testfile.csv"
-- Reading file to memory
set csvDevices to read csvDevices
-- Creating Records (Single Lines)
set csvDevicesRecords to paragraphs of csvDevices
-- Remove Title Line
set csvDevicesRecords to rest of csvDevicesRecords
-- Make each line into a list
set csvDevicesValues to {}
set AppleScript's text item delimiters to ","
repeat with i from 1 to length of csvDevicesRecords
set end of csvDevicesValues to text items of (item i of csvDevicesRecords)
end repeat
set AppleScript's text item delimiters to ""
我希望以上所有内容都有意义。