## 如何在python中进行一些计算之后添加新列？内容来源于 Stack Overflow，并遵循CC BY-SA 3.0许可协议进行翻译与使用

• 回答 (2)
• 关注 (0)
• 查看 (303)
```ID_REF      1007_s_at 1053_at 117_at 121_at 1255_g_at
GSM11111    0.08277 0.00874 0.00363 0.01877 0.00075
GSM95474    0.09503 0.00592 0.00352 0.01944 0.00055
GSM95475    0.08486 0.00678 0.00386 0.01973 0.00039
GSM95476    0.08105 0.00913 1       0.01801 0.00055
GSM95477    0.05918 0.00812 0.00428 0.01597 0.00033
GSM95478    0.07615 0.00777 0.00438 0.01799 0.00129
GSM95479    0.0976  0       0.00399 0.0216  0.00125
GSM95480    0.08499 0.00442 0.00298 0.01897 0.00015
GSM95481    0.08893 0.00734 0.00204 0.01706 0.00089
GSM99999    0.05981 0.01587 0.00365 0.01709 0.0006```

### 2 个回答

```df = df.set_index('ID_REF')
df = df.append(pd.DataFrame(dict(((df.notnull()) & (df != 0)).sum()), index=['Final']))```

```          1007_s_at 1053_at 117_at  121_at  1255_g_at
GSM11111    0.08277 0.00874 0.00363 0.01877 0.00075
GSM95474    0.09503 0.00592 0.00352 0.01944 0.00055
GSM95475    0.08486 0.00678 0.00386 0.01973 0.00039
GSM95476    0.08105 0.00913 1.00000 0.01801 0.00055
GSM95477    0.05918 0.00812 0.00428 0.01597 0.00033
GSM95478    0.07615 0.00777 0.00438 0.01799 0.00129
GSM95479    0.09760 0.00000 0.00399 0.02160 0.00125
GSM95480    0.08499 0.00442 0.00298 0.01897 0.00015
GSM95481    0.08893 0.00734 0.00204 0.01706 0.00089
GSM99999    0.05981 0.01587 0.00365 0.01709 0.00060
Final      10.00000 9.00000 10.00000 10.00000 10.00000```

```import pandas as pd