real panda
June 17, 2019 * Python Programming

Pandas - Adding new static columns

Adding a static constant data column to any Pandas dataframe is simple. As many number of columns can be created by just assigning a value. The constant value is assigned to every row.

Add new data columns

import pandas as pd

#load data
df1 = pd.read_csv(
    'data_deposits.csv'
)
print(df1.head(3))

#data column with constant value
df1['student'] = False
print(df1.head(3))
--[df1 original data]-------------------------------
  firstname lastname    city  age  deposit
0    Herman  Sanchez   Miami   52     9300
1      Phil   Parker   Miami   45     5010
2    Bradie  Garnett  Denver   36     6300

--[df1 new static data column]-----------------------
  firstname lastname    city  age  deposit student
0    Herman  Sanchez   Miami   52     9300   False
1      Phil   Parker   Miami   45     5010   False
2    Bradie  Garnett  Denver   36     6300   False
-------------------------------------------------------

Here a boolean column was created and all the rows were assigned the same 'False' initial value.