Ebay Car Project: Boolean Series key will be reindexed to match DataFrame index

This happens when doing the guided project: Exploring Ebay Car Sales Data. I am dropping a couple of ‘bad’ rows of data using indexing. Just wondering how I might be able to get rid of this warning?

reg_year_low = autos['registration_year'] < 1910
reg_year_high = autos['registration_year'] > 2017
autos.drop(autos[reg_year_low].index, inplace=True)
autos.drop(autos[reg_year_high].index, inplace=True)

It shows the following warning:

/dataquest/system/env/python3/lib/python3.4/site-packages/ipykernel/__main__.py:2: UserWarning: Boolean Series key will be reindexed to match DataFrame index. from ipykernel import kernelapp as app

Hey Heather!

You’ll generally run into this warning when the code you’re writing is ambiguous and relies on Pandas correctly reindexing the df. You’ll want to be more explicit here — try using more explicit logic by combining your conditions/filters, like so:

reg_years_combined = reg_year_low & reg_year_high

You can then drop these rows in a single line instead of doing so iteratively.

Best,
Dee

1 Like

I thought this would be the solution but it turns out I was looking at an old run of the cells. I did Restart & Run All and now I think I am still doing something wrong? The old years are not dropped from the data frame now. When I go back to my old code the years are dropped again but I get the warning.

Here is my updated code:

reg_year_low = autos['registration_year'] < 1910
reg_year_high = autos['registration_year'] > 2017
reg_years_combined = reg_year_low & reg_year_high
autos.drop(autos[reg_years_combined].index, inplace=True)

My result after printing (shortened for this post):

print(sorted(list(autos['registration_year'].unique())))

[1000, 1001, 1111, 1500, 1800, 1910, … 2017, 2018, 2019, 2800, 4100, 4500, 4800, 5000, 5911, 6200, 8888, 9000, 9996, 9999]

Thanks so much for your help! :slight_smile:

Can you shoot over the .ipynb file for your notebook and I’ll take a look on my end?

Hey!

I know is alittle bit late but I dont want to open same post and I found this:

A&E :vulcan_salute: