Advance your Data & AI career with 50 days of live learning, dataviz contests, hands-on challenges, study groups & certifications and more!
Get registeredGet Fabric Certified for FREE during Fabric Data Days. Don't miss your chance! Request now
Hola a todos
Estoy tratando de crear un objeto visual de Python. al ejecutar el script en mi Pycharm que utiliza un archivo CSV tal como se exportó desde el conjunto de datos, el código está funcionando. el código original incluso está trabajando en el informe.
al cambiar el origen al conjunto de datos (data = dataset en lugar de data = pd.read_csv(r"C:\Users\*****.csv")) en las mismas columnas del informe, recibo un error:
Error de script de Python.
KeyError: Marca de tiempo('2021-08-03 00:00:00')
todas las columnas son de tipo fecha o cadena.
agregando el código y el error. cualquier ayuda será apreciada
import pandas as pd
import matplotlib.pyplot as plot
import matplotlib.pyplot as plt
color_dict = {'FV': 'yellow', 'DV': 'green', 'RTL': 'blue'}
data = dataset
data.set_index('TIME_ID')
data['TIME_ID'] = pd.to_datetime(data['TIME_ID'])
data['CALCULATED_DD_SNP'] = pd.to_datetime(data['CALCULATED_DD_SNP'])
data['PLANNED_DD_SNP'] = pd.to_datetime(data['PLANNED_DD_SNP'])
# lines = d.plot.line()
# d.plot.line(title="Milestones Over Time");
# #
# plot.show(block=True)
FV = data.loc[data['PHASE_NAME'] == 'FV']
DV = data.loc[data['PHASE_NAME'] == 'DV']
RTL = data.loc[data['PHASE_NAME'] == 'RTL']
x = data['TIME_ID']
y = data['PLANNED_DD_SNP']
plot.scatter(x, y, color='gray' ,label='Milestone')
list_of_phases = [FV, DV, RTL]
for d in list_of_phases:
phase_name = d.iloc[0,1]
x = d['TIME_ID']
y = d['CALCULATED_DD_SNP']
plot.scatter(x, y, color=color_dict[phase_name], label=phase_name)
plot.legend()
plot.show()
Solved! Go to Solution.
Descubrí que había un error en mi código. El orden de las columnas en el CSV era diferente del orden en el conjunto de datos, por lo que este código abordaba la columna incorrecta - phase_name = d.iloc[0,1]
. lo visual está funcionando ahora.
Hi, @nadavsnn ;
si funciona en pycharm. Antes de poder usar R o Python en Power BI Desktop, debe tener el lenguaje, junto con los paquetes que desee usar, instalado en el equipo.
Cómo usar R y Python en Power BI | Lenguajes de Power BI (iterationinsights.com)
Saludos
Equipo de soporte de la comunidad _ Yalan Wu
Si esta publicación ayuda, considere Aceptarla como la solución para ayudar a los otros miembros a encontrarla más rápidamente.
hola, Python está instalado en mi PC. el script original que se dirige al archivo CSV incluso está funcionando en el informe / Recibo el error cuando cambio al conjunto de datos real en el informe en lugar del archivo CSV (que se exportó desde el conjunto de datos real).
más detalles del error:
Mensaje de error:
Error de script de Python.
KeyError: Marca de tiempo('2021-08-03 00:00:00')
Seguimiento de pila:
Microsoft.PowerBI.ExploreServiceCommon.ScriptHandlerException: error de script de Python.
KeyError: Marca de tiempo('2021-08-03 00:00:00')
---> Microsoft.PowerBI.Scripting.Python.Exceptions.PythonScriptRuntimeException: error de script de Python.
KeyError: Marca de tiempo('2021-08-03 00:00:00')
en Microsoft.PowerBI.Scripting.Python.PythonScriptWrapper.RunScript(String originalScript, Int32 timeoutMs)
en Microsoft.PowerBI.Client.Windows.Python.PythonScriptHandler.GenerateVisual(opciones de ScriptHandlerOptions)
--- Fin del --- de seguimiento de la pila de excepciones interna
en Microsoft.PowerBI.Client.Windows.Python.PythonScriptHandler.GenerateVisual(opciones de ScriptHandlerOptions)
en Microsoft.PowerBI.ExploreHost.SemanticQuery.ScriptVisualCommandFlow.RunInternal(Stream dataShapeResultStream, QueryBindingDescriptor& bindingDescriptor)
en Microsoft.PowerBI.ExploreHost.SemanticQuery.ScriptVisualCommandFlow.Run(Stream dataShapeResultStream, QueryBindingDescriptor& bindingDescriptor)
en Microsoft.PowerBI.ExploreHost.SemanticQuery.ExecuteSemanticQueryFlow.TransformDataShapeResult(QueryCommand transformCommand, Comando SemanticQueryDataShapeCommand, Stream dataShapeResultStream, QueryBindingDescriptor& bindingDescriptor)
en Microsoft.PowerBI.ExploreHost.SemanticQuery.ExecuteSemanticQueryFlow.ExecuteDataQuery(IQueryResultDataWriter queryResultDataWriter, EngineDataModel engineDataModel, DataQuery query, Int32 queryId, ServiceErrorStatusCode& serviceErrorStatusCode, CancellationToken cancelToken)
en Microsoft.PowerBI.ExploreHost.SemanticQuery.ExecuteSemanticQueryFlow.ProcessAndWriteSemanticQueryCommands(IQueryResultsWriter queryResultsWriter, IList'1 queries, HashSet'1 pendingQueriesToCancel, EngineDataModel engineDataModel)
Seguimiento de pila de invocación:
en Microsoft.Mashup.Host.Document.ExceptionExtensions.GetCurrentInvocationStackTrace()
en Microsoft.Mashup.Client.UI.Shared.StackTraceInfo.. ctor(String exceptionStackTrace, String invocationStackTrace, String exceptionMessage)
en Microsoft.PowerBI.Client.Windows.ErrorHostService.GetErrorDetails(ShowErrorDialogArgs args)
en Microsoft.PowerBI.Client.Windows.ErrorHostService.<>c__DisplayClass5_0.b__0()
en System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
en System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
en System.Delegate.DynamicInvokeImpl(Object[] args)
en System.Windows.Forms.Control.InvokeMarshaledCallbackDo(ThreadMethodEntry tme)
en System.Windows.Forms.Control.InvokeMarshaledCallbackHelper(Object obj)
en System.Windows.Forms.Control.InvokeMarshaledCallback(ThreadMethodEntry tme)
en System.Windows.Forms.Control.InvokeMarshaledCallbacks()
en System.Windows.Forms.Control.MarshaledInvoke(Llamador de control, Método delegado, Object[] args, Sincrónico booleano)
en System.Windows.Forms.Control.Invoke(Método Delegado, Object[] args)
en System.Windows.Forms.WindowsFormsSynchronizationContext.Send(SendOrPostCallback d, Estado del objeto)
en Microsoft.PowerBI.Client.Windows.Services.UIBlockingService.AllowModalDialogs(Acción de acción)
en Microsoft.PowerBI.Client.Windows.HostServiceDispatcher.<>c__DisplayClass14_0.b__0()
en Microsoft.PowerBI.Client.Windows.HostServiceDispatcher.ExecuteOnUIThreadAndHandlePromise[T](Func'1 func, IPromiseStore promiseStore, Int64 promiseHandle)
en System.RuntimeMethodHandle.InvokeMethod(Object target, Object[] arguments, Signature sig, Boolean constructor)
en System.Reflection.RuntimeMethodInfo.UnsafeInvokeInternal(Object obj, Object[] parameters, Object[] arguments)
en System.Reflection.RuntimeMethodInfo.Invoke(Object obj, BindingFlags invokeAttr, Binder binder, Object[] parameters, CultureInfo culture)
en Microsoft.PowerBI.Client.Windows.WebView2.WebView2Interop.InvokeCs(llamada InteropCall)
en Microsoft.Mashup.Host.Document.ExceptionHandlerExtensions.HandleExceptions(IExceptionHandler exceptionHandler, Acción de acción)
en System.EventHandler'1.Invoke(Object sender, TEventArgs e)
en System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
en System.Windows.Forms.UnsafeNativeMethods.DispatchMessageW(MSG& msg)
en System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
en System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Motivo Int32, contexto ApplicationContext)
en System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Motivo Int32, contexto ApplicationContext)
en System.Windows.Forms.Form.ShowDialog(propietario de IWin32Window)
en Microsoft.Mashup.Client.UI.Shared.WindowManager.ShowModal[T](cuadro de diálogo T, Func'1 showModalFunction)
en Microsoft.PowerBI.Client.Program.<>c__DisplayClass4_1.b__3()
en Microsoft.PowerBI.Client.Windows.IExceptionHandlerExtensions.<>c__DisplayClass3_0.b__0()
en Microsoft.Mashup.Host.Document.ExceptionHandlerExtensions.HandleExceptions(IExceptionHandler exceptionHandler, Acción de acción)
en Microsoft.PowerBI.Client.Program.Main(String[] args)
Descubrí que había un error en mi código. El orden de las columnas en el CSV era diferente del orden en el conjunto de datos, por lo que este código abordaba la columna incorrecta - phase_name = d.iloc[0,1]
. lo visual está funcionando ahora.
Advance your Data & AI career with 50 days of live learning, contests, hands-on challenges, study groups & certifications and more!
Check out the October 2025 Power BI update to learn about new features.