Created
January 31, 2019 19:27
-
-
Save jtemporal/5e601921f7c900643b9ddc220754eaba to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import pandas as pd | |
import numpy as np | |
raw_data = {'id': [1,2,1,1,3,4], 'categoria': ['A', 'B', 'A', 'B', 'C', np.nan]} | |
t = pd.DataFrame(raw_data, columns=['id', 'categoria']) | |
def cat_mais_freq(user): | |
value_count_index = user['categoria'].value_counts().index | |
if value_count_index.empty: | |
return None | |
return value_count_index.values[0] | |
# t | |
t.groupby('id').apply(cat_mais_freq) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment