• <legend id='isSIN'><style id='isSIN'><dir id='isSIN'><q id='isSIN'></q></dir></style></legend>

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

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

        Pandas:如何将行中的一列旋转为列

        Pandas: How to pivot one column in rows into columns(Pandas:如何将行中的一列旋转为列)
        <legend id='tHNRu'><style id='tHNRu'><dir id='tHNRu'><q id='tHNRu'></q></dir></style></legend>

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

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

                    <tbody id='tHNRu'></tbody>
                • 本文介绍了Pandas:如何将行中的一列旋转为列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  鉴于此数据框:

                     feature score    searchTerm
                  0   a      0.534509 pizza
                  1   b      0.586020 pizza
                  2   c      0.588972 pizza
                  3   a      0.566261 chinese
                  4   b      0.572405 chinese
                  5   c      0.489369 chinese
                  6   a      0.499068 thai
                  7   b      0.431068 thai
                  8   c      0.441617 thai
                  

                  功能仅限于 (a,b,c)

                  我想把数据框转成这个:

                  I want to pivot the dataframe into this:

                     a        b        c          searchTerm
                     0.534509 0.586020 0.588972   pizza
                     0.566261 0.572405 0.489369   chinese    
                     0.499068 0.431068 0.441617   thai
                     ...
                     ...
                  

                  推荐答案

                  你可以使用pivot:

                  df1 = df.pivot(index='searchTerm', columns='feature', values='score').reset_index()
                  print (df1)
                  feature searchTerm         a         b         c
                  0          chinese  0.566261  0.572405  0.489369
                  1            pizza  0.534509  0.586020  0.588972
                  2             thai  0.499068  0.431068  0.441617
                  

                  最后你可以通过 删除列名rename_axis(pandas 0.18.0 中的新功能):

                  Last you can remove columns name by rename_axis (new in pandas 0.18.0):

                  df1 = df1.rename_axis(None, axis=1)
                  #pandas bellow 0.18.0
                  #df.columns.name = None
                  print (df1)
                    searchTerm         a         b         c
                  0    chinese  0.566261  0.572405  0.489369
                  1      pizza  0.534509  0.586020  0.588972
                  2       thai  0.499068  0.431068  0.441617
                  

                  这篇关于Pandas:如何将行中的一列旋转为列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  groupby multiple coords along a single dimension in xarray(在xarray中按单个维度的多个坐标分组)
                  Group by and Sum in Pandas without losing columns(Pandas中的GROUP BY AND SUM不丢失列)
                  Is there a way of group by month in Pandas starting at specific day number?( pandas 有从特定日期开始的按月分组的方式吗?)
                  Group by + New Column + Grab value former row based on conditionals(GROUP BY+新列+基于条件的前一行抓取值)
                  Groupby and interpolate in Pandas(PANDA中的Groupby算法和插值算法)
                  Pandas - Group Rows based on a column and replace NaN with non-null values(PANAS-基于列对行进行分组,并将NaN替换为非空值)
                    <bdo id='Z7TAu'></bdo><ul id='Z7TAu'></ul>

                    <legend id='Z7TAu'><style id='Z7TAu'><dir id='Z7TAu'><q id='Z7TAu'></q></dir></style></legend>
                    <tfoot id='Z7TAu'></tfoot>

                      1. <small id='Z7TAu'></small><noframes id='Z7TAu'>

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