【发布时间】:2019-08-21 18:31:19
【问题描述】:
这是我的代码
data = result["Document"]
df = pd.DataFrame(data)
df["Created"] = pd.to_datetime(df["Created"])
df["Created"] = pd.to_datetime(df["Created"],errors='coerce').dt.tz_localize('Europe/London').dt.tz_convert('Europe/Paris')
#print(df)hour
df['Created'] = df['Created'].dt.date
df["Barcode"] = df["Barcode"].astype(str)
fig, ax = plt.subplots()
myFmt = mdates.DateFormatter('%Y-%m-%d %H:%M')
ax.xaxis.set_major_formatter(myFmt)
df1 = df.groupby(["Created"])["Tag"].count().reset_index()
df2 = df[df["Tag"] == "DISPLAY"].groupby(["Created"])["Tag"].count().reset_index()
plt.plot(df2['Created'],df2['Tag'])
plt.plot(df1['Created'],df1['Tag'])
plt.gcf().autofmt_xdate()
plt.figure(figsize=(30,20))
plt.show()
问题是我有一个不存在的 hpur:
2019-03-31 01:50:24.455000
随着时间的变化,这个时间日期在法国不存在。
所以这就是它崩溃的原因。
如何将日期转换为计数?
问候
【问题讨论】:
-
“已创建”列中的日期和时间最初是否为 UTC?运行代码时收到什么错误消息?