EasyNo. 2887
Fill Missing Data — LeetCode 2887 Python Solution
- Topics
- Pandas
- Reading time
- 2 min
- Source
- leetcode.com
Table 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
DataFrame products
+-------------+--------+
| Column Name | Type |
+-------------+--------+
| name | object |
| quantity | int |
| price | int |
+-------------+--------+Python solution
import pandas as pd
def fillMissingValues(products: pd.DataFrame) -> pd.DataFrame:
products['quantity'] = products['quantity'].fillna(0)
return productsComplexity
- Time
- O(n)
- Space · auxiliary
- O(1) to O(n)
Related problems
| No. | Problem | Difficulty |
|---|---|---|
| 2877 | Create a DataFrame from List | Easy |
| 0057 | Insert Interval | Medium |
| 0192 | Word Frequency | Medium |
| 0193 | Valid Phone Numbers | Easy |
| 0194 | Transpose File | Medium |
| 0195 | Tenth Line | Easy |
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.