# Import XLSX data

**URL:** <https://discourse.julialang.org/t/import-xlsx-data/44302>\
**Category:** General Usage\
**Tags:** question\
**Created:** [August 5, 2020, 2:57am UTC](https://discourse.julialang.org/t/import-xlsx-data/44302 "2020-08-05T02:57:48Z")\
**Posts on this page:** 14\
**Page:** 1

<div class="post-metadata">

**Author:** ![dty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dty/32/16885_2.png) [@dty](https://discourse.julialang.org/u/dty)\
**Post date:** [August 5, 2020, 2:57am UTC](https://discourse.julialang.org/t/import-xlsx-data/44302/1 "2020-08-05T02:57:48Z")

</div>

```julia
using XLSX
Cs=XLSX.readdata("E:\\Julia程序\\Cs.xlsx","Sheet1","A1:C24")

```

The above is my code for importing xlsx file (), which is the data type of array (any, 2) and cannot be directly operated with matrix. How can I import a file to make it a data type that can be operated with matrix? For example, float64etc.

![111](https://global.discourse-cdn.com/julialang/original/3X/8/c/8c4452ed223f3a756dcbb87c1f78d18dd1937a32.png)

in addition,I try to use the file converted to CSV format and then import it. Although a float file will be generated, there will be a warning

```julia
Cb=CSV.read("E:\\Julia程序\\Cb.csv")
Cs=CSV.read("E:\\Julia程序\\Cs.csv")
Pload=CSV.read("E:\\Julia程序\\Pload.csv")
PPV=CSV.read("E:\\Julia程序\\PPV.csv")
PWT=CSV.read("E:\\Julia程序\\PWT.csv")
PDL=CSV.read("E:\\Julia程序\\PDL.csv")
PCL=CSV.read("E:\\Julia程序\\PCL.csv")
PHL=CSV.read("E:\\Julia程序\\PHL.csv")

Cb=convert(Array,Cb)
Cs=convert(Array,Cs)
Pload=convert(Array,Pload)
PPV=convert(Array,PPV)
PWT=convert(Array,PWT)
PDL=convert(Array,PDL)
PDL=convert(Array,PDL)
PDL=convert(Array,PDL)
PCL=convert(Array,PCL)
PHL=convert(Array,PHL)

```

```julia
┌ Warning: `CSV.read(input; kw...)` is deprecated in favor of `DataFrame!(CSV.File(input; kw...))`
└ @ CSV C:\Users\61940\.juliapro\JuliaPro_v1.4.2-1\packages\CSV\hZ1pV\src\CSV.jl:40
┌ Warning: `CSV.read(input; kw...)` is deprecated in favor of `DataFrame!(CSV.File(input; kw...))`
└ @ CSV C:\Users\61940\.juliapro\JuliaPro_v1.4.2-1\packages\CSV\hZ1pV\src\CSV.jl:40
┌ Warning: `CSV.read(input; kw...)` is deprecated in favor of `DataFrame!(CSV.File(input; kw...))`
└ @ CSV C:\Users\61940\.juliapro\JuliaPro_v1.4.2-1\packages\CSV\hZ1pV\src\CSV.jl:40
┌ Warning: `CSV.read(input; kw...)` is deprecated in favor of `DataFrame!(CSV.File(input; kw...))`
└ @ CSV C:\Users\61940\.juliapro\JuliaPro_v1.4.2-1\packages\CSV\hZ1pV\src\CSV.jl:40
┌ Warning: `CSV.read(input; kw...)` is deprecated in favor of `DataFrame!(CSV.File(input; kw...))`
└ @ CSV C:\Users\61940\.juliapro\JuliaPro_v1.4.2-1\packages\CSV\hZ1pV\src\CSV.jl:40
┌ Warning: `CSV.read(input; kw...)` is deprecated in favor of `DataFrame!(CSV.File(input; kw...))`
└ @ CSV C:\Users\61940\.juliapro\JuliaPro_v1.4.2-1\packages\CSV\hZ1pV\src\CSV.jl:40
┌ Warning: `CSV.read(input; kw...)` is deprecated in favor of `DataFrame!(CSV.File(input; kw...))`
└ @ CSV C:\Users\61940\.juliapro\JuliaPro_v1.4.2-1\packages\CSV\hZ1pV\src\CSV.jl:40
┌ Warning: `CSV.read(input; kw...)` is deprecated in favor of `DataFrame!(CSV.File(input; kw...))`
└ @ CSV C:\Users\61940\.juliapro\JuliaPro_v1.4.2-1\packages\CSV\hZ1pV\src\CSV.jl:40

```

---

<div class="post-metadata">

**Author:** ![felipenoris](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/felipenoris/32/553_2.png) [@felipenoris](https://discourse.julialang.org/u/felipenoris)\
**Post date:** [August 5, 2020, 4:57am UTC](https://discourse.julialang.org/t/import-xlsx-data/44302/2 "2020-08-05T04:57:34Z")

</div>

Maybe `convert(Array{Float64,2}, Cs)`.

---

<div class="post-metadata">

**Author:** ![jling](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/jling/32/212909_2.png) [@jling](https://discourse.julialang.org/u/jling)\
**Post date:** [August 5, 2020, 7:24am UTC](https://discourse.julialang.org/t/import-xlsx-data/44302/3 "2020-08-05T07:24:54Z")

</div>

the warning is telling you to use the new syntax (this is what ‘deprecation’ means).

---

<div class="post-metadata">

**Author:** ![dty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dty/32/16885_2.png) [@dty](https://discourse.julialang.org/u/dty)\
**Post date:** [August 5, 2020, 7:45am UTC](https://discourse.julialang.org/t/import-xlsx-data/44302/4 "2020-08-05T07:45:56Z")

</div>

yes!That’s right. thanks!

---

<div class="post-metadata">

**Author:** ![dty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dty/32/16885_2.png) [@dty](https://discourse.julialang.org/u/dty)\
**Post date:** [August 5, 2020, 8:07am UTC](https://discourse.julialang.org/t/import-xlsx-data/44302/5 "2020-08-05T08:07:25Z")

</div>

```julia
PHL=DataFrame!(CSV.File("E:\\Julia程序\\PHL.csv"))

```

sorry，I didn’t really understand the meaning of it. I tried to modify it, but I still reported an error

```julia
ERROR: LoadError: UndefVarError: DataFrame! not defined
Stacktrace:
 [1] top-level scope at untitled-00d5839736e1528ded8439f9249e3ead:6
in expression starting at untitled-00d5839736e1528ded8439f9249e3ead:6

```

---

<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:** [August 5, 2020, 8:11am UTC](https://discourse.julialang.org/t/import-xlsx-data/44302/6 "2020-08-05T08:11:50Z")

</div>

You need to be `using DataFrames` explicitly if you want to call the `DataFrame` constructor, i.e.

```julia
using CSV, DataFrames

DataFrame(CSV.File("path_to_file.csv"))

```

---

<div class="post-metadata">

**Author:** ![dty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dty/32/16885_2.png) [@dty](https://discourse.julialang.org/u/dty)\
**Post date:** [August 5, 2020, 8:16am UTC](https://discourse.julialang.org/t/import-xlsx-data/44302/7 "2020-08-05T08:16:57Z")

</div>

I “add DataFrame”, so I failed without “s”  
Thank you. It’s ok now, and it’s converted to float 64！  
The format is as follows

```julia
PHL=DataFrame!(CSV.File("E:\\Julia程序\\PHL.csv"))
PHL=convert(Array{Float64,2}, PHL)

```

---

<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:** [August 5, 2020, 8:19am UTC](https://discourse.julialang.org/t/import-xlsx-data/44302/8 "2020-08-05T08:19:31Z")

</div>

You can abbreviate the second line to `Matrix(PHL)`. Also note that convention in Julia is to use lowercase identifiers for variables, and uppercase identifiers for types (like `DataFrame`).

---

<div class="post-metadata">

**Author:** ![dty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dty/32/16885_2.png) [@dty](https://discourse.julialang.org/u/dty)\
**Post date:** [August 5, 2020, 8:32am UTC](https://discourse.julialang.org/t/import-xlsx-data/44302/9 "2020-08-05T08:32:34Z")

</div>

First of all, thank you for your correction!  
After I use matrix (PHL), the generated data frame type cannot be used for matrix operation or multiplication and division with integers. It seems that I need float type.

---

<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:** [August 5, 2020, 8:41am UTC](https://discourse.julialang.org/t/import-xlsx-data/44302/10 "2020-08-05T08:41:04Z")

</div>

What do you mean by “data frame type” after you used `Matrix`? If your csv is as shown in your first post (i.e. a bunch of floating point numbers like 0.43 0.82, 1.02) then you’ll get an `Array{Float64, 2}` back from doing `Matrix{PHL}`.

This array can then be used for the usual mathematical operations in Julia:

```julia
julia> using DataFrames

julia> df = DataFrame(rand([0.43, 0.82, 1.02], 5, 5));

julia> df_matrix = Matrix(df) 
5×5 Array{Float64,2}:        
0.43 0.43 0.82 0.82 0.43                               
0.82 0.82 1.02 1.02 1.02                                       
1.02 0.82 1.02 1.02 0.82 
1.02 0.43 0.82 1.02 0.43 
0.43 1.02 0.43 0.82 1.02

julia> df_matrix .* 2     
5×5 Array{Float64,2}:  
0.86 0.86 1.64 1.64 0.86
1.64 1.64 2.04 2.04 2.04 
2.04 1.64 2.04 2.04 1.64 
2.04 0.86 1.64 2.04 0.86 
0.86 2.04 0.86 1.64 2.04 

```

---

<div class="post-metadata">

**Author:** ![dty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dty/32/16885_2.png) [@dty](https://discourse.julialang.org/u/dty)\
**Post date:** [August 5, 2020, 8:51am UTC](https://discourse.julialang.org/t/import-xlsx-data/44302/11 "2020-08-05T08:51:10Z")

</div>

```julia
using XLSX
using CSV ,DataFrames

Cs=XLSX.readdata("E:\\Julia程序\\Cs.xlsx","Sheet1","A1:C24")
Cs=convert(Array{Float64,2}, Cs)

PHL=DataFrame(CSV.File("E:\\Julia程序\\PHL.csv"))
Matrix(PHL)

```

This is my code. After I use `matrix (PHL)`, it is still a dataframe file. It seems a little strange

 ![666666](https://global.discourse-cdn.com/julialang/original/3X/0/e/0e7f274b0662294cfe08aac06e90478f174011ab.png)

---

<div class="post-metadata">

**Author:** ![dty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dty/32/16885_2.png) [@dty](https://discourse.julialang.org/u/dty)\
**Post date:** [August 5, 2020, 8:53am UTC](https://discourse.julialang.org/t/import-xlsx-data/44302/12 "2020-08-05T08:53:35Z")

</div>

I seem to have forgotten to define its name, which leads to this. I’m sorry！ 😅

---

<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:** [August 5, 2020, 8:53am UTC](https://discourse.julialang.org/t/import-xlsx-data/44302/13 "2020-08-05T08:53:39Z")

</div>

`Matrix()` does not operate in place. Again as a convention, functions that do operate in place or change their arguments are denoted by an `!` at the end (this is just a naming convention, so you couldn’t just add a `!` to some function to make it in-place).

You need to do

```julia
PHL = Matrix(PHL)

```

as in my example above.

I would encourage you to read the Julia documentation to familiarise yourself with the basics of the language.

---

<div class="post-metadata">

**Author:** ![dty](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dty/32/16885_2.png) [@dty](https://discourse.julialang.org/u/dty)\
**Post date:** [August 5, 2020, 8:55am UTC](https://discourse.julialang.org/t/import-xlsx-data/44302/14 "2020-08-05T08:55:12Z")

</div>

I forgot, this is my problem  
Thank you very much for your help! 😁
