plydata.one_table_verbs.define¶
-
class
plydata.one_table_verbs.define(*args, **kwargs)[source]¶ Add column to DataFrame
- Parameters
- data
dataframe, optional Useful when not using the
>>operator.- args
strs,tuples, optional Expressions or
(name, expression)pairs. This should be used when the name is not a valid python variable name. The expression should be of typestror an interable with the same number of elements as the dataframe.- kwargs
dict, optional {name: expression}pairs.
- data
Notes
If
plydata.options.modify_input_dataisTrue,definewill modify the original dataframe.Examples
>>> import pandas as pd >>> df = pd.DataFrame({'x': [1, 2, 3]}) >>> df >> define(x_sq='x**2') x x_sq 0 1 1 1 2 4 2 3 9 >>> df >> define(('x*2', 'x*2'), ('x*3', 'x*3'), x_cubed='x**3') x x*2 x*3 x_cubed 0 1 2 3 1 1 2 4 6 8 2 3 6 9 27 >>> df >> define('x*4') x x*4 0 1 4 1 2 8 2 3 12