Use .dropna() to drop missing values of the cust_id column in banking and store the results in banking_fullid. Use inv_a

动态 未结 0 119
小小草
小小草 LV1 2023年9月23日 23:40 发表
Here's the code to drop missing values of the `cust_id` column in `banking`, compute estimated account amounts, impute missing values of `acct_amount`, and print the number of missing values: ```python # Drop missing values of cust_id banking_fullid = banking.dropna(subset=['cust_id']) # Compute estimated acct_amount acct_imp = banking_fullid['inv_amount'] * 5 # Impute missing acct_amount with corresponding acct_imp banking_imputed = banking_fullid.fillna({'acct_amount': acct_imp}) # Print number of missing values print(banking_imputed.isna().sum()) ``` In this code, we first use the `.dropna()` function to drop missing values of the `cust_id` column in `banking`. We specify the `subset` parameter as `['cust_id']` to only consider missing values in that column. We store the result in a new DataFrame called `banking_fullid`. We then compute the estimated account amounts by multiplying the `inv_amount` column by 5, and store the result in a new Series called `acct_imp`. Finally, we use the `.fillna()` function to impute missing values of `acct_amount` in `banking_fullid` with the corresponding values from `acct_imp`. We pass a dictionary with the key `'acct_amount'` and the value `acct_imp` to the `fillna()` function. We print the number of missing values in the resulting DataFrame using the `.isna().sum()` method.
收藏(0)  分享
相关标签: 智能问答
问题没解决?让AI助手帮你作答 AI助手
0个回复
  • 消灭零回复