绘制连锁的熊猫日期框架

时间:2016-07-12 17:37:23

标签: python pandas matplotlib dataframe

我的数据格式如下:

                            age       height     weight     
name1        2011-09-13     21        178        75
             2010-09-13     20        178        80
                            age       height     weight   
name2        2011-09-13     15        130        42
             2010-09-13     14        124        39

移动观众:

format_image

我通过concat(dataframe,keys = names)创建了这种格式,并且这种格式会有多个名称和日期。

我希望能够选择一个(或多个)名称并绘制其中一个参数,其中x轴将是日期和y轴,例如重量。是每个日期重复name1的唯一方法还是有更简单的方法来绘制它?我最初试图在matplotlib中做这件事。

非常感谢你的帮助!

编辑:示例代码

import pandas as pd
import collections
import datetime 

dictionary = {'name1': {str(datetime.date(2016, 5, 5)): {"age": 21, "height": 178, "weight": 75}, str(datetime.date(2016, 5, 4)): {"age": 20, "height": 178, "weight": 80}},'name2': {str(datetime.date(2016, 5, 5)): {"age": 15, "height": 130, "weight": 42}, str(datetime.date(2016, 5, 4)): {"age": 14, "height": 124, "weight": 39}}}
ordered_final = collections.OrderedDict(sorted(dictionary.items()))

names = []
alld = []

for name, c in ordered_final.iteritems():
    names.append(name)
    alld.append(pd.DataFrame.from_dict(c, orient='index'))

concat = pd.concat(alld, keys=names)     

很可能有一种更好的方法将此数据存储为日期框架,而不是我目前使用的数据。

0 个答案:

没有答案
相关问题