8.1.1.3. pandasdmx.writer package¶
8.1.1.3.1. Submodules¶
8.1.1.3.2. pandasdmx.writer.data2pandas module¶
This module contains a writer class that writes a generic data message to pandas dataframes or series.
-
class
pandasdmx.writer.data2pandas.
Writer
(msg, **kwargs)[source]¶ Bases:
pandasdmx.writer.BaseWriter
-
iter_pd_series
(iter_series, dim_at_obs, dtype, attributes, reverse_obs, fromfreq, parse_time)[source]¶
-
write
(source=None, asframe=True, dtype=<class 'numpy.float64'>, attributes='', reverse_obs=False, fromfreq=False, parse_time=True)[source]¶ Transfform a
pandasdmx.model.DataMessage
instance to a pandas DataFrame or iterator over pandas Series.Parameters: - source (pandasdmx.model.DataMessage) – a pandasdmx.model.DataSet or iterator of pandasdmx.model.Series
- asframe (bool) – if True, merge the series of values and/or attributes into one or two multi-indexed pandas.DataFrame(s), otherwise return an iterator of pandas.Series. (default: True)
- dtype (str, NP.dtype, None) – datatype for values. Defaults to NP.float64 if None, do not return the values of a series. In this case, attributes must not be an empty string so that some attribute is returned.
- attributes (str, None) – string determining which attributes, if any, should be returned in separate series or a separate DataFrame. Allowed values: ‘’, ‘o’, ‘s’, ‘g’, ‘d’ or any combination thereof such as ‘os’, ‘go’. Defaults to ‘’. Where ‘o’, ‘s’, ‘g’, and ‘d’ mean that attributes at observation, series, group and dataset level will be returned as members of per-observation namedtuples.
- reverse_obs (bool) – if True, return observations in reverse order. Default: False
- fromfreq (bool) – if True, extrapolate time periods from the first item and FREQ dimension. Default: False
- parse_time (bool) – if True (default), try to generate datetime index, provided that
dim_at_obs is ‘TIME’ or ‘TIME_PERIOD’. Otherwise,
parse_time
is ignored. If False, always generate index of strings. Set it to False to increase performance and avoid parsing errors for exotic date-time formats unsupported by pandas.
-
8.1.1.3.3. pandasdmx.writer.structure2pd module¶
This module contains a writer class that writes artefacts from a StructureMessage to pandas dataFrames. This is useful, e.g., to visualize codes from a codelist or concepts from a concept scheme. The writer is more general though: It can output any collection of nameable SDMX objects.
-
class
pandasdmx.writer.structure2pd.
Writer
(msg, **kwargs)[source]¶ Bases:
pandasdmx.writer.BaseWriter
-
write
(source=None, rows=None, **kwargs)[source]¶ Transfform structural metadata, i.e. codelists, concept-schemes, lists of dataflow definitions or category-schemes from a
pandasdmx.model.StructureMessage
instance into a pandas DataFrame. This method is called bypandasdmx.api.Response.write()
. It is not part of the public-facing API. Yet, certain kwargs are propagated from there.Parameters: - source (pandasdmx.model.StructureMessage) – a
pandasdmx.model.StructureMessage
instance. - rows (str) – sets the desired content to be extracted from the StructureMessage. Must be a name of an attribute of the StructureMessage. The attribute must be an instance of dict whose keys are strings. These will be interpreted as ID’s and used for the MultiIndex of the DataFrame to be returned. Values can be either instances of dict such as for codelists and categoryscheme, or simple nameable objects such as for dataflows. In the latter case, the DataFrame will have a flat index. (default: depends on content found in Message. Common is ‘codelist’)
- columns (str, list) – if str, it denotes the attribute of attributes of the values (nameable SDMX objects such as Code or ConceptScheme) that will be stored in the DataFrame. If a list, it must contain strings that are valid attibute values. Defaults to: [‘name’, ‘description’]
- constraint (bool) – if True (default), apply any constraints to codelists, i.e. only the codes allowed by the constraints attached to the DSD, dataflow and provision agreements contained in the message are written to the DataFrame. Otherwise, the entire codelist is written.
- lang (str) – locale identifier. Specifies the preferred language for international strings such as names. Default is ‘en’.
- source (pandasdmx.model.StructureMessage) – a
-