如何将python字典放入pandas时间序列数据框中,其中键是日期对象 [英] How to get python dictionaries into a pandas time series dataframe where key is date object

查看:99
本文介绍了如何将python字典放入pandas时间序列数据框中,其中键是日期对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个python字典,其中的键是日期对象,值是时间.

I have a python dictionaries where the key is a dateobject and the value is the timeseires.

   timeseries = {datetime.datetime(2013, 3, 17, 18, 19): {'t2': 400, 't1': 1000},
                 datetime.datetime(2013, 3, 17, 18, 20): {'t2': 300, 't1': 3000}
                }

如何将这个时间序列纳入熊猫数据框?

How to I get this time series into a pandas dataframe?

推荐答案

使用DataFrame.from_dict:

import pandas as pd
import datetime
timeseries = {datetime.datetime(2013, 3, 17, 18, 19): {'t2': 400, 't1': 1000},
                 datetime.datetime(2013, 3, 17, 18, 20): {'t2': 300, 't1': 3000}
                }
print pd.DataFrame.from_dict(timeseries, orient="index")

输出:

                      t2    t1
2013-03-17 18:19:00  400  1000
2013-03-17 18:20:00  300  3000

这篇关于如何将python字典放入pandas时间序列数据框中,其中键是日期对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