Skip to content Skip to sidebar Skip to footer

Faster Way To Group Data Than Pandas Groupby

I am implementing a Genetic Algorithm. For this algorithm a number of iterations (between 100 to 500) have to be done where in each iteration all 100 individuals are evaluated for

Solution 1:

let's try:

def get_cost(df, df2):
    '''
    df: deliveries data
    df2: distance data
    '''
    pivot = np.ceil(df.pivot_table(index=['customer', 'warehouse'], columns=['date'], 
                           values='deliveries', aggfunc='sum', fill_value=0)
                      .div(20)
                   )
    
    return pivot.mul(df2.rename_axis(index='customer', columns='warehouse').stack(),
              axis='rows').sum().sum()

Post a Comment for "Faster Way To Group Data Than Pandas Groupby"