Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- in[1]:
- import pandas as pd
- def somefunc(input1, input2):
- output1 = 1
- output2 = 2
- return [output1, output2]
- d = {'col1': ['A1', 'B1'], 'col2': ['A2', 'B2']}
- df = pd.DataFrame(data=d)
- df[['col3', 'col4']] = df.apply(lambda x: somefunc(x['col1'], x['col2']),
- axis=1)
- print df
- out[1]:
- col1 col2 col3 col4
- 0 A1 A2 1 2
- 1 B1 B2 1 2
- in[2]:
- import pandas as pd
- def somefunc(input1, input2):
- output1 = 1
- output2 = 2
- output3 = 3
- return [output1, output2, output3]
- d = {'col1': ['A1', 'B1'], 'col2': ['A2', 'B2']}
- df = pd.DataFrame(data=d)
- df[['col3', 'col4', 'col5']] = df.apply(lambda x: somefunc(x['col1'], x['col2']),
- axis=1)
- print df
- out[2]:
- "ValueError: Columns must be same length as key"
- KeyError: "['col3' 'col4' 'col5'] not in index"
Add Comment
Please, Sign In to add comment