Aporia How to's

How to Add an Empty Column to a DataFrame?

1 min read
pandas and pyspark dataframe add new empty column

In this short how-to article, we will learn how to add an empty column to Pandas and PySpark DataFrames.

add-empty-column-to-dataframe

Pandas

We can create an empty column by assigning an empty string as follows:

df["f4"] = ""

PySpark

The logic is the same as Pandas but the implementation is a bit different. We can assign an empty string to a new column as follows:

from pyspark.sql import functions as F
df = df.withColumn("f4", F.lit(""))				

This question is also being asked as:

  • Add multiple empty columns to Pandas DataFrame

People have also asked for:

Start Monitoring Your Models in Minutes

Book a demo