2887 Fill Missing Data
Problem Statement
DataFrame products
name
object
quantity
int
price
int
Write a solution to fill in the missing value as 0
in the quantity
column.
The result format is in the following example.
For the whole problem statement, please refer here.
Plans
Use pandas to handle the data.
Fill in the missing values in the
quantity
column with0
.Provide the DataFrame with the missing values filled.
Return the result.
Solution
Explanation
Import Pandas
We start by importing the Pandas library, which provides data structures and operations for manipulating numerical tables and time series.
Define the Function
We define a function
fillMissingValues
that takes a single argumentproducts
, which is a DataFrame containing product data.
Filling Missing Values
We use the
fillna
method on the DataFrameproducts
to fill in missing values in thequantity
column with0
.The
value=0
argument specifies the value to use for filling in missing values.The
inplace=True
argument specifies that the changes should be made directly to the DataFrameproducts
.
Return the Result
We return the updated DataFrame after filling in the missing values in the
quantity
column with0
.
Last updated