In data Frames, 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.
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).
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.
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).
- Get column index from column name of a given Pandas DataFrame
- Create a Pandas DataFrame from a Numpy array and specify the index column and column headers
- Convert given Pandas series into a dataframe with its index as another column on the dataframe
- Add column names to dataframe in Pandas
- Add Column to Pandas DataFrame with a Default Value
- Create a DataFrame from a Numpy array and specify the index column and column headers
- Python | Pandas DataFrame.empty
- How to create an empty DataFrame and append rows & columns to it in Pandas?
- Create empty dataframe in Pandas
- Append data to an empty Pandas DataFrame
- How to get column names in Pandas dataframe
- Capitalize first letter of a column in Pandas dataframe
- Python | Change column names and row indexes in Pandas DataFrame
- Convert the column type from string to datetime format in Pandas dataframe
- Apply uppercase to a column in Pandas dataframe
- How to lowercase column names in Pandas dataframe
- Get unique values from a column in Pandas DataFrame
- Adding new column to existing DataFrame in Pandas
- Get n-smallest values from a particular column in Pandas DataFrame
- Get n-largest values from a particular column in Pandas DataFrame
If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to firstname.lastname@example.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.
Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.