<small id='Qwxao'></small><noframes id='Qwxao'>

<tfoot id='Qwxao'></tfoot>

<legend id='Qwxao'><style id='Qwxao'><dir id='Qwxao'><q id='Qwxao'></q></dir></style></legend>

        • <bdo id='Qwxao'></bdo><ul id='Qwxao'></ul>
        <i id='Qwxao'><tr id='Qwxao'><dt id='Qwxao'><q id='Qwxao'><span id='Qwxao'><b id='Qwxao'><form id='Qwxao'><ins id='Qwxao'></ins><ul id='Qwxao'></ul><sub id='Qwxao'></sub></form><legend id='Qwxao'></legend><bdo id='Qwxao'><pre id='Qwxao'><center id='Qwxao'></center></pre></bdo></b><th id='Qwxao'></th></span></q></dt></tr></i><div id='Qwxao'><tfoot id='Qwxao'></tfoot><dl id='Qwxao'><fieldset id='Qwxao'></fieldset></dl></div>
      1. 从 (row,col,values) 的元组列表构造 pandas DataFrame

        Construct pandas DataFrame from list of tuples of (row,col,values)(从 (row,col,values) 的元组列表构造 pandas DataFrame)
        <i id='E0lPU'><tr id='E0lPU'><dt id='E0lPU'><q id='E0lPU'><span id='E0lPU'><b id='E0lPU'><form id='E0lPU'><ins id='E0lPU'></ins><ul id='E0lPU'></ul><sub id='E0lPU'></sub></form><legend id='E0lPU'></legend><bdo id='E0lPU'><pre id='E0lPU'><center id='E0lPU'></center></pre></bdo></b><th id='E0lPU'></th></span></q></dt></tr></i><div id='E0lPU'><tfoot id='E0lPU'></tfoot><dl id='E0lPU'><fieldset id='E0lPU'></fieldset></dl></div>
          <tbody id='E0lPU'></tbody>

        <small id='E0lPU'></small><noframes id='E0lPU'>

        1. <legend id='E0lPU'><style id='E0lPU'><dir id='E0lPU'><q id='E0lPU'></q></dir></style></legend>
        2. <tfoot id='E0lPU'></tfoot>

                • <bdo id='E0lPU'></bdo><ul id='E0lPU'></ul>
                • 本文介绍了从 (row,col,values) 的元组列表构造 pandas DataFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我有一个像这样的元组列表

                  I have a list of tuples like

                  data = [
                  ('r1', 'c1', avg11, stdev11),
                  ('r1', 'c2', avg12, stdev12),
                  ('r2', 'c1', avg21, stdev21),
                  ('r2', 'c2', avg22, stdev22)
                  ]
                  

                  我想将它们放入一个 pandas DataFrame 中,其中行由第一列命名,列由第二列命名.处理行名的方法似乎类似于 pandas.DataFrame([x[1:] for x in data], index = [x[0] for x in data])但是如何处理列以获得 2x2 矩阵(前一组的输出是 3x4)?有没有更智能的方法来处理行标签,而不是明确地忽略它们?

                  and I would like to put them into a pandas DataFrame with rows named by the first column and columns named by the 2nd column. It seems the way to take care of the row names is something like pandas.DataFrame([x[1:] for x in data], index = [x[0] for x in data]) but how do I take care of the columns to get a 2x2 matrix (the output from the previous set is 3x4)? Is there a more intelligent way of taking care of row labels as well, instead of explicitly omitting them?

                  编辑 看来我需要 2 个数据帧 - 一个用于平均值,一个用于标准偏差,对吗?或者我可以在每个单元格"中存储一个值列表吗?

                  EDIT It seems I will need 2 DataFrames - one for averages and one for standard deviations, is that correct? Or can I store a list of values in each "cell"?

                  推荐答案

                  你可以在创建后旋转你的DataFrame:

                  You can pivot your DataFrame after creating:

                  >>> df = pd.DataFrame(data)
                  >>> df.pivot(index=0, columns=1, values=2)
                  # avg DataFrame
                  1      c1     c2
                  0               
                  r1  avg11  avg12
                  r2  avg21  avg22
                  >>> df.pivot(index=0, columns=1, values=3)
                  # stdev DataFrame
                  1        c1       c2
                  0                   
                  r1  stdev11  stdev12
                  r2  stdev21  stdev22
                  

                  这篇关于从 (row,col,values) 的元组列表构造 pandas DataFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Running .jl file from R or Python(从 R 或 Python 运行 .jl 文件)
                  Running Julia .jl file in python(在 python 中运行 Julia .jl 文件)
                  Using PIP in a Azure WebApp(在 Azure WebApp 中使用 PIP)
                  How to run python3.7 based flask web api on azure(如何在 azure 上运行基于 python3.7 的烧瓶 web api)
                  Azure Python Web App Internal Server Error(Azure Python Web 应用程序内部服务器错误)
                  Run python dlib library on azure app service(在 azure app 服务上运行 python dlib 库)
                    <tbody id='LanA8'></tbody>

                  <small id='LanA8'></small><noframes id='LanA8'>

                  • <bdo id='LanA8'></bdo><ul id='LanA8'></ul>

                    <tfoot id='LanA8'></tfoot>

                          1. <legend id='LanA8'><style id='LanA8'><dir id='LanA8'><q id='LanA8'></q></dir></style></legend>

                            <i id='LanA8'><tr id='LanA8'><dt id='LanA8'><q id='LanA8'><span id='LanA8'><b id='LanA8'><form id='LanA8'><ins id='LanA8'></ins><ul id='LanA8'></ul><sub id='LanA8'></sub></form><legend id='LanA8'></legend><bdo id='LanA8'><pre id='LanA8'><center id='LanA8'></center></pre></bdo></b><th id='LanA8'></th></span></q></dt></tr></i><div id='LanA8'><tfoot id='LanA8'></tfoot><dl id='LanA8'><fieldset id='LanA8'></fieldset></dl></div>