Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Python find substring between two markers

Please note i have read other answers on here but they havent worked for me (or I have applied them incorrectly, sorry if I have).

I have a list which I have then converted to Dataframe. I have then converted to string using:

df['URL'] = pd.Series(df['URL'], dtype="string")

However, when i go to use .find, .partition I get the error:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

df['URL'].find('entry/')

AttributeError: 'Series' object has no attribute 'find'

string is as follows and i need to get the unique number between ‘entry/’ and ‘/event’. How can i do this?

https://fantasy.premierleague.com/entry/349289/event/14

>Solution :

You have to use Series.str to access values of the series as strings so that you can start applying the string method(like .find, partition).

But a better approach in this case would be use extract which allows to extract capture groups in the regex entry/(\d+)/event as columns

df['URL'].str.extract("entry/(\d+)/event", expand=False)
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading