【发布时间】:2018-10-05 01:06:37
【问题描述】:
df71 等于:
PIC_1 p_lgth Wgt
420294189300189843900787520557 30 112
420951119300189843900787520618 30 64
**PARTIAL-DECODE***P / 42011721930018984390078... 53 112
420112289300189843900782713107 30 144
420212369300189843900787520397 30 70
下面是我使用 apply() 对 df71 的每一行应用的函数
def pic_mod(row):
if row['p_lgth'] !=30:
n = row['PIC_1'].str.find('42')
PIC_2 = row['PIC_1'].str[int(n):int(n+28)]
elif row['p_lgth']==30:
PIC_2=row['PIC_1']
return PIC_2
df71['PIC_1_master'] = df71.apply(pic_mod, axis=1)
当我运行上面的代码时,我得到:
File "<ipython-input-192-9d112a2f0924>", line 3, in pic_mod
n = row['PIC_1'].str.find('42')
AttributeError: ("'str' object has no attribute 'str'", 'occurred at
index 2')
为什么!!!???以下是您想知道的数据类型。
df71.dtypes
PIC_1 object
p_lgth int64
Wgt object
提前致谢。
【问题讨论】:
-
row['PIC_1]'已经是一个字符串。你只需要row['PIC_1'].find -
下面的答案有帮助吗?随意接受答案(左侧的绿色勾号),或要求澄清。
标签: python string pandas dataframe