[英]Iterating and validating through a pandas dataframe
我有一个名为“heat”的Pandas DataFrame,由2 列 A 和 B 组成
A 列单元格包含以下字符串值:“高”、“低”和“中央”。
我想要实现的是遍历数据框并执行以下检查:
If string at column A ends with 'gh', fill column B with 'Yes'
If string at column A ends with 'ow', fill column B with 'No'
If string at column A ends with 'al', fill column B with 'Maybe'
请问有什么想法吗?
尝试使用map
:
heat["B"] = heat["A"].str[-2:].map({"gh": "Yes", "ow": "No", "al": "Maybe"})
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.