DictOfSeries#
- class DictOfSeries(*args, **kwargs)[source]#
Bases:
DictOfPandas
Attributes Summary
Dictionary of global attributes of this dataset.
Indicator whether DictOfSeries is empty.
Methods Summary
astype
(dtype)Cast a DictOfSeries object to the specified
dtype
clear
()copy
()flatten
([promote_index, multiindex])Promote dataframe columns to first level columns.
fromkeys
(iterable[, value])get
(k[,d])items
()keys
()pop
(k[,d])If key is not found, d is returned if given, otherwise KeyError is raised.
popitem
()as a 2-tuple; but raise KeyError if D is empty.
setdefault
(k[,d])- rtype:
Index
to_dataframe
([how])Transform DictOfPandas to a pandas.DataFrame.
to_pandas
([how, fill_value, multiindex])Transform DictOfSeries to a pandas.DataFrame.
to_string
([max_rows, min_rows, ...])Render a DictOfPandas to a console-friendly tabular output.
- rtype:
Index
update
([E, ]**F)If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
values
()Attributes Documentation
- attrs#
Dictionary of global attributes of this dataset.
- columns#
- empty#
Indicator whether DictOfSeries is empty.
True if DictOfSeries is entirely empty (no items) or all items are empty themselves.
Notes
To only check if DictOfSeries has no items use
len
orbool
buildins.Examples
>>> from saqc import DictOfSeries >>> di1 = DictOfSeries() >>> di1.empty True
A DictOfSeries is also considered empty if all items within it are empty
>>> di2 = DictOfSeries(a=pd.Series(dtype=float), b=pd.Series(dtype='O')) >>> assert di2['a'].empty and di2['b'].empty >>> di2.empty True
To differentiate between a DictOfSeries with no items and a DictOfSeries with empty items use the buildin functions len or bool
>>> len(di1) 0 >>> bool(di1) False >>> len(di2) 2 >>> bool(di2) True
- Return type:
bool
Methods Documentation
- astype(dtype)[source]#
Cast a DictOfSeries object to the specified
dtype
- Parameters:
dtype (data type to cast the entire object to.) –
- Return type:
- clear() None. Remove all items from D. #
- copy()#
- flatten(promote_index=False, multiindex=False)#
Promote dataframe columns to first level columns.
Prepend column names of an inner dataframe with the key/column name of the outer frame.
- Parameters:
promote_index (bool, default False) – Makes pandas.Series from items of type pandas.Index if True. Every item of the resulting DictOfPandas be a series then.
multiindex (bool, default False) – If True, the result column names will be pd.MultiIndex like, if False, unique column names will be generated from the different levels of column indices.
- Return type:
DictOfPandas
Examples
>>> from fancy_collections import DictOfPandas >>> frame = DictOfPandas(key0=pd.DataFrame({'c0': [1, 1], "c1": [2, 2]})) >>> frame key0 | ========= | c0 c1 | 0 1 2 | 1 1 2 |
>>> frame.flatten() key0_c0 | key0_c1 | ======= | ======= | 0 1 | 0 2 | 1 1 | 1 2 |
>>> frame.flatten(multiindex=True) ('key0', 'c0') | ('key0', 'c1') | ============== | ============== | 0 1 | 0 2 | 1 1 | 1 2 |
- classmethod fromkeys(iterable, value=None)#
- get(k[, d]) D[k] if k in D, else d. d defaults to None. #
- items() a set-like object providing a view on D's items #
- keys() a set-like object providing a view on D's keys #
- pop(k[, d]) v, remove specified key and return the corresponding value. #
If key is not found, d is returned if given, otherwise KeyError is raised.
- popitem() (k, v), remove and return some (key, value) pair #
as a 2-tuple; but raise KeyError if D is empty.
- setdefault(k[, d]) D.get(k,d), also set D[k]=d if k not in D #
- Return type:
Index
- to_dataframe(how='outer')#
Transform DictOfPandas to a pandas.DataFrame. :rtype:
DataFrame
Deprecated since version 0.2.0: use DictOfPandas.to_pandas() instead.
- to_pandas(how='outer', fill_value=nan, multiindex=False)#
Transform DictOfSeries to a pandas.DataFrame.
Because a pandas.DataFrame can not handle data of different length, but DictOfSeries can, the missing data is filled with NaNs or is dropped, depending on the keyword how.
- Parameters:
how ({'outer', 'inner'}, default 'outer') –
Defines how the resulting DataFrame index is generated.
outer
The resulting DataFrame index is the combinationof all indices merged together. If a column misses values at new index locations, NaN’s are filled.
inner
Only indices that are present in all columns are usedfor the resulting index. Filling logic is not needed, but values are dropped, if a column has indices that are not known to all other columns.
- Returns:
frame
- Return type:
pandas.DataFrame
Examples
Missing data locations are filled with NaN’s
>>> from saqc import DictOfSeries >>> a = pd.Series(11, index=range(2)) >>> b = pd.Series(22, index=range(3)) >>> c = pd.Series(33, index=range(1,9,3)) >>> di = DictOfSeries(a=a, b=b, c=c) >>> di a | b | c | ===== | ===== | ===== | 0 11 | 0 22 | 1 33 | 1 11 | 1 22 | 4 33 | | 2 22 | 7 33 |
>>> di.to_pandas() a b c 0 11.0 22.0 NaN 1 11.0 22.0 33.0 2 NaN 22.0 NaN 4 NaN NaN 33.0 7 NaN NaN 33.0
or is dropped if how=’inner’
>>> di.to_pandas(how='inner') a b c 1 11 22 33
- to_string(max_rows=None, min_rows=None, show_df_column_names=True)#
Render a DictOfPandas to a console-friendly tabular output.
- Parameters:
max_rows (int, optional) – Maximum number of rows to display in the console.
min_rows (int, optional) – The number of rows to display in the console in a truncated repr (when number of rows is above max_rows).
show_df_column_names (bool, default True) – Prints column names of dataframes if True, otherwise colum names are hidden.
- Returns:
Returns the result as a string.
- Return type:
str
- union_index()#
- Return type:
Index
- update([E, ]**F) None. Update D from mapping/iterable E and F. #
If E present and has a .keys() method, does: for k in E: D[k] = E[k] If E present and lacks .keys() method, does: for (k, v) in E: D[k] = v In either case, this is followed by: for k, v in F.items(): D[k] = v
- values() an object providing a view on D's values #