1

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?

BuddhiLW
  • 608
  • 3
  • 9
  • 2
    I haven't used `Pingouin` before, but you might have the arguments for `push!` around the wrong way, as I see you are trying to assign it to `norm`. If you write `push!(norm, ...)` it will modify `norm` in-place. – Jake Ireland Nov 04 '21 at 07:03
  • I changed it; but, the issue remais the same. Basically, transform `DataFrame` type into `DataFrameRow`. – BuddhiLW Nov 04 '21 at 13:13
  • 1
    Could you try pushing `only(Pingouin.normality(…))`? If `Pengouin.normality` returns a dataframe with exactly one row, `only` should return that row, and thus allow you to push into the `DataFrame`. – Jake Ireland Nov 04 '21 at 18:26
  • 1
    If it doesn’t return one row, you’d want push `eachrow` of what `Pengouin.normality` returns (in another `for` loop, or using `foreach`) – Jake Ireland Nov 04 '21 at 18:34
  • 1
    Please make a comment, so I can accept your answer. It's correct. I just tested it! Thank you. – BuddhiLW Nov 04 '21 at 18:48

1 Answers1

1

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(…)))
Jake Ireland
  • 543
  • 4
  • 11