0

I have some data, the first column is the login, the second column is comment which is string or numbers or both, the data is this:

Login Comment
256   qq456
257   msn176453

I want to find all the rows that the the begining of the comment is qq. I was trying to use:

sentence_begining = r"[qq.]"
re.findall(sentence_begining, orders["Comment"])

however,this way failed, after googling a lot, I still cannot solve this problem. So I am wondering others may also have this question, so post it here. Many thanks

Michael
  • 529
  • 1
  • 8
  • 22
  • _however,this way failed_ Failed how, in what way? _after googling a lot, I still cannot solve this problem._ Googling "pandas check if string starts with", first result: https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.Series.str.startswith.html. – AMC Feb 21 '20 at 17:58
  • Does this answer your question? [pandas select from Dataframe using startswith](https://stackoverflow.com/questions/17957890/pandas-select-from-dataframe-using-startswith) – AMC Feb 21 '20 at 18:09

1 Answers1

3

Try using str.startswith:

orders[orders['Comment'].str.startswith('qq')]
gseva
  • 373
  • 4
  • 10