I am converting the following json string into dataframe. A list of keys is supposed to be unique and represent a primary key column values. For col1 and col2 we also have values set.
{"col1": {"0": col1val0, "1": col1val1}, "col2": {"0" : col2val0, "1": col2val1}, "index": {"0": ["key1","key2",""], "1": ["key1","key2","key3"]}}
using
df = pd.read_json(json_string)
Question about my index - it is a dict in its original form but when converted to df, it becomes a part of the index that I can't seem to extract.
index col1 col2
0 [key1,key2,] col1val0 col2val0
1 [key1,key2,key3] col1val1 col2val1
I tried to copy index into a new column, transposing df, tried getting shape of the index - it only returns numerical part - {0,1} and shows up as Int64Index type despite showing [key1,key2,] part of the index when printed. How can I extract it? Preferably I'd like to create primary key columns pk1, pk2, pk3 and populate them with these values.