Introduction
I am using Power BI desktop and noticed some limitations on the pre-made graph models like the Line Graph. That's why I am trying to make a graph using Python Visuals. I am familiar with Python but I am not familiar with the Python Visual module in Power BI. Currently I am trying to make a simple Line Graph with this module.
I verified that I can draw a graph using Python Visuals (using matplotlib.pyplot) with some of my variables
# dataset = pandas.DataFrame(User field, Tag, Value, Resultaat, Timestamp)
# dataset = dataset.drop_duplicates()
import matplotlib.pyplot as plt
x = dataset.Timestamp
y = dataset.Value
plt.plot(x, y, 'ro')
plt.show()
However I am unable to plot some of my variables
For example I have the following two variables:
User field (timestamp)
Resultaat (int)
And I want to plot these two values.
x = dataset['User Field']
y = dataset.Resultaat
plt.plot(x, y, 'ro')
plt.show()
Unfortunately the code shown above does not create a working graph. I want to know what is going wrong. That's why I would like to print the variable dataset['User field'].
Question
Is it possible to debug a value in Python Visuals? Can I dump/print a variable like print(dataset['User field']) to see if the data of this variable is correct?
I was not able to print the values in the Python editor in Power BI. However it's possible to edit the code that is used Power BI in an external editor.
When clicking on the export button a Python script is being generated and automatically opened in your default editor for Python files. All the variables from Power BI are exported to a CSV file. The automatically generated Python script reads these values.
Because a Python script is generated and can be used outside of Power BI all the Python functionalities can be used. This includes printing variables.
# Prolog - Auto Generated #
import os, matplotlib.pyplot, uuid, pandas
os.chdir(u'C:/Users/Fakeuser/PythonEditorWrapper_886e059e-ab5c-423e-a20b-a224ee311990')
dataset = pandas.read_csv('input_df_d776f9db-be3f-4120-90f8-d9abe5c31964.csv')
matplotlib.pyplot.figure(figsize=(5.55555555555556,4.16666666666667))
matplotlib.pyplot.show = lambda args=None,kw=None: matplotlib.pyplot.savefig(str(uuid.uuid1()))
# dataset = pandas.DataFrame(User field, Tag, Value, Resultaat, Timestamp)
# dataset = dataset.drop_duplicates()
import matplotlib.pyplot as plt
tags = set(dataset['Tag'])
print(tags)
Related
I've been trying to import my geojson file in PowerBi in order to create a map. I want actually to create a map showing the polygons by region. Why? because i have already a column that contains the dtype: geometry, so I already have polygons with a set of coordonates. But everytime i import my file in PowerBi and I use my visual the polygon column is not recognised. Do you know if I need to prepare my data in python before? My initial file is geojason and I export it in csv. I'm open in recommendation and I attach photos of what I've done so far.seperating lat et lon displaying my polygon i tried to tranform my column wkt, but it's not working
After converting shapefile from mapshaper.org and importing it to Power BI I'm getting the below data structure in power query. I have seen countless custom map tutorials where the data is loaded straightaway to power query but I cannot seem to understand how to make this structure work. Can anyone please help me with this?
Data can be found here: data link: radacad.com
If you want to use the imported topoJSON file in the Power BI Shape map visual, you do not import it via Power Query. It is imported via the option in the visual in the Shape '+Add Map' option.
You then need another dataset that you can drag into the location field of the Shape map to map the data.
Hope that helps
I have 2 Queries in Power BI
one is Import and the other is Direct Query
I was looking at the Advance Editor for both queries.
they both look exactly the same, no difference what do ever
How can I change Import query to become Direct Query from the Advanced editor?
Import query script
let
Source = Sql.Database("DSServer", "DSDB", [Query="EXEC stat_DailyNumbers"])
in
Source
Direct Query script
let
Source = Sql.Database("DSServer", "DSDB", [Query="EXEC stat_DailyNumbers"])
in
Source
You cannot switch between query methods.
Workaround:
1. copy the code from your advanced editor to notepad.
2. Create a new query, where you will be able to choose direct query / import.
3. Open advanced editor for the new query and paste the code you copied earlier.
I have a pandas dataframe that looks like this:
A B C
1 2 =A2+B2
3 4 =A3+B3
I write this to an Excel file using xlsxwriter in Python and convert the data frame to Excel. Now, when I read the Excel from Python, I get 0.0 as the value for C2 and not 3 (=A2+B2). However, if I open Excel manually, the formulas are evaluated and has '3' in 'C2'. So the problem occurs while reading from code.
Is there a way in Python to read Excel columns with formulas as values?
So the problem is while reading from code.
Not really.
The issue is that XlxsWriter doesn't write the value of a formula to an Excel file. From the XlsxWriter FAQ:
Formula results displaying as zero in non-Excel applications
Due to wide range of possible formulas and interdependencies between them XlsxWriter doesn’t, and realistically cannot, calculate the result of a formula when it is written to an XLSX file. Instead, it stores the value 0 as the formula result. It then sets a global flag in the XLSX file to say that all formulas and functions should be recalculated when the file is opened.
This is the method recommended in the Excel documentation and in general it works fine with spreadsheet applications. However, applications that don’t have a facility to calculate formulas, such as Excel Viewer, or several mobile applications, will only display the 0 results.
If required, it is also possible to specify the calculated result of the formula using the optional value parameter in write_formula():
worksheet.write_formula('A1', '=2+2', num_format, 4)
I would save the Excel file as a .csv. Excel should automatically convert all formulae to values. You can then read the .csv into Python with the usual file methods.
I have a csv file with two identical columns:
X,X
0,0
1,1
2,2
I would like to import this into Stata 13, but it does not like importing the second X (since the names are the same):
. import delimited "filename.csv"
X already defined
Error creating variables
r(109);
Is there a simple way to force the import?
I do not want to specify the rows to import. The actual dataset has 100+ variables, and the duplicated variables are distributed throughout.
Similarly, I do not want to manually rename the variables.
I am fine if Stata wants to either drop or rename the second X.
As background, this csv file is being generated by some sloppy SQL code. The duplicated variables are precisely the variables I use for the joins. I could clean up the SQL code or pre-clean (with e.g. Python), but I would ideally like to have Stata force the import.
Try insheet.
With this example data in a .csv file:
x,x,y,y
238965,586,127,192864
238965,586,127,192864
1074,198264,5186,2947
1074,198264,5186,2947
All variables are imported and the resulting names in Stata are:
x
v2
y
v4
The command would be:
insheet using "~/some/file.csv"
(I'm on Stata 12.1 and according to the Stata 13 [U] manual, insheet is superseded by import delimited, p.21.)
import delimited was patched for this particular problem in the 07oct2013 update. To update Stata 13 type...
. update all
in the Stata Command window.