Last answered:

17 Nov 2024

Posted on:

16 Nov 2024

0

Resolved: Error in Section 4

Can anyone help me on this error please?
1 answers ( 1 marked as helpful)
Super learner
This user is a Super Learner. To become a Super Learner, you need to reach Level 8.
Posted on:

17 Nov 2024

1
Hi Gia, I also had the problem of trying to replace '10+ years' using ..str.replace('\+ years', '').
I solved it by removing the escape character '\', leaving the line like this:
             
loan_data['emp_length_int'] = loan_data['emp_length'].str.replace('+ years', '')

I suppose that in older versions of Python it was necessary to place the escape character before the plus sign in the strings.

Ultimately the goal is to keep only the characters that are numbers, so for the case '10+ years' I have to manage to replace the string '+ years' with the string '' (nothing - null).
Using Python raw strings I can also get the same result:
loan_data['jm_int'] = loan_data['emp_length'].str.replace(r'+ years', '')

Submit an answer