Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

'Series' object has no attribute 'values_counts'

When I try to apply the values_count() method to series within a function, I am told that 'Series' object has no attribute 'values_counts'.

def replace_1_occ_feat(col_list, df):
    for col in col_list:
        feat_1_occ = df[col].values_counts()[df[col].values_counts() == 1].index 
        feat_means = df[col].groupby(col)['SalePrice'].mean()
        feat_means_no_1_occ = feat_means.iloc[feat_means.difference(feat_1_occ),:]
        for feat in feat_1_occ:
            # Find the closest mean SalePrice
            replacement = (feat_means_no_1_occ - feat_means.iloc[feat,:]).idxmin()
            df.col.replace(feat, replacement, inplace = True)

However when running df.column.values_count() outside a function it works.

The problem occurs on the first line when the values_counts() methods is used. I checked the pandas version it's 0.23.0.

like image 234
Azorx Avatar asked Dec 06 '22 10:12

Azorx


1 Answers

The function is value_counts(). Note only count is plural.

like image 144
Kyle Avatar answered Feb 15 '23 17:02

Kyle