Python脚本在Power BI中出现NameError错误。

huangapple go评论165阅读模式
英文:

Python script NameError in power bi

问题

以下是您提供的内容的翻译:

在Power BI桌面应用程序中出现以下名称错误。已经查阅了一些Stack Overflow帖子,但没有帮助。提前致谢。也将同样的问题发布在Power BI社区中。

请参考下面的截图。

Python脚本在Power BI中出现NameError错误。

Python代码:

  1. import matplotlib.pyplot as plt
  2. dataset = pandas.DataFrame(Agent, Resolved)
  3. dataset = dataset.drop_duplicates()
  4. dataset.plot(kind='scatter', x='Agent', y='Resolved', color='green')
  5. plt.show()

尝试的选项:

  1. 卸载并重新安装Power BI桌面应用程序。
  2. 尝试不同版本的Python。
  3. 甚至尝试了Python虚拟环境,但没有成功。

看起来是Python和Power BI版本兼容性问题。

错误堆栈跟踪:

  1. 反馈类型:
  2. Frown(错误)
  3. 错误消息:
  4. Python脚本错误。
  5. <pi>NameError: name 'Agent' is not defined
  6. </pi>
  7. 堆栈跟踪:
  8. JavaScript:错误
  9. Microsoft.PowerBI.ExploreServiceCommon.ScriptHandlerExceptionPython脚本错误。
  10. NameErrorname 'Agent' is not defined
  11. ---&gt; Microsoft.PowerBI.Scripting.Python.Exceptions.PythonScriptRuntimeExceptionPython脚本错误。
  12. NameErrorname 'Agent' is not defined
  13. ...
  14. (此处省略中间内容)
  15. ...
  16. PowerBIUserFeedbackServices_IsReported
  17. True
英文:

Getting below name error in Power BI-desktop application.Already explored some stack-overflow threads but no help.Thanks in advance.also put same in Power BI community.

Please refer below screenshot.

Python脚本在Power BI中出现NameError错误。

