I want to take 2 pandas dataframe columns and combine them into 1.
Input: 3 Column df (columns: a , b , num)
Desired Output: 2 Column df (columns: (a,b), num)
Example df:
a b c
1 2 3
2 2 8
2 1 4
Example output:
a_b c
(1,2) 3
(2,2) 8
(2,1) 4
df['a_b'] = np.dstack((df['a'], df['b']))
returns an error:
"Length of values does not match length of index"
Which I have tried to fix but do not fully understand since a, b, and num are all the same length, and the dstack version of a/b should also be that length.
What is going wrong with my approach and what would be the most understandable way to combine these two columns?