plydata.one_table_verbs.rename¶
-
class
plydata.one_table_verbs.
rename
(*args, **kwargs)[source]¶ Rename columns
- Parameters
- data
dataframe
, optional Useful when not using the
>>
operator.- args
tuple
, optional A single positional argument that holds
{'new_name': 'old_name'}
pairs. This is useful if the old_name is not a valid python variable name.- kwargs
dict
, optional {new_name: 'old_name'}
pairs. If all the columns to be renamed are valid python variable names, then they can be specified as keyword arguments.
- data
Notes
If
plydata.options.modify_input_data
isTrue
,rename
will modify the original dataframe.Examples
>>> import pandas as pd >>> import numpy as np >>> x = np.array([1, 2, 3]) >>> df = pd.DataFrame({'bell': x, 'whistle': x, ... 'nail': x, 'tail': x}) >>> df >> rename(gong='bell', pin='nail') gong whistle pin tail 0 1 1 1 1 1 2 2 2 2 2 3 3 3 3 >>> df >> rename({'flap': 'tail'}, pin='nail') bell whistle pin flap 0 1 1 1 1 1 2 2 2 2 2 3 3 3 3