Generation

generate functionThu, 16 Feb 2023

There is a Pandas Series column: 'loan_amnt' 10 78 54 GOOD 64 23 There is a Pandas dataframe that has column 'loan_amnt' with both numbers and letters and words. Write a function that checks the rows in column 'loan_amnt' for numbers and letters. If the string has numbers it is converted to float64 If the string is not a number, it is replaced by np.nan. Example: replace_non_numbers(df, 'loan_amnt') df Result: 10 78 54 NaN 64 23

def replace_non_numbers(df, column): df[column] = pd.to_numeric(df[column], errors = 'coerce')

Want to kickstart your project?Use the new AI Studio to create your code