代码之家  ›  专栏  ›  技术社区  ›  Feng Chen

如何在powerbi中使用Python/R生成的表?

  •  0
  • Feng Chen  · 技术社区  · 6 年前

    id  name    score
    1   zhao    65
    2   qian    98
    3   sun 100
    4   li  45
    5   zhou    98
    

    假设这是我的数据,名为id。我使用这个按钮 enter image description here 将数据读入Power BI。

    然后我用这个按钮 enter image description here 要启动powerquery编辑器,在这里我可以通过单击 enter image description here 在转换中。

    然后在运行Python脚本中有一个非常简单的Python代码:

    # 'dataset' holds the input data for this script
    import pandas as pd
    
    myid=dataset
    myid.loc[:,'id']=myid.loc[:,'id']*100
    

    到现在为止一切正常。但您可能会注意到,我使用'dataset'来表示数据,而不是真正的数据名'id'。所以我想知道在powerbi中,数据库名是否总是默认的“dataset”?

    当我完成编码后,我有这个:

    enter image description here

    您可以看到,在左侧部分没有名为“myid”的新表。此外,当我使用按钮 enter image description here

    enter image description here

    你可以看到这里也没有新的桌子。那么,如果我想使用Python生成的表来做其他事情,比如绘图,或者在其他地方使用另一个Python分析,我应该怎么做呢?

    0 回复  |  直到 6 年前
        1
  •  1
  •   Alexis Olson    6 年前

    let
        Source = Table.FromRows({{1,"zhao",65},{2,"qian",98},{3,"sun",100},{4,"li",45},{5,"zhou",98}},{"id","name","score"}),
        #"Run R script" = R.Execute("# 'dataset' holds the input data for this script#(lf)#(lf)myid <- dataset#(lf)myid$id <- 100*myid$id",[dataset=Source]),
        myid = #"Run R script"{[Name="myid"]}[Value]
    in
        myid
    

    R脚本窗口中的代码

    # 'dataset' holds the input data for this script
    
    myid <- dataset
    myid$id <- 100*myid$id
    

    当您输入该脚本时,它应该创建一个或两个新步骤。

    R Script

    只需单击Value列中的表以深入到该表(如果它没有自动执行)。

    Drilldown