I understand Julia DataFrames do not have a .set_index() function and you need to just use a column instead. However, is there any way to transpose a dataframe or go from dataframe -> matrix -> transpose and preserve a column that consists of a tuple, or do column names definitionally have to be strings?
I have some python code from an original PuLP model which is as follows:
edgedata = df_edges
edgedata['orig_dest'] = list(zip(edgedata['orig_node_id'], edgedata['dest_node_id']))
edgedata = edgedata.set_index(['orig_dest'])
edgedata = edgedata[['transp_cost_tot_usd', 'transm_cost_usd_GJ', 'cap_Mt', 'conversion_eff']]
edgedata = edgedata.T.to_dict('list')
(transp_cost_tot_usd, transm_cost_usd_GJ, cap_Mt, conversion_eff) = splitDict(edgedata)
I have worked this in Julia as follows:
edgedata = df_edges
edgedata[:,"orig_dest"] = collect(zip(edgedata[:,"orig_node_id"],edgedata[:,"dest_node_id"]))
edgedata = edgedata[:,["orig_dest","transp_cost_tot_usd","transm_cost_usd_GJ","cap_Mt","conversion_eff"]]
edgedata_matrix = Matrix(edgedata)
The next line fails however:
edgedata_transpose = transpose(edgedata_matrix)
The error is:
MethodError: no method matching transpose(::Tuple{String15, String15})
The problem I am having here is there is an index in the original python dataframe that has two tuples and I am trying to transpose that and keep column names that are two tuples. Is there any way to do this in Julia or does DataFrames.jl not accept column names with tuple objects?
You want
permutedims.