janitor.add_columns(df: pandas.core.frame.DataFrame, fill_remaining: bool = False, **kwargs) → pandas.core.frame.DataFrame[source]

Add multiple columns to the dataframe.

This method does not mutate the original DataFrame.

Method to augment add_column with ability to add multiple columns in one go. This replaces the need for multiple add_column calls.

Usage is through supplying kwargs where the key is the col name and the values correspond to the values of the new DataFrame column.

Values passed can be scalar or iterable (list, ndarray, etc.)

Usage example:

x = 3
y = np.arange(0, 10)
df = pd.DataFrame(...).add_columns(x=x, y=y)
  • df – A pandas dataframe.

  • fill_remaining – If value is a tuple or list that is smaller than the number of rows in the DataFrame, repeat the list or tuple (R-style) to the end of the DataFrame. (Passed to add_column)

  • kwargs – column, value pairs which are looped through in add_column calls.


A pandas DataFrame with added columns.