---
title: "init(contentsOfCSVFile:columns:rows:types:options:)"
framework: tabulardata
role: symbol
role_heading: Initializer
path: "tabulardata/dataframe/init(contentsofcsvfile:columns:rows:types:options:)"
---

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

Creates a data frame from a CSV file.

## Declaration

```swift
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

Discussion note: A CSVReadingError instance.

## See Also

### Creating a Data Frame from a CSV

- [init(csvData:columns:rows:types:options:)](tabulardata/dataframe/init(csvdata:columns:rows:types:options:).md)
- [CSVType](tabulardata/csvtype.md)
- [CSVReadingOptions](tabulardata/csvreadingoptions.md)
