I am a little confused as to when and why to use this syntax and what the difference is between them. In Regular Expressions lesson we jump between these two a few times:
titles.str.contains(pattern) this code matches the pattern with each row in series and gives a boolean value - True if matched and False if not matched.
try this to see the results: print(titles.str.contains(pattern_ending)) on the console.
Then titles[titles.str.contains(pattern)] filters out only those rows where the pattern matched i.e. where titles.str.contains(pattern) == True
titles.str.contains(pattern_ending).sum() this code sums the rows where the pattern matched. True is considered as 1 and False is considered as 0. so sum() will result in count of rows where pattern matched.
You may also refer to a similar post here there is a detailed explanation about the syntax.
Hope this helps you somewhat. please do reply if you have an issue with any part of the post.
And for future queries , please attach a link to the screen you are working with and facing an issue. It helps the other members to help you better.