Python,Pandas和交叉点 - 不是枢轴
这不是一个直接的枢轴问题。我不想创建新命名列(或编号为编号的列)。
我正在寻找的是找到一种方法来寻找满足问问题的演员,例如:
Any ACTOR that has UP and DOWN
在下表中。
演员 | 事件 |
---|---|
A | UP |
B | UP |
C | 剩下的 |
D | c |
,只需使用事件列搜索多个事件并返回 | 左C向下 |
向上 | c向上 |
c | 上 |
的答案应该如此
[A,C]
满足此要求的演员。
我有这样的场景:
演员 | 事件 |
---|---|
A | UP |
C | UP |
C | 留下了 |
d | 向下 |
d | 左 |
c | 向上 |
C | 向上, |
我想找到所有具有事件相交的演员。 喜欢:
Any ACTOR that has UP and DOWN
因此,这应该返回a,c
以及其他任何具有两者的东西。
一种解决方案是按事件“爆炸”到新的数据框架中,由参与者合并,创建一个新的数据框架,例如:
Actors | Event01 | Event02 Event02 | Event03 |
---|---|---|---|
A | Up | Down | |
b | a up down | ||
up cous cous | cous cous | dows | 左 |
D | 左D |
甚至是带有列表的字典,例如:
{'A':['Up', 'Down'], 'B': ... }
但是这些解决方案看起来不太聪明,因此会消耗时间,内存和过程来爆炸和重建。
plus,大型新数据框架应该具有新名称的新列(不仅是一个命名事件),这可能对管理有些压力。
有人有更好的解决方案吗?
This isn't a straightforward pivot question. I don't want to create new named columns (or numbered ones).
What I am looking for is to find a way to search for actors that satisfy the asked question, such as:
Any ACTOR that has UP and DOWN
in the table below.
Actors | Events |
---|---|
A | Up |
B | Up |
C | Left |
A | Down |
D | Left |
C | Down |
C | Up |
The expected answer should be
[A,C]
So, using just event column to search for more than one event and returning the actor(s) that fulfill this requirement.
I have a set like this:
Actors | Events |
---|---|
A | Up |
B | Up |
C | Left |
A | Down |
D | Left |
C | Down |
C | Up |
I want to find all actors that has events intersection.
Like:
Any ACTOR that has UP and DOWN
So this should return A , C
and any other that has both.
One solution was to "explode" into new data frames by events, merge all by actors, creating a new data frame like:
Actors | Event01 | Event02 | Event03 |
---|---|---|---|
A | Up | Down | |
B | Up | ||
C | Up | Down | Left |
D | Left |
or even a dictionary with lists, like:
{'A':['Up', 'Down'], 'B': ... }
But these solutions don't look very smart, thus consuming time, memory and process to explode and rebuild it.
Plus, the big new DataFrame should have new columns with new names for events (not only one named events) which could be a little stressful to managing.
Does anyone have a better solution?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论