Created
July 4, 2017 23:54
-
-
Save mmas/627f0ceae8e468bde92b1a0fb9ed5f05 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
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, | |
index=pd.date_range(date_0, date_1)).fillna(0) | |
# Rest of filtered visits. | |
visits_by_os = get_visits('os') | |
visits_by_city = get_visits('city') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment