
这将座垫按空间划分,并给每个单独的行。
In [43]: dfOut[43]: CustNum CustomerName ItemQty Item Seatblocks ItemExt0 32363 McCartney, Paul 3 F04 2:218:10:4,6 601 31316 Lennon, John 25 F01 1:13:36:1,12 1:13:37:1,13 300In [44]: s = df['Seatblocks'].str.split(' ').apply(Series, 1).stack()In [45]: s.index = s.index.droplevel(-1) # to line up with df's indexIn [46]: s.name = 'Seatblocks' # needs a name to joinIn [47]: sOut[47]: 0 2:218:10:4,61 1:13:36:1,121 1:13:37:1,13Name: Seatblocks, dtype: objectIn [48]: del df['Seatblocks']In [49]: df.join(s)Out[49]: CustNum CustomerName ItemQty Item ItemExt Seatblocks0 32363 McCartney, Paul 3 F04 60 2:218:10:4,61 31316 Lennon, John 25 F01 300 1:13:36:1,121 31316 Lennon, John 25 F01 300 1:13:37:1,13In [50]: df.join(s.apply(lambda x: Series(x.split(':'))))Out[50]: CustNum CustomerName ItemQty Item ItemExt 0 1 2 30 32363 McCartney, Paul 3 F04 60 2 218 10 4,61 31316 Lennon, John 25 F01 300 1 13 36 1,121 31316 Lennon, John 25 F01 300 1 13 37 1,13这有点丑陋,但也许有人会采用更漂亮的解决方案。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)