You can use :
df = DataFrame(
cat = ["a", "b", "c","a"],
prices = [1,2,3,4],
vol = [10,20,30,40],
)
df2 = by(df, :cat) do sub
t = DataFrame(prices=mean(sub[:prices]), vol=sum(sub[:vol]))
end
df2
3Γ3 DataFrames.DataFrame
β Row β cat β prices β vol β
βββββββΌββββββΌβββββββββΌββββββ€
β 1 β "a" β 2.5 β 50 β
β 2 β "b" β 2.0 β 20 β
β 3 β "c" β 3.0 β 30 β
If you need to make some totals by day / month / etc, you might be interested in answering that as well .
source
share