Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Make unstack + rename + join nice #1

Open
oxinabox opened this issue Feb 6, 2020 · 1 comment
Open

Make unstack + rename + join nice #1

oxinabox opened this issue Feb 6, 2020 · 1 comment

Comments

@oxinabox
Copy link
Member

oxinabox commented Feb 6, 2020

Example:

	function wrangle(combined_df, df, time_index, value_field, variates_field)
		reduced_df = DataFrame(
			time_index = time_index,
			values = df[:, value_field],
			variates = map(df[:, variates_field]) do variate
				Symbol(
					spec.value_field, :_, spec.variates_field, :_,
					variate
				)
			end
		)
		unique!(reduced_df, [:time_index, :variates])
		wide_df = unstack(reduced_df, :time_index, :variates, :values)
		combined_df = join(combined_df, wide_df; on=time_index, kind=:inner)
	end

What this actually does is:

  • take a categorical column.
  • Renaming all the categories
  • unstacking them to go from narrow to wide.
  • join on time.
@oxinabox
Copy link
Member Author

oxinabox commented Jun 9, 2020

cf re:join: JuliaData/DataFrames.jl#1333 (comment)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant