あなたが関数からSeries
を返す必要があります。
def find_data_from_ip(x):
tup = (1,2,3,4)
return (pd.Series(tup, index=['w','x','y','z']))
a = pd.DataFrame({'existing':[1,2,3]})
print (a)
a[['w','x','y','z']] = a["existing"].apply(lambda x: find_data_from_ip(x))
print (a)
existing w x y z
0 1 1 2 3 4
1 2 1 2 3 4
2 3 1 2 3 4
もう1つの解決策は、DataFrame
f ROMの列にfrom_records
、次にconcat
を元にして:
def find_data_from_ip(x):
tup = (1,2,3,4)
return (tup)
a = pd.DataFrame({'existing':[1,2,3]})
#print (a)
print (a["existing"].apply(lambda x: find_data_from_ip(x)))
0 (1, 2, 3, 4)
1 (1, 2, 3, 4)
2 (1, 2, 3, 4)
Name: existing, dtype: object
a1 = pd.DataFrame.from_records(a["existing"].apply(lambda x: find_data_from_ip(x))
.values
.tolist(),
columns = ['w','x','y','z'])
print (a1)
w x y z
0 1 2 3 4
1 1 2 3 4
2 1 2 3 4
print (pd.concat([a,a1],axis=1))
existing w x y z
0 1 1 2 3 4
1 2 1 2 3 4
2 3 1 2 3 4