<!--
{
  "availability" : [
    "iOS: 15.0.0 -",
    "iPadOS: 15.0.0 -",
    "macCatalyst: 15.0.0 -",
    "macOS: 12.0.0 -",
    "tvOS: 15.0.0 -",
    "visionOS: 1.0.0 -",
    "watchOS: 8.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "TabularData",
  "identifier" : "/documentation/TabularData/DataFrame/init(contentsOfCSVFile:columns:rows:types:options:)",
  "metadataVersion" : "0.1.0",
  "role" : "Initializer",
  "symbol" : {
    "kind" : "Initializer",
    "modules" : [
      "TabularData"
    ],
    "preciseIdentifier" : "s:11TabularData0B5FrameV17contentsOfCSVFile7columns4rows5types7optionsAC10Foundation3URLV_SaySSGSgSnySiGSgSDySSAA7CSVTypeOGAA17CSVReadingOptionsVtKcfc"
  },
  "title" : "init(contentsOfCSVFile:columns:rows:types:options:)"
}
-->

# init(contentsOfCSVFile:columns:rows:types:options:)

Creates a data frame from a CSV file.

```
init(contentsOfCSVFile url: URL, columns: [String]? = nil, rows: Range<Int>? = nil, types: [String : CSVType] = [:], options: CSVReadingOptions = .init()) throws
```

## Parameters

`url`

A URL for a CSV file.

`columns`

An array of column names; Set to `nil` to use every column in the CSV file.

`rows`

A range of indices; Set to `nil` to use every row in the CSV file.

`types`

A dictionary of column names and their CSV types.
The data frame infers the types for column names that aren’t in the dictionary.

`options`

The options that tell the data frame how to read the CSV file.

## Discussion> Throws: A `CSVReadingError` instance.

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)