Forum Discussion
Python data connection
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:
- Import the necessary libraries:
import pandas as pd import matplotlib.pyplot as plt import seaborn as sns - Read the data from the CSV file:
df = pd.read_csv("data.csv") - 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