You can select your desired columns and do it by assignment:

df[['a', 'b']] = df[['a','b']].fillna(value=0)

The resulting output is as expected:

     a    b    c
0  1.0  4.0  NaN
1  2.0  5.0  NaN
2  3.0  0.0  7.0
3  0.0  6.0  8.0
Answer from root on Stack Overflow
🌐
Statology
statology.org › home › pandas: how to use fillna() with specific columns
Pandas: How to Use fillna() with Specific Columns
June 10, 2022 - #replace NaNs with zeros in 'rating' column df['rating'] = df['rating'].fillna(0) #view DataFrame df rating points assists rebounds 0 0.0 25.0 5.0 11 1 85.0 NaN 7.0 8 2 0.0 14.0 7.0 10 3 88.0 16.0 NaN 6 4 94.0 27.0 5.0 6 5 90.0 20.0 7.0 9 6 76.0 12.0 6.0 6 7 75.0 15.0 9.0 10 8 87.0 14.0 9.0 10 9 86.0 19.0 5.0 7 · Notice that the NaN values have been replaced only in the “rating” column and every other column remained untouched.
Discussions

Pandas: Is it possible to use the fillna() method using a calculation between two columns of a specific row?
The way to do this would be to just calculate a series with all of the values, then pass the name of that series to fillna() as the first argument. Something like df["fill_value"] = df["Unit_Cost"] * df["Quantity"] df["Total_Cost"] = df["Total_Cost"].fillna(df["fill_value"]) More on reddit.com
🌐 r/learnpython
1
0
February 23, 2025
How can I replace all NaN values in my DF except the NaN values of some specific columns?
https://pandas.pydata.org/docs/reference/api/pandas.DataFrame.fillna.html Pass a dict to the values argument. More on reddit.com
🌐 r/learnpython
5
1
January 13, 2023
I need to replace NaN in one column with value for other col
I've seen this come up before. You want to use np.where. data['Grade'] = np.where(data['Grade'].isna(),data['Score'],data['Grade']) here's an example that sets null values in grade to values in score, and if it's not null, leaves the current value. More on reddit.com
🌐 r/learnpython
10
1
July 15, 2021
Pandas conditional fillna based on another column values

I finally solved in this way :

missing = train["Outlet_Size"].isna()

condlist = [train.loc[missing, "Outlet_Size"] & train.loc[missing,'Item_Outlet_Sales'] <= 1000,

train.loc[missing, "Outlet_Size"] & train.loc[missing,'Item_Outlet_Sales'] > 1000]

choicelist = ["Small", "Medium"]

train.loc[missing, 'Outlet_Size'] = np.select(condlist, choicelist)

