Find the rows where the sum of all rows of the fund_columns in banking are equal to the inv_amount column. Store the val

动态 未结 0 158
小小草
小小草 LV1 2023年9月23日 23:40 发表
Here's the code to find the rows where the sum of all rows of the fund_columns in banking are equal to the inv_amount column, store the values of banking with consistent inv_amount in `consistent_inv`, and those with inconsistent ones in `inconsistent_inv`: ```python # Store fund columns to sum against fund_columns = ['fund_A', 'fund_B', 'fund_C', 'fund_D'] # Find rows where fund_columns row sum == inv_amount inv_equ = banking[fund_columns].sum(axis=1) == banking['inv_amount'] # Store consistent and inconsistent data consistent_inv = banking[inv_equ] inconsistent_inv = banking[~inv_equ] # Print number of inconsistent investments print("Number of inconsistent investments: ", inconsistent_inv.shape[0]) ``` In this code, we first define a list `fund_columns` that contains the names of the columns we want to sum against. We then create a boolean mask `inv_equ` that checks if the sum of each row of the `fund_columns` is equal to the `inv_amount` column. We use this boolean mask to filter the `banking` DataFrame into two separate DataFrames: `consistent_inv` and `inconsistent_inv`. The `consistent_inv` DataFrame contains the rows where the sum of the `fund_columns` is equal to the `inv_amount` column, while the `inconsistent_inv` DataFrame contains the rows where they are not equal. Finally, we print the number of inconsistent investments using the `shape` attribute of the `inconsistent_inv` DataFrame.
收藏(0)  分享
相关标签: 智能问答
问题没解决?让AI助手帮你作答 AI助手
0个回复
  • 消灭零回复