October 2019
Beginner to intermediate
674 pages
16h 43m
English
While the contains() function helps evaluate whether a substring is present in each element of a series, the startswith() and endswith() functions specifically look for the presence of the substring at the start and the end of strings, respectively:
start_series = pd.Series(["strange", "stock", "cost", "past", "state"])start_series.str.startswith("st")
The following is the output:

Similarly, endswith can be used as shown here:
end_series= pd.Series(["ramen", "program", "cram", "rammed", "grammer"])end_series.str.endswith("ram")
The following is the output:
However, ...
Read now
Unlock full access