# Entering xlsx columns into HypothosisTests

**URL:** <https://discourse.julialang.org/t/entering-xlsx-columns-into-hypothosistests/35157>\
**Category:** Statistics\
**Tags:** gettingstarted\
**Created:** [February 26, 2020, 8:33am UTC](https://discourse.julialang.org/t/entering-xlsx-columns-into-hypothosistests/35157 "2020-02-26T08:33:29Z")\
**Posts on this page:** 7\
**Page:** 2

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [February 27, 2020, 6:19pm UTC](https://discourse.julialang.org/t/entering-xlsx-columns-into-hypothosistests/35157/21 "2020-02-27T18:19:47Z")

</div>

Alas, I can’t find a way to add a file as an attachment, since I,m adding a foreign file, it’s a real pain, unless it created a DataFrame code line, that I can access. When I add the line you provided, I don’t get the matching error, now my error is

```julia
ERROR: MethodError: no method matching ChisqTest(::Array{Any,1})

```

I think that means it’s looking at all the values for Q1, but not all the data, that I want to compare actual to expected. Should I be using one of the packages you mentioned? I’m think I have the indexers mostly understood, but I’m not sure how to include all the rows in a column.

---

<div class="post-metadata">

**Author:** ![Tero\_Frondelius](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tero_frondelius/32/7629_2.png) [@Tero\_Frondelius](https://discourse.julialang.org/u/Tero_Frondelius)\
**Post date:** [February 27, 2020, 7:54pm UTC](https://discourse.julialang.org/t/entering-xlsx-columns-into-hypothosistests/35157/22 "2020-02-27T19:54:46Z")

</div>

> [@brett\_knoss](#):
>
> I,m adding a foreign file, it’s a real pain

People usually use gist: [Discover gists · GitHub](https://gist.github.com/discover) at least csv file works.

---

<div class="post-metadata">

**Author:** ![pdeffebach](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/pdeffebach/32/10320_2.png) [@pdeffebach](https://discourse.julialang.org/u/pdeffebach)\
**Post date:** [February 27, 2020, 8:19pm UTC](https://discourse.julialang.org/t/entering-xlsx-columns-into-hypothosistests/35157/23 "2020-02-27T20:19:03Z")

</div>

I know your problem. `XLSX.jl` returns arrays of type `Any` and `ChisqTest` requires arrays of type `<:Real`. In your dataframe, do

```julia
julia> for name in names(df)
       df[!, name] = identity.(df[:, name])
end

```

This will ensure that the types are no longer `Any`.

Sorry this has been such a frustrating experience, hopefully we can work on some PRs to XLSX.jl to make this easier.

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [February 27, 2020, 9:57pm UTC](https://discourse.julialang.org/t/entering-xlsx-columns-into-hypothosistests/35157/24 "2020-02-27T21:57:57Z")

</div>

I’m not finding it in the documentation, what is name? What is ! ?

---

<div class="post-metadata">

**Author:** ![nilshg](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/nilshg/32/2283_2.png) [@nilshg](https://discourse.julialang.org/u/nilshg)\
**Post date:** [February 27, 2020, 10:29pm UTC](https://discourse.julialang.org/t/entering-xlsx-columns-into-hypothosistests/35157/25 "2020-02-27T22:29:28Z")

</div>

Here’s what an MWE would look like:

```julia
using XLSX, DataFrames, HypothesisTests

# Set up - create a dummy data set and write out to xlsx
out = DataFrame(Q1 = [1,2,3,4,5],
                Q2 = [1.0, 2.0, 3.0, 4.0, 5.0])

XLSX.writetable("df.xlsx", collect(eachcol(out)), names(out))
    
# Use XLSX to read data into DataFrames
df = DataFrame(XLSX.readtable("df.xlsx", "Sheet1")...)

# Perform ChisqTest
ChisqTest(identity.(df.Q1))

```

The DataFrames indexing documentation is [here](https://juliadata.github.io/DataFrames.jl/stable/lib/indexing/), which explains amongst other things the usage of `!` as a row indexer.

`name` in the above is just a temporary variable used in the loop to iterate over the column names (which are contained in `names(df)`). If this isn’t clear to you you might benefit from a more basic introduction to programming in Julia - the official manual is a good starting point, as is Ben Lauwens’ [Think Julia](https://juliadata.github.io/DataFrames.jl/stable/lib/indexing/)

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [February 27, 2020, 10:48pm UTC](https://discourse.julialang.org/t/entering-xlsx-columns-into-hypothosistests/35157/26 "2020-02-27T22:48:03Z")

</div>

Thanks, for letting me know about setting up a dummy table, that will help in the futre.

---

<div class="post-metadata">

**Author:** ![brett\_knoss](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/brett_knoss/32/13050_2.png) [@brett\_knoss](https://discourse.julialang.org/u/brett_knoss)\
**Post date:** [February 27, 2020, 10:55pm UTC](https://discourse.julialang.org/t/entering-xlsx-columns-into-hypothosistests/35157/27 "2020-02-27T22:55:59Z")

</div>

For some reason it didn’t work, then I rentered it, and it worked just fine. So, Cool!

[Previous page](https://discourse.julialang.org/t/entering-xlsx-columns-into-hypothosistests/35157.md?page=1)
