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

Score big with last-minute savings on the final tickets to FabCon Vienna. Secure your discount

Reply
TK093552
New Member

notebook

I'm trying to extract data from csv file to use bar chat using python. I have loaded the data from the csv file to pandas data frame. However, to make a bar chart I'm unable to use the data from the csv file. e.g. the csv file has 4 columns. I'm trying to extract two of the columns to make a bar chart.

 
import pandas as pd
import matplotlib as plt

# Load data into pandas DataFrame from "/lakehouse/default/Files/data.csv"
df = pd.read_csv("/lakehouse/default/Files/data.csv")
x = df['Duration']
y = df['Pulse']
 
plt.bar(x, y, label="Blue Bar", color='b')
plt.show()
 
In this program, I'm unable to extract the data for x and y axis.

 

 

1 REPLY 1
saud968
Super User
Super User

Try this

import pandas as pd
import matplotlib.pyplot as plt

# Load data into pandas DataFrame from "/lakehouse/default/Files/data.csv"
df = pd.read_csv("/lakehouse/default/Files/data.csv")

# Extract the columns you want to use for the bar chart
x = df['Duration']
y = df['Pulse']

# Create the bar chart
plt.bar(x, y, label="Blue Bar", color='b')

# Add labels and title for better readability
plt.xlabel('Duration')
plt.ylabel('Pulse')
plt.title('Duration vs Pulse')
plt.legend()

# Display the bar chart
plt.show()
Here are a few things to check:

Column Names: Ensure that the column names in your CSV file match exactly with 'Duration' and 'Pulse'. Column names are case-sensitive.
Data Types: Verify that the data in these columns are suitable for plotting. For example, 'Duration' should be numerical or categorical, and 'Pulse' should be numerical.
Matplotlib Import: Make sure you import pyplot from matplotlib correctly.

Best Regards
Saud Ansari
If this post helps, please Accept it as a Solution to help other members find it. I appreciate your Kudos!

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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