earthkit.data.data.csv

Classes

CSVData

Represent data in the CSV format.

Module Contents

class earthkit.data.data.csv.CSVData(source_or_reader)

Bases: earthkit.data.data.source.SourceData

Represent data in the CSV format.

CSV (Comma-Separated Values) is a simple file format used to store tabular data, such as a spreadsheet or database.

CSV data can be converted with the following methods:

property available_types

Return the list of available types that this data object can be converted to.

Type:

list[str]

describe()

Provide a description of the CSV data.

Returns:

A DataDescriber object containing a description of the CSV data.

Return type:

earthkit.data.utils.summary.DataDescriber

is_stream()

Return False as this data object is not a stream.

to(to_type, *args, **kwargs)

Convert the data object into another type.

Parameters:
  • to_type (str or Any) – The type to convert to. It can be a str or an object that can be used to determine the target type. In the latter case, the object can be an earthkit-data object or an object that earthkit-data supports as an input. If no suitable conversion method is found, a NotImplementedError will be raised.

  • *args – Positional arguments to pass to the conversion method.

  • **kwargs – Keyword arguments to pass to the conversion method.

Returns:

The converted data object in the target type.

Return type:

Any

Raises:

NotImplementedError – If conversion to the target type is not implemented.

to_array(*args, **kwargs)

Convert into an array of a given array-like type.

This method is not implemented for this data object and raises NotImplementedError.

to_featurelist(*args, **kwargs)

Convert into a featurelist.

This method is not implemented for this data object and raises NotImplementedError.

to_fieldlist(*args, **kwargs)

Convert into a fieldlist.

This method is not implemented for this data object and raises NotImplementedError.

to_geopandas(**kwargs)

Convert into a GeoPandas dataframe.

This method is not implemented for this data object and raises NotImplementedError.

to_numpy(*args, **kwargs)

Convert into a numpy array.

This method is not implemented for this data object and raises NotImplementedError.

to_pandas(comment='#', pandas_read_csv_kwargs=None)

Convert into a Pandas DataFrame.

Parameters:
  • comment (str) – Character that represents a comment line in the CSV file. This value is ignored if the comment character is defined in pandas_read_csv_kwargs.

  • pandas_read_csv_kwargs (dict, None, optional) – Keyword arguments passed to pandas.read_csv(). This is used for safe parsing of kwargs via intermediate methods.

Returns:

A Pandas DataFrame containing the CSV data.

Return type:

pandas.DataFrame

to_target(target, *args, **kwargs)

Write the data to a target.

Parameters:
  • target (str) – The target to write to. See to_target() for more details on the supported targets.

  • *args – Positional arguments to pass to the to_target()

  • **kwargs – Keyword arguments to pass to the to_target(). Cannot specify data in kwargs.

See also

to_target()

to_value(*args, **kwargs)

Convert into a single value.

This method is not implemented for this data object and raises NotImplementedError.

to_xarray(pandas_read_csv_kwargs=None, **kwargs)

Convert into an Xarray dataset.

First, the data is converted into a pandas.DataFrame with pandas.read_csv(), then pandas.DataFrame.to_xarray() is called to generate the xarray object.

Parameters:
Returns:

An Xarray dataset containing the CSV data.

Return type:

xarray.Dataset