3

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:

enter image description here

You can inspect your table using VISUALIZATIONS | Table and get:

enter image description here

With this setup, one should think that you were all set for unleashing the power of a Py VISUALIZATION using this beautiful new feature:

enter image description here

If you click that, you get this:

enter image description here

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:

enter image description here

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.

enter image description here

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:

enter image description here

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:

enter image description here

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:

enter image description here

This still returns an error edning with:

TypeError: from_bounds() takes 4 positional arguments but 6 were given

Trenton McKinney
  • 56,955
  • 33
  • 144
  • 158
vestland
  • 55,229
  • 37
  • 187
  • 305

1 Answers1

2

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()

images


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"

timeseries

Foxan Ng
  • 6,883
  • 4
  • 34
  • 41
  • That's cool, AND mildly infuriating! Yes, I have tried dropping both columns into Values. I'll add a screenshot in an edit. And the last part of the error message. – vestland Aug 09 '18 at 08:49
  • Could you go to the Data Tab and take a screenshot of what your table looks like? – vestland Aug 09 '18 at 08:58
  • 1
    @vestland Sure! Updated with M query and screenshot. – Foxan Ng Aug 09 '18 at 09:18
  • we've got the exact same setup. What Python version are you running? I'm on Python 3.6.0 (Anaconda) – vestland Aug 09 '18 at 09:46
  • 1
    Python 3.6.4 (Anaconda) – Foxan Ng Aug 09 '18 at 10:47
  • 1
    More importantly: matplotlib==2.1.2 as the .from_bounds() method are from [here](https://matplotlib.org/api/transformations.html?highlight=from_bounds#matplotlib.transforms.Bbox.from_bounds) – Foxan Ng Aug 09 '18 at 11:02
  • I've upgraded to Python 3.6.6 and matplotlib 2.2.2, and it still doesn't work. Strange... – vestland Aug 10 '18 at 13:38
  • 1
    I think what you can do is to try other visualization libraries / other machine to narrow down the possible root cause.. – Foxan Ng Aug 10 '18 at 13:53
  • what pandas version are you running? – vestland Aug 14 '18 at 09:51
  • @vestland 0.22.0 – Foxan Ng Aug 14 '18 at 11:05
  • I've updated, Python, Matplotlib and Pandas to the latest versions, but I'm still having the same problem. Since you've ruled out that the dataset itself is not the problem here, I'm just going to mark your answer as the accepted answer, and ask a new question about package version requirements. Hope to see you there as well! – vestland Aug 15 '18 at 09:46