Skip to main content
`Ctrl`+`K`

# read_ecsv

astropy.io.misc.ecsv.read_ecsv(input_file, *, encoding='utf-8', engine='io.ascii', null_values=None)

  Read an ECSV (Enhanced Character Separated Values) file and return an Astropy Table.

  Parameters:
    input_file `python:str`, `os.PathLike`, `io.BytesIO`, `io.StringIO`, `Iterable`[`python:str`]

      The ECSV input to read. This can be a file path, a file-like object, a string containing the file contents, or an iterable of strings representing lines of the file. Note that providing `io.StringIO` or an iterable of strings will be less memory efficient, as it will be converted to a bytes stream.

    encoding `python:str`, optional

      The encoding to use when reading the file. Default is “utf-8”.

    engine `python:str`, optional

      The engine to use for reading the CSV data. Default is “io.ascii”, which uses astropy to read the CSV data. Other built-in options are “pyarrow” and “pandas”. The “pyarrow” engine is optimized for performance and can handle large datasets efficiently. The “pandas” engine uses the pandas CSV reader, which is also faster than the default “io.ascii” engine.

    null_values `python:list` of `python:str` or `python:None`, optional

      List of string values to interpret as null/missing values. Default is [“”]. The ECSV standard requires the null values are represented as empty strings in the CSV data, but this allows reading non-compliant ECSV files. A notable example are the Gaia source download files which are ECSV but use “null”.

  Returns:
    table `astropy.table.Table`

      The table read from the ECSV file.

  Raises:
    `astropy.io.ascii.core.InconsistentTableError`

      If the column names in the ECSV header do not match the column names in the CSV data.

  Notes

  - The function handles various input types, including file paths, file-like objects, and in-memory strings or lists of strings.

  - Metadata and column attributes (such as unit, description, format, and meta) are transferred from the ECSV header to the resulting Table object.

  - Handles JSON-encoded data and ensures appropriate numpy dtypes for columns.