如何在不重复值的情况下同时展开一行列表中的所有列表? [英] How can I expand all lists in a row of lists at the same time without repeating values?

查看:29
本文介绍了如何在不重复值的情况下同时展开一行列表中的所有列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

响应

我想得到这个结果:

我不希望在处理每个后续列时在先前处理的列中重复值.

是否对 Carl 的代码进行了简单的修改,可以让我到达那里?

解决方案

也许不是很简单,但很有效:下面的代码将列与调整后的代码组合在一起,以便压缩列表并将内部列表转换为记录.接下来,列表列被展开,产生一个包含嵌套记录的列,这些记录随后被展开.

不幸的是,您不能将列与嵌套列表结合使用,因此我首先创建了一些虚拟文本列,然后将它们组合起来以生成基本代码,随后我对其进行了调整,并删除了包含虚拟列的步骤.

letSource = #table({"A", "B"}, {{ {1,2}, {3,4}} }),#"合并列" = Table.CombineColumns(Source,{"A", "B"}, each List.Transform(List.Zip(_), each Record.FromList(_,{"A","B"}))),"合并"),#"扩展合并" = Table.ExpandListColumn(#"合并列", "合并"),#"Expanded Merged1" = Table.ExpandRecordColumn(#"Expanded Merged", "Merged", {"A", "B"}, {"A", "B"})在#"扩展合并1"

In response to this question regarding how to expand all lists in a row of lists at the same time, @Carl Walsh kindly provided this succinct and helpful code:

let
Source = #table({"A", "B"}, {{ {1,2}, {3,4}} }),
Expanded = List.Accumulate(
    Table.ColumnNames(Source), 
    Source, 
    (state, column) => Table.ExpandListColumn(state, column))
in
Expanded

Which yields this:

I would like to get this result instead:

I don't want values repeated in previously processed columns as each follow-on column is processed.

Is there a simple modification to Carl's code that will get me there?

解决方案

Maybe not really simple, but effective: the code below combines the columns with adjusted code so the lists are zipped and the inner lists are transformed into records. Next the list column is expanded, resulting in a column with nested records which are subsequently expanded.

Unfortunately, you can't use combine columns with nested lists, so I created some dummy text columns first that I combined in order to generate the base code, which I subsequently adjusted and I removed the steps with the dummy columns.

let
    Source = #table({"A", "B"}, {{ {1,2}, {3,4}} }),
    #"Merged Columns" = Table.CombineColumns(Source,{"A", "B"}, each List.Transform(List.Zip(_), each Record.FromList(_,{"A","B"})),"Merged"),
    #"Expanded Merged" = Table.ExpandListColumn(#"Merged Columns", "Merged"),
    #"Expanded Merged1" = Table.ExpandRecordColumn(#"Expanded Merged", "Merged", {"A", "B"}, {"A", "B"})
in
    #"Expanded Merged1"

这篇关于如何在不重复值的情况下同时展开一行列表中的所有列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