konstantgr/themisto huggingface dataset:
for _, row in df.iterrows():
    actions = row['info'].split('-> ')
    for action in actions:
        parts = action.strip().split('(')
        action_name = parts[0].strip()
        action_time = parts[1].strip(')')
        new_row = {'user_id': row['user_id'], 'session_num': 0, 'action_name': action_name, 'action_time': action_time}
        df_temp.loc[len(df_temp)] = new_row
for _, row in df.iterrows():
    actions = row['info'].split('-> ')
    for action in actions:
        print(action)
        parts = action.strip().split('(')
        action_name = parts[0].strip()
        action_time = parts[1].strip(')')
        new_row = {'user_id': row['user_id'], 'session_num': 0, 'action_name': action_name, 'action_time': action_time}
        df_temp.loc[len(df_temp)] = new_row
for _, row in df.iterrows():
    actions = row['info'].split('-> ')
    for action in actions:
        print(action)
        if action != ' ':
            parts = action.strip().split('(')
            action_name = parts[0].strip()
            action_time = parts[1].strip(')')
            new_row = {'user_id': row['user_id'], 'session_num': 0, 'action_name': action_name, 'action_time': action_time}
            df_temp.loc[len(df_temp)] = new_row
for _, row in df.iterrows():
    actions = row['info'].split('-> ')
    for action in actions:
        print(action)
        if action != '':
            parts = action.strip().split('(')
            action_name = parts[0].strip()
            action_time = parts[1].strip(')')
            new_row = {'user_id': row['user_id'], 'session_num': 0, 'action_name': action_name, 'action_time': action_time}
            df_temp.loc[len(df_temp)] = new_row
for _, row in df.iterrows():
    actions = row['info'].split('-> ')
    for action in actions:
        if action != '':
            parts = action.strip().split('(')
            action_name = parts[0].strip()
            action_time = parts[1].strip(')')
            new_row = {'user_id': row['user_id'], 'session_num': 0, 'action_name': action_name, 'action_time': action_time}
            df_temp.loc[len(df_temp)] = new_row
for _, row in df.iterrows():
    actions = row['info'].split('-> ')
    for action in actions:
        if len(action) > 5:
            parts = action.strip().split('(')
            action_name = parts[0].strip()
            action_time = parts[1].strip(')')
            new_row = {'user_id': row['user_id'], 'session_num': 0, 'action_name': action_name, 'action_time': action_time}
            df_temp.loc[len(df_temp)] = new_row
for _, row in df.iterrows():
    actions = row['info'].split('-> ')
    for action in actions:
        if len(action) > 5:
            print(action)
            parts = action.strip().split('(')
            action_name = parts[0].strip()
            action_time = parts[1].strip(')')
            new_row = {'user_id': row['user_id'], 'session_num': 0, 'action_name': action_name, 'action_time': action_time}
            df_temp.loc[len(df_temp)] = new_row
for _, row in df.iterrows():
    actions = row['info'].split('-> ')
    for action in actions:
        try:
            parts = action.strip().split('(')
            action_name = parts[0].strip()
            action_time = parts[1].strip(')')
            new_row = {'user_id': row['user_id'], 'session_num': 0, 'action_name': action_name, 'action_time': action_time}
            df_temp.loc[len(df_temp)] = new_row 
        except IndexError:
            print("Index out of range")
            print(action)
            continue
