I am trying to use df['column_name'].str.count("+") in python pandas, but I receive
"error: nothing to repeat"
. With the regular characters the method works, e.g. df['column_name'].str.count("a") works fine.
Also, there is a problem with the "^"-sign. If I use df['column_name'].str.contains("^") the result is incorrect - it looks like "^" gets interpreted as " " (empty space).
Surprisingly, if I use .count("+") and .contains("^") on a regular, non-pandas string they work perfectly fine.
simple working example:
df = pd.DataFrame({'column1': ['Nighthawks+', 'Dragoons'], 'column2': ['1st', '2nd']}, columns = ['column1', 'column2']) When applying df["column1"].str.contains("^") one gets "True, True" but is should be "False, False".
And when applying df["column1"].str.count("+") one gets
"error: nothing to repeat"
But then, outside of panda, "bla++".count("+") gives correctly the result "2".
Any solutions? Thanks