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

<tfoot id='VUjVT'></tfoot>

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

        df.append() 未附加到 DataFrame

        df.append() is not appending to the DataFrame(df.append() 未附加到 DataFrame)

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

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

                <tbody id='ydxTG'></tbody>
              <tfoot id='ydxTG'></tfoot>

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

                  本文介绍了df.append() 未附加到 DataFrame的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我制定了 this question关于添加带索引的行,但我还不清楚当没有索引时如何/为什么会发生这种情况:

                  columnsList=['A','B','C','D']df8=pd.DataFrame(columns=columnsList)L=['值 aa','值 bb','值 cc','值 dd']s = pd.Series(dict(zip(df8.columns, L)))df8.append(s,ignore_index=True)df8.append(s,ignore_index=True)

                  我希望这里有一个 2X4 数据帧.但是没有添加任何值,也没有发生错误.

                  打印(df8.shape)#>>>(0,4)

                  为什么没有添加系列,为什么没有报错?

                  <小时>

                  如果我尝试使用 LOC 添加一行,则会添加一个索引,

                  df8.loc[df8.index.max() + 1, :] = [4, 5, 6,7]打印(df8)

                  结果:

                   A B C D南 4 5 6 7

                  我猜LOC和iLOC都不能用来追加没有索引名的行(即Loc添加索引名NaN,当索引号高于数据库的行时不能使用iLoc)

                  解决方案

                  DataFrame.append 不是就地操作.从文档中,

                  <块引用>

                  DataFrame.append(other, ignore_index=False, verify_integrity=False, sort=None)

                  将其他行追加到此帧的末尾,返回一个新对象.不在此框架中的列将作为新列添加.

                  您需要将结果分配回去.

                  df8 = df8.append([s] * 2, ignore_index=True)df8A B C D0 值 aa 值 bb 值 cc 值 dd1 值 aa 值 bb 值 cc 值 dd

                  I formulated this question about adding rows WITH index, but it is not yet clear to me how/why this happens when there are no indexes:

                  columnsList=['A','B','C','D']
                  df8=pd.DataFrame(columns=columnsList)
                  L=['value aa','value bb','value cc','value dd']
                  s = pd.Series(dict(zip(df8.columns, L)))
                  df8.append(s,ignore_index=True)
                  df8.append(s,ignore_index=True)
                  

                  I EXPECT HERE A 2X4 DATAFRAME. nevertheless no values where added, nor an error occurred.

                  print(df8.shape)
                  #>>> (0,4)
                  

                  Why is the series not being added, and why is not given any error?


                  If I try to add a row with LOC, an index is added,

                  df8.loc[df8.index.max() + 1, :] = [4, 5, 6,7]
                  print(df8)
                  

                  result:

                       A  B  C  D
                  NaN  4  5  6  7
                  

                  I guess neither LOC, nor iLOC could be used to append rows without index name (i.e. Loc adds the index name NaN, and iLoc can not be used when the index number is higher than the rows of the database)

                  解决方案

                  DataFrame.append is not an in-place operation. From the docs,

                  DataFrame.append(other, ignore_index=False, verify_integrity=False, sort=None)
                  

                  Append rows of other to the end of this frame, returning a new object. Columns not in this frame are added as new columns.

                  You need to assign the result back.

                  df8 = df8.append([s] * 2, ignore_index=True)
                  df8
                            A         B         C         D
                  0  value aa  value bb  value cc  value dd
                  1  value aa  value bb  value cc  value dd
                  

                  这篇关于df.append() 未附加到 DataFrame的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

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

                  相关文档推荐

                  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 数据框制作线图?)

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

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