【发布时间】:2019-06-10 14:41:22
【问题描述】:
背景
我有以下代码
import pandas as pd
#create df
df = pd.DataFrame({'Before' : ['there are many different',
'i like a lot of sports ',
'the middle east has many '],
'After' : ['in the bright blue box',
'because they go really fast ',
'to ride and have fun '],
'P_ID': [1,2,3],
'Word' : ['crayons', 'cars', 'camels'],
'N_ID' : ['A1', 'A2', 'A3']
})
#rearrange
df = df[['P_ID', 'N_ID', 'Before', 'Word','After']]
创建以下df
P_ID N_ID Before Words After
0 1 A1 there are many different crayons in the bright blue box
1 2 A2 i like a lot of sports cars because they go really fast
2 3 A3 the middle east has many camels to ride and have fun
目标
1) 将Before 和After 列中的单词与Word 列中的单词联系起来
2) 创建new_column
期望的输出
具有以下输出的new_column
new_column
there are many different crayons in the bright blue box
i like a lot of sports cars because they go really fast
the middle east has many camels to ride and have fun
问题
我如何实现我的目标?
【问题讨论】:
标签: python string pandas dataframe nlp