Reputation: 134
I am going to describe males and females groups by gender to visualize how Churn Rate (1-Retention Rate) looks like for each value.
My output
df_data.groupby(by='gender')['Churn'].mean()
error
---------------------------------------------------------------------------
DataError Traceback (most recent call last)
<ipython-input-46-75992efc6958> in <module>()
----> 1 df_data.groupby(by='gender')['Churn'].mean()
1 frames
/usr/local/lib/python3.7/dist-packages/pandas/core/groupby/groupby.py in mean(self, numeric_only)
1396 "mean",
1397 alt=lambda x, axis: Series(x).mean(numeric_only=numeric_only),
-> 1398 numeric_only=numeric_only,
1399 )
1400
/usr/local/lib/python3.7/dist-packages/pandas/core/groupby/groupby.py in _cython_agg_general(self, how, alt, numeric_only, min_count)
1051
1052 if len(output) == 0:
-> 1053 raise DataError("No numeric types to aggregate")
1054
1055 return self._wrap_aggregated_output(output, index=self.grouper.result_index)
DataError: No numeric types to aggregate
Upvotes: 2
Views: 5973
Reputation: 57033
All your columns, even those that look like numbers, are strings. You must convert "numeric" columns into numeric columns with .astype(int)
before applying .mean()
. For example:
df.tenure = df.tenure.astype(int)
Upvotes: 4