【发布时间】:2019-05-20 08:38:17
【问题描述】:
我正在尝试运行经过验证的 Python 脚本来估算 PowerBI 中的数据。数据最初在 Power BI 中整合,然后导出到 Excel,使用 Python 进行估算和分析。
现在,我想将 Python 中的代码用于 Power BI 的查询编辑器,这样我就可以将估算数据直接导入 Power BI 并使用它的可视化效果,但我会出错。
我尝试在 Power BI 中粘贴与 Python 相同的代码 - 我认为语法可能存在问题。
dataset=#"PreviousStep"
import pandas as pd
byISO = dataset.groupby(['country ISO'])
byIG = dataset.groupby(['WBG Income Group'])
bytIG = dataset.groupby(['WBG Income Group','Year'])
bytR = dataset.groupby(['UN Sub-Region','Year'])
#Country-level
#Filling up and down
dataset[['col1','col2']] = byISO[['col1','col2']].fillna(
method='ffill')
dataset[['col1','col2']] = byISO[['col1','col2']].fillna(
method='bfill')
#Interpolation
dataset[['col1','col2']] = byISO[['col1','col2']]\
.apply(lambda i: i.interpolate(method='linear', limit_area='inside'))
#Extrapolation (FILLING DOWN CURRENTLY)
dataset[['col1','col2']] = byISO[['col1','col2']]\
.apply(lambda i: i.interpolate(method='linear', limit_area='outside'))
#Median
dataset[['col1','col2']] = byISO[['col1','col2']]\
.transform(lambda i: i.fillna(i.median()))
#Group-level
#Median
dataset[['col1','col2']] = byIG[['col1','col2']]\
.transform(lambda i: i.fillna(i.median()))
#Yearly median
dataset[['col1','col2']] = bytIG[['col1','col2']]\
.transform(lambda i: i.fillna(i.median()))
#Region-level
#Yearly median
dataset[['col1','col2']] = bytR[['col1','col2']]\
.transform(lambda i: i.fillna(i.median()))
#No level (All)
#0
dataset[['col1','col2']].fillna(0)
我希望有一个估算值的表,但结果却出现了这个错误:
DataSource.Error: ADO.NET: Python script error.
Traceback (most recent call last):
File "PythonScriptWrapper.PY", line 2, in <module>
import os, pandas, matplotlib.pyplot
File "C:\Users\GEscamilla\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\__init__.py", line 19, in <module>
"Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']
Details:
DataSourceKind=Python
DataSourcePath=Python
Message=Python script error.
Traceback (most recent call last):
File "PythonScriptWrapper.PY", line 2, in <module>
import os, pandas, matplotlib.pyplot
File "C:\Users\GEscamilla\AppData\Local\Continuum\anaconda3\lib\site-packages\pandas\__init__.py", line 19, in <module>
"Missing required dependencies {0}".format(missing_dependencies))
ImportError: Missing required dependencies ['numpy']
ErrorCode=-2147467259
ExceptionType=Microsoft.PowerBI.Scripting.Python.Exceptions.PythonScriptRuntimeException
【问题讨论】:
-
尝试安装
numpy库 -
import numpy,如果没有安装请使用pip install numpy
标签: python powerbi powerquery