pandas matplotlib example
时间: 2023-09-06 16:11:07 浏览: 151
Matplotlib案例
Here's an example of using pandas and matplotlib to plot a line graph:
```
import pandas as pd
import matplotlib.pyplot as plt
# create a dataframe with some sample data
data = {'year': [2010, 2011, 2012, 2013, 2014, 2015, 2016],
'sales': [100, 120, 140, 160, 180, 200, 220]}
df = pd.DataFrame(data)
# plot the data as a line graph
plt.plot(df['year'], df['sales'])
# add labels and title
plt.xlabel('Year')
plt.ylabel('Sales')
plt.title('Sales over Time')
# display the plot
plt.show()
```
This will create a line graph of sales over time, with the year on the x-axis and the sales on the y-axis. The plot will have labels and a title, and will be displayed using matplotlib.
阅读全文