I seem to be going wrong with the URL/local URL.
Most Apple APIs use file URLs to reference places in the file system. If you just need to cook up a file URL for a quick test, URL(fileURLWithPath:)
is your friend:
let url = URL(fileURLWithPath: "/Users/quinn/test.csv")
If you’re building real code things get more complex because you have to choose where to save your file, which is platform specific. If that’s the case, let me know what platform you’re targeting.
I would also like to combine several CSV’s into one big CSV. How can I
do this using TabularData?
Use the append(_:)
method to add one frame to the other and then save the complete frame. See the example below.
Share and Enjoy
—
Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"
import Foundation
import TabularData
let novels60s = """
"Title","Year"
"Rocannon's World","1966"
"Planet of Exile","1966"
"City of Illusions","1967"
"A Wizard of Earthsea","1968"
"The Left Hand of Darkness","1969"
"""
let novels70s = """
"Title","Year"
"The Tombs of Atuan","1971"
"The Lathe of Heaven","1971"
"The Farthest Shore","1972"
"The Dispossessed","1974"
"Very Far Away from Anywhere Else","1976"
"The Eye of the Heron","1978"
"Malafrena","1979"
"""
func mergeCSV() throws {
var df = try DataFrame(csvData: Data(novels60s.utf8))
let df70s = try DataFrame(csvData: Data(novels70s.utf8))
df.append(df70s)
let result = try df.csvRepresentation()
print(String(decoding: result, as: UTF8.self))
}
/*
Title,Year
Rocannon's World,1966
Planet of Exile,1966
City of Illusions,1967
A Wizard of Earthsea,1968
The Left Hand of Darkness,1969
The Tombs of Atuan,1971
The Lathe of Heaven,1971
The Farthest Shore,1972
The Dispossessed,1974
Very Far Away from Anywhere Else,1976
The Eye of the Heron,1978
Malafrena,1979
*/
try! mergeCSV()