df = df.assign(actions=df['info'].str.split('-> ')).explode('actions')
df = df.assign(actions=df['info'].str.split('-> ')).explode('actions')
df
import pandas as pd
import numpy as np
import zipfile
df = df.assign(actions=df['info'].str.split('-> ')).explode('actions')
df = df.drop('info', axis=1)
df
df = df.join(df['actions'].str.extract(r'(?P<action_name>[^(]+)\((?P<action_time>[^)]+)\)'))
df
df = df.drop(columns=['actions'])
df.head()
# For each instance separate the user and their list of actions
df['user_id'] = df[0].str.split(':').str[0]
df['info'] = df[0].str.split(': ').str[1]
df['user_id'] = df['user_id'].str.replace('@', '')
df = df.drop(0, axis=1)
df
df = df.assign(actions=df['info'].str.split('>')).explode('actions')
df = df.drop('info', axis=1)
df
# Looking at the row data
df.head()
df = df.assign(actions=df['info'].str.split('>')).explode('actions')
df['actions'] = df['actions'].str.strip('-')
df = df.drop('info', axis=1)
df
pattern = r'^([A-Za-z_]+)_\d+ \((\d{2}/\d{2}/\d{2} \| \d{2}:\d{2}:\d{2})\)$'
df[['action_name', 'action_time']] = df['actions'].str.extract(pattern, expand=True)
df
pattern = r'^(\w+_\d+)\s+\((\d+/\d+/\d+)\s+\|\s+(\d+:\d+:\d+)\)$'
df[['action_name', 'action_time']] = df['actions'].str.extract(pattern, expand=True)
df
# Looking at the raw data
df.head()
# Making list of actions with corresponding user info
df = df.assign(actions=df['info'].str.split('>')).explode('actions')
df['actions'] = df['actions'].str.strip('-')
df = df.drop('info', axis=1)
df
df['action_name'] = df['actions'].str.split().str.get(0)
df['action_name'] = df['actions'].str.split().str.get(0)
df['action_time'] = df['actions'].str.split().str.get(1)
df['action_name'] = df['actions'].str.split().str.get(0)
df['action_type'] = df['actions'].str.split(n=1).str[1]
df['action_name'] = df['actions'].str.split().str.get(0)
df['action_time'] = df['actions'].str.split(n=1).str[1]
df = df.drop('actions', axis=1)
df
df['action_time'] = df['actions'].str.split(n=1).str[1]
df['action_name'] = df['actions'].str.split().str.get(0)
df = df.drop('actions', axis=1)
df
df['action_time'] = df['actions'].str.split(n=1).str[1]
df['action_time'] = pd.to_datetime(df['action_time'], format='(%m/%d/%y | %H:%M:%S)')
df['action_name'] = df['actions'].str.split().str.get(0)
df = df.drop('actions', axis=1)
df
df['action_time'] = df['actions'].str.split(n=1).str[1]
df['action_time'] = pd.to_datetime(df['action_time'], format='(%d/%m/%y | %H:%M:%S)')
df['action_name'] = df['actions'].str.split().str.get(0)
df = df.drop('actions', axis=1)
df
df['action_time'] = df['actions'].str.split(n=1).str[1]
#df['action_time'] = pd.to_datetime(df['action_time'], format='(%d/%m/%y | %H:%M:%S)')
df['action_name'] = df['actions'].str.split().str.get(0)
df = df.drop('actions', axis=1)
df
df['action_time'] = pd.to_datetime(df['action_time'], format='(%d/%m/%y | %H:%M:%S)')
df['action_time']
df['action_time'] = df['actions'].str.split(n=1).str[1]
df['action_time'] = df['action_time'].str.strip(' ')
df['action_name'] = df['actions'].str.split().str.get(0)
df = df.drop('actions', axis=1)
df
# Making list of actions with corresponding user info
df = df.assign(actions=df['info'].str.split('>')).explode('actions')
df['actions'] = df['actions'].str.strip('-')
df = df.drop('info', axis=1)
df = df.reindex()
df
# Making list of actions with corresponding user info
df = df.assign(actions=df['info'].str.split('>')).explode('actions')
df['actions'] = df['actions'].str.strip('-')
df = df.drop('info', axis=1)
df = df.reset_index(drop=True)
df
import re

pattern = r'\(\d{2}/\d{2}/\d{2} \| \d{2}:\d{2}:\d{2}\)'
mask = df['action_time'].str.contains(pattern)
df1 = df[mask]
df1
corrupt = []

