I want to partition dataframe and then combine to find multiples or divisions of columns in partition.
My example such: to calculate area sums (column square), price sums and get price per square.
I was unable to do this using combine despite combine would be preferred method.
Get some success in more complicated way, but can not calculate number of rows.
Any solutions ?
# Sample DataFrame df = DataFrame( Size = ["A", "B", "A", "B"], Price = [1000000, 2000000, 3000000, 4000000], Square = [100, 200, 150, 250] ) # Group by "Size" partitions_by_size = groupby(df, :Size) # Define a custom function to calculate PriceM2 within a partition function calculate_priceM2(partition) return sum(partition.Price) / sum(partition.Square) end # Calculate "Kaina_sum_mln" and "KainaM2" within each partition using the custom function data_by_size = DataFrame( Size = unique(df.Size), # nrow = nrow(partitions_by_size), # nrow => count, Price_sum_mln = combine(partitions_by_size, :Price => (price -> sum(price) / 1000000)), PriceM2 = [calculate_priceM2(partition) for partition in partitions_by_size] )