How to add an empty column to a dataframe?

后端 未结 11 636
自闭症患者
自闭症患者 2020-11-28 01:06

What\'s the easiest way to add an empty column to a pandas DataFrame object? The best I\'ve stumbled upon is something like

df[\'foo\'] = df.ap         


        
11条回答
  •  萌比男神i
    2020-11-28 01:38

    You can do

    df['column'] = None #This works. This will create a new column with None type
    df.column = None #This will work only when the column is already present in the dataframe 
    

提交回复
热议问题