# DataFrame column names with symbols

**URL:** https://discourse.julialang.org/t/dataframe-column-names-with-symbols/62985
**Category:** General Usage
**Tags:** dataframes
**Created:** [June 16, 2021, 2:16am UTC](https://discourse.julialang.org/t/dataframe-column-names-with-symbols/62985 "2021-06-16T02:16:27Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Ismam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ismam/32/26140_2.png) [@Ismam](https://discourse.julialang.org/u/Ismam)
#### Post date: [June 16, 2021, 2:16am UTC](https://discourse.julialang.org/t/dataframe-column-names-with-symbols/62985/1 "2021-06-16T02:16:27Z")

</div>

I’m using DataFramesMeta and would like to calculate a new column called “p\*”.

I’ve tried:  
@transform(df, p\* = … )  
@transform(df, “p\*” = … )

No luck.

I can make do with:  
Disc[!,“p\*”] .= …  
But, not ideal.

Thanks!

---

<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: [June 16, 2021, 5:14am UTC](https://discourse.julialang.org/t/dataframe-column-names-with-symbols/62985/2 "2021-06-16T05:14:06Z")

</div>

I don’t think this has anything to do with Symbols, you’re just not using the `transform` syntax correctly, it should be `source => transformation => destination`:

```julia
julia> df = DataFrame(a = 1:3)
3×1 DataFrame
 Row │ a     
     │ Int64 
─────┼───────
   1 │ 1
   2 │ 2
   3 │ 3

julia> transform!(df, :a => cumsum => "p*")
3×2 DataFrame
 Row │ a p*    
     │ Int64 Int64 
─────┼──────────────
   1 │ 1 1
   2 │ 2 3
   3 │ 3 6

```

---

<div class="post-metadata">

### Author: ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)
#### Post date: [June 16, 2021, 5:33am UTC](https://discourse.julialang.org/t/dataframe-column-names-with-symbols/62985/3 "2021-06-16T05:33:55Z")

</div>

> [@nilshg](#):
>
> you’re just not using the `transform` syntax correctly,

@Ismam is using DataFramesMeta.jl

---

<div class="post-metadata">

### Author: ![xiaodai](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/xiaodai/32/15937_2.png) [@xiaodai](https://discourse.julialang.org/u/xiaodai)
#### Post date: [June 16, 2021, 5:38am UTC](https://discourse.julialang.org/t/dataframe-column-names-with-symbols/62985/4 "2021-06-16T05:38:15Z")

</div>

> [@Ismam](#):
>
> @transform(df, p\* = … )  
> @transform(df, “p\*” = … )

I think DataFramesMeta.jl doesn’t support weird characters in the name I think.

But with DFMacros.jl you can do

`@transform(df, Symbol("p*" = … )`

> [@Ismam](#):
>
> I’ve tried:  
> @transform(df, p\* = … )  
> @transform(df, “p\*” = … )
> 
> No luck.
> 
> I can make do with:  
> Disc[!,“p\*”] .= …

You can write ur code in ``` for better formatting

```julia
@transform(df, p* = … )
@transform(df, “p*” = … )

```

---

<div class="post-metadata">

### Author: ![Ismam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ismam/32/26140_2.png) [@Ismam](https://discourse.julialang.org/u/Ismam)
#### Post date: [June 21, 2021, 7:05am UTC](https://discourse.julialang.org/t/dataframe-column-names-with-symbols/62985/5 "2021-06-21T07:05:24Z")

</div>

Thanks everyone. Lots of useful suggestions here!

---

<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: [June 21, 2021, 11:33am UTC](https://discourse.julialang.org/t/dataframe-column-names-with-symbols/62985/6 "2021-06-21T11:33:16Z")

</div>

DataFramesMeta absolutely supports creating column names with weird symbols. See the documentation [Working with column names programmatically with `cols`](https://juliadata.github.io/DataFramesMeta.jl/stable/#Working-with-column-names-programmatically-with-cols).

You do

```julia
@transform(df, cols("p*") = ...)

```

---

<div class="post-metadata">

### Author: ![Ismam](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/ismam/32/26140_2.png) [@Ismam](https://discourse.julialang.org/u/Ismam)
#### Post date: [July 13, 2021, 12:56am UTC](https://discourse.julialang.org/t/dataframe-column-names-with-symbols/62985/7 "2021-07-13T00:56:19Z")

</div>

Just curious,

how do you paste tables as text so nicely like that?

My tables look like this in Jupyter

> 5×2 DataFrame  
> Row │ x y  
> │ Int64 Int64?  
> ─────────────────────  
> 1 │ 1 missing  
> 2 │ 2 4  
> 3 │ 3 missing  
> 4 │ 4 2  
> 5 │ 5 1

![image](https://global.discourse-cdn.com/julialang/original/3X/0/7/07f28a0aefead4b27864bfb176c4b5e15d7f756d.png)

---

<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: [July 13, 2021, 5:47am UTC](https://discourse.julialang.org/t/dataframe-column-names-with-symbols/62985/8 "2021-07-13T05:47:26Z")

</div>

I copy them from the REPL, which has plain text output. Jupyter is HTML output so some formatting info gets lost when you copy the text displayed in your browser.
