我用我的代码来获得所有返回匹配给定的范围。我的数据样本是:如何使用正则表达式按给定范围获得匹配结果?
comment
0 [intj74, you're, whipping, people, is, a, grea...
1 [home, near, kcil2, meniaga, who, intj47, a, l...
2 [thematic, budget, kasi, smooth, sweep]
3 [budget, 2, intj69, most, people, think, of, e...
我想要得到的结果为:(当给定的范围是intj1到intj75)
comment
0 [intj74]
1 [intj47]
2 [nan]
3 [intj69]
我的代码是:
df.comment = df.comment.apply(lambda x: [t for t in x if t=='intj74'])
df.ix[df.comment.apply(len) == 0, 'comment'] = [[np.nan]]
我m不知道如何使用正则表达式来找到t =='range'的范围。或者任何其他想法做到这一点?
由于提前,
熊猫Python的新手
'intj \ d +'匹配'intj'后跟一个或多个数字。 – Maroun
@Maroun Maroun谢谢你的回复。不幸的是它不工作。返回所有[nan] ....或者如何应用您的建议? –