python-根据不同数据框中的条件从数据框中读取日期

我有2个数据框.
我需要根据另一数据框中的值读取数据

话:

words = pd.DataFrame()
words['no'] = [1,2,3,4,5,6,7,8,9]
words['word'] = ['cat', 'in', 'hat', 'the', 'dog', 'in', 'love', '!', '<3']
words

句子:

sentences =  pd.DataFrame()
sentences['no'] =[1,2,3]
sentences['start'] = [1, 4, 6]
sentences['stop'] = [3, 5, 9]
sentences

所需的输出到文本文件中:

cat in hat
***
the dog
***
in love ! <3

但是我无法通过此步骤,我尝试运行以下代码

对于x的情感:
    print(words [‘word’] [words [‘no’].between(句子[‘start’],句子[‘stop’],包括= True)

但返回此错误

 File "<ipython-input-16-ae3f5333be66>", line 3
    print(words['word'][words['no'].between(sentences['start'], sentences['stop'], inclusive = True)
                                                                                                    ^
SyntaxError: unexpected EOF while parsing

解决方法:

解决这个问题的一种方法,

res=pd.DataFrame()
res['s']=sentences.apply(lambda x: ' '.join(words.iloc[(x['start']-1):(x['stop'])]['word']),axis=1)
res.to_csv('a.txt',index=False,header=False,line_terminator='\n***\n')

相关文章

转载:一文讲述Pandas库的数据读取、数据获取、数据拼接、数...
Pandas是一个开源的第三方Python库,从Numpy和Matplotlib的基...
整体流程登录天池在线编程环境导入pandas和xrld操作EXCEL文件...
 一、numpy小结             二、pandas2.1为...
1、时间偏移DateOffset对象DateOffset类似于时间差Timedelta...
1、pandas内置样式空值高亮highlight_null最大最小值高亮背景...