如何从 return 一个元组 (col_a, col_b) 的向量函数填充两列

How to populate two columns from vector function that return a tuple (col_a, col_b)

下面会报错

def test(throwaway):
    return(1,2)

df['prices_study'], df['prices_bench'] = list(map(dates_ok, df.date_announce))

我知道我可以单独创建每一列,但肯定有办法压缩它吗?

IIUC:

使用 splat 在 zip

中解压 map 对象
df = pd.DataFrame(1, range(4), [*'abc'])

def test(_): return (2, 3)

df['d'], df['e'] = zip(*map(test, df.index))

df

   a  b  c  d  e
0  1  1  1  2  3
1  1  1  1  2  3
2  1  1  1  2  3
3  1  1  1  2  3