In [4]:
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 = {1:'on',0:'off'}


events=[]
for i in range(n_events): 
    day = random.randint(1, 28)
    # add a few null values
    #if i & 3 == 2 :
    #    user = np.nan
    #else:
    user = int(random.randint(1,10))
    timestamp = datetime(year, month, day).timestamp()
    action = action_dic[random.randint(0,1)]
    events.append([timestamp,user,action])

    

#>>> from datetime import datetime
#>>> datetime.fromtimestamp(1172969203.1)
#datetime.datetime(2007, 3, 4, 0, 46, 43, 100000)

In [5]:
import numpy as np
import pandas as pd
# numpy array to df

events = np.array(events)
columns = ['timestamp','user','action']
df = pd.DataFrame(events,columns=columns)
df.head(10)


Out[5]:
timestamp user action
0 1514102400.0 3 off
1 1513411200.0 8 on
2 1512201600.0 7 off
3 1514188800.0 3 on
4 1514188800.0 9 on
5 1512547200.0 4 off
6 1513238400.0 3 off
7 1514102400.0 6 on
8 1513411200.0 7 off
9 1512547200.0 10 off

In [6]:
df.to_csv('tracks.csv')

In [ ]: