如果您使用包含列名而不是字符串的列表,则data.set_index将起作用
以下内容应在x轴上显示日期:
#! /usr/bin/env pythonimport pandas as pdimport matplotlib.pyplot as pltdata = pd.read_fwf('myfile.log',header=None,names=['time','amount'],widths=[27,5])data.time = pd.to_datetime(data['time'], format='%Y-%m-%d %H:%M:%S.%f')data.set_index(['time'],inplace=True)data.plot()#OR plt.plot(data.index, data.amount)


