我有一个带有2列的DataFrame-一个带有单词,另一个带有pos_tags。
word1 tag1
0 Why WRB
1 is VBZ
2 this DT
3 happening NN
4 to TO
5 us PRP
6 Asterix NNP
7 and CC
8 Obelix NNP
我如何添加另外两个列,其值是列'word1'和'tag1'的第(i + 1)个值;
word1 tag1 word2 tag2
0 Why WRB is VBZ
1 is VBZ this DT
2 this DT happening NNP
3 happening NNP to TO
4 to TO us PRP
5 us PRP Asterix NNP
6 Asterix NNP and CC
7 and CC Obelix NNP
8 Obelix NNP nan nan
shift(-1)
在数据框上使用
In [109]: df[['word2', 'tag2']] = df.shift(-1)
In [110]: df
Out[110]:
word1 tag1 word2 tag2
0 Why WRB is VBZ
1 is VBZ this DT
2 this DT happening NN
3 happening NN to TO
4 to TO us PRP
5 us PRP Asterix NNP
6 Asterix NNP and CC
7 and CC Obelix NNP
8 Obelix NNP NaN NaN
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句