Intro to Python in Power BI

In Business Intelligence & Analytics

Intro to Python in Power BI - read the full article about business intelligence, Business Intelligence & Analytics and Data analytics and consulting from Guy in a Cube on Qualified.One
Guy in a Cube
Youtube Blogger

- Yooo! Whats up? This is Patrick from Guy in a Cube and in this video, Im gonna do a quick introduction to using Python in Power BI, stay tuned.

(upbeat music) If you find this for the very first time be sure to hit that subscribe button, to stay up to date from all the videos from both Adam and this guy.

Okay. Python, Patrick, why are you talking about Python? You guys never talk about anything like that except when Ryan Wade came on and did a video on R, which is a cool video.

If you havent watched it you should go check that video out but in this video, I want to talk about Python.

I had to build a demo of Python integrated in power BI and I decided why not quick make a quick video of all the steps that I took on how to get started with this Python integration.

Okay? So you guys know what I like to do instead of all this talking lets do what? Lets head over to my laptop.

So the first thing you need to do is download and install Python, but I had no idea where to start but I knew I needed to get it integrated.

So I went to File > Options and settings and then I chose Options, cause I remember there was a choice in the global section of the Options and so you can see right here theres R and Python scripting.

So I went there and it was empty because I hadnt downloaded Python, anything like that but there was a hyperlink.

So I clicked on that hyperlink and it took me here to this page.

and then it said, Hey, theres a work through.

So I clicked on that and thinking it brought me to the Python website and then I was looking at this, theres documentation and everything, but I clicked on downloads and you could see right here, theres a section for windows.

So I click windows and then I scroll down a little bit and theres a 64 bit installer.

I clicked it, download it and as I was going through the install you need to make note of where you install it the path that you installed it cause youll need that path a little later because youll need to install additional libraries and there is a executable like pip or something like that that you can use to install these executables.

So you need to make note of that path.

So after I downloaded and installed it and I closed the desktop opened it back up and then I saw everything it just automatically picked these things up and I was excited.

Then I was like, okay, well I need some data but I didnt even know how to write Python, so I needed some steps.

So I searched the internet and on that site that it leads you to theres some tutorials and things but I did a quick search of the internet and I landed here.

I thought this was a pretty cool website that I want to share with you guys.

If you go to this webpage and itll be down in the links below this video, youll see, theres lots of options and I just clicked one.

Before I got started I remembered theres two things two ways you can use Python and Power BI.

You can use it to get data and visualize data and I thought, wouldnt it be cool if I got some data and prepped some data and then I visualized it, using Python to do both.

I thought that would be cool.

So I noticed that there was these datasets this sns_load stuff and I said, well, lets see if I can do this in power BI.

So I went over to the desktop and chose to get data and I selected more because I remembered there was a Python connector out there, right? So I typed in Python and theres my Python script and I clicked connect.

I did have to tinker a little bit to figure out how to make this work, but it was pretty easy.

I imported that seaborn library.

Its just import and you give it an alias then you can use it.

So I said, tips, thats the name of the dataset equals sns.lo and theres a method there that I can use to get some data and then you just provide the name of the dataset that you want to get.

Theres lots of data sets out there that you can use.

Okay and I clicked, okay.

I didnt think it was gonna work, but look its a dataset cause they have sample data sets out there.

Right? I checked it and I clicked transform because I wanted to see what the M looked like.

So you can see theres a source, If I click on the source and see the script that I wrote and then on the navigation, it just rendered my data for me.

If I go here and go to the advanced editor I can see the code that it wrapped around it, nothing too complicated and I can continue to transform this data if I wanted to but this is enough for Patrick.

I was excited just to get the data in.

So now its gonna load that tip data up and I was like, okay, I want to create a visual and I decided Id seen these swarm plots.

I wanted to create something that was not already in Power BI.

I know theres probably some custom visuals and things like that, but I said, Hey, lets lets be a little adventurous.

Okay? So I decided Im gonna create this swarm plot.

Let me show you how I did it.

So the first thing I did was I found the Python visual and I just clicked in the white space on the page and I clicked it and then I received a little prompt set.

Hey, you need to enable these script visuals Sure! Its easy.

Put that right there, expand this guy out and then what you need to do, any of the columns in your dataset that youre gonna use as part of your code, you need to make sure you bring them over into the value section.

I was gonna use day and total bill.

So I dropped that right there and I can start writing some code.

So lets see, lets see if Patrick got some, some Python skills.

So imports > seaborn.

One thing I didnt mention, sometimes youll need to import these libraries and remember when I said you need to remember the path where you install Python at so you will have to, you can go to a command line and like seaborn, I had to install it.

So you do pip install, like we need change our directory.

So if we change our directory to the location of that executable, and then if you do pip install and then if I do seaborn, its got to go and install that package.

I think its already installed because I ran through this before, but anyway, youll need to do that and you may possibly need to do that for other libraries and also theres a list of supported packages and so you can see theres these are the supported packages for Python and Power BI.

So import seaborn, write a little Python.

This is Patricks adventure, sns.

So (mumbles) and then I needed another one for my visual, matplotlib and I already imported this one, pyplot something like this, as lib and then I actually did it right? snsswarmplot(x) So what I want an X axis daily.

Thats what I want an x-axis and this is case sensitive, so you need to be very careful with that and then the total bill, these are the columns.

So you can see the columns already there and then the dataset and this is where I got tripped up a little bit because in the documentation, they said give it the name of the dataset but in my case, I just specified dataset just like that and then I said, pit that show which is actually gonna render that, that visual for me.

So now theres a little play icon, if I click play, hopefully I dont get an error Ah, lets see what I got, Lets see what I got here is seaborn theres no attributes, warm plot.

So that means I spelled it wrong, right? Thats okay.

Its really particular but I mean, its like any other program link youve got to specify the right things.

Boom. A couple of things in the script.

I need to make sure Im paying attention to what Im typing there but once I did that, it all works.

The last thing that when you deploy this out, Python and R refreshes are only supported by the personal gateway.

So if you want to use Python and are integrated into your power BI desktop, youll definitely need to install a personal gateway on your machine.

Okay. What do you guys think? Are you working with Python? Have you run into any challenges? Are you just getting started? These are some great resources to get started.

I thought they were because it helped me quick quickly get started with this.

If you have any questions, comments, you know what to do.

Lets continue the conversation, where? In the comments below.

If its your first time visiting Guy in a Cube channel, hit that subscribe button.

Like my video, big thumbs up.

As always from Adam and myself.

Thanks for watching, See you in the next video.

Guy in a Cube: Intro to Python in Power BI - Business Intelligence & Analytics