# Removing the header of a dataframe

**URL:** <https://discourse.julialang.org/t/removing-the-header-of-a-dataframe/57921>\
**Category:** New to Julia\
**Tags:** dataframes, csv\
**Created:** [March 25, 2021, 12:03pm UTC](https://discourse.julialang.org/t/removing-the-header-of-a-dataframe/57921 "2021-03-25T12:03:22Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![yogi1](https://avatars.discourse-cdn.com/v4/letter/y/439d5e/32.png) [@yogi1](https://discourse.julialang.org/u/yogi1)\
**Post date:** [March 25, 2021, 12:03pm UTC](https://discourse.julialang.org/t/removing-the-header-of-a-dataframe/57921/1 "2021-03-25T12:03:22Z")

</div>

Hi all,

I have read in a csv using “csv.read()” and then using the link below I have transposed the data.  
[Transpose of Julia DataFrame - Stack Overflow](https://stackoverflow.com/questions/37668312/transpose-of-julia-dataframe)

This is great and transposes the data as expected, however Julia has added a header on top of the header that already existed.  
When I return println(names(df)) I get:  
[“variable”, “1”, “2”, “3”, “4”]

Whereas I would expect a header of:  
[“YEAR”, “CASH”, “COUNTRY”, “REGION”, “INDICATOR”]  
Which is now in Row2

However I want to use the actual header names which are now on row 2, is there any way I can remove this sudo-header and use the actual headers?

My next step is to produce a new column which will sum and subtract based on the column headers “CASH”, “COUNTRY”, “REGION”, “INDICATOR”

I can remove the headers using csv.write(headers = false). However, if it were possible to do this without outputting the data then that would be ideal.

Any suggestions would be greatly appreciated!

---

<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:** [March 25, 2021, 2:35pm UTC](https://discourse.julialang.org/t/removing-the-header-of-a-dataframe/57921/2 "2021-03-25T14:35:03Z")

</div>

```julia
julia> DataFrame(x[2:end, :], string.(x[1, :]))
1×2 DataFrame
 Row │ x y   
     │ Any Any 
─────┼──────────
   1 │ 1 2

julia> using DataFrames

julia> df = DataFrame(a = ["x", 1], b = ["y", 2])
2×2 DataFrame
 Row │ a b   
     │ Any Any 
─────┼──────────
   1 │ x y
   2 │ 1 2

julia> x = Matrix(df)
2×2 Matrix{Any}:
  "x" "y"
 1 2

julia> DataFrame(x[2:end, :], string.(x[1, :]))
1×2 DataFrame
 Row │ x y   
     │ Any Any 
─────┼──────────
   1 │ 1 2

```

But also note that you can just read in the csv transposed using the `transpose = true` kwarg, from the `CSV.File` docstring:

```julia
• transpose::Bool: read a csv file "transposed", i.e. each column is parsed as a row

```

---

<div class="post-metadata">

**Author:** ![yogi1](https://avatars.discourse-cdn.com/v4/letter/y/439d5e/32.png) [@yogi1](https://discourse.julialang.org/u/yogi1)\
**Post date:** [March 25, 2021, 2:47pm UTC](https://discourse.julialang.org/t/removing-the-header-of-a-dataframe/57921/3 "2021-03-25T14:47:23Z")

</div>

Thank you so much 🙂 didnt realise that was a built in function, thank you. will definitely use this again 😃
