Guided Project: Exploring Ebay Car Sales Data step 5

cols = ['date_crawled', 'ad_created', 'last_seen']
for v in cols:
    autos[cols].value_counts(normalize=True, dropna=False).describe()

error=

'DataFrame' object has no attribute 'value_counts'

pointing at the line after the start of the for loop.

Have a closer look: Where is v being used in the loop? :wink:

tried

for v in cols:
    autos[v].value_counts(normalize=True, dropna=False).describe()

but it now doesn’t return anything or an error

tried

for v in cols:
    autos[cols[v]].value_counts(normalize=True, dropna=False).describe()

but it returns

 list indices must be integers or slices, not str

stackoverflow recommended

for cols in autos.columns:
    autos[cols].value_counts(normalize=True, dropna=False).describe()

no error, but no information either.

Ah ok. I know the reason for the DataFrame error was because it was using multiple columns.

I copied and pasted the code (fixing the v issue). The reason it doesn’t show anything because it’s not printing each result as you go. I did this:

cols = ['date_crawled', 'ad_created', 'last_seen']
for v in cols:
    temp = autos[v].value_counts(normalize=True, dropna=False).describe()
    print(temp)

And I got these results:

count    46882.000000
mean         0.000021
std          0.000004
min          0.000021
25%          0.000021
50%          0.000021
75%          0.000021
max          0.000062
Name: date_crawled, dtype: float64
count    76.000000
mean      0.013158
std       0.015956
min       0.000021
25%       0.000021
50%       0.000144
75%       0.032112
max       0.038855
Name: ad_created, dtype: float64
count    38474.000000
mean         0.000026
std          0.000013
min          0.000021
25%          0.000021
50%          0.000021
75%          0.000021
max          0.000165
Name: last_seen, dtype: float64
1 Like

I kinda wish this site had something like reddits gold here, so when people solve a lot of problems there’s something that follows them saying “this person does good work”.

3 Likes