-2

行等于下面。PIC_loc = 23; 我想要 42 和 42 之后的 15 位。输出应该是 42011721930018984

                                            PIC_1  p_lgth  Wgt
**PARTIAL-DECODE***P / 42011721930018984390078...      53  112

Output = row['PIC_1'][PIC_loc:PIC_loc+15]

上面的代码给出了这个错误信息

TypeError: cannot do slice indexing on    
class 'pandas.core.indexes.range.RangeIndex'> with these indexers [2    23
Name: PIC_1, dtype: int64] of <class 'pandas.core.series.Series'>
4

1 回答 1

1

row['PIC_1']返回 Pandas 系列,因此您需要先访问这些值,然后才能对它们进行切片。您正在寻找对字符串进行切片,以便可以使用pandas.Series.str矢量化字符串方法:

row['PIC_1'].str[PIC_loc:PIC_loc+15]
于 2018-04-24T15:35:13.387 回答