Display Bar Graph in Python [Jupyter]

import pandas as pd
import matplotlib.pyplot as plt

#Read the CSV file into a DataFrame
df = pd.read_csv(‘First-5-Rows.csv’)

#Group the data by ‘Variable_name’ and aggregate the ‘Value’ column by sum
grouped_df = df.groupby(‘Variable_name’)[‘Value’].sum().reset_index()

#Create a bar chart of the data
plt.bar(grouped_df[‘Variable_name’], grouped_df[‘Value’])

#Add labels and title to the chart
plt.xlabel(‘Variable Name’)
plt.ylabel(‘Value’)
plt.title(‘Bar Chart of First 5 Rows by Variable Name’)

Show the chart
plt.show()

Leave a comment