gpt4 book ai didi

python - 将 pandas 系列转换为对象数组,如 JavaScript 中所示

转载 作者:太空宇宙 更新时间:2023-11-03 21:38:32 25 4
gpt4 key购买 nike

我是Python新手。我有一个如下的 Pandas 系列,

                        count
timestamp
1980-10-05 01:12:00 56.4691
1980-10-05 01:13:00 54.9415
1980-10-05 01:14:00 52.0359
1980-10-05 01:15:00 47.7313
1980-10-05 01:16:00 50.5876
1980-10-05 01:17:00 48.2846
1980-10-05 01:18:00 44.6438
1980-10-05 01:19:00 42.3077
1980-10-05 01:20:00 38.8363
1980-10-05 01:21:00 41.0145
1980-10-05 01:22:00 39.5523
1980-10-05 01:23:00 38.9117
1980-10-05 01:24:00 37.3052
1980-10-05 01:25:00 36.1725
1980-10-05 01:26:00 37.5150
1980-10-05 01:27:00 38.1387
1980-10-05 01:28:00 39.5351
1980-10-05 01:29:00 38.1834
1980-10-05 01:30:00 37.5988
1980-10-05 01:31:00 43.6522
1980-10-05 01:32:00 47.9571
1980-10-05 13:08:00 210.0000
1980-10-05 13:18:00 40.0000
1980-10-05 13:28:00 250.0000
1980-10-05 13:38:00 40.0000

我想将其转换为对象数组;

[
{timestamp: 1980-10-05 13:38:00, count: 40.0000},
{timestamp: 1980-10-05 13:38:00, count: 40.0000},
{timestamp: 1980-10-05 13:38:00, count: 40.0000},
{timestamp: 1980-10-05 13:38:00, count: 40.0000}
]

可以用Python实现吗?

最佳答案

尝试这样:

arr_obj = df.to_dict(orient='records')

关于python - 将 pandas 系列转换为对象数组,如 JavaScript 中所示,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53082422/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com