Is it bad practice to assign values to the String entries of a DataFrame?

summarizer was a stand in for your function that you’re using to summarize stuff… @by is a super handy macro from DataFramesMeta.jl which I consider a core package that everyone who uses DataFrames should check out and definitely use a lot.

The @by macro splits a data frame “by” the value of the first argument after the data frame, and then for each group, it creates new variables by calling the summarization functions you call on each sub-group, and then combines the results back into a new DataFrame. This is the “split-apply-combine” pattern.

For example

@by(mydataframe,:county,:meanincome = mean(:income))

will give you a new data frame with columns “county” and “meanincome”

in your case, it sounds like you want to run multiple summary functions on each group, and keep track of the results of each of those, so you’ll have multiple assignments…

@by(mydataframe, :artist, :summary1 = summarizer1(:column_for_1), :summary2 = summarizer2(:column_for_2,:other_column_for_2), ... )

where you fill in more columns where I’ve put …

2 Likes