Introduction¶
daul is a collection of utilities for dealing with pandas’ DataFrames, numpy arrays, and files.
One of the purpose of daul is to allow constructive updates of pandas.DataFrame using utilities in daul.pandas_utils to encourage programming in functional style. As use of some of these functions is rather frequent, they are also incorporated in abbreviated form in the daul.shortcuts module.
Example¶
Let us have a
DataFramewith a simple content.>>> import pandas as pd >>> adf = pd.DataFrame({'x': [0, 1]}) >>> adf x 0 0 1 1Now, using the utils in
daul.pandas_utils, we will constructively update the column, meaning that we will create a new frame with the updated column.>>> from daul import pandas_utils as pdu >>> bdf = pdu.update_column(adf, 'x', adf['x'] + 1)Now, let us take a look at the frame bdf:
>>> bdf x 0 1 1 2We see that bdf has the desired content.
Note, however, that adf remains the same.
>>> adf x 0 0 1 1As this update operation is common, it is also part of the
daul.shortcutsmodule.>>> from daul import shortcuts as ds >>> cdf = ds.pduc(adf, 'x', adf['x'] + 2) >>> cdf x 0 2 1 3When implementing some functionality, we often see a series of such assignments.
For instance:
>>> ddf = adf >>> ddf = ds.pduc(ddf, 'x', ddf['x'] + 1) >>> ddf = ds.pduc(ddf, 'y', ddf['x'] * 2) >>> ddf x y 0 1 2 1 2 4Note, however, that adf still remains the same:
>>> adf x 0 0 1 1
However, daul also contains utilities that can be of general use, e.g., for dealing with nested DataFrames (Inner frames), transformations of DataFrames (Transformations), and many others.
The daul.numpy_utils and daul.file_utils are modules with less functions, they, nevertheless, contain some potentially useful utilities.