Hi!
I want to know how to rename the column of GroupedDataFrame easily.
The following code is an example of what I want to do.
Note: the real data I want to handle is a huge dataframe(~ 10 millions of rows).
Any suggestions are welcomed !!
Thank you in advance.
using CategoricalArrays
using CSV
using DataFrames
import MLJBase.int
iris = DataFrame(CSV.File(joinpath(dirname(pathof(DataFrames)),
"../docs/src/assets/iris.csv")))
gdf = groupby(iris, :Species)
# bin the data and convert the label(CategoricalArray) to int
# transform! function will name the new column as :SepaiWidth_function automatically.
transform!(
gdf, :SepalWidth => x -> int(
cut(x, range(0, stop=10, length=10),
extend=true), type=Int), ungroup=false
)
# specifying the column name here didn't work.
# please try this code
# transform!(
# gdf, :SepalWidth => x ->
# int(cut(x, range(0, stop=10, length=10),extend=true), type=Int) => :new_name,
# ungroup=false
# )
# this does not work
rename!(gdf, :SepalWidth_function => :new_name)