Created
September 28, 2018 08:32
-
-
Save sdia-zz/5b400fd6f3de78809a85914fbdb7354f to your computer and use it in GitHub Desktop.
This file contains 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
#!/usr/bin/env python3 | |
#-*- coding:utf-8 -*- | |
import random | |
import os | |
import binascii | |
import pandas as pd | |
def metric(): | |
return int(random.random() * 1000) | |
def session_long(): | |
return random.choice('abcd') | |
DATA = [ | |
dict(sl=session_long(), metric=metric()), | |
dict(sl=session_long(), metric=metric()), | |
dict(sl=session_long(), metric=metric()), | |
dict(sl=session_long(), metric=metric()), | |
dict(sl=session_long(), metric=metric()), | |
dict(sl=session_long(), metric=metric()), | |
dict(sl=session_long(), metric=metric()), | |
dict(sl=session_long(), metric=metric()), | |
dict(sl=session_long(), metric=metric()), | |
dict(sl=session_long(), metric=metric()), | |
dict(sl=session_long(), metric=metric()), | |
dict(sl=session_long(), metric=metric()), | |
dict(sl=session_long(), metric=metric()), | |
dict(sl=session_long(), metric=metric()), | |
dict(sl=session_long(), metric=metric()), | |
dict(sl=session_long(), metric=metric()), | |
dict(sl=session_long(), metric=metric()), | |
dict(sl=session_long(), metric=metric()), | |
dict(sl=session_long(), metric=metric()), | |
dict(sl=session_long(), metric=metric()), | |
dict(sl=session_long(), metric=metric()), | |
dict(sl='a', metric=None) # IMPORTANT: Nan are excluded | |
] | |
df = pd.DataFrame(DATA) | |
df_agg = df.groupby(['sl'])['metric'].max().reset_index() | |
if __name__ == '__main__': | |
print(df) | |
print(df_agg) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment