Generation

generate functionThu, 16 Feb 2023

There is a Pandas Series column: 'loan_amnt' 10 78 54 GOOD 64 23 Write a function that replace all rows with letters in the column to NaN. Example: replace_non_numbers(df, 'loan_amnt') df Result: 10 78 54 NaN 64 23

def replace_non_numbers(df, column): df[column] = df[column].astype(str).str.replace('[^0-9]', '') return df[column].astype(float) #replace_non_numbers(df, 'loan_amnt')

Questions about programming?Chat with your personal AI assistant