df.append() is not appending to the DataFrame

后端 未结 2 1767
感动是毒
感动是毒 2020-11-30 12:44

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         


        
相关标签:
2条回答
  • 2020-11-30 13:20

    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
    
    0 讨论(0)
  • 2020-11-30 13:36

    The statement data.append(sub_data) does not work on its own.

    But the statement data=data.append(sub_data) will work

    Assigning it back solved the issue for me. Good tip not available elsewhere.

    0 讨论(0)
提交回复
热议问题