数据帧称为df,如下所示:name id age text
a 1 1 very good, and I like him
b 2 2 I play basketball with his brother
c 3 3 I hope to get a offer
d 4 4 everything goes well, I think
a 1 1 I will visit china
b 2 2 no one can understand me, I will solve it
c 3 3 I like followers
d 4 4 maybe I will be good
a 1 1 I should work hard to finish my research
b 2 2 water is the source of earth, I agree it
c 3 3 I hope you can keep in touch with me
d 4 4 My baby is very cute, I like him
你知道,有四个名字:a,b,c,d。每个名字都有id,年龄和文字。实际上每个名字组的id、年龄都是一样的,但是每个名字组的文本是不同的,每个名字有三行(这个只是例子,真实的数据是一个大数据)
我想得到每个名字组的id、年龄(例如)。另外,我想通过函数extract_text(text)计算文本中每个组的所有文本中的字符索引。我的意思是我想得到以下数据:以名字'a'为例:年龄:1,身份证号:1我用三行索引(我只是举个例子,不是实数):20,0,0。在
我试着做如下工作:
^{pr2}$
但有一个错误:Traceback (most recent call last):File
bot_test_new.py", line 25, in
id_num = df.groupby('name')['id'].value[0]
AttributeError: 'SeriesGroupBy' object has no attribute 'value'
请把你的手给我,提前谢谢!在