[Solved] Pandas – Count Vectorize Series of Transaction Activities by User [closed]


The pivot_table function in pandas should do what you want. For instance:

import pandas as pd

frame = pd.read_csv('myfile.csv', header=None)
frame.columns = ['user_id', 'date', 'event_type']
frame_pivoted = frame.pivot_table(
    index='user_id', columns="event_type", aggfunc="count"
)

In general, using vectorized Pandas functions is much faster than for loops, although I haven’t compared the performance in your specific case.

0

solved Pandas – Count Vectorize Series of Transaction Activities by User [closed]