Home > Net >  DataFrame to DataFrameRow conversion (Julia)
DataFrame to DataFrameRow conversion (Julia)

Time:11-05

I'm using Pingouin.jl to test normality.

In their docs, we have

dataset = Pingouin.read_dataset("mediation")
Pingouin.normality(dataset, method="jarque_bera")

Which should return a DataFrame with normality true or false for each name in the dataset.

Currently, this broadcasting is deprecated, and I'm unable to concatenate the result in one DataFrame for each unique-column-output (which is working and outputs a DataFrame).

So, what I have so far.

function var_norm(df)
  norm = DataFrame([])
  for i in 1:1:length(names(df))
        push!(norm, Pingouin.normality(df[!,names(df)[i]], method="jarque_bera"))
  end
  return norm
end

The error I get:

julia> push!(norm, Pingouin.normality(df[!,names(df)[1]], method="jarque_bera"))
ERROR: ArgumentError: `push!` does not allow passing collections of type DataFrame to be pushed into a DataFrame. Only `Tuple`, `AbstractArray`, `AbstractDict`, `DataFrameRow` and `NamedTuple` are allowed.
Stacktrace:
 [1] push!(df::DataFrame, row::DataFrame; promote::Bool)
   @ DataFrames ~/.julia/packages/DataFrames/vuMM8/src/dataframe/dataframe.jl:1603
 [2] push!(df::DataFrame, row::DataFrame)
   @ DataFrames ~/.julia/packages/DataFrames/vuMM8/src/dataframe/dataframe.jl:1601
 [3] top-level scope
   @ REPL[163]:1

EDIT: push! function was not properly written at my first version of the post. But, the error persists after the change. How can I reformat the output of type DataFrame from Pingouin into DataFrameRow?

CodePudding user response:

As Pengouin.normality returns a DataFrame, you will have to iterate over its results and push one-by-one:

df = Pengouin.normality(…)
for row in eachrow(df)
    push!(norms, row)
end

If you are sure Pengouin.normality returns a DataFrame with exactly one row, you can simply write

push!(norms, only(Pengouin.normality(…)))
  • Related