python - How to get unique from dataframe using pandas? -
i have df
2016-06-21 06:25:09 upi88@yandex.ru http/1.1 mozilla/5.0 (iphone; cpu iphone os 7_1_2 mac os x) applewebkit/537.51.2 (khtml, gecko) version/7.0 mobile/11d257 safari/9537.53 200 application/json 2130 https://edge-chat.facebook.com/pull?channel=p_100006170407238&seq=27&clientid=1d67ca6e&profile=mobile&partition=-2&sticky_token=185&msgs_recv=27&qp=y&cb=1830997782&state=active&sticky_pool=frc3c09_chat-proxy&uid=100006170407238&viewer_uid=100006170407238&m_sess=&__dyn=1z3p5wne-4upwdf3gagy78qzoc6erz8b0gxg9xu3z0qwfzohxo3o2g2a1mwyxm48sxadwpvey1qk78gwux6&__req=79&__ajax__=aylbtcbwgc2suzli-j88v0pwa58vtqeg3ylqlydfrsal6uwlsjsspd7peu8mgl6nshvd2zxfdcb6a0-xunbugusyz1lmymuu97r43iv7xsfpyg&__user=100006170407238 2016-06-22 06:25:20 upi88@yandex.ru post http/1.1 mozilla/5.0 (iphone; cpu iphone os 7_1_2 mac os x) applewebkit/537.51.2 (khtml, gecko) version/7.0 mobile/11d257 safari/9537.53 200 application/x-javascript 20248 https://m.facebook.com/stories.php?aftercursor=mtq2njy2mzewntoxndy2njyzmta1ojg6nzm0odg0mdexmjayndy1mza5ntoxndy2njyynzk1oja%3d&tab=h_nor&__m_log_async__=1 2016-06-23 06:25:25 upi88@yandex.ru connect http/1.1 mozilla/5.0 (iphone; cpu iphone os 7_1_2 mac os x) applewebkit/537.51.2 (khtml, gecko) version/7.0 mobile/11d257 safari/9537.53 200 - 0 scontent.xx.fbcdn.net:443 2016-06-23 06:25:25 upi88@yandex.ru http/1.1 mozilla/5.0 (iphone; cpu iphone os 7_1_2 mac os x) applewebkit/537.51.2 (khtml, gecko) version/7.0 mobile/11d257 safari/9537.53 200 text/html 1105 https://m.facebook.com/xti.php?xt=2.qid.6299270070554694533%3amf_story_key.343726573953754118%3aei.ai%40ecf11fb3faf9c0b1f73ce2a74bc9f228 2016-06-24 06:25:25 lemuska@mail.ru connect http/1.1 mozilla/5.0 (iphone; cpu iphone os 7_1_2 mac os x) applewebkit/537.51.2 (khtml, gecko) version/7.0 mobile/11d257 safari/9537.53 200 - 0 scontent.xx.fbcdn.net:443 2016-06-25 06:25:25 lemuska@mail.ru connect http/1.1 mozilla/5.0 (iphone; cpu iphone os 7_1_2 mac os x) applewebkit/537.51.2 (khtml, gecko) version/7.0 mobile/11d257 safari/9537.53 200 - 0 scontent.xx.fbcdn.net:443 2016-06-25 06:25:25 lemuska@mail.ru connect http/1.1 mozilla/5.0 (iphone; cpu iphone os 7_1_2 mac os x) applewebkit/537.51.2 (khtml, gecko) version/7.0 mobile/11d257 safari/9537.53 200 - 0 scontent.xx.fbcdn.net:443
i need unique date every id
(only year, month , date). desired output:
upi88@yandex.ru - 2016-06-21, 2016-06-22, 2016-06-23 lemuska@mail.ru - 2016-06-24, 2016-06-25
how can date?
you can first extract info need dates:
df['filtered date'] = [w[:10] w in df['date']]
then use `drop duplicates':
output = df[['id','filtered date']].drop_duplicates()
you can reorder data frame clarity:
output.sort_values(by['id','filtered date'],inplace = true)
you'll kind of output:
id filtered date 0 lemuska@mail.ru 2016-06-24 1 lemuska@mail.ru 2016-06-25 3 upi88@yandex.ru 2016-06-21 4 upi88@yandex.ru 2016-06-22 5 upi88@yandex.ru 2016-06-23
Comments
Post a Comment