gpt4 book ai didi

python - key 错误 : '[datetime.time(12, 19, 29) not in index'

转载 作者:行者123 更新时间:2023-11-28 17:04:38 24 4
gpt4 key购买 nike

数据以纪元纳秒为单位,如下例所示:

time               duration
1.530706769E+018 40000000000
1.53070683E+018 41000000000
1.530706891E+018 41000000000
1.530706951E+018 41000000000
1.530707011E+018 41000000000
1.530707068E+018 37000000000
1.530707128E+018 41000000000
1.530707188E+018 41000000000
1.530707248E+018 40000000000
1.530707313E+018 45000000000
1.530707368E+018 40000000000
1.530707432E+018 44000000000
1.530707492E+018 44000000000
1.530707552E+018 44000000000
1.530707612E+018 39000000000
1.530707673E+018 41000000000
1.530707729E+018 37000000000
1.530712952E+018 45000000000
1.530713007E+018 40000000000
1.530713067E+018 35000000000
1.530713132E+018 40000000000
1.530713187E+018 36000000000
1.530713248E+018 36000000000
1.530713308E+018 40000000000
1.530713369E+018 41000000000
1.530713429E+018 40000000000
1.53071349E+018 41000000000
1.530713551E+018 42000000000
1.530713611E+018 40000000000
1.530713671E+018 40000000000
1.530713732E+018 40000000000
1.530713792E+018 39000000000
1.530713852E+018 39000000000
1.530713913E+018 40000000000
1.530713973E+018 40000000000
1.530714029E+018 36000000000
1.53071409E+018 36000000000
1.530714151E+018 41000000000
1.530714212E+018 41000000000
1.530714272E+018 41000000000
1.530714332E+018 40000000000
1.530714393E+018 41000000000
1.530714454E+018 41000000000
1.530714515E+018 42000000000
1.530714574E+018 39000000000
1.53071463E+018 39000000000
1.530714694E+018 44000000000
1.530714753E+018 40000000000
1.530714814E+018 41000000000
1.530714874E+018 42000000000
1.530714934E+018 41000000000
1.530714995E+018 41000000000
1.530715056E+018 41000000000
1.530715112E+018 37000000000
1.530715245E+018 16000000000
1.530715275E+018 15000000000
1.530715305E+018 15000000000
1.530715335E+018 15000000000
1.530715366E+018 16000000000
1.530715396E+018 15000000000
1.530715427E+018 16000000000
1.530715456E+018 15000000000
1.530715487E+018 16000000000
1.530715517E+018 15000000000
1.530715548E+018 16000000000
1.530715578E+018 15000000000

为了进行转换,我在 pandas 中使用了以下代码:

import pandas as pd
import matplotlib.pyplot as plt
import datetime from datetime

df = pd.read_csv('d1.csv')

df['time']=pd.to_datetime(df['time'], unit='ns')

df['Time'] = df['time'].dt.time

以上代码将数据转换为以下形式:

df.head(20)
Out[100]:
time d Time
0 2018-07-04 12:19:29 4.000000e+10 12:19:29
1 2018-07-04 12:20:30 4.100000e+10 12:20:30
2 2018-07-04 12:21:31 4.100000e+10 12:21:31
3 2018-07-04 12:22:31 4.100000e+10 12:22:31
4 2018-07-04 12:23:31 4.100000e+10 12:23:31
5 2018-07-04 12:24:28 3.700000e+10 12:24:28
6 2018-07-04 12:25:28 4.100000e+10 12:25:28
7 2018-07-04 12:26:28 4.100000e+10 12:26:28
8 2018-07-04 12:27:28 4.000000e+10 12:27:28
9 2018-07-04 12:28:33 4.500000e+10 12:28:33
10 2018-07-04 12:29:28 4.000000e+10 12:29:28
11 2018-07-04 12:30:32 4.400000e+10 12:30:32
12 2018-07-04 12:31:32 4.400000e+10 12:31:32
13 2018-07-04 12:32:32 4.400000e+10 12:32:32
14 2018-07-04 12:33:32 3.900000e+10 12:33:32
15 2018-07-04 12:34:33 4.100000e+10 12:34:33
16 2018-07-04 12:35:29 3.700000e+10 12:35:29
17 2018-07-04 14:02:32 4.500000e+10 14:02:32
18 2018-07-04 14:03:27 4.000000e+10 14:03:27
19 2018-07-04 14:04:27 3.500000e+10 14:04:27

现在我需要 Timed 之间的散点图 所以我编码为:

x = df['Time']

y = df['d']

df.plot(x,y, 'scatter')

但出现错误:

KeyError: '[datetime.time(12, 19, 29) datetime.time(12, 20, 30)\n datetime.time(12, 21, 31) ... datetime.time(23 , 54, 39)\n datetime.time(23, 55, 16) datetime.time(23, 55, 52)] 不在索引中

上述错误意味着什么...如何解决此问题并在此处获取散点图?

最佳答案

你可以使用这个:

df.plot(x='Time', y='d', style=".")

关于python - key 错误 : '[datetime.time(12, 19, 29) not in index' ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51816869/

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