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 - This tutorial explains how to use the fillna() function in pandas to replace values in specific columns, including examples.
Discussions

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
How do I fill NaN values of a column with its mean/median/mode? (Pandas DataFrame)
Hey, easiest way is to save the mean into a variable like col_mean=df['col'].mean() and then df['col']=df['col'].fillna(col_mean) - there are more elegant versions but this should do the work. More on reddit.com
🌐 r/learnpython
1
2
October 15, 2020
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
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
🌐
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
🌐
Linux find Examples
queirozf.com › entries › pandas-fillna-examples-filling-in-missing-data
Pandas Fillna Examples: Filling in Missing Data
May 29, 2023 - 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': ['foo', None, 'baz', 'quux', 'bax'], 'col4': ['xxx', None, None, None, 'xxx'], }) ...
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-pandas-dataframe-fillna-to-replace-null-values-in-dataframe
Pandas DataFrame.fillna() | Python - GeeksforGeeks
February 23, 2026 - This example replaces missing values in the College column with a fixed text "No College" using fillna(). This is useful when you want to assign a default value to missing entries. ... import pandas as pd nba = pd.read_csv("nba.csv") nba["College"].fillna("No College", inplace = True) print(nba)
🌐
Reddit
reddit.com › r/learnpython › pandas conditional fillna based on another column values
r/learnpython on Reddit: Pandas conditional fillna based on another column values
July 28, 2020 -

Hello,

I am working on bigmart dataset and I would like to substitute missing values of a column based on the values of another column, practically:

Outlet_Size sales_bin
Medium 3000-4000
NaN 0-1000
Small 0-1000
.... ....

So if train[“Outlet_Size”] value is a NaN and train[“sales_bin”] is “0-1000”

train[“Outlet_Size”] value shoud become “Small”

else == Medium

But I really don’t know how to write it and all the information I found seems confusing to me

Is it possible to do it? How?

Many thanks

Find elsewhere
🌐
Spark By {Examples}
sparkbyexamples.com › home › pandas › pandas.dataframe.fillna() – explained by examples
pandas.DataFrame.fillna() - Explained by Examples
June 26, 2025 - To fill NaN values with different values for different columns, you can use a dictionary with the .fillna() method. The dictionary specifies the replacement value for each column.
🌐
W3Schools
w3schools.com › python › pandas › ref_df_fillna.asp
Pandas DataFrame fillna() Method
Pandas HOME Pandas Intro Pandas ... Wrong Format Cleaning Wrong Data Removing Duplicates ... The fillna() method replaces the NULL values with a specified value....
🌐
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] ...
🌐
Apache
spark.apache.org › docs › latest › api › python › reference › pyspark.sql › api › pyspark.sql.DataFrame.fillna.html
pyspark.sql.DataFrame.fillna — PySpark 4.1.1 documentation
DataFrame.fillna() and DataFrameNaFunctions.fill() are aliases of each other. New in version 1.3.1. Changed in version 3.4.0: Supports Spark Connect. ... If the value is a dict, then subset is ignored and value must be a mapping from column name (string) to replacement value. The replacement value must be an int, float, boolean, or string. ... optional list of column names to consider. Columns specified ...
🌐
Edureka Community
edureka.co › home › community › categories › python › pandas - fillna with another column
Pandas - FillNa with another column | Edureka Community
July 5, 2019 - How do I fill the missing value in one column with the value of another column? I read that looping ... cat giraf 4 ant ant How do I resolve this?
🌐
KDnuggets
kdnuggets.com › 2023 › 02 › optimal-way-input-missing-data-pandas-fillna.html
The Optimal Way to Input Missing Data with Pandas fillna() - KDnuggets
To do that, we can use the Pandas function called fillna. Using the function is simple, but there are a few methods to optimally fill up our data, including replacing missing data in multiple columns, limiting the imputation, and using other rows to fill the data.
🌐
Saturn Cloud
saturncloud.io › blog › how-to-fill-missing-values-of-one-column-from-another-column-in-pandas
How to Fill Missing Values of One Column from Another Column in Pandas | Saturn Cloud Blog
November 10, 2023 - To fill missing values of one column from another column in pandas, we can use the fillna() method. This method allows us to replace missing values with a specified value or with values from another column.
🌐
IONOS
ionos.com › digital guide › websites › web development › python pandas: dataframe fillna()
What is Pandas fillna() and how to use it
June 26, 2025 - Since there was no preceding value in column B for row 0, the NaN value is retained: A B C 0 1.0 NaN 1.0 1 2.0 2.0 1.0 2 2.0 3.0 3.0 3 4.0 4.0 4.0 · NaN values can also be filled with suc­ceed­ing values based on their row position. To do this, you need to use the bfill method and set the axis parameter to 1: df_bfill = df.fillna(method='bfill', axis=1) print(df_bfill)python
🌐
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
🌐
Pandas
pandas.pydata.org › pandas-docs › version › 0.22 › generated › pandas.DataFrame.fillna.html
pandas.DataFrame.fillna — pandas 0.22.0 documentation
>>> df.fillna(method='ffill') A B C D 0 NaN 2.0 NaN 0 1 3.0 4.0 NaN 1 2 3.0 4.0 NaN 5 3 3.0 3.0 NaN 4 · Replace all NaN elements in column ‘A’, ‘B’, ‘C’, and ‘D’, with 0, 1, 2, and 3 respectively.
🌐
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': ...
🌐
Pandas
pandas.pydata.org › docs › reference › api › pandas.DataFrame.html
pandas.DataFrame — pandas 3.0.2 documentation
>>> df2 = pd.DataFrame( ... np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]), columns=["a", "b", "c"] ...
🌐
Statology
statology.org › home › pandas: how to fill nan values with mean (3 examples)
Pandas: How to Fill NaN Values with Mean (3 Examples)
January 20, 2022 - #fill NaNs with column mean in 'rating' column df['rating'] = df['rating'].fillna(df['rating'].mean()) #view updated DataFrame df rating points assists rebounds 0 85.125 25.0 5.0 11 1 85.000 NaN 7.0 8 2 85.125 14.0 7.0 10 3 88.000 16.0 NaN 6 4 94.000 27.0 5.0 6 5 90.000 20.0 7.0 9 6 76.000 12.0 6.0 6 7 75.000 15.0 9.0 10 8 87.000 14.0 9.0 10 9 86.000 19.0 5.0 7