Talentd
FleetCode

2887. Fill Missing Data

Easy72.0% acceptance3 companies
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 1:
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 0.

Asked at 3 companies

Hints open one at a time

Hint 1
Consider using a build-in function in pandas library to fill the missing values of specified columns.
0:56
Still stuck?Read 2 approaches, or watch a walkthrough.
Open solution
Loading editor…
1class Solution:
2 def solve(self):
3 pass
4
Starter codePython 3Spaces: 4
Examples
Input
{"headers":{"products":["name","quantity","price"]},"rows":{"products":[["Wristwatch",null,135],["WirelessEarbuds",null,821],["GolfClubs",779,9319],["Printer",849,3051]]}}
Your code is saved on this device.Solution