Python 按计数排序的带条返回的熊猫图?

Python 按计数排序的带条返回的熊猫图?,python,pandas,plot,bar-chart,Python,Pandas,Plot,Bar Chart,我正在使用以下代码创建一个绘图,以显示我的df中出现了多少个空值,并按日期列排序: df[df['Gas'].isnull()]['ReportDate_Time'].sort_values().value_counts().plot() 这是它返回的图,这是确定的,但我宁愿使用条形图。但是,如果我将'bar'参数传递给plot方法,我会自动按总计数而不是按ReportDate\u时间排序,这正是我最初想要的: df[df['Gas'].isnull()]['ReportDate_Time']

我正在使用以下代码创建一个绘图,以显示我的df中出现了多少个空值,并按日期列排序:

df[df['Gas'].isnull()]['ReportDate_Time'].sort_values().value_counts().plot()
这是它返回的图,这是确定的,但我宁愿使用条形图。但是,如果我将'bar'参数传递给plot方法,我会自动按总计数而不是按ReportDate\u时间排序,这正是我最初想要的:

df[df['Gas'].isnull()]['ReportDate_Time'].sort_values().value_counts().plot('bar')

如何使用条形图并同时按ReportDate\u时间排序?

如果我理解正确,您只需按报告日期对数据框进行排序,对值“ReportDate”进行排序即可

请参见下面的示例

dates = pd.date_range(pd.to_datetime('2020-01-21'), pd.to_datetime('2020-02-01'),freq='D')
vals = np.random.randint(0,500,size=len(dates))
df = pd.DataFrame({'ReportDate' : dates, 'count' : vals})
df.sort_values('count',inplace=True)
df.reset_index(drop=True,inplace=True)
还有一种:

df.sort_values('ReportDate',ascending=True).set_index('ReportDate').plot(kind='bar')

在sort_值之后使用value_计数实际上会覆盖排序。在调用plot之前,请确保按照您的意愿对数据进行排序。您好,没有数据很难尝试,但是…您是否尝试反转df[df['Gas'].isnull]['ReportDate\u Time'].value\u counts.sort\u values.plot'bar'
df.sort_values('ReportDate',ascending=True).set_index('ReportDate').plot(kind='bar')