【发布时间】:2020-02-19 14:26:00
【问题描述】:
我想绘制时间线,我的日期格式为日/月/年。
在构建索引时,我会处理:
# format Date
test['DATA'] = pd.to_datetime(test['DATA'], format='%d/%m/%Y')
test.set_index('DATA', inplace=True)
通过仔细检查,我发现月份和日期的解释正确:
#the number of month reflect the month, not the day : correctly imported!
test['Year'] = test.index.year
test['Month'] = test.index.month
test['Weekday Name'] = test.index.weekday_name
但是,当我绘图时,我看到数据点连接不规律(尽管它们的分布似乎是正确的,因为我预计会有季节性):
# Start and end of the date range to extract
start, end = '2018-01', '2018-04'
# Plot daily, weekly resampled, and 7-day rolling mean time series together
fig, ax = plt.subplots()
ax.plot(test.loc['2018', 'TMIN °C'],
marker='.', linestyle='-', linewidth=0.5, label='Daily')
我怀疑这可能与错误解释的日期有关,或者日期没有按正确的顺序排列,但无法找到验证错误所在的方法。
您能否帮助验证如何正确导入我的时间序列?
【问题讨论】:
标签: python pandas datetime time-series seaborn