gpt4 book ai didi

python - 在 Delimiter 上拆分 Dataframe 列并保留所有其他列

转载 作者:太空宇宙 更新时间:2023-11-04 05:06:46 25 4
gpt4 key购买 nike

我在下面有“raw_input”数据框。如果您查看“摘要”列。有一个 分隔符“:”,我想在其上创建两个额外的列,并将其附加到现有数据框

我想将该“摘要”列拆分为两列('工作 包”和“任务”)

我可以使用下面的命令拆分定界符。但我不知道如何将它追加/合并回现有数据框

split_data = pd.DataFrame(raw_input['Summary'].str.split(':',1).tolist(),columns=['Work Package','Task'])

print(raw_input)

Key Summary Status Description Updated
0 XTBOW-310 Data Mgmt: Product Assesment and Selection In Analysis - To establish a provider for the solution of ... 2017-05-26
1 XTBOW-420 Data Mgmt: Vendor > CIBC Implemention NaN - Integrate with Vendor to fetch Corporate Act... 2017-05-19
2 XTBOW-421 Trade Migration: PVs and Greeks NaN - PVs and Greeks regression gap analysis betwe... 2017-05-19
3 XTBOW-422 Trade Migration: Reports (XTC vs XT2) NaN NaN 2017-05-19



print(split_data)

Work Package Task
0 Data Mgmt Product Assesment and Selection
1 Data Mgmt Vendor > CIBC Implemention
2 Trade Migration PVs and Greeks
3 Trade Migration Reports (XTC vs XT2)

最佳答案

有一个更简单的方法:

In [11]: df[['Work Package','Task']] = df['Summary'].str.split(':',1, expand=True)

In [12]: df
Out[12]:
Key Summary Status Description Updated \
0 XTBOW-310 Data Mgmt: Product Assesment and Selection In Analysis - To establish a provider for the... 2017-05-26 NaN
1 XTBOW-420 Data Mgmt: Vendor > CIBC Implemention NaN - Integrate with Vendor to fetch Corporat... 2017-05-19 NaN
2 XTBOW-421 Trade Migration: PVs and Greeks NaN - PVs and Greeks regression gap analysis ... 2017-05-19 NaN
3 XTBOW-422 Trade Migration: Reports (XTC vs XT2) NaN ... 2017-05-19 NaN

Work Package Task
0 Data Mgmt Product Assesment and Selection
1 Data Mgmt Vendor > CIBC Implemention
2 Trade Migration PVs and Greeks
3 Trade Migration Reports (XTC vs XT2)

关于python - 在 Delimiter 上拆分 Dataframe 列并保留所有其他列,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44219216/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com