Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
3 years ago

Python data connection

Hi All,

do I need connect data via Python Script to be able to use them for visualisation by python?

All manuals I have seen are using data connected by python only. 

I have complex report with several kind of data source. Do I need to connect all sources via python which I want to use for python script visualization?

 

If not, how I can in python script for visualisation use data which has been connected in standard way (using top ribbon menu)?

4 Replies

  • Hi , Anonymous 

    The Python script can get the data from the code return and in my research , it can also create Power BI visuals with Python.For more information, you can refer to :
    Create Power BI visuals using Python in Power BI Desktop - Power BI | Microsoft Learn

     

    Thank you for your time and sharing, and thank you for your support and understanding of PowerBI! 

     

    Best Regards,

    Aniya Zhang

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly

    • Anonymous's avatar
      Anonymous
      Not applicable

      v-yueyunzh-msftyou didn't answered on my question and an article on link doesn't describe data connected in standard way.

  • ichavarria's avatar
    ichavarria
    Solution Specialist

    You don't necessarily need to connect your data sources via Python in order to use them for visualization with Python in Power BI. Power BI supports a wide range of data sources that can be connected and used for visualization without needing to use Python to access the data.

     

    If you have already connected your data sources in Power BI, you can use them directly in Python visualizations by using the pandas library in Python. The pandas library provides a way to read data from various sources, including CSV files, Excel files, SQL databases, and more.

     

    Here's an example of how you can use pandas to read data from a CSV file and use it for visualization in a Python visualization in Power BI:

     

    1. Import the necessary libraries:

      import pandas as pd import matplotlib.pyplot as plt import seaborn as sns

    2. Read the data from the CSV file:

      df = pd.read_csv("data.csv")

    3. Create a visualization using the data:

      sns.set(style="darkgrid") plt.figure(figsize=(10,6)) sns.barplot(x="Category", y="Sales", data=df) plt.title("Sales by Category") plt.xlabel("Category") plt.ylabel("Sales") plt.show()

     

    In this example, we're using pandas to read data from a CSV file named "data.csv". We then create a bar chart using the seaborn library and matplotlib library, and display it using plt.show().

     

    You can use this approach to read data from any data source that pandas supports and use it for visualization in a Python visualization in Power BI. Keep in mind that if you have multiple data sources with different structures or schemas, you may need to do some data manipulation or transformation before you can use them together in a Python visualization.


    Best regards, 

    Isaac Chavarria 


    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly