I have a simple dataframe:
import pandas as pd
d = pd.DataFrame({'a':[[1], [2], [3]], 'b': [[4], [5], [6]]})
print d
a b
0 [1] [4]
1 [2] [5]
2 [3] [6]
combined
0 [1, 4]
1 [2, 5]
2 [3, 6]
d['combined'] = d.apply(lambda row: row.a + row.b, axis=1)
ValueError: Wrong number of items passed 2, placement implies 1
d['combined'] = d.apply(lambda row: row.a[0] + row.b[0], axis=1)
d = pd.DataFrame({'a':[[1, 2], [2, 3], [3, 4]], 'b': [[4, 5], [5, 6], [6, 7]]})
a b
0 [1, 2] [4, 5]
1 [2, 3] [5, 6]
2 [3, 4] [6, 7]
combined
0 [1, 5]
1 [2, 6]
2 [3, 7]
Just create a blank series name 'combined' as column first, I dont know why though ValueError: Wrong number of items passed - Meaning and suggestions?
import pandas as pd
d = pd.DataFrame({'a':[[1], [2], [3]], 'b': [[4], [5], [6]]})
d['combined'] = ''
d['combined'] = d.apply(lambda row: row.a + row.b, axis=1)