Skip to content
Advertisement

Create new column in Pandas and fill down with a specific value

I have a dataset, df, where I would like to create a new column to my dataset and fill down this column with a specific value

Data

JavaScript

Desired

JavaScript

Doing

JavaScript

However, this is not actually creating the new column. Any suggestion is appreciated.

Advertisement

Answer

Simply try: df['plan'] = '21'

Or df['plan'] = 21 if an integer type is wanted.

Pandas will automatically broadcast scalars to all rows.

User contributions licensed under: CC BY-SA
2 People found this is helpful
Advertisement