import pandas as pd
def fillMissingValues(products: pd.DataFrame) -> pd.DataFrame:
2887. Fill Missing Data
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 | 32 | 135 | | WirelessEarbuds | None | 821 | | GolfClubs | None | 9319 | | Printer | 849 | 3051 | +-----------------+----------+-------+ Output: +-----------------+----------+-------+ | name | quantity | price | +-----------------+----------+-------+ | Wristwatch | 32 | 135 | | WirelessEarbuds | 0 | 821 | | GolfClubs | 0 | 9319 | | Printer | 849 | 3051 | +-----------------+----------+-------+ Explanation: The quantity for Toaster and Headphones are filled by 0.
原站题解
pythondata 解法, 执行用时: 240 ms, 内存消耗: 59 MB, 提交时间: 2023-10-07 10:36:59
''' None填充0 ''' import pandas as pd def fillMissingValues(products: pd.DataFrame) -> pd.DataFrame: products['quantity'].fillna(0, inplace=True) return products