0

I have a pandas dataframe, let's say

import pandas as pd
df = pd.DataFrame({"A":[8,6,7,5],"B":["cat", "hat","","d"],"C":[3,5,4,0]})

I want to select all rows in which column B ends in 'at'. I have no guarantee on the existence of an entry in column B, and I have no guarantee about how long the string is if it's there. I know I could basically write a for-loop for that, but I'm wondering if that's the best solution, elegance- and performance-wise.

Addem
  • 3,118
  • 3
  • 24
  • 47
  • `df.B.str.endswith('at')`. If you care about performance, use a list comprehension with the python method, instead of the string accessor – user3483203 Dec 06 '18 at 20:39
  • Replace `contains` with `endswith` in the linked duplicate above. – cs95 Dec 06 '18 at 20:40

0 Answers0