2887. Fill Missing Data
DataFrame products
Column Name | Type |
---|---|
name | object |
quantity | int |
price | int |
Instructions
- Write a solution to fill in the missing value as
in the quantity
column. - The result format is in the following example.
Example
Input:
name | quantity | price |
---|---|---|
Wristwatch | None | 135 |
WirelessEarbuds | None | 821 |
GolfClubs | 779 | 9319 |
Printer | 849 | 3051 |
Output:
name | quantity | price |
---|---|---|
Wristwatch | 0 | 135 |
WirelessEarbuds | 0 | 821 |
GolfClubs | 779 | 9319 |
Printer | 849 | 3051 |
Explanation:
The quantity for Wristwatch and WirelessEarbuds are filled by
.
Submissions
python
import pandas as pd
def fillMissingValues(products: pd.DataFrame) -> pd.DataFrame:
products['quantity'] = products['quantity'].fillna(0)
return products
Explanation
Python (Pandas)
Submitted by @noeyislearning
import pandas as pd
: Import the pandas library to work with DataFrames.def fillMissingValues(products: pd.DataFrame) -> pd.DataFrame
: Define a function that takes a DataFrame as input and returns a DataFrame.products['quantity'] = products['quantity'].fillna(0)
: Fill the missing values in thequantity
column with. return products
: Return the updated DataFrame.