且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

pandas :具有multiIndex数据框的条形图

更新时间:2023-11-21 23:51:34

以下内容应该可以工作,但是没有一些数据很难进行测试.

The following should work, but it is difficult to test without some data.

首先重置索引以访问TIMESTAMP列.然后使用strftime将其格式化为所需的文本表示形式(例如mm-yy).最后,将索引重置为AXLESTIMESTAMP.

Start by resetting your index to get access to the TIMESTAMP column. Then use strftime to format it to your desired text representation (e.g. mm-yy). Finally, reset the index back to AXLES and TIMESTAMP.

df = resamp.reset_index()
df['TIMESTAMP'] = [ts.strftime('%m-%y') for ts in df.TIMESTAMP]
df.set_index(['AXLES', 'TIMESTAMP'], inplace=True)
>>> df.xs(3, level=0).plot(kind='bar')