Skip to content

Tag: python

Pandas str.extract() regex to extract city info

I have a pandas df of addresses like this: I want to extract the name of city such that expected results: My code is below: My results: However, when the city name doesn’t end with a , it will pick up the rest of the string. If i don’t end my regex in , I won’t get the full city

Regex [0-9]* matches empty string on “(2434525)”

I was trying to match all numbers in a string, this is an example code: Why is this strange behavior happening here? Answer In your case re.search will stop on first match. re.search(r'[0-9]*’, ‘(123)’).group() – will search for digits starting from empty string to infinity long string…

import with no known parent package

I found similar discussion here. But my problem is it works running python code in normal mode. When I run in debugging as python -m pdb nmt.py, I have ImportError: attempted relative import with no known parent package. My python version is Python 3.7.13. Error is coming from the following line. How to make …