首页 \ 问答 \ 在数据框中查找列的共现(Find co-occurrence of columns in dataframe)

在数据框中查找列的共现(Find co-occurrence of columns in dataframe)

我有一个包含数千列的数据框。 大多数列具有仅与其他列共存的值。 例如 :

A       | B    | C
Null    |"val" |"other"
"random"|"rand"| Null

在这个例子中,我想要一个输出告诉我:

  • 列与B共同出现
  • B柱与A和C共同出现
  • C柱与B共同出现

我可以编写某种循环并为每列做一些sql,但它会非常昂贵。

我使用python和任何可以帮助的库或代码是受欢迎的:)

对不起,如果使用错误的术语来描述问题...

谢谢


I have a dataframe of thousands of columns. Most of the columns have values that co-occur only with other columns. For example :

A       | B    | C
Null    |"val" |"other"
"random"|"rand"| Null

In this exemple I would like an output that tells me :

  • A column co-occur with B
  • B column co-occur with A and C
  • C column co-occur with B

I could write some kind of loop and do some sql for each column, but it will be really expensive.

I use python and any library or code that could help is welcome :)

Sorry if used the wrong terminology to describe the problem ...

Thanks


原文:https://stackoverflow.com/questions/41705406
更新时间:2021-10-31 15:10

最满意答案

是的,使用引导选择库很容易。 请参阅文档

您可以通过在您的网页中添加以下CSS和js CDN来使用它:

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.4/css/bootstrap-select.min.css">

<!-- Latest compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.4/js/bootstrap-select.min.js"></script>

<!-- (Optional) Latest compiled and minified JavaScript translation files -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.4/js/i18n/defaults-*.min.js"></script>

一旦添加了CDN,您的HTML将如下所示:

<select class="selectpicker" data-size="5">
  <option data-subtext="Heinz">Ketchup</option>
</select>

在你的HTML下面,你必须定义selectpicker初始化JS函数,如:

$('.selectpicker').selectpicker({
  showSubtext:true
});

Yes it is easily possible using bootstrap select library. See docs

You can use it by adding the below css and js CDNs in your webpage, :

<!-- Latest compiled and minified CSS -->
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.4/css/bootstrap-select.min.css">

<!-- Latest compiled and minified JavaScript -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.4/js/bootstrap-select.min.js"></script>

<!-- (Optional) Latest compiled and minified JavaScript translation files -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-select/1.12.4/js/i18n/defaults-*.min.js"></script>

Once the CDN is added, your HTML will look like:

<select class="selectpicker" data-size="5">
  <option data-subtext="Heinz">Ketchup</option>
</select>

Beneath your HTML you have to have to define the selectpicker initialization JS function like:

$('.selectpicker').selectpicker({
  showSubtext:true
});

相关问答

更多