1

I have a dataframe and would like to create a custom feature to the frequency of the category. How can I achieve this using a featuretools custom primitive?

In pandas, this looks like the following:

df = pd.DataFrame({'category': ['a' ,'b', 'a']})
df['frequency' ] = df.groupby('category')['category'].transform('count')

df
|   | category | frequency |
|---|:--------:|----------:|
| 0 |     a    |         2 |
| 1 |     b    |         1 |
| 2 |     a    |         2 |

This seems like a more general instance of the question here, and may be helpful for ft newcomers.


Note: This is specifically about the featuretools library and custom primitives, not about computing category frequency in a dataframe.

alacarter
  • 349
  • 2
  • 11

0 Answers0