【发布时间】:2019-07-11 08:56:27
【问题描述】:
我正在清理 pandas 数据框中的数据,我想将一列拆分为另一列。
我想按列 'eNBID' 拆分列 'id',但不知道如何拆分
import pandas as pd
id_list = ['4600375067649','4600375077246','460037495681','460037495694']
eNBID_list = ['750676','750772','749568','749569']
df=pd.DataFrame({'id':id_list,'eNBID':eNBID_list})
df.head()
id eNBID
4600375067649 750676
4600375077246 750772
460037495681 749568
460037495694 749569
What I want:
df.head()
id eNBID
460-03-750676-49 750676
460-03-750772-46 750772
460-03-749568-1 749568
460-03-749569-4 749569
#column 'eNBID' is the third part of column 'id', the item length in column 'eNBID' is 6 or 7.
【问题讨论】:
-
你试过
df.iterrows()吗? -
我试试
df.id.str.map(lambda x:x.split(df.eNBID.str))不行
标签: python pandas dataframe split data-cleaning