Trouble on exploring price by brand

Screen Link:
https://app.dataquest.io/m/294/guided-project%3A-exploring-ebay-car-sales-data/4/exploring-the-odometer-and-price-columns

My Code:

autos_pt2 = autos[autos["yearofregistration"] > 1950]
autos_pt3 = autos_pt2[autos_pt2["yearofregistration"] < 2000]
chevrolet_autos = autos_pt3[autos_pt3["brand"] == "chevrolet"]
chevrolet_autos["brand"].value_counts()
autos_pt3 = autos_pt3.reset_index(drop = True)

aggregate_data = {}

for vt in chevrolet_autos:
    selected_vt = autos[autos["vehicletype"] == vt]
    mean_price = selected_vt["price"].mean()
    aggregate_data[b] = int(mean_price)


What I expected to happen:
I decided to look instead of by price for brand, i wanted to do price by vehicle type for chevys. I thought this would allow me to aggregate the data, but instead I’m getting this error:

ValueErrorTraceback (most recent call last)
in ()
12 selected_row = autos[autos[“brand”] == b]
13 mean_price = selected_row[“price”].mean()
—> 14 aggregate_data[b] = int(mean_price)

ValueError: cannot convert float NaN to integer

What actually happened:

Replace this line with the output/error

Hi @adam.t.rafael

The best way to find out the exact issue is to try to print out the result of each code that you do.

Let’s begin with this code and find out exactly what value(s) vt takes up.

Comment everything below this, and just code, print(vt) let us know what you observe.

Also, if you are selecting only one brand for a testing purpose also, you won’t need a for loop to calculate the mean price. you can directly calculate that since now you have a dataframe (chevrolet_autos) that only consists of cars made by chevrolet brand. Although I am assuming you are only doing it for the testing purpose.

try to print each and every variable you have under for loop (one at a time) to verify the results.

Hi! Thanks for responding. So what I noticed was the issue was with the “chevrolet_autos”. I was playing around with it and ended up changing my goal, but I still had one question- when i have chevrolet brand (in the place of chevrolet_autos) , why does the “value_counts().index” need to be there?
This worked:
chevrolet_brand = chevrolet_autos[“vehicletype”].value_counts().index
but this didnt:
chevrolet_brand = chevrolet_autos[“vehicletype”]

hi @adam.t.rafael

I am still not sure about exactly what your goal was/is while writing the code from your original post.

Coming to the question of the difference between chevrolet_brand variable, I would again suggest you to use a print(chevrolet_brand) and print(type(chevrolet_brand)) to see the difference, after each of the two codes.

answer-wise - the code will only select the brand names and assign them to chevrolet_brand as an index!

  • and this code will assign the complete series as is.