Data structures¶
- class datatoolbox.Datatable(*args, **kwargs)[source]¶
Datatable is derrived from pandas dataframe. Datatables contain the addition meta attribute and have autotmated unit conversions
- add(other, **kwargs)[source]¶
Method to add to datatable making use of pd.Dataframe.add but addtionally consider update of the meta data.
Parameters¶
- otherTYPE
DESCRIPTION.
- **kwargsTYPE
DESCRIPTION.
Returns¶
- tableTYPE
DESCRIPTION.
- aggregate_region(mapping, skipna=False)[source]¶
This functions added the aggregates to the table according to the provided mapping.( See datatools.mapp.regions)
Returns the result, but does not inplace add it.
- append(other, **kwargs)[source]¶
Append data to the datatable
Parameters¶
- otherdatatable
New data that will be added to the datatable.
- kwargsTYPE
Default pandas append arguments.
Returns¶
datatable
- clean()[source]¶
Clean up the dataframe to only recogniszed regions, years and numeric values. Removed columns and rows with only nan values.
Returns¶
- datatable
DESCRIPTION.
- columns_to_datetime()[source]¶
Conversion method that does convert the colume values to a pandas DatetimeIndex.
Returns¶
None.
- convert(newUnit, context=None, suffix_dict={}, **new_meta)[source]¶
Convert datatable to different unit and returns converted datatable.
Parameters¶
- newUnitstr
New unit string in which the datatable should be converted.
- contextstr, optional
Optional context (e.g. GWPAR4). The default is None.
Returns¶
- datatable
Datatable converted in the new unit.
- diff(periods=1, axis=0)[source]¶
Compute the difference between different years in the datatable Equivalent do pandas diff but return datatable.
Parameters¶
- periodsint, optional
DESCRIPTION. The default is 1.
- axisint, optional
DESCRIPTION. The default is 0.
Returns¶
- outTYPE
DESCRIPTION.
- classmethod from_excel(filepath, sheetName=None)[source]¶
Create a dataframe from a suitable excel file that is saved by datatoolbox.
Parameters¶
cls : class
- filepathstr
Path to the file.
- sheetNamestr, optional
Sheetn ame that is read in. The default is None.
Returns¶
- datatable
DESCRIPTION.
- classmethod from_multi_indexed_dataframe(df)[source]¶
Class function to create a datatable from a multi-indexed dataframe
Parameters¶
df : multi index dataframe
Returns¶
table : Datatable
- classmethod from_pyam(idf, **kwargs)[source]¶
Create a datatable from an iam dataframe.
Parameters¶
- clsdatatable class
DESCRIPTION.
- idfpyam dataframe
dataframe that contrains the data that is used to create the datatable.
- kwargsTYPE
DESCRIPTION.
Returns¶
- datatatbledatatoolbox datatable
Datatable with original unit and related meta data.
- generateTableID()[source]¶
Generates the table ID based on the meta data of the table.
Returns¶
- datatable
DESCRIPTION.
- getTableFileName()[source]¶
For compatibility to windows based sytems, the pipe symbols is replaces by double underscore for the csv filename.
- info()[source]¶
Returns information about the dataframe like shape, index and column extend and the number of non-nan entries.
Returns¶
- str
Information about datatable.
- interpolate(method='linear', add_missing_years=False)[source]¶
Interpoltate missing data between year with the option to add missing years in the columns.
Parameters¶
- methodsting, optional
Interpolation method. The default is “linear”. - linear
- add_missing_yearsbool, optional
If true, missing years within the time value range are added to the dataframe. The default is False.
Returns¶
- datatable
Interpolated dataframe.
- reduce(method='linear_piece_wise', eps=1e-06)[source]¶
Reduce data that is piecewise linear to the core data points (kinks).
- squeeze_index_to_attrs()[source]¶
Does move all unique index levels to attrs.
Returns¶
- Datatable
Datatable with only index levels that are non-unique. All other levels are in attrs. This operation can be reversed with table.to_multi_index_dataframe()
- to_csv(fileName=None)[source]¶
Save the datatable to an annotated csv file.
Parameters¶
- fileNamestr, optional
Path to file. The default is None.
Returns¶
None.
- to_excel(fileName=None, sheetName='Sheet0', writer=None, append=False)[source]¶
Save datatable to excel.
Parameters¶
- fileNamestr, optional
Relative file path. If None is provide, a writer is expected. The default is None.
- sheetNamestr, optional
Sheet name that is read in. The default is “Sheet0”.
- writerpandas excel writer, optional
Pandas writer that is used instead opening a new one. The default is None.
- appendbool, optional
If true, data is appended to the writer. The default is False.
Returns¶
None.
- to_multi_index_dataframe(meta_keys=None, exclude_meta=['ID', 'creator', 'source_name', 'source_year', '_timeformat'])[source]¶
Return a new datatable with a mult-index that has all meta data assigned
Parameters¶
exclude_meta: optinal list of meta keys that should be ignored
Returns¶
- Datatable
New Datatable with multi_index and not meta data.