# Sum() one column in dataframe

**URL:** <https://discourse.julialang.org/t/sum-one-column-in-dataframe/72387>\
**Category:** New to Julia\
**Tags:** dataframes\
**Created:** [December 1, 2021, 4:45pm UTC](https://discourse.julialang.org/t/sum-one-column-in-dataframe/72387 "2021-12-01T16:45:43Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![AlexanderChen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alexanderchen/32/22007_2.png) [@AlexanderChen](https://discourse.julialang.org/u/AlexanderChen)\
**Post date:** [December 1, 2021, 4:45pm UTC](https://discourse.julialang.org/t/sum-one-column-in-dataframe/72387/1 "2021-12-01T16:45:43Z")

</div>

Hi,

This is the structure of the dataframe:

```julia
  Row │ NAMES NAMES_NUMBER P_NUMBER_NAMES P_NUMBER_NUMBERS TOTAL  
      │ String Int64 Int64 Int64 Int64  
──────┼─────────────────────────────────────────────────────────────────────
    1 │ ADA 6 11 1 6
    2 │ ABE 8 6 2 16
    3 │ BEA 8 416 3 24
    4 │ ED 9 1354 4 36
    5 │ HA 9 1889 5 45
  ⋮ │ ⋮ ⋮ ⋮ ⋮ ⋮
 5160 │ MARYLOUISE 138 3381 5160 712080
 5161 │ CHRISTOPHER 139 862 5161 717379
 5162 │ KRISTOPHER 139 2687 5162 717518
 5163 │ SYLVESTER 145 4598 5163 748635

```

I want this (I write it in select since that is what makes the most sense to me):

`select SUM(total) from df`

Wat is the dataframe equivalent of this?

thanks,

---

<div class="post-metadata">

**Author:** ![oheil](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/oheil/32/220745_2.png) [@oheil](https://discourse.julialang.org/u/oheil)\
**Post date:** [December 1, 2021, 4:48pm UTC](https://discourse.julialang.org/t/sum-one-column-in-dataframe/72387/2 "2021-12-01T16:48:10Z")

</div>

```julia
sum(df[!,:TOTAL])

```

where df is your DataFrame.

---

<div class="post-metadata">

**Author:** ![AlexanderChen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alexanderchen/32/22007_2.png) [@AlexanderChen](https://discourse.julialang.org/u/AlexanderChen)\
**Post date:** [December 1, 2021, 5:23pm UTC](https://discourse.julialang.org/t/sum-one-column-in-dataframe/72387/3 "2021-12-01T17:23:56Z")

</div>

I get this error:

```julia
ERROR: LoadError: syntax: extra token "names" after end of expression
Stacktrace:
 [1] top-level scope at c:\Users\achen\Desktop\Julia\Visual Basic Code\EULER22.jl:4
in expression starting at c:\Users\achen\Desktop\Julia\Visual Basic Code\EULER22.jl:4

```

---

<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:** [December 1, 2021, 5:28pm UTC](https://discourse.julialang.org/t/sum-one-column-in-dataframe/72387/4 "2021-12-01T17:28:29Z")

</div>

can you show your code? you should be able to just:

```julia
sum(df.TOTAL)

```

---

<div class="post-metadata">

**Author:** ![AlexanderChen](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/alexanderchen/32/22007_2.png) [@AlexanderChen](https://discourse.julialang.org/u/AlexanderChen)\
**Post date:** [December 1, 2021, 5:38pm UTC](https://discourse.julialang.org/t/sum-one-column-in-dataframe/72387/5 "2021-12-01T17:38:21Z")

</div>

Hi,

I see the problem.

the last transform doesn’t save the transformation. it only changes it at that time. I gave it the name df and it worked!

thanks @jling and @oheil

```julia
df = DataFrame(NAMES=sort(a))
df.NAMES_NUMBER = count_char.(df.NAMES)
df.P_NUMBER_NAMES = 1:nrow(df)
sort!(df, :NAMES_NUMBER)
df.P_NUMBER_NUMBERS = 1:nrow(df)

@transform df @byrow begin
    :TOTAL =:P_NUMBER_NUMBERS*:NAMES_NUMBER
end

```
