chemistry_tools.formulae.dataarray
Attention
This module has the following additional requirements:
cawdrey>=0.5.0 mathematical>=0.5.1 pyparsing>=2.4.6 tabulate>=0.8.9
These can be installed as follows:
python -m pip install chemistry-tools[formulae]
Provides a base class which can output data as a pandas.DataFrame
,
to CSV, or as a pretty-printed table in a variety of formats.
-
class
DataArray
(formula, data)[source] Bases:
FrozenOrderedDict
A class which can output data as a
pandas.DataFrame
, to CSV, or as a pretty-printed table in a variety of formats.To use this class it must first be subclassed. Subclasses must implement
as_array()
which handles the conversion of the data to a list of lists of values.- Parameters
Attributes:
Methods:
__contains__
(key)Return
key in self
.__eq__
(other)Return
self == other
.__getitem__
(key)Return
self[key]
.__iter__
()Iterates over the dictionary’s keys.
__len__
()Returns the number of keys in the dictionary.
__repr__
()Return a string representation of the
DataArray
.__str__
()Return
str(self)
.as_array
(sort_by[, reverse])Must be implemented in subclasses to hand the conversion of the data to a list of lists of values.
as_csv
(*args[, sep])Returns the data as a CSV formatted string.
as_dataframe
(*args, **kwargs)Returns the isotope distribution data as a
pandas.DataFrame
.as_table
(*args, **kwargs)Returns the isotope distribution data as a table using tabulate.
copy
(*args, **kwargs)Return a copy of the
FrozenOrderedDict
.fromkeys
(iterable[, value])Create a new dictionary with keys from iterable and values set to value.
get
(k[, default])Return the value for
k
ifk
is in the dictionary, elsedefault
.items
()Returns a set-like object providing a view on the
FrozenOrderedDict
's items.keys
()Returns a set-like object providing a view on the
FrozenOrderedDict
's keys.values
()Returns an object providing a view on the
FrozenOrderedDict
's values.-
__class_getitem__
= <bound method GenericAlias of <class 'chemistry_tools.formulae.dataarray.DataArray'>> Type:
MethodType
-
__getitem__
(key) Return
self[key]
.- Parameters
key (
~KT
)- Return type
~VT
-
abstract
as_array
(sort_by, reverse=False)[source] Must be implemented in subclasses to hand the conversion of the data to a list of lists of values.
-
as_csv
(*args, sep=',', **kwargs)[source] Returns the data as a CSV formatted string.
- Parameters
*args – Arguments passed to
as_array()
.sep (
str
) – The separator for the CSV data. Default','
.**kwargs – Additional keyword arguments passed to
as_array()
.
- Return type
-
as_dataframe
(*args, **kwargs)[source] Returns the isotope distribution data as a
pandas.DataFrame
.Any arguments taken by
as_array()
can also be used here.- Return type
-
as_table
(*args, **kwargs)[source] Returns the isotope distribution data as a table using tabulate.
Any arguments taken by
as_array()
can also be used here.Additionally, any valid keyword argument for
tabulate.tabulate()
can be used.- Return type
-
copy
(*args, **kwargs) Return a copy of the
FrozenOrderedDict
.- Parameters
args
kwargs
-
classmethod
fromkeys
(iterable, value=None) Create a new dictionary with keys from iterable and values set to value.
- Return type
FrozenBase
[~KT
,~VT
]
-
get
(k, default=None) Return the value for
k
ifk
is in the dictionary, elsedefault
.- Parameters
k – The key to return the value for.
default – The value to return if
key
is not in the dictionary. DefaultNone
.
-
items
() Returns a set-like object providing a view on the
FrozenOrderedDict
's items.- Return type
AbstractSet
[Tuple
[~KT
,~VT
]]
-
keys
() Returns a set-like object providing a view on the
FrozenOrderedDict
's keys.- Return type
AbstractSet
[~KT
]
-
values
() Returns an object providing a view on the
FrozenOrderedDict
's values.- Return type
ValuesView
[~VT
]