[ SciPy v1.12.0 Manual  ](../../index.html)

  * [ Installing ](https://scipy.org/install/)
  * [ User Guide ](../../tutorial/index.html)
  * [ API reference ](../index.html)
  * [ Building from source ](../../building/index.html)
  * [ Development ](../../dev/index.html)
  * [ Release notes ](../../release.html)

__ __ __

1.12.0

  * [ __ GitHub  ](https://github.com/scipy/scipy "GitHub")
  * [ __ Twitter  ](https://twitter.com/SciPy_team "Twitter")

__

  * [ scipy ](../main_namespace.html)
  * [ scipy.cluster ](../cluster.html)
  * [ scipy.constants ](../constants.html)
  * [ scipy.datasets ](../datasets.html)
  * [ scipy.fft ](../fft.html)
  * [ scipy.fftpack ](../fftpack.html)
  * [ scipy.integrate ](../integrate.html)
  * [ scipy.interpolate ](../interpolate.html)
  * [ scipy.io ](../io.html)
  * [ scipy.linalg ](../linalg.html)
  * [ scipy.misc ](../misc.html)
  * [ scipy.ndimage ](../ndimage.html)
  * [ scipy.odr ](../odr.html)
  * [ scipy.optimize ](../optimize.html)
  * [ scipy.signal ](../signal.html)
  * [ scipy.sparse ](../sparse.html)
  * [ scipy.spatial ](../spatial.html)
  * [ scipy.special ](../special.html)
  * [ scipy.stats ](../stats.html)

__ On this page

  * ` loadarff  `

#  scipy.io.arff.loadarff  #

scipy.io.arff.  loadarff  (  _ f  _ )  [ [source]
](https://github.com/scipy/scipy/blob/v1.12.0/scipy/io/arff/_arffread.py#L729-L807)
#

    

Read an arff file.

The data is returned as a record array, which can be accessed much like a
dictionary of NumPy arrays. For example, if one of the attributes is called
âpressureâ, then its first 10 data points can be accessed from the ` data
` record array like so: ` data['pressure'][0:10]  `

Parameters  :

    

**f** file-like or str

    

File-like object to read from, or filename to open.

Returns  :

    

**data** record array

    

The data of the arff file, accessible by attribute names.

**meta** [ ` MetaData  ` ](scipy.io.arff.MetaData.html#scipy.io.arff.MetaData
"scipy.io.arff.MetaData")

    

Contains information about the arff file such as name and type of attributes,
the relation (name of the dataset), etc.

Raises  :

    

ParseArffError

    

This is raised if the given file is not ARFF-formatted.

NotImplementedError

    

The ARFF file has an attribute which is not supported yet.

Notes

This function should be able to read most arff files. Not implemented
functionality include:

  * date type attributes 

  * string type attributes 

It can read files with numeric and nominal attributes. It cannot read files
with sparse data ({} in the file). However, this function can read files with
missing data (? in the file), representing the data points as NaNs.

Examples

    
    
    >>> from scipy.io import arff
    >>> from io import StringIO
    >>> content = """
    ... @relation foo
    ... @attribute width  numeric
    ... @attribute height numeric
    ... @attribute color  {red,green,blue,yellow,black}
    ... @data
    ... 5.0,3.25,blue
    ... 4.5,3.75,green
    ... 3.0,4.00,red
    ... """
    >>> f = StringIO(content)
    >>> data, meta = arff.loadarff(f)
    >>> data
    array([(5.0, 3.25, 'blue'), (4.5, 3.75, 'green'), (3.0, 4.0, 'red')],
          dtype=[('width', '<f8'), ('height', '<f8'), ('color', '|S6')])
    >>> meta
    Dataset: foo
        width's type is numeric
        height's type is numeric
        color's type is nominal, range is ('red', 'green', 'blue', 'yellow', 'black')
    

[ __ previous  scipy.io.wavfile.WavFileWarning
](scipy.io.wavfile.WavFileWarning.html "previous page") [ next
scipy.io.arff.MetaData  __ ](scipy.io.arff.MetaData.html "next page")

© Copyright 2008-2024, The SciPy community.  

Created using [ Sphinx ](http://sphinx-doc.org/) 7.2.6.