# CSV.jl, Write to files

**URL:** https://discourse.julialang.org/t/csv-jl-write-to-files/30265
**Category:** General Usage
**Tags:** csv
**Created:** [October 24, 2019, 10:15am UTC](https://discourse.julialang.org/t/csv-jl-write-to-files/30265 "2019-10-24T10:15:03Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![Anil\_Mathews](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@Anil\_Mathews](https://discourse.julialang.org/u/Anil_Mathews)
#### Post date: [October 24, 2019, 10:15am UTC](https://discourse.julialang.org/t/csv-jl-write-to-files/30265/1 "2019-10-24T10:15:03Z")

</div>

I was trying wite the companies name to CSV files. But I am getting the values  
what is the error in this code

```nohighlight
Letters=["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
url = "https://www.moneycontrol.com/india/stockpricequote/"
global CompanyList=Array{String,1}()

    for Letter in Letters

        response = HTTP.get(url*Letter)
        html = response.body |> String |> parsehtml
        elements = eachmatch(sel".bl_12", html.root)
        #global CompanyList=Array{String,1}()
        for ele in Array{Int,1}(range(3,length(elements)))

            try
                #println(ele,"========", elements[ele][1].text)
                Name=elements[ele].attributes["href"]
                println(Name)
                df=DataFrame(Companies=Name)
                CSV.write("C:\\Users\\Office\\Documents\\Code\\Company.csv",df)
                #elements[3][1].text

            catch err
                if isa(err,BoundsError)
                    break
                end
                #for com in range(1:length(CompanyList))
                    #println(com)
                #end
            end
        end
    end

```

ERROR: ArgumentError: ‘String’ iterates ‘Char’ values, which don’t satisfy the Tables.jl Row-iterator interface

---

<div class="post-metadata">

### Author: ![dmolina](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmolina/32/5246_2.png) [@dmolina](https://discourse.julialang.org/u/dmolina)
#### Post date: [October 24, 2019, 11:39am UTC](https://discourse.julialang.org/t/csv-jl-write-to-files/30265/2 "2019-10-24T11:39:54Z")

</div>

Change the complex:

```julia
for ele in Array{Int,1}(range(3,length(elements)))

```

to

```julia
for ele in 3:length(elements)

```

Also, the catch of the error avoid to receive any important error, please, do not do that.

The rest of the source has not much sense, you are creating a DataFrame with only a string, that is the error. Something like that could be more useful:

```julia
    for Letter in Letters
        response = HTTP.get(url*Letter)
        html = response.body |> String |> parsehtml
        elements = eachmatch(sel".bl_12", html.root)
        names = String[]
        # global CompanyList=Array{String,1}()
        for ele in 3:length(elements)
            try
                push!(names, elements[ele].attributes["href"])
            catch err
                println(err)
            end
        end

        df=DataFrame(Companies=names)
        CSV.write("Company.csv",df)
end

```

In that case the file is still always been rewritten, but at least it is working, because you are creating the DataFrame using an array.

---

<div class="post-metadata">

### Author: ![Anil\_Mathews](https://avatars.discourse-cdn.com/v4/letter/a/b9e5f3/32.png) [@Anil\_Mathews](https://discourse.julialang.org/u/Anil_Mathews)
#### Post date: [October 24, 2019, 11:55am UTC](https://discourse.julialang.org/t/csv-jl-write-to-files/30265/3 "2019-10-24T11:55:41Z")

</div>

> [@dmolina](#):
>
> df=DataFrame(Companies=names) CSV.write(“Company.csv”,df)

Could you please explain the mistakes in my code?  
Array can not be pushed to CSV?

---

<div class="post-metadata">

### Author: ![dmolina](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dmolina/32/5246_2.png) [@dmolina](https://discourse.julialang.org/u/dmolina)
#### Post date: [October 24, 2019, 11:58am UTC](https://discourse.julialang.org/t/csv-jl-write-to-files/30265/4 "2019-10-24T11:58:43Z")

</div>

Your variable Name was an String, and to create a DataFrame you have to give an Iterator (as an Array), not a String. So I have created an array, “names”, push all names in it, and at the end I create the DataFrame using the Array as parameter.
