简体   繁体   English

如何在 PowerBI 中运行 Python 脚本?

[英]How do I run a Python Script in PowerBI?

I am new to Python.我是 Python 的新手。 I am trying to create a Bar Chart in Power BI using Python but the script does not seem to work.我正在尝试使用 Python 在 Power BI 中创建条形图,但脚本似乎不起作用。 The code is below:代码如下:

pip install pandas
pip install matplotlib
import matplotlib.pyplot as plt
plt.plot(dataset.Letter,dataset.Number)
plt.show()

Please find attached the file:请查找附件:

https://www.mediafire.com/file/f0bwt9cp4ha1sfb/Example.pbix/file https://www.mediafire.com/file/f0bwt9cp4ha1sfb/Example.pbix/file

enter image description here在此处输入图像描述

First, you should not be required to run pip install every time you run your script.首先,每次运行脚本时都不需要运行 pip 安装。 You should only have to use pip install commands when installing a library for the first time.第一次安装库时,您应该只需要使用 pip 安装命令。 This might require you ensuring that you have the correct libraries located on your computer.这可能需要您确保您的计算机上有正确的库。 However, I do not know what your error is since I do not have your error code.但是,我不知道您的错误是什么,因为我没有您的错误代码。

Also, be sure to specify what type of plot you wish to produce from matplotlob.此外,请务必指定您希望从 matplotlob 生成的 plot 类型。

Try:尝试:

    import matplotlib.pyplot as plt
    dataset.plot('bar', dataset.Letter, dataset.Number)
    plt.show()

After installing only one (1) initial time pip install pandas and pip install matplotlib , you only need to write in your code:仅安装一 (1) 个初始时间pip install pandaspip install matplotlib ,您只需在您的代码中写入 4666:

import matplotlib.pyplot as plt
dataset.plot('bar', dataset.Letter, dataset.Number)
plt.show()

import is for setting up the library and you must always use it in your code, while pip install pandas and pip install matplotlib only need to be installed once at the beginning. import is for setting up the library and you must always use it in your code, while pip install pandas and pip install matplotlib only need to be installed once at the beginning.

Here is the code that I wrote:这是我写的代码:

import matplotlib.pyplot as plt
dataset.plot('bar', dataset.Letter, dataset.Number)
plt.show()

The visual still does not seem to work.视觉似乎仍然不起作用。 Please find an image here:请在此处找到图片:

在此处输入图像描述

I'm not too sure why it is like this.我不太清楚为什么会这样。 I have also attached an image of the Python scripts folder:我还附上了 Python 脚本文件夹的图像:

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM