是指通过pandas库中的函数和方法,将包含在一个列中的列表数据展开为多个列的操作。
具体步骤如下:
完整的代码示例如下:
import pandas as pd
df = pd.DataFrame({'col1': [[1, 2, 3], [4, 5, 6], [7, 8, 9]]})
df[['col2', 'col3', 'col4']] = df['col1'].apply(lambda x: pd.Series(x))
print(df)
以上代码的输出结果为:
col1 col2 col3 col4
0 [1, 2, 3] 1 2 3
1 [4, 5, 6] 4 5 6
2 [7, 8, 9] 7 8 9
这样就实现了将列表列展开为多列的操作。
推荐的腾讯云相关产品和产品介绍链接地址:
领取专属 10元无门槛券
手把手带您无忧上云