counting elements in a specific dataframe.iloc

Viewed 565

I have a feature that only consist of binary Values (0,1). I'm trying to count the number of occurrences of each binary value in a single column or feature.

Code:

df   = pd.read_csv(training_file)
data = df.iloc[:, 2]

#This only returns the size of the column and not sure why
print(data.count())

Is there a way with panda to only return the number of occurrence for a specific value like 0?

1 Answers

You can use data.sum() if the type in the column is not string especially because the data is binary (0,1).

Related