I am running the following function but somehow struggling to have it take the length condition into account (the if part). It simply runs the first part if the function only:
stringDataFrame.apply(lambda x: x.str.replace(r'[^0-9]', '') if (len(x) >= 7) else x)
it somehow only runs the x.str.replace(r'[^0-9]', '')
part for some reason, what am I doing wrong here i have been stuck.