How to plot bar graph in Python Using CSV file
In this article, we will be discussing how to plot a bar graph in Python. We are using the Matplotlib library for this.
Matplotlib is a visualization library in Python. You can install this library using the command,
pip install matplotlib
Below is given the code for plotting a Bar chart using a csv file.
import pandas as pd from matplotlib import pyplot as plt df = pd.read_csv("Students.csv") #print(df) students_groupedby_age = df.groupby('Name')[['Age']].sum() print(students_groupedby_age.sort_values(by = ['Age'])) fig, ax = plt.subplots() ax.bar(students_groupedby_age.index, students_groupedby_age['Age']) plt.title('Students vs Age Bar chart') plt.xlabel('Students') plt.ylabel('Age') plt.show()
Output:
Subscribe
Login
Please login to comment
0 Discussion