Rename Dataframe column names julia v1.0

Rename columns:

names!(df, [:c1,:c2,:c3]) #(all)

rename!(df, Dict(:oldCol => :newCol)) # (a selection)

(from: https://syl1.gitbook.io/julia-language-a-concise-tutorial/useful-packages/dataframes )


You can rename column through select also

For Ex:

df = DataFrame(col1 = 1:4, col2 = ["John", "James", "Finch", "May"])

│ Row │ col1  │ col2   │
│     │ Int64 │ String │
├─────┼───────┼────────┤
│ 1   │ 1     │ John   │
│ 2   │ 2     │ James  │
│ 3   │ 3     │ Finch  │
│ 4   │ 4     │ May    │


select(df, "col1" => "Id", "col2" => "Name")

│ Row │ Id    │ Name   │
│     │ Int64 │ String │
├─────┼───────┼────────┤
│ 1   │ 1     │ John   │
│ 2   │ 2     │ James  │
│ 3   │ 3     │ Finch  │
│ 4   │ 4     │ May    │

Assuming data1_date_time_index is a DataFrame that has three columns use:

colnames = ["Date_Time","Date_index","Time_index"]
names!(data1_date_time_index, Symbol.(colnames))

I am not 100% sure if this is what you want, as your example was not fully reproducible (so if actually you needed something else can you please submit full code that can be run).

The problem with data1_date_time_index.colindex is that currently . is used to access columns of a DataFrame by their name (and not fields of DataFrame type). In general you are not recommended to use colindex as it is not part of exposed API and might change in the future. If you really need to reach it use getfield(data_frame_name, :colindex).

EDIT

In DataFrames 0.20 you should write:

rename!(data1_date_time_index, Symbol.(colnames))

and in DataFrames 0.21 (which will be released before summer 2020) also passing strings directly will most probably be allowed like this:

rename!(data1_date_time_index, colnames)

(see here for a related discussion)