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

时间:2017-05-27 16:32:34

标签: python pandas

我在下面有“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)

1 个答案:

答案 0 :(得分:1)

有一种更简单的方法:

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)