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

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

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

    1. <tfoot id='jy1cg'></tfoot>

      附加两个具有相同列、不同顺序的数据框

      Appending two dataframes with same columns, different order(附加两个具有相同列、不同顺序的数据框)

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

            <tbody id='tdkce'></tbody>
              <bdo id='tdkce'></bdo><ul id='tdkce'></ul>

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

                本文介绍了附加两个具有相同列、不同顺序的数据框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我有两个 pandas 数据框.

                I have two pandas dataframes.

                noclickDF = DataFrame([[0, 123, 321], [0, 1543, 432]],
                                      columns=['click', 'id', 'location'])
                clickDF = DataFrame([[1, 123, 421], [1, 1543, 436]],
                                      columns=['click', 'location','id'])
                

                我只是想加入这样最终的 DF 看起来像:

                I simply want to join such that the final DF will look like:

                click  |  id   |   location
                0         123        321
                0         1543       432
                1         421        123
                1         436       1543
                

                如您所见,两个原始 DF 的列名相同,但顺序不同.列中也没有连接.

                As you can see the column names of both original DF's are the same, but not in the same order. Also there is no join in a column.

                推荐答案

                你也可以使用 pd.concat:

                In [36]: pd.concat([noclickDF, clickDF], ignore_index=True)
                Out[36]: 
                   click    id  location
                0      0   123       321
                1      0  1543       432
                2      1   421       123
                3      1   436      1543
                

                在底层,DataFrame.append 调用 pd.concat.DataFrame.append 包含处理各种类型输入的代码,例如系列、元组、列表和字典.如果你给它传递一个DataFrame,它会直接传递给pd.concat,所以使用pd.concat会更直接一些.

                Under the hood, DataFrame.append calls pd.concat. DataFrame.append has code for handling various types of input, such as Series, tuples, lists and dicts. If you pass it a DataFrame, it passes straight through to pd.concat, so using pd.concat is a bit more direct.

                这篇关于附加两个具有相同列、不同顺序的数据框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                相关文档推荐

                Adding config modes to Plotly.Py offline - modebar(将配置模式添加到 Plotly.Py 离线 - 模式栏)
                Plotly: How to style a plotly figure so that it doesn#39;t display gaps for missing dates?(Plotly:如何设置绘图图形的样式,使其不显示缺失日期的间隙?)
                python save plotly plot to local file and insert into html(python将绘图保存到本地文件并插入到html中)
                Plotly: What color cycle does plotly express follow?(情节:情节表达遵循什么颜色循环?)
                How to save plotly express plot into a html or static image file?(如何将情节表达图保存到 html 或静态图像文件中?)
                Plotly: How to make a line plot from a pandas dataframe with a long or wide format?(Plotly:如何使用长格式或宽格式的 pandas 数据框制作线图?)

                    <tbody id='DheaV'></tbody>

                      • <bdo id='DheaV'></bdo><ul id='DheaV'></ul>
                      • <legend id='DheaV'><style id='DheaV'><dir id='DheaV'><q id='DheaV'></q></dir></style></legend>

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