pandas groupby.count doesn't count zero occurrences I am using groupby.count for 2 columns to get value occurrences under a class constraint. However, if value $x$ in feature never occurs with class $y$, then this pandas method returns only non-zero frequencies. Is there any solution or alternate method?
The script is like:
combine = np.vstack([X_train[:,-1], y_train]).T
combine_df = pd.DataFrame(combine, columns = ['feature','class'])
class_count_groupby = combine_df[combine_df['class'] == 2]['class'].groupby(combine_df['feature']).count()
Use crosstab instead:
pd.crosstab(combine_df.class, combine_df.feature)