# Cant add or create new column for my data csv

**URL:** <https://discourse.julialang.org/t/cant-add-or-create-new-column-for-my-data-csv/124923>\
**Category:** General Usage\
**Tags:** question\
**Created:** [January 19, 2025, 2:11pm UTC](https://discourse.julialang.org/t/cant-add-or-create-new-column-for-my-data-csv/124923 "2025-01-19T14:11:00Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![522Hendriadi\_DN](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/522hendriadi_dn/32/214788_2.png) [@522Hendriadi\_DN](https://discourse.julialang.org/u/522Hendriadi_DN)\
**Post date:** [January 19, 2025, 2:11pm UTC](https://discourse.julialang.org/t/cant-add-or-create-new-column-for-my-data-csv/124923/1 "2025-01-19T14:11:01Z")

</div>

hello everyone, im newbie in julia. i need help for my problem. I just to try using PyCall in my code. this is my code:

```julia
using Pandas
using Dates
@pyimport re
py"""
import pandas as pd

df = pd.read_csv(" my path tweets.csv", index_col = None, encoding="ISO-8859-1")

"""
df_sample = df.sample(n=200, random_state=42)
df_sample["Date"] = pd.to_datetime(df_sample["Date"], format="%a %b %d %H:%M:%S PDT %Y")
df_sample["Month"] = df_sample.Date.dt.month
df_sample["Month"].sort_values()

```

And i got warning this : sys:1: UserWarning: Pandas doesn’t allow columns to be created via a new attribute name.

myenv for python in julia is i use python 3.11.7.  
hopefully all of u can help me, thanks.

---

<div class="post-metadata">

**Author:** ![eldee](https://avatars.discourse-cdn.com/v4/letter/e/b5a626/32.png) [@eldee](https://discourse.julialang.org/u/eldee)\
**Post date:** [January 20, 2025, 5:12pm UTC](https://discourse.julialang.org/t/cant-add-or-create-new-column-for-my-data-csv/124923/2 "2025-01-20T17:12:56Z")

</div>

Hi, and welcome to the Julia community!

The problem seems to be that `df_sample["Date"] = ...` (i.e. `setindex!(df_sample, ..., "Date")` gets converted to `df_sample.Date = ...` (`setproperty!(df_sample, :Date, ...)`), which is not allowed in Pandas:

```julia
function setindex!(o::PyObject, v, s::Union{Symbol, AbstractString})
    Base.depwarn("`setindex!(o::PyObject, v, s::Union{Symbol, AbstractString})` is deprecated in favor of `setproperty!(o, s, v)`.", :setindex!)
    return _setproperty!(o, s, v)
end

```

(you can find this by prepending `@which` in front of the `df_sample["Data"] = ...` line.)

As a workaround you could use e.g. `df_sample = df_sample.assign(Date = ...)` In general, I’ll refer to the Pandas documentation for alternative ways to add columns.

* * *

By the way, note that PythonCall.jl does not exhibit this issue:

```julia
using Pkg
Pkg.add("PythonCall")

ENV["PYTHON"] = "/path/to/your/python/envs/executable"  
using PythonCall # after setting the environment variable

pd = pyimport("pandas")
df = pd.read_csv("data.csv")
#=
Python:
     A B C
0 1.0 2.0 3.0
1 -1.0 -2.0 -3.0
=#
df["New"] = ["x", "y"]
display(df)
#=
Python:
     A B C New
0 1.0 2.0 3.0 x
1 -1.0 -2.0 -3.0 y
=#

```
