Reputation: 397
I have a dataframe:
v1 v2
[1,2] [4,5,6]
[1,1,5] [4,5,6,7]
I want to join them into column with nested lists:
v1 v2 v3
[1,2] [4,5,6] [[1,2],[4,5,6]]
[1,1,5] [4,5,6,7] [[1,1,5],[4,5,6,7]]
Upvotes: 0
Views: 29
Reputation: 428
You can try this :
df['v3'] = df.apply(lambda row : [row['v1'], row['v2']], axis = 1)
print(df)
# Output :
# v1 v2 v3
#0 [1, 2] [4, 5, 6] [[1, 2], [4, 5, 6]]
#1 [1, 1, 5] [4, 5, 6, 7] [[1, 1, 5], [4, 5, 6, 7]]
Upvotes: 1