df['col'].fillna('NULL').map(lambda x: ';'.join(sorted(x.split(';'key=lambda x:…
- User
df['col'].fillna('NULL').map(lambda x: ';'.join(sorted(x.split(';'key=lambda x: int(re.search(r'\d+'> x).group())))) AttributeError: NoneType object has no attribute 'group*
- Assistant
The error you're encountering suggests that at least one of the strings being processed by
re.search(r'\d+', x)does not contain a number, which results inre.searchreturningNone. When you then call.group()on thatNoneresult, you get anAttributeError.To correct this, you can update your
lambdafunction to handle cases where there is no number found in the string. You can do this by checking whetherre.search()returnsNonebefore attempting to call.group().Here’s your corrected code:
python