EasyNo. 2887

Fill Missing Data — LeetCode 2887 Python Solution

Topics
Pandas
Reading time
2 min

Table schema

SQLTable schema
DataFrame products +-------------+--------+ | Column Name | Type | +-------------+--------+ | 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.

Example

SQLExample
DataFrame products
+-------------+--------+
| Column Name | Type   |
+-------------+--------+
| name        | object |
| quantity    | int    |
| price       | int    |
+-------------+--------+

Python solution

PythonSolution
import pandas as pd


def fillMissingValues(products: pd.DataFrame) -> pd.DataFrame:
    products['quantity'] = products['quantity'].fillna(0)
    return products

Complexity

Time
O(n)
Space · auxiliary
O(1) to O(n)

Related problems

Related problems
No.ProblemDifficulty
2877Create a DataFrame from ListEasy
0057Insert IntervalMedium
0192Word FrequencyMedium
0193Valid Phone NumbersEasy
0194Transpose FileMedium
0195Tenth LineEasy

Frequently asked questions

How hard is LeetCode 2887. Fill Missing Data?

LeetCode 2887. Fill Missing Data is rated Easy on LeetCode.

What topics does LeetCode 2887. Fill Missing Data cover?

LeetCode 2887. Fill Missing Data is tagged Pandas on LeetCode.

Stuck on problems like this in a live interview?

Stealth Interview is a desktop app for macOS and Windows. It reads the problem off your screen and returns a working solution with a step-by-step explanation and its time and space complexity, invisible to screen sharing.

Free to download. Check it runs on your machine, then pick a plan.