簡體   English   中英

通過 Pandas 數據框迭代和驗證

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM