Python,Pandas和交叉点 - 不是枢轴

发布于 2025-01-23 07:44:32 字数 3230 浏览 1 评论 0原文

这不是一个直接的枢轴问题。我不想创建新命名列(或编号为编号的列)。

我正在寻找的是找到一种方法来寻找满足问问题的演员,例如:

Any ACTOR that has UP and DOWN

在下表中。

演员事件
AUP
BUP
C剩下的
Dc
,只需使用事件列搜索多个事件并返回左C向下
向上c向上
c

的答案应该如此

[A,C]

满足此要求的演员。


我有这样的场景:

演员事件
AUP
CUP
C留下了
d向下
d
c向上
C向上,

我想找到所有具有事件相交的演员。 喜欢:

Any ACTOR that has UP and DOWN

因此,这应该返回a,c以及其他任何具有两者的东西。

一种解决方案是按事件“爆炸”到新的数据框架中,由参与者合并,创建一个新的数据框架,例如:

ActorsEvent01Event02 Event02Event03
AUpDown
ba up down
up cous couscous cousdows
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.

ActorsEvents
AUp
BUp
CLeft
ADown
DLeft
CDown
CUp

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:

ActorsEvents
AUp
BUp
CLeft
ADown
DLeft
CDown
CUp

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:

ActorsEvent01Event02Event03
AUpDown
BUp
CUpDownLeft
DLeft

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文