Reputation: 469
I am using Power BI desktop and noticed some limitations on the pre-made graph models like the Line Graph. That's why I am trying to make a graph using Python Visuals. I am familiar with Python but I am not familiar with the Python Visual module in Power BI. Currently I am trying to make a simple Line Graph with this module.
# dataset = pandas.DataFrame(User field, Tag, Value, Resultaat, Timestamp)
# dataset = dataset.drop_duplicates()
import matplotlib.pyplot as plt
x = dataset.Timestamp
y = dataset.Value
plt.plot(x, y, 'ro')
plt.show()
For example I have the following two variables:
And I want to plot these two values.
x = dataset['User Field']
y = dataset.Resultaat
plt.plot(x, y, 'ro')
plt.show()
Unfortunately the code shown above does not create a working graph. I want to know what is going wrong. That's why I would like to print the variable dataset['User field'].
Upvotes: 0
Views: 4001
Reputation: 469
I was not able to print the values in the Python editor in Power BI. However it's possible to edit the code that is used Power BI in an external editor.
When clicking on the export button a Python script is being generated and automatically opened in your default editor for Python files. All the variables from Power BI are exported to a CSV file. The automatically generated Python script reads these values.
Because a Python script is generated and can be used outside of Power BI all the Python functionalities can be used. This includes printing variables.
# Prolog - Auto Generated #
import os, matplotlib.pyplot, uuid, pandas
os.chdir(u'C:/Users/Fakeuser/PythonEditorWrapper_886e059e-ab5c-423e-a20b-a224ee311990')
dataset = pandas.read_csv('input_df_d776f9db-be3f-4120-90f8-d9abe5c31964.csv')
matplotlib.pyplot.figure(figsize=(5.55555555555556,4.16666666666667))
matplotlib.pyplot.show = lambda args=None,kw=None: matplotlib.pyplot.savefig(str(uuid.uuid1()))
# dataset = pandas.DataFrame(User field, Tag, Value, Resultaat, Timestamp)
# dataset = dataset.drop_duplicates()
import matplotlib.pyplot as plt
tags = set(dataset['Tag'])
print(tags)
Upvotes: 1