Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Simple python script - extracting value from data frame

Hello,

 

I am trying to build custom waterfall with python in PBI as there exists no chart that would work the way i want it to. For that I decided to assign values to variables which later will be used for columns. It works fine in Spyder, however not in PBI.

 

I have imported 2 columns to dataframe called dataset(standard procedure after creating a blank python script). One has names for the columns and the other one values, where names are repeated multiple times(I am planning to filter whole report with country and date which will created single names).

data = pd.pivot_table(dataset, aggfunc = np.sum, values = dataset[['Waterfall Value']], index = "Data Type")
#Here I create a pivot in order to sum all values because in original columns there are lots of countries per which chart has to be created, but I decided to leave country for filtering.

data = data.reset_index()
#Here I reset index to get back column "Data Type" which has names for each column.

z = float(data['Waterfall Value'][(data['Data Type'] == "Production")])
#Here I am testing one variable to which I assign specific field - Waterfall value where data type is "production". I have tested that in spyder and it works.

plt.bar([1], [z])
plt.show()
#Here I create simple bar chart to see if it has values.

Again, my goal here is to extract single value from the dataframe created by PBI and assign it to variable as I need to create my waterfall column by column. I would apreciate any suggestions.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

I was digging a lot around the subject, and after lots of trials I came up with the answer.

 

df = pd.pivot_table(dataset, aggfunc = np.sum, values = "Waterfall_Value", index = "Data_Type")
dictionary = df.to_dict()

col_Prod = dictionary["Waterfall_Value"]["Production"]

plt.bar('production', col_Prod)
plt.show()

 I hope it might help anyone in future. 

View solution in original post

1 REPLY 1
Anonymous
Not applicable

I was digging a lot around the subject, and after lots of trials I came up with the answer.

 

df = pd.pivot_table(dataset, aggfunc = np.sum, values = "Waterfall_Value", index = "Data_Type")
dictionary = df.to_dict()

col_Prod = dictionary["Waterfall_Value"]["Production"]

plt.bar('production', col_Prod)
plt.show()

 I hope it might help anyone in future. 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.