I have this DataFrame structure:
df = pd.DataFrame([
{'key1': 1, 'key2': 1, 'key3':1, 'col1': 'value1', 'col2': 'value2', 'col3': 'value3'},
{'key1': 1, 'key2': 1, 'key3':2, 'col1': 'value4', 'col2': 'value5', 'col3': 'value6'},
{'key1': 1, 'key2': 1, 'key3':3, 'col1': 'value7', 'col2': 'value8', 'col3': 'value9'},
])
>>
key1 key2 key3 col1 col2 col3
0 1 1 1 value1 value2 value3
1 1 1 2 value4 value5 value6
2 1 1 3 value7 value8 value9
I want to apply some transformations so that my DataFrame looks like this:
>>
key1 key2 key3 col_name col_value
0 1 1 1 col1 value1
1 1 1 1 col2 value2
2 1 1 1 col3 value3
3 1 1 2 col1 value4
4 1 1 2 col2 value5
5 1 1 2 col3 value6
6 1 1 3 col1 value7
7 1 1 3 col2 value8
8 1 1 3 col3 value9
Is there a simple way of doing this in Pandas, or will I need to apply a more complex logic?