# Cannot place this error in dataframes

**URL:** <https://discourse.julialang.org/t/cannot-place-this-error-in-dataframes/72081>\
**Category:** New to Julia\
**Tags:** dataframes\
**Created:** [November 25, 2021, 8:24pm UTC](https://discourse.julialang.org/t/cannot-place-this-error-in-dataframes/72081 "2021-11-25T20:24:54Z")\
**Posts on this page:** 6\
**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:** [November 25, 2021, 8:24pm UTC](https://discourse.julialang.org/t/cannot-place-this-error-in-dataframes/72081/1 "2021-11-25T20:24:55Z")

</div>

hi,

I have a simple dataframe

```julia
csv_file = ["MARY","PATRICIA","LINDA","BARBARA","ELIZABETH","JENNIFER","MARIA","SUSAN","MARGARET","DOROTHY","LISA","NANCY","KAREN","BETTY"]

df = DataFrame(NAMES=sort(csv_file))

```

I then want to transform (add a column that is based on the first column in the df,

```julia

###Takes the letters in the string and counts them up
function count_char(n::String)
    foldr(+,[Int(i)-64 for i in n])
end

```

But if I do this, I get an error:

```julia
@transform df begin
    :NAMES_NUMBER = count_char(:NAMES)
end

ERROR: LoadError: MethodError: no method matching Int64(::String)
Closest candidates are:
  Int64(::Union{Bool, Int32, Int64, UInt32, UInt64, UInt8, Int128, Int16, Int8, UInt128, UInt16}) at boot.jl:708
  Int64(::Ptr) at boot.jl:718
  Int64(::Float32) at float.jl:706

```

I thought maybe its the function itself so I took a base function that should work on this:

```julia
@transform df begin
    :NAMES_NUMBER = lowercase(:NAMES)
end

ERROR: LoadError: MethodError: no method matching lowercase(::Array{String,1})
Closest candidates are:
  lowercase(::T) where T<:AbstractChar at strings/unicode.jl:245
  lowercase(::AbstractString) at strings/unicode.jl:531

```

I am new to dataframes so I think that is the reason. Could someone explain the essence behind this error (i assume they are the same, if not please correct me).

thanks!

---

<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:** [November 25, 2021, 8:29pm UTC](https://discourse.julialang.org/t/cannot-place-this-error-in-dataframes/72081/2 "2021-11-25T20:29:38Z")

</div>

You want `@rtransform`, for row-wise transformations, instead of `@transform`, which takes in the whole column.

```julia
julia> @rtransform df begin
           :NAMES_NUMBER = count_char(:NAMES)
       end
14×2 DataFrame
 Row │ NAMES NAMES_NUMBER 
     │ String Int64        
─────┼─────────────────────────
   1 │ BARBARA 43
   2 │ BETTY 72
   3 │ DOROTHY 105
   4 │ ELIZABETH 88
   5 │ JENNIFER 81
   6 │ KAREN 49
   7 │ LINDA 40
   8 │ LISA 41
   9 │ MARGARET 83
  10 │ MARIA 42
  11 │ MARY 57
  12 │ NANCY 57
  13 │ PATRICIA 77
  14 │ SUSAN 74

```

and the second example

```julia
julia> @rtransform df begin
           :NAMES_NUMBER = lowercase(:NAMES)
       end
14×2 DataFrame
 Row │ NAMES NAMES_NUMBER 
     │ String String       
─────┼─────────────────────────
   1 │ BARBARA barbara
   2 │ BETTY betty
   3 │ DOROTHY dorothy
   4 │ ELIZABETH elizabeth
   5 │ JENNIFER jennifer
   6 │ KAREN karen
   7 │ LINDA linda
   8 │ LISA lisa
   9 │ MARGARET margaret
  10 │ MARIA maria
  11 │ MARY mary
  12 │ NANCY nancy
  13 │ PATRICIA patricia
  14 │ SUSAN susan

```

See the docs [here](https://juliadata.github.io/DataFramesMeta.jl/stable/#Row-wise-transformations-with-@byrow-and-@rtransform/@rselect/etc.).

---

<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:** [November 25, 2021, 8:42pm UTC](https://discourse.julialang.org/t/cannot-place-this-error-in-dataframes/72081/3 "2021-11-25T20:42:22Z")

</div>

> [@pdeffebach](#):
>
> ```julia
> @rtransform df begin
> :NAMES_NUMBER = count_char(:NAMES)
> end
> 
> ```

this did not seem to work for me but, this did:

```julia
 @transform df @byrow begin
           :NAMES_NUMBER = count_char(:NAMES)
       end

```

Thank you for pointing me in the right direction!

---

<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:** [November 25, 2021, 8:47pm UTC](https://discourse.julialang.org/t/cannot-place-this-error-in-dataframes/72081/4 "2021-11-25T20:47:44Z")

</div>

`@rtransform` was added after `@byrow`. So if you upgrade your version of DataFramesMeta.jl they should both work.

---

<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:** [November 26, 2021, 5:50am UTC](https://discourse.julialang.org/t/cannot-place-this-error-in-dataframes/72081/5 "2021-11-26T05:50:02Z")

</div>

Or just

```julia
df.NAMES_NUMBER = count_chars.(df.NAMES)

```

---

<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:** [November 26, 2021, 8:11am UTC](https://discourse.julialang.org/t/cannot-place-this-error-in-dataframes/72081/6 "2021-11-26T08:11:00Z")

</div>

> [@nilshg](#):
>
> `df.NAMES_NUMBER = count_chars.(df.NAMES)`

Yes, that seems to work to 🙂
