【发布时间】:2021-12-22 10:51:59
【问题描述】:
作为 pandas 的新手,我可能有一个非常基本的问题。我在一个黄褐色的猫头鹰巢箱里有一台相机,我记下了猫头鹰在巢箱里度过的时间。我想使用 Python 可视化嵌套框中的时间。我制作了一个熊猫 DatetimeIndex,并用它制作了一个熊猫数据框,如下所示。然而,这表明猫头鹰一直在场。有没有办法仅在 DatetimeIndex 指定的时间范围内绘制 1?
import pandas as pd
import matplotlib.pyplot as plt
presence = pd.DatetimeIndex(["2021-12-01 18:08","2021-12-01 18:11",
"2021-12-02 05:27","2021-12-02 05:29",
"2021-12-02 22:40","2021-12-02 22:43",
"2021-12-03 19:24","2021-12-03 19:27",
"2021-12-06 18:04","2021-12-06 18:06",
"2021-12-07 05:28","2021-12-07 05:30",
"2021-12-10 03:05","2021-12-10 03:10",
"2021-12-10 07:11","2021-12-10 07:13",
"2021-12-10 20:40","2021-12-10 20:41",
"2021-12-12 19:42","2021-12-12 19:45",
"2021-12-13 04:13","2021-12-13 04:17",
"2021-12-15 04:28","2021-12-15 04:30",
"2021-12-15 05:21","2021-12-15 05:25",
"2021-12-15 17:40","2021-12-15 17:44",
"2021-12-15 22:31","2021-12-15 22:37",
"2021-12-16 04:24","2021-12-16 04:28",
"2021-12-16 19:58","2021-12-16 20:09",
"2021-12-17 17:42","2021-12-17 18:04",
"2021-12-17 22:19","2021-12-17 22:26",
"2021-12-18 05:41","2021-12-18 05:44",
"2021-12-19 07:40","2021-12-19 16:55",
"2021-12-19 20:39","2021-12-19 20:52",
"2021-12-19 21:56","2021-12-19 23:17",
"2021-12-21 04:53","2021-12-21 04:59",
"2021-12-21 05:37","2021-12-21 05:39",
"2021-12-22 08:06","2021-12-22 18:00",
])
df = pd.DataFrame({'owl presence' : np.ones(len(presence))}, index=presence)
df.plot()
``
【问题讨论】:
标签: python pandas datetimeindex