Код: Выделить всё
period = datetime.today().date() - timedelta(days=1)
archive = zipfile.ZipFile("/Users/steven/Downloads/export.zip", "r")
df = pd.read_xml(
archive.open("apple_health_export/export.xml"),
xpath="//Record",
attrs_only=True,
parse_dates=["creationDate", "startDate", "endDate"],
)
d1 = df[
(df["endDate"].dt.date == period)
& (df["type"] == "HKQuantityTypeIdentifierHeartRate")
]
d1["value"] = [pd.to_numeric(x) for x in d1["value"]]
plt.style.use("ggplot")
plt.rcParams["font.family"] = "PT Sans"
d1.sort_values(by="endDate").plot(
x="endDate",
y="value",
xlabel="Time",
ylabel="Heart Rate (BPM)",
title="Heart Rate, Intraday",
).xaxis.set_major_formatter(mdates.DateFormatter("%-I:%M %p"))
plt.tight_layout()
plt.savefig(
f"/Users/steven/Library/Mobile Documents/com~apple~CloudDocs/Web/gloriouslyawkwardlife.github.io/images/{period}-heartrateintraday.png",
format="PNG",
)
Код: Выделить всё
785810 HKQuantityTypeIdentifierHeartRateVariabilitySDNN Steven’s Apple Watch 11.1 ms ... 2024-11-01 20:07:42-04:00 2024-11-01 20:08:42-04:00 67.3322
Подробнее здесь: [url]https://stackoverflow.com/questions/79150430/pandas-plot-showing-utc-instead-of-local-time-zone[/url]