cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
Highlighted
perezco Regular Visitor
Regular Visitor

Filter with slicer the data for a Python HeatMap Script Visual in power BI using Python

This is a basic python headmap script visual in Power BI.

I am looking to apply a filter to this python script code bellow.

How can be this be filter by slicer(dimension) in this correlation Heatmap code? Below is the code I have written.

------

# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script: 

# dataset = pandas.DataFrame(A_DENO, A_NUM, _Acceptable,_S_ASIS,_A_ASIS, _Offered,_Region)
# dataset = dataset.drop_duplicates()

# Paste or type your script code here:
import pandas as pd # for data analysis
import matplotlib.pyplot as plt
import seaborn as sns
# Compute the correlation matrix #filter by Region # HERE NEED TO MAKE DATASET3.['REGION'] ###dataset2= dataset.loc[dataset.Region =='North America' ]
corr = dataset2.corr() ##plt.figure(figsize=(17,17))
sns.heatmap(corr,cmap='coolwarm', annot = True, fmt='.5g',linewidth =1.9) #plt.title("Correlation HeatMap", fontsize = 16)
plt.xlabel("Features", fontsize = 10)
plt.ylabel("Features", fontsize = 10)
plt.show()

------

The dataset contains several columns.

But I took the picture for those I am interest to work in this python script.

 

 

cluster.1579892631.png

 

_S_ASIS=
DIVIDE( SUM('Cad_KPI'[_Acceptable]), SUM('Cad_KPI'[_Offered]))*100
_A_ASIS
=DIVIDE(DIVIDE( SUM('Cad_KPI'[_A_NUM]), SUM('Cad_KPI'[_A_DENO])), 60)

 Sample data in this image.

 

cluster.p.png

1 ACCEPTED SOLUTION

Accepted Solutions
Super User III
Super User III

Re: Filter with slicer the data for a Python HeatMap Script Visual in power BI using Python

Hi @perezco,

 

I think your heat map needs at least two lines of data.

PythonHeatmap.png

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Proud to be a Super User!

View solution in original post

7 REPLIES 7
Super User III
Super User III

Re: Filter with slicer the data for a Python HeatMap Script Visual in power BI using Python

Hi @perezco ,

 

Power BI replots the Python visual, whenever a data change occurs. (filtering)

The Python visual always only receives the filtered data.

https://docs.microsoft.com/en-us/power-bi/desktop-python-visuals

Regards,

Marcus

Dortmund - Germany
If I answered your question, please mark my post as solution, this will also help others.
Please give Kudos for support. 

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Proud to be a Super User!

perezco Regular Visitor
Regular Visitor

Re: Filter with slicer the data for a Python HeatMap Script Visual in power BI using Python

right, @mwegener .... yes I can used the filters section for the Vizulation from the left but I need is to use slicer filter.

 

 

example for Bar chart code:

 

# The following code to create a dataframe and remove duplicated rows is always executed and acts as a preamble for your script:

# dataset = pandas.DataFrame(_Region, _A_DENO))
# dataset = dataset.drop_duplicates()

# Paste or type your script code here:
import pandas
import matplotlib.pyplot as plt
plt.bar(dataset['_Region'],dataset['_A_DENO'])
plt.show()
 
 
 
Here in this image allow mhas the control that I need but for a chart bar
cluster.1580150670.png
Super User III
Super User III

Re: Filter with slicer the data for a Python HeatMap Script Visual in power BI using Python

Hi @perezco ,

 

could you share your sample pbix?

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Proud to be a Super User!

perezco Regular Visitor
Regular Visitor

Re: Filter with slicer the data for a Python HeatMap Script Visual in power BI using Python

@mwegener 

Here is the file

https://1drv.ms/f/s!Au2MNJlU7lrShnbliSMHNzsD73W4

 

Thanks for any advice.

Super User III
Super User III

Re: Filter with slicer the data for a Python HeatMap Script Visual in power BI using Python

Hi @perezco,

 

I think your heat map needs at least two lines of data.

PythonHeatmap.png

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Proud to be a Super User!

View solution in original post

perezco Regular Visitor
Regular Visitor

Re: Filter with slicer the data for a Python HeatMap Script Visual in power BI using Python

@mwegener 

 

yes, I am aware this demo file brings few records.. But I see that work fine with the filters slicers.

 

thanks

 

 

Super User III
Super User III

Re: Filter with slicer the data for a Python HeatMap Script Visual in power BI using Python

Hi @perezco ,

 

If I answered your question, please mark my post as solution, this will also help others.
Please give Kudos for support.

Did I answer your question?
Please mark my post as solution, this will also help others.
Please give Kudos for support.

Proud to be a Super User!

Helpful resources

Announcements
Exclusive LIVE Community Event #3 – Ask Arun Anything

Exclusive LIVE Community Event #3 – Ask Arun Anything

Join us in the third Triple A event!

Meet the 2020 Season 1 Power BI Super Users!

Meet the 2020 Season 1 Power BI Super Users!

It’s the start of a new Super User season! Learn all about the new Super Users and brand-new tiered recognition system.

Super User Challenge: Can You Solve These?

Super User Challenge: Can You Solve These?

We're celebrating the start of the New Super User season with our first ever Super User 'Can You Solve These?' challenge.

Power BI Desktop Update - February 2020

Power BI Desktop Update - February 2020

We are super excited for our update this month, as we are releasing two of our top community requests!

Power Platform Online Conference

Power Platform Online Conference

Join us for the first ever Power Platform Online Conference!

Top Solution Authors