简体   繁体   English

在 PowerBI 中执行 python 脚本时出错

[英]Error when executing python script in PowerBI

Error错误

Details: "ADO.NET: Python script error.
<pi>Traceback (most recent call last):
File "PythonScriptWrapper.PY", line 2, in <module>
import os, pandas, matplotlib
ModuleNotFoundError: No module named 'pandas'
</pi>"

I have imported data into PowerBi, I am now trying to execute some python script on the imported data, but I get the above error.我已将数据导入 PowerBi,我现在正在尝试对导入的数据执行一些 python 脚本,但出现上述错误。

Please note that I have installed both numpy and pandas through the pip install function in cmd. Please note that I have installed both numpy and pandas through the pip install function in cmd.

Also note that I am not using anaconda, I have installed python directly on my machine (most of the threads I've looked at reference solutions that are to do with Anaconda).另请注意,我没有使用 anaconda,而是直接在我的机器上安装了 python(我查看的大多数线程都与 Anaconda 相关的参考解决方案)。

Thanks谢谢

Install python latest version using https://www.python.org/downloads/ In cmd, verify python installation using command 'python –version' Then install os,pandas,matplotlib,numpy using pip install. Install python latest version using https://www.python.org/downloads/ In cmd, verify python installation using command 'python –version' Then install os,pandas,matplotlib,numpy using pip install. import and load the required dataset in Powerbi Desktop.在 Powerbi Desktop 中导入并加载所需的数据集。 We can also create visualization graphs and plots using python script.我们还可以使用 python 脚本创建可视化图形和绘图。 in visualizations tab, select python visual(PY) and select required fields from the dataset.在可视化选项卡中,select python visual(PY) 和 select 需要数据集中的字段。 a python script editor will be displayed.将显示 python 脚本编辑器。 For example, We used Iris dataset The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script:例如,我们使用 Iris 数据集创建 dataframe 并删除重复行的以下代码始终被执行并充当脚本的序言:

dataset = pandas.DataFrame(Species, Id, PetalLengthCm, PetalWidthCm, SepalLengthCm, SepalWidthCm) dataset = dataset.drop_duplicates()数据集 = pandas.DataFrame(物种,ID,PetalLengthCm,PetalWidthCm,SepalLengthCm,SepalWidthCm)数据集 = dataset.drop_duplicates()

import matplotlib.pyplot as plt
ax=plt.gca()
dataset.plot(kind='line',x='Species',y='SepalLengthCm',color='blue',ax=ax)
plt.show()

output output

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

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