DataFramesMeta.jl is undergoing a significant refactoring now. Maybe @pdeffebach can suggest an idiomatic use of it using the functionality on master.

Here is how I would rewrite your code using raw DataFrames.jl and Pipe.jl:

df =, "confirmed.csv"), DataFrame)

@pipe df |>
      rename(_, 1 => :Province, 2 => :Country) |> # avoid ! to make sure we do not mutate the source
      select!(_, Not([:Province, :Lat, :Long])) |>
      groupby(_, :Country) |>
      combine(_, valuecols(_) .=> sum .=> valuecols(_)) |>
      stack(_, Not(:Country), :Country, variable_name=:Date, value_name=:Confirmed) |>
      transform!(_, :Date => ByRow(x -> parse(Date, string(x), DateFormat("m/d/Y")) + Year(2000)) => :Date) |>
      last(_, 10)

Note that in your code:

  •, "confirmed.csv")) (add DataFrame as a second argument as in my code)
  • df[:Date] should be df.Date or df."Date" (the second style is in case the name containse e.g. spaces)

are deprecated.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top