There is skiprow option in MLDataTable framework and I am wondering what would be the equivalent in Swift TabularData framework ?

I was working in this csv file and header in located in 4th row so how to skip 3 rows in TabularData framework.

Note that skiprow option in available in MLDataTable framework as well as in Python's Panda

import Foundation

import TabularData

let options = CSVReadingOptions(

hasHeaderRow: false,

nilEncodings: ["","nil"],

ignoresEmptyLines: true

)

let dataPath = "
https://www2.census.gov/programs-surveys/saipe/datasets/time-series/model-tables/irs.csv"

var dataFrame = try! DataFrame(contentsOfCSVFile: URL(string: dataPath)!, rows: 0..<15, options: options)

print (dataFrame.description)

Replies

You can do this by supplying a lower bound to the range value you pass to the rows argument:

let dataFrame = try! DataFrame(contentsOfCSVFile: url, rows: 3..<15, options: options)

WARNING This code is wrong:

URL(string: dataPath)!

To create a string from a path, use this:

URL(fileURLWithPath: dataPath)

As an added benefit, it doesn’t require a force unwrap (-:

Share and Enjoy

Quinn “The Eskimo!” @ Developer Technical Support @ Apple
let myEmail = "eskimo" + "1" + "@" + "apple.com"

  • The file is not located in local machine to use URL(fileURLWithPath: dataPath), it has a URL link. In addition to that the Header is on 3rd row so once you change hasHeaderRow: true then it crashes. So couldn't load the header from 3rd row. Would you mind running the avove code with hasHeaderRow: true

Add a Comment