add_columns_to_dataframe
- trashpanda.add_columns_to_dataframe(frame_to_enlarge: pandas.core.frame.DataFrame, column_names: List[str], fill_value: Optional[Any] = None) pandas.core.frame.DataFrame
Adds columns to a dataframe. By default the columns are filled with pandas.NA values if no fill_value is explizitly given.
- Parameters
frame_to_enlarge (DataFrame) – pandas.DataFrame which gets additional columns.
column_names (List[str]) – Names of additional columns to create.
fill_value (Optional[Any]) – Value which will fill the newly created columns. Default pandas.NA
- Returns
DataFrame
Examples
>>> from pandas import DataFrame >>> import numpy >>> sample_series = DataFrame(numpy.arange(4).reshape((2,2)), columns=["b", "a"]) >>> sample_series b a 0 0 1 1 2 3 >>> add_columns_to_dataframe(sample_series, ["d", "c"], "+") b a d c 0 0 1 + + 1 2 3 + + >>> add_columns_to_dataframe(sample_series, ["d", "c"]) b a d c 0 0 1 NaN NaN 1 2 3 NaN NaN