我有一个5列的数据框,每列包含可变长度的列表。我的数据框中的一行是这样的:
A B
1 [aircrafts, they, agreement, airplane] [are, built, made, built]
现在我想“解包”或“取消堆叠”这些列表,以便每个单元格只包含一个值(一个单词)。在解包过程中,一列单元格中的单词应与下一列中相应的值成对组合。结果是:
A B
1 aircrafts are
2 they built
3 agreement made
4 airplane built
作为参考,我的完整数据框如下所示:
obj rel1 \
0 [Boeing] [sells]
1 [aircrafts, they, agreement, airplane] [are, built, made, built]
2 [exception, these] [are, are]
3 [sales, contract] [regulated, consist]
4 [contract] [stipulates]
5 [acquisition] [has]
6 [contract] [managed]
7 [employee] [act]
8 [salesperson, Boeing] [change, ensures]
9 [airlines, airlines] [related, have]
10 [Boeing] [keep]
dep1 rel2 \
0 [aircrafts] [to]
1 [] [on, with]
2 [] [of, of, for]
3 [] [by, of, with, of, of]
4 [elements] [across, as]
5 [details] [of, as, of, for]
6 [] [by]
7 [] [as, for]
8 [] [Given, of, over, for]
9 [company] [to, for]
10 [track, aircrafts] [of, between, to, of]
dep2
0 [companies]
1 [demand, customer]
2 [airplanes, scope, case]
3 [means, contracts, companies, acquisitions, ai...
4 [acquisitions, conditions]
5 [airplane, model, airplane, options]
6 [salesperson]
7 [salesperson, contracts]
8 [term, contracts, time, client]
9 [other, example]
10 [relationships, companies, airlines, buyer]
如何在python中执行“解包”和重新排列操作?如果这些操作可以在数据帧本身上执行,那就太好了。如果这被证明是困难的或不可能的,有没有一种方法可以在将列表中的数据组合成数据帧之前重新排列它们?你知道吗
非常感谢您的帮助和建议。你知道吗
我相信你想把这些行读成句子
相关问题 更多 >
编程相关推荐