Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/python-3.x/16.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 如何通过将时间戳指定为键值从字典中获取值。?_Python_Python 3.x_Pandas - Fatal编程技术网

Python 如何通过将时间戳指定为键值从字典中获取值。?

Python 如何通过将时间戳指定为键值从字典中获取值。?,python,python-3.x,pandas,Python,Python 3.x,Pandas,我通过迭代Series对象来创建字典。这个系列看起来像这样 2018-02-05 00:00:00+00:00 4803.0 2018-02-05 00:15:00+00:00 4803.0 2018-02-05 00:30:00+00:00 4806.0 2018-02-05 00:45:00+00:00 4806.0 Freq: 15T, Name: Biomass, dtype: float64 通过提供索引作为键和数据作为值来创建字典,字典如下所示 print(

我通过迭代Series对象来创建字典。这个系列看起来像这样

2018-02-05 00:00:00+00:00    4803.0
2018-02-05 00:15:00+00:00    4803.0
2018-02-05 00:30:00+00:00    4806.0
2018-02-05 00:45:00+00:00    4806.0
Freq: 15T, Name: Biomass, dtype: float64
通过提供索引作为键和数据作为值来创建字典,字典如下所示

print(Entsoe.dictionary_value)

 {Timestamp('2018-02-05 00:00:00+0000', tz='UTC', freq='15T'): 4803.0,
 Timestamp('2018-02-05 00:15:00+0000', tz='UTC', freq='15T'): 4803.0,
 Timestamp('2018-02-05 00:30:00+0000', tz='UTC', freq='15T'): 4806.0,
 Timestamp('2018-02-05 00:45:00+0000', tz='UTC', freq='15T'): 4806.0}
Dictionary是类成员,因此使用类名“Entsoe”进行访问

使用此代码分别打印密钥和值对

for key in Entsoe.dictionary_value:
       print(f"key: {key}, value: {Entsoe.dictionary_value[key]}")
输出结果如下:

key: 2018-02-05 00:00:00+00:00, value: 4803.0
key: 2018-02-05 00:15:00+00:00, value: 4803.0
key: 2018-02-05 00:30:00+00:00, value: 4806.0
key: 2018-02-05 00:45:00+00:00, value: 4806.0
但是当尝试使用像这样的键值访问时

“没有”


有人能给我解释一下这里出了什么问题吗

Entsoe
字典中的键当前是
Timestamp
对象,而不仅仅是表示特定时间戳的字符串。尝试打印(Entsoe.dictionary\u value.get(Timestamp('2018-02-05 00:00:00+0000',tz='UTC',freq='15T'))@Chillie所以我现在需要将密钥转换为
Timestamp
对象。您有了
s.to_dict()
@Chillie尝试了您的解决方案,显示
未解决的时间戳引用错误
@Wen这里是
s
,你能详细说明你的答案吗。
print(Entsoe.dictionary_value.get('2018-02-05 00:00:00+00:00'))