cancel
Showing results for 
Search instead for 
Did you mean: 
Data Engineering
Join discussions on data engineering best practices, architectures, and optimization strategies within the Databricks Community. Exchange insights and solutions with fellow data engineers.
cancel
Showing results for 
Search instead for 
Did you mean: 

unable to replace null with 0 in dataframe using Pyspark databricks notebook (community edition)

db-avengers2rul
Contributor II

Hello Experts,

I am unable to replace nulls with 0 in a dataframe ,please refer to the screen shot

from pyspark.sql.functions import col
emp_csv_df = emp_csv_df.na.fill(0).withColumn("Total_Sal",col('sal')+col('comm'))
display(emp_csv_df)

erorr

unable to fill nulls with 0 in dataframe using PySpark in databricks 

desired output

Screenshot 2022-10-03 at 20.26.23 

any suggestions ?

Regards,

Rakesh

1 ACCEPTED SOLUTION

Accepted Solutions

Hubert-Dudek
Esteemed Contributor III

I bet that it is not real null but the string "null". Please check what is in the source and try luck with replacing it.

View solution in original post

1 REPLY 1

Hubert-Dudek
Esteemed Contributor III

I bet that it is not real null but the string "null". Please check what is in the source and try luck with replacing it.

Connect with Databricks Users in Your Area

Join a Regional User Group to connect with local Databricks users. Events will be happening in your city, and you won’t want to miss the chance to attend and share knowledge.

If there isn’t a group near you, start one and help create a community that brings people together.

Request a New Group