plydata.one_table_verbs.create

class plydata.one_table_verbs.create(*args, **kwargs)[source]

Create DataFrame with columns

Similar to define, but it drops the existing columns.

Parameters
datadataframe, optional

Useful when not using the >> operator.

argsstrs, 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 type str or an interable with the same number of elements as the dataframe.

kwargsdict, optional

{name: expression} pairs.

kwargsdict, optional

{name: expression} pairs.

Examples

>>> import pandas as pd
>>> df = pd.DataFrame({'x': [1, 2, 3]})
>>> df >> create(x_sq='x**2')
   x_sq
0     1
1     4
2     9
>>> df >> create(('x*2', 'x*2'), ('x*3', 'x*3'), x_cubed='x**3')
   x*2  x*3  x_cubed
0    2    3        1
1    4    6        8
2    6    9       27
>>> df >> create('x*4')
   x*4
0    4
1    8
2   12