编辑在Power BI中用作数据条目的python脚本 [英] Edit python script used as Data entry in Power BI

查看:290
本文介绍了编辑在Power BI中用作数据条目的python脚本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个python脚本,并用它在Power BI中创建了一个数据框。



现在,我想在Power BI中编辑该数据框,但是不要从头开始输入新数据,因为我想将所有图表保留在Power BI模型中。 / p>

例如,在我的旧数据框中,我在脚本中指定了一些日期,因此信息仅限于这些日期。现在我想将日期更改为新日期,但又不想丢失所有模型。



df = df

解决方案

我希望您不要在PowerBI Python Visual中使用它。如果在Power Query编辑器的转换选项卡下使用Python,则问题的关键不在于Python本身,而在于在Power Query编辑器中的查询下右键单击表时可用的参考函数。 :





尝试一下:



1:将以下示例数据保存为csv中的 C:\pbidata\src.csv 文件,然后使用 Get Data>将其加载到PowerBI中。文字/ Csv

  A,B,C 
1,1 * 0,100
2,20,200
3,30,300

2:将其显示为表格:





4:添加一些Python



在这里您可以在 Applied steps 下的 Changed type 步骤之后,通过 Transform>插入Python代码段。运行Python脚本。插入以下示例代码:

 #'dataset'保存此脚本的输入数据
import pandas as pd
df = dataset.copy(deep = True)
df ['D'] = df ['C'] * 2

...将为您提供:





5:假设您对此感到满意,并且想在Power BI上重新设计桌面。我正在使用群集条形图来获取此信息:





6:现在,就像您说的那样,如果您想拥有 df ['D'] = df ['C'] / 4 ,但保留相同的数据集,Python脚本和图图1,Py脚本1 ,返回到Power Query Editor并使用该功能我在一开始就提到过:





现在,您有两个基于相同数据集的不同Python片段。您仍然拥有第一个代码段中的数据,并且您可以对第二个代码段执行任何操作,而不会弄乱数据源。



8:插入另一张图表以进行验证:





9:也许可以通过更改源文件来使整个过程变得有趣:



数据:

  A,B,C 
100,10,100
2,20,200
3,30,150

新地块:




I have a python script and used it to create a dataframe in Power BI.

Now I want to edit that dataframe in Power BI but don´t enter from scratch as new data because I want to keep all the charts inside my Power BI model.

For example in my old dataframe i specified some dates inside my script so the information was limited to those dates. Now i want to change the dates to new ones but dont want to lose all the model.

df = df

解决方案

I hope you're not dong this in a PowerBI Python Visual. If you're using Python under the Transform tab in the Power Query Editor, the key to your problem lies not in Python itself, but rather in the reference function available to you if you right-click the table under queries in the Power Query Editor:

Try this:

1: Save the following sample data in a csv as C:\pbidata\src.csv file and load it into PowerBI using Get Data > Text/Csv

A,B,C
1,1*0,100
2,20,200
3,30,300

2: Display it as a table:

3: Open the Power Query Editor through Edit Queries

4: Add some Python

Here you can insert a Python snippet after the Changed type step under Applied steps with Transform > Run Python Script. Inserting the following example code:

# 'dataset' holds the input data for this script
import pandas as pd
df=dataset.copy(deep=True)
df['D']=df['C']*2

... will give you this:

5: And let's say that you're happy with this for now and that you'd like to make a plot out of it back on the Power BI Desktop. I'm using a clustered bar chart to get this:

6: Now, like you're saying, if you'd like to have df['D']=df['C']/4 instead, but retain the same dataset, Python script and figure Plot 1, Py script 1, go back to the Power Query Editor and use the functionality that I mentioned in the beginning:

7: And add another Python snippet:

# 'dataset' holds the input data for this script
import pandas as pd
df=dataset.copy(deep=True)
df['D']=df['D']/4

And there we go:

Now you have two different Python snippets that build on the same dataset. You still have the data from the first snippet, and you can do whatever you want with the second snippet without messing up your data source.

8: Insert another chart to verify:

9: Maybe have some fun with the whole thing by changing the source file:

Data:

A,B,C
100,10,100
2,20,200
3,30,150

New plots:

这篇关于编辑在Power BI中用作数据条目的python脚本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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