In [1]:
import random
from datetime import datetime
import numpy as np
#year = random.randint(1950, 2000)
#month = random.randint(1, 12)
year = 2017
month = 12
# Generate 300 random timestamps and users
n_events = 300
action_dic = {0:'send',1:'accept',2:'reject'}
events=[]
for i in range(n_events):
day = random.randint(1, 24)
# add a few null values
#if i & 3 == 2 :
# user = np.nan
#else:
# One sent event
userid = int(random.randint(1,10))
timestamp = datetime(year, month, day).timestamp()
action = 'send'
events.append([timestamp,userid,action])
# One random accept or reject after random number of days:
days_to_answer = random.randint(1, 4)
day = day + days_to_answer
timestamp = datetime(year, month, day).timestamp()
action=action_dic[random.randint(1,2)]
events.append([timestamp,userid,action])
#>>> from datetime import datetime
#>>> datetime.fromtimestamp(1172969203.1)
#datetime.datetime(2007, 3, 4, 0, 46, 43, 100000)
In [2]:
import numpy as np
import pandas as pd
# numpy array to df
events = np.array(events)
columns = ['timestamp','userid','action']
df = pd.DataFrame(events,columns=columns)
df.head(10)
Out[2]:
In [3]:
df.to_csv('actions.csv')
In [ ]:
In [ ]: