我试图在散点图的x轴上绘制以下日期,以便日期适当地间隔开。
这是我到目前为止所尝试的:
在df
我有以下数据:
date str A
1 06-Jul-13 9.27
2 25-Jul-13 7.55
5 31-Jul-13 18.22
8 27-Aug-13 12.25
11 18-Sep-13 5.80
df.dtypes
返回:
date str object
A float64
dtype: object
尝试几个版本的日期列:
from dateutil.parser import parse
df['date obj'] = df['date str'].apply(parse)
df['date int'] = df['date obj'].astype(np.int64)
# this produces "KeyError: u'no item named date str'"
df.plot(x='date str', y='A', kind='scatter')
# this produces "KeyError: u'no item named date obj'"
df.plot(x='date obj', y='A', kind='scatter')
# this produces correctly spaced dates, but the x-axis labels do not display the dates
df.plot(x='date int', y='A', kind='scatter')
如何正确间隔日期,并在x轴上保留适当的日期标签?