import pandas as pd
import re
df = pd.DataFrame({"A":['1324 cats',pd.np.nan,'There were 25647900 tickets',34254], "B":[543,678678,0,0]})
In an example DataFrame, like the one above, I am trying to calculate a new column where I extract any consecutive runs of numbers. I'm treating the cell value as a string when I hand it to re.search() in cases where there's only an integer in the cell, and I'm attempting to use pd.isna() to bypass null values, but I still get the following error: "'NoneType' object is not subscriptable"
df['C'] = df['A'].apply(lambda x: re.search(r'\d+',str(x))[0] if not pd.isna(x) else x)
This approach works fine when not involving re in the process, like this:
df['C'] = df['A'].apply(lambda x: 'Y' if not pd.isna(x) else x)