More on reddit.com
🌐 r/learnpython
3
2
July 28, 2020
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.fillna.html
pandas.DataFrame.fillna — pandas 3.0.2 documentation
Replace all NaN elements in column ‘A, ‘B’, ‘C’, and ‘D’, with 0, 1, 2, and 3 respectively. >>> values = {"A": 0, "B": 1, "C": 2, "D": 3} >>> df.fillna(value=values) A B C D 0 0.0 2.0 2.0 0.0 1 3.0 4.0 2.0 1.0 2 0.0 1.0 2.0 3.0 3 0.0 3.0 2.0 4.0 · Only replace the first NaN element.
🌐
Linux find Examples
queirozf.com › entries › pandas-fillna-examples-filling-in-missing-data
Pandas Fillna Examples: Filling in Missing Data
May 29, 2023 - AFTER: only values in the row indexed by 1 were filled with "--" (other rows left unchanged) To fill nulls in multiple specific columns, pass a dict to fillna · import pandas as pd import numpy as np df = pd.DataFrame({ 'col1': [1.0, 2.0, 3.0, np.nan, None ], 'col2': [1, 2, 3, 4, 5 ], 'col3': ...
🌐
Python Examples
pythonexamples.org › pandas-dataframe-fillna
Pandas DataFrame.fillna: Fill Missing Values in a DataFrame
import pandas as pd # Create a DataFrame with NaN values df = pd.DataFrame({ 'A': [1, 2, None, 4], 'B': [None, 2, 3, None] }) # Fill NaN values with different values for each column df_filled_dict = df.fillna({'A': 100, 'B': 200}) print(df_filled_dict)
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas.dataframe.fillna() – explained by examples
pandas.DataFrame.fillna() - Explained by Examples - Spark By {Examples}
June 26, 2025 - pandas.DataFrame.fillna() method is used to fill column (one or multiple columns) containing NA/NaN/None with 0, empty, blank, or any specified values
🌐
Bobby Hadz
bobbyhadz.com › blog › pandas-fillna-only-some-specific-columns-in-dataframe
Panda: Using fillna() with specific columns in a DataFrame | bobbyhadz
April 12, 2024 - You can also pass a dictionary to the fillna() method to only call the method on specific columns. ... Copied!import pandas as pd df = pd.DataFrame({ 'ID': [1, 1, None, 2, 2, None], 'Animal': ['Cat', 'Cat', None, 'Dog', 'Dog', None], 'Max Speed': ...
Find elsewhere
🌐
Reddit
reddit.com › r/learnpython › pandas: is it possible to use the fillna() method using a calculation between two columns of a specific row?
r/learnpython on Reddit: Pandas: Is it possible to use the fillna() method using a calculation between two columns of a specific row?
February 23, 2025 -

I am currently cleaning data using Pandas of bike sales.

Each bike sale is broken down into: 'Quantity_Sold' 'Total_Cost', 'Total_Revenue', 'Total_Profit' , 'Unit_Cost', 'Unit_Price', 'Unit_Profit'.

There are Null values for some of these columns, however, it is possible to calculate the missing column's valuing using the other remaining columns that are filled. For example a null "Total_Cost" column can be calculated via "Unit_Cost"*"Quantity" etc.

How do I use the fillna() method to do this, so I can fill in the columns without resorting to mean, median and averages?

🌐
W3Schools
w3schools.com › python › pandas › ref_df_fillna.asp
Pandas DataFrame fillna() Method
Pandas HOME Pandas Intro Pandas Getting Started Pandas Series Pandas DataFrames Pandas Read CSV Pandas Read JSON Pandas Analyzing Data · Cleaning Data Cleaning Empty Cells Cleaning Wrong Format Cleaning Wrong Data Removing Duplicates ... The fillna() method replaces the NULL values with a specified value.
🌐
Favtutor
favtutor.com › articles › pandas-fillna-method
Pandas DataFrame fillna() Method (with Examples)
November 25, 2023 - In the below example, the fillna() method is applied to the “age” column of the df DataFrame. The NaN values in this column are replaced with the mean age of the column and the axis parameter is set to 0 to fill along the rows.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-pandas-dataframe-fillna-to-replace-null-values-in-dataframe
Pandas DataFrame.fillna() | Python - GeeksforGeeks
February 23, 2026 - Example: This example creates a DataFrame with missing values and replaces all NaN values with 0 using fillna(). ... import pandas as pd df = pd.DataFrame({"A": [1, None, 3], "B": [None, 5, 6]}) r = df.fillna(0) print(r) ... method (Filling ...
🌐
Pandas
pandas.pydata.org › docs › dev › reference › api › pandas.DataFrame.fillna.html
pandas.DataFrame.fillna — pandas 3.0.0rc2+8.g2b571cac91 documentation
Replace all NaN elements in column ‘A’, ‘B’, ‘C’, and ‘D’, with 0, 1, 2, and 3 respectively. >>> values = {"A": 0, "B": 1, "C": 2, "D": 3} >>> df.fillna(value=values) A B C D 0 0.0 2.0 2.0 0.0 1 3.0 4.0 2.0 1.0 2 0.0 1.0 2.0 3.0 3 0.0 3.0 2.0 4.0 · Only replace the first NaN element.
🌐
LabEx
labex.io › tutorials › pandas-dataframe-fillna-method-68621
Mastering Pandas DataFrame Fillna Method | LabEx
print("Filling NaN values using ... different specified values. For example, let's replace missing values in columns 'A', 'B', 'C', and 'D' with values 0, 1, 2, and 3, respectively....
🌐
Pandas
pandas.pydata.org › pandas-docs › version › 1.5 › reference › api › pandas.DataFrame.fillna.html
pandas.DataFrame.fillna — pandas 1.5.3 documentation
Replace all NaN elements in column ‘A’, ‘B’, ‘C’, and ‘D’, with 0, 1, 2, and 3 respectively. >>> values = {"A": 0, "B": 1, "C": 2, "D": 3} >>> df.fillna(value=values) A B C D 0 0.0 2.0 2.0 0.0 1 3.0 4.0 2.0 1.0 2 0.0 1.0 2.0 3.0 3 0.0 3.0 2.0 4.0 · Only replace the first NaN element.
🌐
IONOS
ionos.com › digital guide › websites › web development › python pandas: dataframe fillna()
What is Pandas fillna() and how to use it
June 26, 2025 - # Replace all NaN values with the value that precedes them df_ffill = df.fillna(method='ffill') print(df_ffill)python · In this example, the NaN values in columns A and C have been filled with the preceding values in the same column.
🌐
Medium
medium.com › @whyamit101 › understanding-fillna-in-pandas-85108c3e67e9
Understanding fillna() in Pandas. If you think you need to spend $2,000… | by why amit | Medium
February 26, 2025 - You might be thinking, “Can’t ... NaNs with different values for each column df.fillna({'Name': 'Unknown', 'Age': 0, 'City': 'Not Specified'}, inplace=True) print(df) What’s Happening Here?...
🌐
Tutorial Reference
tutorialreference.com › python › examples › faq › python-pandas-how-to-use-fillna-only-some-specific-columns-in-dataframe
Python Pandas: How to Use fillna() on Specific DataFrame Columns Only | Tutorial Reference
Handling missing values (NaN, None, NaT) is a critical step in data cleaning and preparation with Pandas. The DataFrame.fillna() method is a versatile tool for this, but often you only want to fill missing values in specific columns, possibly with different fill values for each.
🌐
IncludeHelp
includehelp.com › python › dataframe-fillna-only-some-columns-in-place.aspx
Pandas dataframe fillna() only some columns in place
September 22, 2023 - To apply this method to specific columns, we need to define the specific columns at time of function calling. ... # Importing pandas package import pandas as pd # Importing numpy package import numpy as np # Creating a dictionary d = { 'A':[1,2,3,np.NaN], 'B': [np.NaN,4,5,6], 'C':[7,8,np.NaN,9] } # Creating an empty DataFrame df = pd.DataFrame(d) # Display DataFrame print("Created DataFrame:\n",df,"\n") # Filling 0 in place of NaN values df[['A','C']] = df[['A','C']].fillna(value=0) # Display modified DataFrame print("Modified DataFrame:\n",df)
🌐
PythonForBeginners.com
pythonforbeginners.com › home › use the pandas fillna method to fill nan values
Use the Pandas fillna Method to Fill NaN Values - PythonForBeginners.com
December 23, 2022 - Instead of filling all the NaN values with the same value, you can also replace the NaN value in each column with a specific value. For this, we need to pass a dictionary containing column names as its keys and the values to be filled in the columns as the associated values to the fillna() method.
🌐
GeeksforGeeks
geeksforgeeks.org › fillna-in-multiple-columns-in-place-in-python-pandas
Fillna in multiple columns in place in Python Pandas - GeeksforGeeks
We can use fillna() function to impute the missing values of a data frame to every column defined by a dictionary of values. The limitation of this method is that we can only use constant values to be filled.
Published   September 13, 2022