How to add Empty Column to Dataframe in Pandas?

25 Oct, 2021
In dataFrames, Empty columns are defined and represented with NaN Value(Not a Number value or undefined or unrepresentable value). There are various methods to add Empty Column to Pandas Dataframe.
Method 1: Using the Assignment Operator.
This method is used to forcefully assign any column a null or NaN value. 
Python3
# import required librariesimport numpy as npimport pandas as pd  # create a DataframeMydataframe = pd.DataFrame({'FirstName': ['Vipul',                                          'Ashish',                                          'Milan'],                            "Age": [21,22,23]})# show the dataframeprint("\n\n---Original Dataframe---\n",       Mydataframe)  # add an empty columnsMydataframe['Gender'] = ''Mydataframe['Department'] = np.nan  # show the dataframeprint("---Updated Dataframe---\n",       Mydataframe)
 Output:
In the above example, we are using the assignment operator to assign empty string and Null value to two newly created columns as “Gender” and “Department” respectively for pandas data frames (table). Numpy library is used to import NaN value and use its functionality.
Method 2: Using Dataframe.reindex().
This method is used to create new columns in a dataframe and assign value to these columns(if not assigned, null will be assigned automatically).Example : 
Python3
# import pandas libraryimport pandas as pd  # create a dataframeMydataframe = pd.DataFrame({'FirstName': ['Preetika',                                          'Tanya',                                          'Akshita'],                            "Age": [25,21,22]})# show the dataframeprint("---Original Dataframe---\n",      Mydataframe)  # add an empty columnsMydataframe = Mydataframe.reindex(columns = Mydataframe.columns.tolist()                                   + ['Gender','Roll Number'])  # show the dataframeprint("\n\n---Updated Dataframe---\n",      Mydataframe)
Output:
In the above example, we created a data frame with two columns “First name and “Age” and later used Dataframe.reindex() method to add two new columns “Gender” and ” Roll Number” to the list of columns with NaN values.
Method 3: Using Dataframe.insert().
This method is used to add a new column to a pandas dataframe at any index location we want and assign the appropriate value as per need. Example: 
Python3
# import pandas libraryimport pandas as pd  # create a dataframeMydataframe = pd.DataFrame({'FirstName': ['Rohan',                                          'Martin',                                          'Mary'],                            "Age": [28,39,21]})# show the dataframeprint("---Original Dataframe---\n",      Mydataframe)  # add an empty columnMydataframe.insert(0,'Roll Number','')  # show the dataframeprint("\n\n---Updated Dataframe---\n",      Mydataframe)
Output:
In the above example, we are using the Dataframe.insert() method on pandas data frames (table) to add an empty column “Roll Number”, here we can also insert the column at any index position we want (as here we placed the value at index location 0).
Python pandas-dataFrame
Python-pandas
Python
Writing code in comment?
Please use ide.geeksforgeeks.org,
generate link and share the link here.