python - add one more new column supplytypecheck, check if supply type IMPG that should be Y else N
问题描述
df["supplyType"]
0 TAX
1 TAX
2 TAX
3 TAX
4 TAX
5 TAX
6 IMPG
Name: SupplyType, dtype: object
Question is when supplyType is IMPG i should add a new column supplytypecheck with value "Y" for True else "Y" for false
i done it like
a =df["SupplyType"].index
for i in a:
if (df["SupplyType"][i]) == "IMPG":
df["supplytypecheck"] = "Y"
else:
df["supplytypecheck"] = "N"
It givens all df["supplytypecheck"] values as "Y" but "Y" should only be value for last index because it equals to IMPG all the upper values are equal to TAX.
Please help how to solve it
解决方案
推荐阅读
- sql - 如何在 BigQuery 中进行分区外连接
- docker - 使用 CircleCI 的预建镜像与拉取私有镜像之间的权衡是什么?
- android - styles.xml 未按预期应用
- docker - Docker容器到容器连接:连接被拒绝
- java - 如何通过在 java-sql 应用程序上输入所有列数据来过滤搜索?
- c - 如何在 C 代码中使用单精度浮点实现 FIR 滤波器?
- tcp - 使用 netstat -s 在 Solaris 10 中计算 TCP 重传
- python - 读取超时。向 node.js API 发送 POST 请求时出错
- android - My App crashes when I try to use ArrayAdapter
- reactjs - mapStateToProps returns no data, data is undefined