【发布时间】:2018-01-03 17:23:03
【问题描述】:
如何拆分 pandas 列并将新结果附加到数据框中?我也希望没有空白。
我想要的输出示例:
col1
Smith, John
Smith, John
col2
Smith
Smith
col3
John
John
我一直在尝试这个,但是 lambda 函数并没有按照我想要的方式附加结果。
df_split = df1['col1'].apply(lambda x: pd.Series(x.split(',')))
df1['col2']= df_split.apply(lambda x: x[0])
df1['col3']= df_split.apply(lambda x: x[1])
我最终得到了
col2 col3
Smith Smith
John John
【问题讨论】: