[Solved] AttributeError: ‘DataFrame’ object has no attribute

I keep getting different attribute errors when trying to run this file in ipython…beginner with pandas so maybe I’m missing something


from pandas import Series, DataFrame

import pandas as pd

import json

data = []
with open('file.json') as f:
for line in f:

df = DataFrame(data, columns=['accepted', 'user', 'object', 'response'])
clean = df.replace('NULL', nan)
clean = clean.dropna()

print clean.value_counts() 

AttributeError: 'DataFrame' object has no attribute 'value_counts'

Any ideas?

Solution #1:

value_counts is a Series method rather than a DataFrame method (and you are trying to use it on a DataFrame, clean). You need to perform this on a specific column:


It doesn’t usually make sense to perform value_counts on a DataFrame, though I suppose you could apply it to every entry by flattening the underlying values array:

Respondent: Andy Hayden
Solution #2:

To get all the counts for all the columns in a dataframe, it’s just df.count()

Respondent: szeitlin
Solution #3:

value_counts() is now a DataFrame method since pandas 1.1.0

Respondent: peractio
Solution #4:

value_counts work only for series. It won’t work for entire DataFrame. Try selecting only one column and using this attribute.
For example:


It also won’t work if you have duplicate columns. This is because when you select a particular column, it will also represent the duplicate column and will return dataframe instead of series.

At that time remove duplicate column by using

df = df.loc[:,~df.columns.duplicated()]
Respondent: Barath M
The answers/resolutions are collected from stackoverflow, are licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0 .

Most Popular

To Top
India and Pakistan’s steroid-soaked rhetoric over Kashmir will come back to haunt them both clenbuterol australia bossier man pleads guilty for leadership role in anabolic steriod distribution conspiracy