Wolfram Function Repository
Instant-use add-on functions for the Wolfram Language
Function Repository Resource:
Import CSV and TSV files to datasets
ResourceFunction["ImportCSVToDataset"][fname,"format"] imports the file fname into a Dataset, assuming the file is in the specified format. |
"ColumnNames" | True | whether to treat the first row as column names |
"RowNames" | False | whether to treat the first column as row names |
CharacterEncoding | "UTF8ISOLatin1" | raw character encoding used in the file |
"CurrencyTokens" | {{"$", "£", "¥", "€"}, {"c", "¢", "p", "F"}} | currency units to be skipped when importing numerical values |
"DateStringFormat" | None | date format, given as a DateString specification |
"FieldSeparators" | "," | field separator |
"FillRows" | Automatic | whether to fill rows to the max column length |
"HeaderLines" | 0 | number of lines to assume as headers |
"IgnoreEmptyLines" | False | whether to ignore empty lines |
Method | Import | importing method to use |
"NumberPoint" | "." | decimal point string |
"Numeric" | Automatic | whether to import data fields as numbers if possible |
"SkipLines" | 0 | number of lines to skip at the beginning of the file |
Here, a CSV file from GitHub is imported:
In[1]:= |
|
Out[1]= |
|
If the first argument is a CSV string (not a file name or URL), then that string can be imported by specifying ImportString as the importing method:
In[2]:= |
|
Out[3]= |
|
Treat the first row and column of the file as ordinary data:
In[4]:= |
|
Out[4]= |
|
Treat both the first row and column of the array as names:
In[5]:= |
|
Out[5]= |
|
CSV files can use field separators other than commas, such as ";":
In[6]:= |
|
Import using the default field separator:
In[7]:= |
|
Out[7]= |
|
Importing using a proper field separator:
In[8]:= |
|
Out[8]= |
|
ImportCSVToDataset will give similar results to Import with "Dataset" specified as the result type:
In[9]:= |
|
Out[9]= |
|
A dataset exported as CSV can be imported back to a dataset:
In[10]:= |
|
Export the dataset to a temporary location as a CSV file:
In[11]:= |
|
Use ImportCSVToDataset to bring it back to a dataset:
In[12]:= |
|
Out[12]= |
|
Importing CSV files as TSV produces a one-column dataset:
In[13]:= |
|
Out[13]= |
|
This work is licensed under a Creative Commons Attribution 4.0 International License