As of today, August 9 2018, Power BI supports Python Visualizations. They've had support for R Visualizations before, but I still find these integrations to be a bit awkward. Let me show you what I mean:
Let's say that you have a table with time series data, where the top row containts the names 'Date' and 'Value', and the contents are dates of the form yyyy-mm-dd and a number, respectively:
Date,Value
2017-01-12,1
2017-01-13,4
2017-01-14,2
2017-01-15,4
2017-01-16,2
2017-01-17,2
2017-01-18,2
2017-01-19,5
2017-01-20,5
2017-01-21,5
2017-01-22,5
2017-01-23,6
2017-01-24,3
2017-01-25,6
2017-01-26,6
2017-01-27,5
2017-01-28,8
2017-01-29,4
2017-01-30,2
If you store that dataset as a textfile like timerseries.csv and import it using Get Data | Text/CSV, you get a table uner VISUALIZATIONS | FIELDS, like this:
You can inspect your table using VISUALIZATIONS | Table and get:
With this setup, one should think that you were all set for unleashing the power of a Py VISUALIZATION using this beautiful new feature:
If you click that, you get this:
And you're told to
Drag fields into the Values area in the Visualization pane to start
scripting
If you start with Value, you get this default setup in the editor:
And if you follow the instructions given by the Power BI team in the August 2018 feature summary you should be able to make a matplotlib plot quite easily.
But this is where it ends for me at the time being.
If the default dataframe in the editor shares the features of a standard dataframe, you should be able to reference a column in that dataframe and easily make a plot with this snippet:
import matplotlib.pyplot as plt
plt.plot(dataset['Value'])
plt.show()
But when you run it, it onlu returns an error:
And the details are elaborate to say the least.
I've also tried to import both Dates and Values, and I've tried plotting the dataframe directly with dataset.plot(), but nothing seems to be working. I've also tried stripping the date hierarchy down to simple dates this way:
So, any ideas on the dataformat, import method and/or the snippet?
Thank you for any suggestions!
EDIT 1 - Following the answer from Foxan Ng:
Add both columns in the Value field:
This still returns an error edning with:
TypeError: from_bounds() takes 4 positional arguments but 6 were given
解决方案
I didn't encounter errors that you've mentioned. Have you dropped in both columns into Values?
import matplotlib.pyplot as plt
plt.plot(dataset['Date'], dataset['Value'])
plt.show()
UPDATED with M query:
let
Source = Csv.Document(File.Contents("C:\your-directory..\timerseries.csv"),[Delimiter=",", Columns=2, Encoding=1252, QuoteStyle=QuoteStyle.None]),
#"Promoted Headers" = Table.PromoteHeaders(Source, [PromoteAllScalars=true]),
#"Changed Type" = Table.TransformColumnTypes(#"Promoted Headers",{{"Date", type date}, {"Value", Int64.Type}})
in
#"Changed Type"