Class CSV
java.lang.Object
smile.io.CSV
Reads and writes files in variations of the Comma Separated Value
(CSV) format.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionSets the charset.inferSchema(Reader reader, int limit) Infer the schema from the top n rows.Reads a CSV file.Reads a limited number of records from a CSV file.Reads a CSV file.Reads a limited number of records from a CSV file.schema(StructType schema) Sets the schema.voidWrites the data frame to a csv file with UTF-8 encoding.
-
Constructor Details
-
CSV
public CSV()Constructor. Standard Comma Separated Value format, as for RFC4180 but allowing empty lines. -
CSV
public CSV(org.apache.commons.csv.CSVFormat format) Constructor.- Parameters:
format- the CSV file format.
-
-
Method Details
-
schema
Sets the schema.- Parameters:
schema- the data schema.- Returns:
- this object.
-
charset
-
read
Reads a CSV file.- Parameters:
path- the input file path.- Returns:
- the data frame.
- Throws:
IOException- when fails to read the file.URISyntaxException- when the file path syntax is wrong.
-
read
Reads a limited number of records from a CSV file.- Parameters:
path- the input file path.limit- the number of records to read.- Returns:
- the data frame.
- Throws:
IOException- when fails to read the file.URISyntaxException- when the file path syntax is wrong.
-
read
Reads a CSV file.- Parameters:
path- the input file path.- Returns:
- the data frame.
- Throws:
IOException- when fails to read the file.
-
read
Reads a limited number of records from a CSV file.- Parameters:
path- the input file path.limit- the number of records to read.- Returns:
- the data frame.
- Throws:
IOException- when fails to read the file.
-
inferSchema
Infer the schema from the top n rows.- Infer type of each row.
- Merge row types to find common type
- String type by default.
- Parameters:
reader- the file reader.limit- the number of records to read.- Returns:
- the data frame.
- Throws:
IOException- when fails to read the file.
-
write
Writes the data frame to a csv file with UTF-8 encoding.- Parameters:
data- the data frame.path- the output file path.- Throws:
IOException- when fails to write the file.
-