for i, row in df.iterrows():
    try:
        pd.to_datetime(row['action_time'], format='(%d/%m/%y | %H:%M:%S)')
    except ValueError:
        corrupt.append(i)

print(len(corrupt))
df = df.drop(corrupt)
df['action_time'] = pd.to_datetime(df['action_time'], format='(%d/%m/%y | %H:%M:%S)', errors='ignore')
df['action_time'] = pd.to_datetime(df['action_time'], format='(%d/%m/%y | %H:%M:%S)', errors='coerce')
df = df.sort_values(['user_id', 'action_time'])
df
df = df.sort_values(['user_id', 'action_time'])
df.dropna(how='any', inplace=True)
df
end_mask = df['action_name'] == 'END'
df['session'] = df.groupby('user_id')['action_name'].apply(lambda x: end_mask.loc[x.index].cumsum())
df
end_mask = df['action_name'] == 'END'
df['session'] = df.groupby('user_id')['action_name'].apply(lambda x: end_mask.loc[x.index].cumsum() - 1)
df
end_mask = df['action_name'] == 'END'
df['session_num'] = df.groupby('user_id')['action_name'].apply(lambda x: (~mask[:x.index[-1]+1]).cumsum()).reset_index(drop=True)
df
df['session_num'] = 0
df['session_num'] = (df['action'] == 'END').groupby(df['user_id']).cumsum()
df
df['session_num'] = (df['action_name'] == 'END').groupby(df['user_id']).cumsum()
df
df.head(n=30)
df.head(n=250)
df.head(n=80)
df.head(n=50)
df.iloc[0:50]
df.iloc[50:100]
df.tail(50)
df.iloc[2453:2487]
df['action'] = df['action'].replace('END', np.NaN)
df = df.dropna()
df['action_name'] = df['action_name'].replace('END', np.NaN)
df = df.dropna()
df.reset_index()
df.reset_index(drop=True)
df = df.reset_index(drop=True)
df.groupby('user_id')['action'].count().mean()
df.groupby('user_id')['action_name'].count().mean()
df['user_id'].nunique()
print(pd.unique(df['user_id']))
print(pd.unique(df['action_name']))
df.count()
df.value_counts()
df['action_name'].value_counts()
df['action_name'] = df['action_name'].replace('END', NaN)
df = df.dropna()
df = df.reset_index(drop=True)
df['action_name'] = df['action_name'].replace('END', np.NaN)
df = df.dropna()
df = df.reset_index(drop=True)
df = df[df['action_name'] != 'END']
df = df.dropna()
df = df.reset_index(drop=True)
df = df[df['action_name'] != 'null']
df['action_name'].value_counts()
df = df[df['action_name'] != 'END']
df = df[df['action_name'] != 'null']
df = df.dropna()
df = df.reset_index(drop=True)
df['user_id'].value_counts()
df.groupby('user_id')['action_time'].count().mean()
df.groupby('user_id')['action_time'].count()
df.groupby(['user_id', df['action_time'].dt.date]).size()
df.groupby(['user_id', df['action_time'].dt.date]).size().mean(level='user_id')
df.groupby(['user_id', df['action_time'].dt.date]).size().mean(
df.groupby(['user_id', df['action_time'].dt.date]).size().mean()
import pandas as pd
import numpy as np
import zipfile
import seaborn as sns
!pip install seaborn
df_timed = df.set_index('action_time')
grouped = df.groupby([df_timed.index.date, 'action_name'])
counts = grouped.size().reset_index(name='count')
sns.lineplot(data=counts, x='action_time', y='count', hue='action_name')
df_timed = df

df_timed.set_index('action_time', inplace=True)

grouped = df_timed.groupby([df_timed.index.date, 'action_name'])
counts = grouped.size().reset_index(name='count')
sns.lineplot(data=counts, x='action_time', y='count', hue='action_name')
df_timed = df

df_timed.set_index('action_time', inplace=True)

grouped = df_timed.groupby([df_timed.index.date, 'action_name'])
counts = grouped.size().reset_index(name='count')
sns.lineplot(data=counts, x='level_0', y='count', hue='action_name')
action_counts = df.groupby("action_name")["user_id"].count().reset_index(name="count")

sns.set(style="whitegrid")
sns.barplot(x="action_name", y="count", data=action_counts)
action_counts = df.groupby("action_name")["user_id"].count().reset_index(name="count")

sns.set(style="whitegrid")
sns.barplot(x="action_name", y="count", data=action_counts, xticklabels=list(for i in range(10)))
action_counts = df.groupby("action_name")["user_id"].count().reset_index(name="count")

sns.set(style="whitegrid")
sns.barplot(x="action_name", y="count", data=action_counts, xticklabels=(for i in range(10)))
action_counts = df.groupby("action_name")["user_id"].count().reset_index(name="count")

sns.set(style="whitegrid")
sns.barplot(x="action_name", y="count", data=action_counts, xticklabels=[0,1,2,3,4,5,6,7,8,9])
action_counts = df.groupby("action_name")["user_id"].count().reset_index(name="count")

sns.set(style="whitegrid")
sns.barplot(x="action_name", y="count", data=action_counts)
plt.xticks(rotation=70)
plt.tight_layout()
import pandas as pd
import numpy as np
import zipfile
import matplotlib.pyplot as plt
import seaborn as sns
pd.DataFrame(df.groupby('user_id')['action_time'].count())
pd.DataFrame(df.groupby('user_id')['action_time'].count()).T
pd.DataFrame(df.groupby('user_id')['action_time'].count()).T.head()
pd.DataFrame(df.groupby('user_id')['action_time'].count()).head()
pd.DataFrame(df.groupby('user_id')['action_time'].count()).sample()
pd.DataFrame(df.groupby('user_id')['action_time'].count()).sample(n=10)
# For each instance separate the user and their list of actions
df['user_id'] = df[0].str.split(':').str[0]
df['info'] = df[0].str.split(': ').str[1]
df['user_id'] = df['user_id'].str.replace('@', '')
df = df.drop(0, axis=1)
# Making list of actions with corresponding user info
df = df.assign(actions=df['info'].str.split('>')).explode('actions')
df['actions'] = df['actions'].str.strip('-')
df = df.drop('info', axis=1)
df = df.reset_index(drop=True)
df['action_time'] = df['actions'].str.split(n=1).str[1]
df['action_time'] = df['action_time'].str.strip(' ')
df['action_name'] = df['actions'].str.split().str.get(0)
df = df.drop('actions', axis=1)
df['action_time'] = pd.to_datetime(df['action_time'], format='(%d/%m/%y | %H:%M:%S)', errors='coerce')
df = df.sort_values(['user_id', 'action_time'])
df.dropna(how='any', inplace=True)
df['session_num'] = (df['action_name'] == 'END').groupby(df['user_id']).cumsum()
import numpy as np
import matplotlib.pyplot as plt
import scipy.stats as stats
import pandas as pd
import seaborn as sns
import zipfile
!pip install scipy
df['day_of_week'] = df['action_time'].dt.dayofweek
data = [df.loc[df['day_of_week'] == i, 'action_time'] for i in range(7)]
f_statistic, p_value = stats.f_oneway(*data)

print("F-statistic:", f_statistic)
print("p-value:", p_value)
df['day_of_week'] = df['action_time'].dt.dayofweek
data = [df.loc[df['day_of_week'] == i, 'action_time'] for i in range(7)]
plt.boxplot(data)
plt.xlabel('Day of the week')
plt.xticks(range(1, 8), ['Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat', 'Sun'])
plt.ylabel('Number of actions')
plt.show()
weekday_counts = pd.DataFrame({
    'Monday': [0]*len(df),
    'Tuesday': [0]*len(df),
    'Wednesday': [0]*len(df),
    'Thursday': [0]*len(df),
    'Friday': [0]*len(df),
    'Saturday': [0]*len(df),
    'Sunday': [0]*len(df)})

grouped = df.groupby(df['action_time'].dt.weekday_name).count()

for day in grouped.index:
    weekday_counts[day][grouped.index == day] = grouped.loc[day]['action_time']

weekday_counts
weekday_counts = pd.DataFrame({
    'Monday': [0]*len(df),
    'Tuesday': [0]*len(df),
    'Wednesday': [0]*len(df),
    'Thursday': [0]*len(df),
    'Friday': [0]*len(df),
    'Saturday': [0]*len(df),
    'Sunday': [0]*len(df)})

grouped = df.groupby(df['action_time'].dt.day_name).count()

for day in grouped.index:
    weekday_counts[day][grouped.index == day] = grouped.loc[day]['action_time']

weekday_counts
grouped = df.groupby(df['action_time'].dt.day_name).count()
grouped
grouped = df.groupby(df['action_time'].dt.weekday.count()
grouped
grouped = df.groupby(df['action_time'].dt.weekday.count())
grouped
df['action_time'].dt.weekday.count()
df['action_time'].weekday.count()
df['action_time'].dt.weekday
df['action_time'].dt.weekday.value_counts()
df['day_of_week'] = df['action_time'].apply(lambda x: x.strftime('%A'))

# group by day of the week and count the number of entries
day_counts = df.groupby('day_of_week')['action_time'].count()

# create a new dataframe with columns for each day of the week
weekday_df = pd.DataFrame({
    'Monday': 0,
    'Tuesday': 0,
    'Wednesday': 0,
    'Thursday': 0,
    'Friday': 0,
    'Saturday': 0,
    'Sunday': 0
}, index=[0])

# fill in the values for each day of the week
for day, count in day_counts.items():
    weekday_df[day][0] = count

# display the resulting dataframe
print(weekday_df)
df['day_of_week'] = df['action_time'].apply(lambda x: x.strftime('%A'))

day_counts = df.groupby('day_of_week')['action_time'].count()

weekday_df = pd.DataFrame({
    'Monday': 0,
    'Tuesday': 0,
    'Wednesday': 0,
    'Thursday': 0,
    'Friday': 0,
    'Saturday': 0,
    'Sunday': 0
}, index=[0])

for day, count in day_counts.items():
    weekday_df[day][0] = count

print(weekday_df)
df['day_of_week'] = df['action_time'].apply(lambda x: x.strftime('%A'))

# group by day of the week and create a list of counts for each day
day_counts = df.groupby('day_of_week')['action_time'].apply(list)

# create a new dataframe with columns for each day of the week
weekday_df = pd.DataFrame({
    'Monday': [],
    'Tuesday': [],
    'Wednesday': [],
    'Thursday': [],
    'Friday': [],
    'Saturday': [],
    'Sunday': []
})

# fill in the values for each day of the week
for day, counts in day_counts.items():
    weekday_df[day] = pd.Series(counts)

# display the resulting dataframe
print(weekday_df)
sns.lineplot(data=df.groupby([pd.Grouper(key='action_time', freq='D'), 'action_name']).size().reset_index(name='count'), x='action_time', y='count', hue='action_name')

plt.show()
sns.lineplot(data=df.groupby([pd.Grouper(key='action_time', freq='D'), 'action_name']).size().reset_index(name='count'), x='action_time', y='count', hue='action_name')

plt.figure(figsize=(12, 6))
plt.show()
sns.lineplot(data=df.groupby([pd.Grouper(key='action_time', freq='D'), 'action_name']).size().reset_index(name='count'), x='action_time', y='count', hue='action_name')

plt.figure(figsize=(18, 10))
plt.show()
sns.lineplot(data=df.groupby([pd.Grouper(key='action_time', freq='D'), 'action_name']).size().reset_index(name='count'), x='action_time', y='count', hue='action_name', linewidth=1.5)

plt.figure(figsize=(18, 10))
plt.show()
sns.lineplot(data=df.groupby([pd.Grouper(key='action_time', freq='D'), 'action_name']).size().reset_index(name='count'), x='action_time', y='count', hue='action_name', linewidth=0.5)

plt.figure(figsize=(18, 10))
plt.show()
sns.lineplot(data=df.groupby([pd.Grouper(key='action_time', freq='D'), 'action_name']).size().reset_index(name='count'), x='action_time', y='count', hue='action_name', linewidth=0.5, interpolate=True)

plt.figure(figsize=(18, 10))
plt.show()
sns.lineplot(data=df.groupby([pd.Grouper(key='action_time', freq='W'), 'action_name']).size().reset_index(name='count'), x='action_time', y='count', hue='action_name', linewidth=0.5)

plt.show()
sns.lineplot(data=df.groupby([pd.Grouper(key='action_time', freq='D'), 'action_name']).size().reset_index(name='count'), x='action_time', y='count', hue='action_name', linewidth=0.5)

plt.show()
sns.lineplot(data=df.groupby([pd.Grouper(key='action_time', freq='D'), 'action_name']).size().reset_index(name='count'), x='action_time', y='count', hue='action_name', linewidth=0.5, legend=False)

plt.show()
sns.lineplot(data=df.groupby([pd.Grouper(key='action_time', freq='W'), 'action_name']).size().reset_index(name='count'), x='action_time', y='count', hue='action_name', linewidth=0.5, legend=False)

plt.show()
user_daily_actions = df.groupby(['user_id', pd.Grouper(key='action_time', freq='D')])['action_name'].count().reset_index()
user_total_actions = user_daily_actions.groupby('user_id')['action_name'].sum().reset_index()
top_users = user_total_actions.nlargest(int(0.2*len(user_total_actions)), 'action_name')['user_id']
df_top_users = df[df['user_id'].isin(top_users)]
top_user_daily_actions = df_top_users.groupby(['user_id', pd.Grouper(key='action_time', freq='D')])['action_name'].count().reset_index()
actions_per_day = top_user_daily_actions.pivot(index='action_time', columns='user_id', values='action_name')
actions_per_day.plot(figsize=(10, 6))
plt.title('Time series of actions for top 20% active users')
plt.xlabel('Date')
plt.ylabel('Number of actions')
plt.show()
df_top_users
user_daily_actions = df.groupby(['user_id', pd.Grouper(key='action_time', freq='D')])['action_name'].count().reset_index()
user_total_actions = user_daily_actions.groupby('user_id')['action_name'].sum().reset_index()
top_users = user_total_actions.nlargest(int(0.2*len(user_total_actions)), 'action_name')['user_id']
df_top_users = df[df['user_id'].isin(top_users)]

sns.lineplot(data=df_top_users.groupby([pd.Grouper(key='action_time', freq='D'), 'action_name']).size().reset_index(name='count'), x='action_time', y='count', hue='action_name', linewidth=0.5, legend=False)

plt.show()
user_daily_actions = df.groupby(['user_id', pd.Grouper(key='action_time', freq='D')])['action_name'].count().reset_index()
user_total_actions = user_daily_actions.groupby('user_id')['action_name'].sum().reset_index()
top_users = user_total_actions.nlargest(int(0.2*len(user_total_actions)), 'action_name')['user_id']
df_top_users = df[df['user_id'].isin(top_users)]

sns.lineplot(data=df_top_users.size().reset_index(name='count'), x='action_time', y='count', hue='action_name', linewidth=0.5, legend=False)

plt.show()
user_daily_actions = df.groupby(['user_id', pd.Grouper(key='action_time', freq='D')])['action_name'].count().reset_index()
user_total_actions = user_daily_actions.groupby('user_id')['action_name'].sum().reset_index()
top_users = user_total_actions.nlargest(int(0.2*len(user_total_actions)), 'action_name')['user_id']
df_top_users = df[df['user_id'].isin(top_users)]

sns.lineplot(data=df_top_users.groupby([pd.Grouper(key='action_time', freq='D')]).size().reset_index(name='count'), x='action_time', y='count', hue='action_name', linewidth=0.5, legend=False)

plt.show()
user_daily_actions = df.groupby(['user_id', pd.Grouper(key='action_time', freq='D')])['action_name'].count().reset_index()
user_total_actions = user_daily_actions.groupby('user_id')['action_name'].sum().reset_index()
top_users = user_total_actions.nlargest(int(0.2*len(user_total_actions)), 'action_name')['user_id']
df_top_users = df[df['user_id'].isin(top_users)]

df_top_users = df_top_users.set_index('action_time')
daily_actions = df_top_users.resample('D').count()

plt.plot(daily_actions.index, daily_actions['action_time'])
plt.xlabel('Date')
plt.ylabel('Number of actions')
plt.title('Daily actions')
plt.show()
action_time
daily_actions
user_daily_actions = df.groupby(['user_id', pd.Grouper(key='action_time', freq='D')])['action_name'].count().reset_index()
user_total_actions = user_daily_actions.groupby('user_id')['action_name'].sum().reset_index()
top_users = user_total_actions.nlargest(int(0.2*len(user_total_actions)), 'action_name')['user_id']
df_top_users = df[df['user_id'].isin(top_users)]

df_top_users = df_top_users.set_index('action_time')
daily_actions = df_top_users.resample('D').count()

plt.plot(daily_actions.index, daily_actions.index)
plt.xlabel('Date')
plt.ylabel('Number of actions')
plt.title('Daily actions')
plt.show()
user_daily_actions = df.groupby(['user_id', pd.Grouper(key='action_time', freq='D')])['action_name'].count().reset_index()
user_total_actions = user_daily_actions.groupby('user_id')['action_name'].sum().reset_index()
top_users = user_total_actions.nlargest(int(0.2*len(user_total_actions)), 'action_name')['user_id']
df_top_users = df[df['user_id'].isin(top_users)]

df_top_users = df_top_users.set_index('action_time')
daily_counts = df_top_users.resample('D').count()

# plot line plot of daily counts
plt.plot(df_top_users.index, daily_counts['action'], '-o')
plt.xlabel('Date')
plt.ylabel('Number of actions')
plt.show()
user_daily_actions = df.groupby(['user_id', pd.Grouper(key='action_time', freq='D')])['action_name'].count().reset_index()
user_total_actions = user_daily_actions.groupby('user_id')['action_name'].sum().reset_index()
top_users = user_total_actions.nlargest(int(0.2*len(user_total_actions)), 'action_name')['user_id']
df_top_users = df[df['user_id'].isin(top_users)]

df_top_users = df_top_users.set_index('action_time')
daily_counts = df_top_users.resample('D').count()

# plot line plot of daily counts
plt.plot(df_top_users.index, daily_counts['action_name'], '-o')
plt.xlabel('Date')
plt.ylabel('Number of actions')
plt.show()
user_daily_actions = df.groupby(['user_id', pd.Grouper(key='action_time', freq='D')])['action_name'].count().reset_index()
user_total_actions = user_daily_actions.groupby('user_id')['action_name'].sum().reset_index()
top_users = user_total_actions.nlargest(int(0.2*len(user_total_actions)), 'action_name')['user_id']
df_top_users = df[df['user_id'].isin(top_users)]

df_top_users = df_top_users.set_index('action_time')
daily_counts = df_top_users.resample('D').count()

# plot line plot of daily counts
plt.plot(daily_counts.index, daily_counts['action_name'], '-o')
plt.xlabel('Date')
plt.ylabel('Number of actions')
plt.show()