-
Bert Palm authored2207db3f
Dios Methods and Properies
Methods
Brief
-
copy(deep=True)
: Return a copy. See also pandas.DataFrame.copy -
copy_empty()
: Return a new DictOfSeries object, with same properties than the original. -
all(axis=0)
: Return whether all elements are True, potentially over an axis. See also pandas.DataFrame.all -
any(axis=0)
: Return whether any element is True, potentially over an axis. See also pandas.DataFrame.any -
squeeze(axis=None)
: Squeeze a 1-dimensional axis objects into scalars. See also pandas.DataFrame.squeeze -
to_df()
: Transform the Dios to a pandas.DataFrame -
to_string(kwargs)
: Return a string representation of the Dios. -
apply()
: apply the given function to every column in the dios eg. -
astype()
: Cast the data to the given data type. -
isin()
: return a boolean dios, that indicates if the corresponding value is in the given array-like -
isna()
: Return a bolean array that isTrue
if the value is a Nan-value -
notna()
: inverse ofisnan()
-
dropna()
: drop all Nan-values -
index_of()
: Return a single(!) Index that is constructed from all the indexes of the columns. -
len(Dios)
: return the number of columns the dios has.
Properties
-
columns
: Column index -
indexes
: Series of indexes of columns -
lengths
: Series of lengths of columns -
values
: A array of length of the columns, with arrays of values, as sub-arrays -
dtypes
: Series of dtypes of columns -
itype
: The index type the Dios accept -
empty
: True if the dios holds no data. Nevertheless the dios can have empty columns.
dios.DictOfSeries.copy_empty
DictOfSeries.copy_empty(columns=True)
Return a new DictOfSeries object, with same properties than the original.
If columns=True
, the copy will have the same, but empty columns like the original.
Parameter:
-
columns : bool, default True
Function to apply to each column or row.
Examples
>>> d
a | b | c | d |
===== | ==== | ===== | ===== |
0 0 | 2 5 | 4 7 | 6 0 |
1 7 | 3 6 | 5 17 | 7 1 |
2 14 | 4 7 | 6 27 | 8 2 |
3 21 | 5 8 | 7 37 | 9 3 |
4 28 | 6 9 | 8 47 | 10 4 |
>>> d.copy_empty()
Empty DictOfSeries
Columns: ['a', 'b', 'c', 'd']
>>> d.copy_empty(columns=False)
Empty DictOfSeries
Columns: []
dios.DictOfSeries.to_df
DictOfSeries.to_df()
Transform the Dios to a pandas.DataFrame. Missing common indices are filled with NaN's.
Examples
>>> d
a | b | c | d |
===== | ==== | ===== | ===== |
0 0 | 2 5 | 4 7 | 6 0 |
1 7 | 3 6 | 5 17 | 7 1 |
2 14 | 4 7 | 6 27 | 8 2 |
3 21 | 5 8 | 7 37 | 9 3 |
4 28 | 6 9 | 8 47 | 10 4 |
>>> d.to_df()
columns a b c d
0 0.0 NaN NaN NaN
1 7.0 NaN NaN NaN
2 14.0 5.0 NaN NaN
3 21.0 6.0 NaN NaN
4 28.0 7.0 7.0 NaN
5 NaN 8.0 17.0 NaN
6 NaN 9.0 27.0 0.0
7 NaN NaN 37.0 1.0
8 NaN NaN 47.0 2.0
9 NaN NaN NaN 3.0
10 NaN NaN NaN 4.0
dios.DictOfSeries.apply
DictOfSeries.apply(func, axis=0, raw=False, args=(), **kwds)
Apply the given function to every column in the dios. This is a very mighty tool to apply functions that are defined on pandas.Series to multiple columns.
Parameters:
-
func : function
Function to apply to each column or row.
-
axis : {0 or ‘index’, 1 or ‘columns’}, default 0
Axis along which the function is applied:
- 0 or ‘index’: apply function to each column.
-
1 or ‘columns’: apply function to each row. not implemented
-
raw : bool, default False
Determines if row or column is passed as a Series or ndarray object:
-
False
: passes each row or column as a Series to the function. -
True
: the passed function will receive ndarray objects instead. If you are just applying a NumPy reduction function this will achieve much better performance.
-
-
args : tuple
Positional arguments to pass to func in addition to the array/series.
-
**kwds
Additional keyword arguments to pass as keywords arguments to func.
Returns: Series or DataFrame
- Result of applying func along the given axis of the DataFrame.
See also:
Examples
>>> d
a | b | c | d |
===== | ==== | ===== | ===== |
0 0 | 2 5 | 4 7 | 6 0 |
1 7 | 3 6 | 5 17 | 7 1 |
2 14 | 4 7 | 6 27 | 8 2 |
3 21 | 5 8 | 7 37 | 9 3 |
4 28 | 6 9 | 8 47 | 10 4 |
>>> d.apply(max)
columns
a 28
b 9
c 47
d 4
dtype: int64
>>> d.apply(pd.Series.count)
columns
a 5
b 5
c 5
d 5
dtype: int64
>>> d.apply(pd.Series.value_counts, normalize=True)
a | b | c | d |
======= | ====== | ======= | ====== |
7 0.2 | 7 0.2 | 7 0.2 | 4 0.2 |
14 0.2 | 6 0.2 | 37 0.2 | 3 0.2 |
21 0.2 | 5 0.2 | 47 0.2 | 2 0.2 |
28 0.2 | 9 0.2 | 27 0.2 | 1 0.2 |
0 0.2 | 8 0.2 | 17 0.2 | 0 0.2 |
>>> d.apply(lambda s : 'high' if max(s) > 10 else 'low')
columns
a high
b low
c high
d low
dtype: object
>>> d.apply(lambda s : ('high', max(s)) if min(s) > (max(s)//2) else ('low',max(s)))
a | b | c | d |
====== | ======= | ====== | ====== |
0 low | 0 high | 0 low | 0 low |
1 28 | 1 9 | 1 47 | 1 4 |
dios.DictOfSeries.index_of
DictOfSeries.index_of(method='union)
Aggregate indexes of all columns to one index by a given method.
Parameters:
-
method : str, default "union"
Aggregation method
- 'all' : get all indices from all columns
- 'shared' : get indices that are present in every columns
- 'uniques' : get indices that are only present in a single column
- 'union' : alias for 'all'
- 'intersection' : alias for 'shared'
- 'non-uniques' : get indices that are present in more than one column
-
axis : {0 or ‘index’, 1 or ‘columns’}, default 0
Returns: pandas.Index
The aggregated Index
Examples
>>> di
a | b | c | d |
===== | ====== | ====== | ===== |
0 0 | 2 5 | 4 7 | 6 0 |
1 7 | 3 6 | 5 17 | 7 1 |
2 14 | 4 7 | 6 27 | 8 2 |
3 21 | 5 8 | 7 37 | 9 3 |
4 28 | 6 9 | 8 47 | 10 4 |
5 35 | 7 10 | 9 57 | 11 5 |
6 42 | 8 11 | 10 67 | 12 6 |
7 49 | 9 12 | 11 77 | 13 7 |
8 56 | 10 13 | 12 87 | 14 8 |
9 63 | 11 14 | 13 97 | 15 9 |
>>> di.index_of()
RangeIndex(start=0, stop=16, step=1)
>>> di.index_of("shared")
Int64Index([6, 7, 8, 9], dtype='int64')
>>> di.index_of("uniques")
Int64Index([0, 1, 14, 15], dtype='int64')