Prompt engineering sucks. Break free from the endless tweaking with this revolutionary approach  - Learn more

Securing AI systems is tricky, ignoring it is risky. Discover the easiest way to secure your AI end to end  - Learn more

Back to Blog
How-To

How to Add an Empty Column to a DataFrame

Aporia Team Aporia Team 1 min read Sep 06, 2022

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:

Rate this article

Average rating 0 / 5. Vote count: 0

No votes so far! Be the first to rate this post.

On this page

Blog
Building a RAG app?

Consider AI Guardrails to get to production faster

Learn more
Table of Contents

Related Articles