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
from datetime import datetime, timedelta | |
import pandas as pd | |
source = pd.read_csv('data.csv', index_col='uuid', parse_dates=['date']) | |
date_1 = datetime.utcnow() | |
date_0 = date_1 - timedelta(days=30) | |
data = source[(source['date'] > date_0) & (source['date'] < date_1)] |
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
def get_visits(groupby): | |
ip_visits = data.groupby(groupby)['ip'] | |
return pd.DataFrame( | |
{'unique_visits': ip_visits.apply(lambda x: len(set(x))), | |
'total_visits': ip_visits.apply(len)}) | |
data['date_day'] = data['date'].apply(datetime.date) | |
visits_by_date = get_visits('date_day') | |
# Redefine with date index to avoid lack of dates. | |
visits_by_date = pd.DataFrame(visits_by_date, |
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
#!/usr/bin/env python | |
import sys | |
for line in sys.stdin: | |
if not line.strip() or line.startswith('Wban'): | |
continue | |
_, k, v = line[:17].split(',', 2) | |
try: |
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
#!/usr/bin/env python | |
import sys | |
last_k = None | |
max_v = 0 | |
for line in sys.stdin: | |
k, v = line.strip().split('\t') |
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
#!/usr/bin/env python | |
import re | |
import sys | |
started = False | |
for line in sys.stdin: | |
if started: |
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
#!/usr/bin/env python | |
import sys | |
last_k = None | |
last_v = 0 | |
for line in sys.stdin: | |
k, v = line.strip().split('\t') |
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
#!/usr/bin/env python | |
import sys | |
for line in sys.stdin: | |
if line.startswith('"'): | |
index = line.find('"', 1) | |
fields = [line[1:index]]+line[index+2:].split(',') | |
else: | |
fields = line.split(',') |
OlderNewer