def process_log_file(cur, filepath):
    df = pd.read_json(filepath, lines=True)
    df = df.query("page=='NextSong'")
    t = pd.to_datetime((df['ts'] / 1000), unit='s')
    time_data = np.transpose(np.array([df['ts'].values, t.dt.hour.values, t.dt.day.values, t.dt.week.values, t.dt.month.values, t.dt.year.values, t.dt.weekday.values]))
    column_labels = ('timestamp', 'hour', 'day', 'week of year', 'month', 'year', 'weekday')
    time_df = pd.DataFrame(data=time_data, columns=column_labels)
    for (i, row) in time_df.iterrows():
        cur.execute(time_table_insert, list(row))
    user_df = df[['userId', 'firstName', 'lastName', 'gender', 'level']]
    for (i, row) in user_df.iterrows():
        cur.execute(user_table_insert, row)
    for (index, row) in df.iterrows():
        cur.execute(song_select, (row.song, row.artist, row.length))
        results = cur.fetchone()
        if results:
            (songid, artistid) = results
        else:
            (songid, artistid) = (None, None)
        songplay_data = (row.ts, row.userId, row.level, songid, artistid, row.sessionId, row.location, row.userAgent)
        cur.execute(songplay_table_insert, songplay_data)
def process_log_file(cur, filepath):
    df = pd.read_json(filepath, lines=True)
    df = df.query("page=='NextSong'")
    t = pd.to_datetime((df['ts'] / 1000), unit='s')
    time_data = np.transpose(np.array([df['ts'].values, t.dt.hour.values, t.dt.day.values, t.dt.week.values, t.dt.month.values, t.dt.year.values, t.dt.weekday.values]))
    column_labels = ('timestamp', 'hour', 'day', 'week of year', 'month', 'year', 'weekday')
    time_df = pd.DataFrame(data=time_data, columns=column_labels)
    for (i, row) in time_df.iterrows():
        cur.execute(time_table_insert, list(row))
    user_df = df[['userId', 'firstName', 'lastName', 'gender', 'level']]
    for (i, row) in user_df.iterrows():
        cur.execute(user_table_insert, row)
    for (index, row) in df.iterrows():
        cur.execute(song_select, (row.song, row.artist, row.length))
        results = cur.fetchone()
        if results:
            (songid, artistid) = results
        else:
            (songid, artistid) = (None, None)
        songplay_data = (row.ts, row.userId, row.level, songid, artistid, row.sessionId, row.location, row.userAgent)
        cur.execute(songplay_table_insert, songplay_data)