Python code:

  1. import matplotlib.pyplot as plt
  2. dataset = pandas.DataFrame(Agent, Resolved)
  3. dataset = dataset.drop_duplicates()
  4. dataset.plot(kind=&#39;scatter&#39;, x=&#39;Agent&#39;, y=&#39;Resolved&#39;, color=&#39;green&#39;)
  5. plt.show()

option tried:

  1. Uninstall and install power BI desktop application.
  2. Try with different version of python.
     3. Even tried with python virtual environment but no success

Looks like python and power BI version compatibility issue.

Error stack-trace:

  1. Feedback Type:
  2. Frown (Error)
  3. Error Message:
  4. Python script error.
  5. &lt;pi&gt;NameError: name &#39;Agent&#39; is not defined
  6. &lt;/pi&gt;
  7. Stack Trace:
  8. JavaScript: Error
  9. Microsoft.PowerBI.ExploreServiceCommon.ScriptHandlerException: Python script error.
  10. NameError: name &#39;Agent&#39; is not defined
  11. ---&gt; Microsoft.PowerBI.Scripting.Python.Exceptions.PythonScriptRuntimeException: Python script error.
  12. NameError: name &#39;Agent&#39; is not defined
  13. at Microsoft.PowerBI.Scripting.Python.PythonScriptWrapper.RunScript(String originalScript, Int32 timeoutMs)
  14. at Microsoft.PowerBI.Client.Windows.Python.PythonScriptHandler.GenerateVisual(ScriptHandlerOptions options)
  15. --- End of inner exception stack trace ---
  16. at Microsoft.PowerBI.Client.Windows.Python.PythonScriptHandler.GenerateVisual(ScriptHandlerOptions options)
  17. at Microsoft.PowerBI.ExploreHost.SemanticQuery.ScriptVisualCommandFlow.RunInternal(Stream dataShapeResultStream, QueryBindingDescriptor&amp; bindingDescriptor)
  18. at Microsoft.PowerBI.ExploreHost.SemanticQuery.ScriptVisualCommandFlow.Run(Stream dataShapeResultStream, QueryBindingDescriptor&amp; bindingDescriptor)
  19. at Microsoft.PowerBI.ExploreHost.SemanticQuery.ExecuteSemanticQueryFlow.TransformDataShapeResult(QueryCommand transformCommand, SemanticQueryDataShapeCommand command, Stream dataShapeResultStream, QueryBindingDescriptor&amp; bindingDescriptor)
  20. at Microsoft.PowerBI.ExploreHost.SemanticQuery.ExecuteSemanticQueryFlow.ExecuteDataQuery(IQueryResultDataWriter queryResultDataWriter, EngineDataModel engineDataModel, DataQuery query, Int32 queryId, ServiceErrorStatusCode&amp; serviceErrorStatusCode, CancellationToken cancelToken)
  21. at Microsoft.PowerBI.ExploreHost.SemanticQuery.ExecuteSemanticQueryFlow.ProcessAndWriteSemanticQueryCommands(IQueryResultsWriter queryResultsWriter, IList`1 queries, HashSet`1 pendingQueriesToCancel, EngineDataModel engineDataModel)
  22. Stack Trace Message:
  23. Python script error.
  24. &lt;pi&gt;NameError: name &#39;Agent&#39; is not defined
  25. &lt;/pi&gt;
  26. Invocation Stack Trace:
  27. at Microsoft.Mashup.Host.Document.ExceptionExtensions.GetCurrentInvocationStackTrace()
  28. at Microsoft.Mashup.Client.UI.Shared.StackTraceInfo..ctor(String exceptionStackTrace, String invocationStackTrace, String exceptionMessage)
  29. at Microsoft.PowerBI.Client.Windows.Telemetry.PowerBIUserFeedbackServices.GetStackTraceInfo(Exception e)
  30. at Microsoft.PowerBI.Client.Windows.Telemetry.PowerBIUserFeedbackServices.ReportException(IWindowHandle activeWindow, IUIHost uiHost, FeedbackPackageInfo feedbackPackageInfo, Exception e, Boolean useGDICapture)
  31. at Microsoft.Mashup.Client.UI.Shared.UnexpectedExceptionHandler.&lt;&gt;c__DisplayClass14_0.&lt;HandleException&gt;b__0()
  32. at Microsoft.Mashup.Client.UI.Shared.UnexpectedExceptionHandler.HandleException(Exception e)
  33. at Microsoft.PowerBI.Client.PowerBIUnexpectedExceptionHandler.HandleException(Exception e)
  34. at Microsoft.PowerBI.Client.Windows.Utilities.PowerBIFormUnexpectedExceptionHandler.HandleException(Exception e)
  35. at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
  36. at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
  37. at System.Delegate.DynamicInvokeImpl(Object[] args)
  38. at System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
  39. at System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
  40. at System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
  41. at System.Windows.Forms.Control.InvokeMarshaledCallbacks()
  42. at System.Windows.Forms.Control.MarshaledInvoke(Control caller, Delegate method, Object[] args, Boolean synchronous)
  43. at System.Windows.Forms.Control.Invoke(Delegate method, Object[] args)
  44. at System.Windows.Forms.WindowsFormsSynchronizationContext.Send(SendOrPostCallback d, Object state)
  45. at Microsoft.PowerBI.Client.Windows.Services.UIBlockingService.AllowModalDialogs(Action action)
  46. at Microsoft.PowerBI.Client.Windows.HostServiceDispatcher.&lt;&gt;c__DisplayClass14_0.&lt;ExecuteOnUIThreadAndHandlePromise&gt;b__0()
  47. at Microsoft.PowerBI.Client.Windows.HostServiceDispatcher.ExecuteOnUIThreadAndHandlePromise[T](Func`1 func, IPromiseStore promiseStore, Int64 promiseHandle)
  48. at System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
  49. at System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
  50. at System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
  51. at Microsoft.PowerBI.Client.Windows.WebView2.WebView2Interop.InvokeCs(InteropCall call)
  52. at Microsoft.Mashup.Host.Document.ExceptionHandlerExtensions.HandleExceptions(IExceptionHandler exceptionHandler, Action action)
  53. at System.EventHandler`1.Invoke(Object sender, TEventArgs e)
  54. at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp; msg)
  55. at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG&amp; msg)
  56. at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
  57. at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
  58. at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
  59. at System.Windows.Forms.Form.ShowDialog(IWin32Window owner)
  60. at Microsoft.Mashup.Client.UI.Shared.WindowManager.ShowModal[T](T dialog, Func`1 showModalFunction)
  61. at Microsoft.PowerBI.Client.Program.&lt;&gt;c__DisplayClass6_0.&lt;RunApplication&gt;b__0()
  62. at Microsoft.PowerBI.Client.Windows.IExceptionHandlerExtensions.&lt;&gt;c__DisplayClass3_0.&lt;HandleExceptionsWithNestedTasks&gt;b__0()
  63. at Microsoft.Mashup.Host.Document.ExceptionHandlerExtensions.HandleExceptions(IExceptionHandler exceptionHandler, Action action)
  64. at Microsoft.PowerBI.Client.Program.RunApplication(String[] args)
  65. at Microsoft.PowerBI.Client.Program.Main(String[] args)
  66. PowerBINonFatalError:
  67. {&quot;AppName&quot;:&quot;PBIDesktop&quot;,&quot;AppVersion&quot;:&quot;2.118.621.0&quot;,&quot;ModuleName&quot;:&quot;&quot;,&quot;Component&quot;:&quot;&quot;,&quot;Error&quot;:&quot;Error&quot;,&quot;MethodDef&quot;:&quot;&quot;,&quot;ErrorOffset&quot;:&quot;-1:-1&quot;,&quot;ErrorCode&quot;:&quot;&quot;}
  68. Snapshot Trace Logs:
  69. C:\Users\AppData\Local\Microsoft\Power BI Desktop\FrownSnapShotc7961737-aeb3-43dc-8a36-8ba93ecf010a.zip
  70. Model Default Mode:
  71. Import
  72. Model Version:
  73. PowerBI_V3
  74. Performance Trace Logs:
  75. C:\Users\AppData\Local\Microsoft\Power BI Desktop\PerformanceTraces.zip
  76. Enabled Preview Features:
  77. PBI_enableWebView2
  78. PQ_WebView2Connector
  79. PBI_sparklines
  80. PBI_scorecardVisual
  81. PBI_NlToDax
  82. PBI_fieldParametersSuperSwitch
  83. PBI_horizontalFusion
  84. PBI_setLabelOnExportPdf
  85. PBI_newCard
  86. Disabled Preview Features:
  87. PBI_shapeMapVisualEnabled
  88. PBI_SpanishLinguisticsEnabled
  89. PBI_qnaLiveConnect
  90. PBI_b2bExternalDatasetSharing
  91. PBI_enhancedTooltips
  92. PBI_angularRls
  93. PBI_onObject
  94. PBI_dynamicFormatString
  95. PBI_oneDriveSave
  96. PBI_oneDriveShare
  97. PBI_gitIntegration
  98. Disabled DirectQuery Options:
  99. TreatHanaAsRelationalSource
  100. Cloud:
  101. GlobalCloud
  102. PowerBIUserFeedbackServices_IsReported:
  103. True

答案1

得分: 0

以下是要翻译的内容:

"Got issue actually no need of below lines in python code.

dataset = pandas.DataFrame(Agent, Resolved)
dataset = dataset drop_duplicates()

Its handled internally.Power BI desktop app create temporary folder by name PythonEditorWrapper_XXXX on machine and in same folder data source of pandas frame is present along with python code.

Screenshot of created folder:

Python脚本在Power BI中出现NameError错误。

New bare minimum code to visualize chart.

import matplotlib.pyplot as plt

dataset plot(kind='scatter', x='Agent', y='Resolved', color='green')
plt.show()"

英文:

Got issue actually no need of below lines in python code.

  1. dataset = pandas.DataFrame(Agent, Resolved)
  2. dataset = dataset.drop_duplicates()

Its handled internally.Power BI desktop app create temporary folder by name PythonEditorWrapper_XXXX on machine and in same folder data source of pandas frame is present along with python code.

Screenshot of created folder:

Python脚本在Power BI中出现NameError错误。

New bare minimum code to visualize chart.

  1. import matplotlib.pyplot as plt
  2. dataset.plot(kind=&#39;scatter&#39;, x=&#39;Agent&#39;, y=&#39;Resolved&#39;, color=&#39;green&#39;)
  3. plt.show()

huangapple
  • 本文由 发表于 2023年6月19日 23:40:26
  • 转载请务必保留本文链接:https://go.coder-hub.com/76508159.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定