Screen Link:
My Code:
autos[‘price’] = autos[autos[‘price’].between(1000,10000)]
Replace this line with your code
What I expected to happen:
I tried to cut down the numbers less than 1000 and grater than 10000 in the “price” column because they are extraordinary.
But after I coded above, the data was converted into the dates.
Why did that happen?
What actually happened:
Replace this line with the output/error
The above returns all data from autos
corresponding to where the price
is between that range. If you print out just that code you will see the output as a dataframe (table with multiple rows and columns) where the price
column will have values between that range .
However, you are also trying to assign the above back not into the autos
dataframe but into the price
column of autos
.
autos[‘price’] = autos[autos[‘price’].between(1000,10000)]
You can’t assign a dataframe to a specific column. When you try to do that, pandas just uses the last column from the dataframe and assigns that to autos['price']
instead.
And the last column in the dataframe you get from autos[autos[‘price’].between(1000,10000)]
is the last_seen
column. That’s why you get the date and time data in the price
column.
Be more careful about what kind of operations you are doing on your data and how and where you are storing it. Take it one step at a time and print out value to be sure of what’s happening.
1 Like