简体   繁体   中英

Iterating and validating through a pandas dataframe

I have a pandas DataFrame called 'heat' consisting of 2 columns, A and B

Column A cells hold string values of : 'High' 'Low' and 'Central'.

What I want to achieve is iterate through the dataframe and do the following checks:

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'

Any ideas please?

尝试使用map

heat["B"] = heat["A"].str[-2:].map({"gh": "Yes", "ow": "No", "al": "Maybe"})

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM