Python:使用给定列绘制具有x轴的pandas数据帧的条形图

Python:使用给定列绘制具有x轴的pandas数据帧的条形图,python,pandas,jupyter-notebook,python-ggplot,Python,Pandas,Jupyter Notebook,Python Ggplot,我想在Jupyter笔记本上为以下熊猫数据框绘制条形图 | Month | number ------------------------- 0 | Apr | 6.5 1 | May | 7.3 2 | Jun | 3.9 3 | Jul | 5.1 4 | Aug | 4.1 我做到了: %matplotlib notebook import matplotlib.pyplot as plt import m

我想在Jupyter笔记本上为以下熊猫数据框绘制条形图

      | Month | number
-------------------------
    0 | Apr   |  6.5
    1 | May   |  7.3
    2 | Jun   |  3.9
    3 | Jul   |  5.1
    4 | Aug   |  4.1
我做到了:

%matplotlib notebook
import matplotlib.pyplot as plt
import matplotlib
matplotlib.style.use('ggplot')
trend_df.plot(kind='bar')

如何确保x轴在此处实际显示月份?

您只需在调用
plot
时指定
x
y
,即可获得所需的条形图

store the data in a csv file.

example i named my file plot.csv

    save data in following format in plot.csv

Month,number

Apr,6.5

May,7.3

Jun,3.9

Jul,5.1

Aug,4.1


import pandas as pd

import matplotlib.pyplot as plt

import numpy as np

import csv

#first read the data
data = pd.read_csv('plot.csv',sep=',')

print(data)
#create  a data frame
df = data.ix[-5:,['Month','number']]
#plot
df.plot(kind = 'bar')

plt.show()
#for ggplot
plt.style.use('ggplot')

df.plot()

plt.show()
trend_df.plot(x='Month', y='number', kind='bar')

给定
trend\u df
as

In [20]: trend_df
Out[20]: 
  Month  number
0   Apr     6.5
1   May     7.3
2   Jun     3.9
3   Jul     5.1
4   Aug     4.1

导入matplotlib之前,请在上面的回答中执行
%matplotlib inline
,不要在数据中给出换行符