从以元组为键的字典中获取 pandas 数据框 [英] Obtaining a pandas dataframe from a dict with tuples as keys

查看:70
本文介绍了从以元组为键的字典中获取 pandas 数据框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是python的新手,已经为这个问题苦苦挣扎了一段时间了.我有一个像这样的字典:

I am new to python and have been struggling with this problem for quite a while. I have a dict like this:

dict1 = {(a,a) : 5, (a,b) :10, (a,c) : 11, (b,a): 4, (b,b) : 8, (b,c) : 3....}

我想做的是将其转换为如下所示的熊猫数据框:

What I would like to do is convert this into a pandas dataframe that looks like this:

    a    b    c
a   5    10   11
b   4    8    3
c   ..   ..   ..

之后,我想在jupyter笔记本中创建一个多条形图.我知道您可以将数据显示为熊猫系列,以显示以下内容:

After that I would like to create a multiple bar plot in the jupyter notebook. I know you can display the data as a pandas series to show the following:

dataset = pd.Series(dict1)
print dataset
    a  a  5
       b  10
       c  11
    b  a  4
       b  8
       c  3
    c  a  ..
       b  ..
       c  ..

但是,我无法由此创建多条图.

However, I was not able to create a multiple bar plot from that.

推荐答案

您快到了,只需要我更喜欢使用

I prefer to use this page for reference, rather than the official documentation.

这篇关于从以元组为键的字典中获取 pandas 数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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