How to plot bar graph in Python Using CSV file
![how to plot bar graph in python using csv file](https://pythonpoint.net/wp-content/uploads/2021/01/how-to-plot-bar-graph-in-python-using-csv-file-1024x576.jpg)
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:
![](https://pythonpoint.net/wp-content/uploads/2021/01/Screenshot-2021-01-04-155016-1024x702.jpg)
Subscribe
Login
Please login to comment
0 Discussion