Avatar ·

Python Pandas. Replace some values in a column with others

📁 question, Error, example, AI

The task is as follows: there is a column BasePay1 containing numbers, but also the following values: Not Provided. So, I need to convert this feature to type float64.
I do this: df['BasePay'].astype('float64')
And I get an error: could not convert string to float: 'Not Provided'
For obvious reasons) The type of the BasePay feature is object
The question is: how can I replace the values in the BasePay feature that are equal to Not provided with, for example, 0.00? This is the main question) I even tried writing functions, nothing helps. I understand that the task is quite simple, but I've been stuck in one place for about 3 hours.

Avatar ·

The essence of this error is very simple - an attempt to access a list/array element with a non-existent index.

Example:

lst = [1, 2, 3]print(lst[3])

output:

----> 2 print(lst[3])IndexError: list index out of range

The list shown in the example has three elements. Indexing in Python starts from 0 and ends at n-1, where n is the number of elements in the list (AKA list length). Accordingly, for the list lst

Log in to leave an answer

Blogs