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

2 REPLIES 2

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.

Kaniz_Fatma
Community Manager
Community Manager

Hi @Rakesh Reddy Gopidi​ ​, We haven’t heard from you since the last response from @Hubert Dudek​ , and I was checking back to see if you have a resolution yet.

If you have any solution, please share it with the community as it can be helpful to others. Otherwise, we will respond with more details and try to help.

Also, Please don't forget to click on the "Select As Best" button whenever the information provided helps resolve your question.

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