alex_bn_lee

导航

【810】pandas的DataFrame的append方法详细介绍

参考:pandas的DataFrame的append方法详细介绍


官方说明:pandas.DataFrame.append

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

  Append rows of other to the end of caller, returning a new object.

  Columns in other that are not in the caller are added as new columns.

  Parameters
other: DataFrame or Series/dict-like object, or list of these

The data to append.

ignore_index: bool, default False

If True, the resulting axis will be labeled 0, 1, …, n - 1.

verify_integrity: bool, default False

If True, raise ValueError on creating index with duplicates.

sort: bool, default False

Sort columns if the columns of self and other are not aligned.

Changed in version 1.0.0: Changed to not sort by default.

  Returns: DataFrame

A new DataFrame consisting of the rows of caller and the rows of other.


append 添加字典

import pandas as pd

data = pd.DataFrame()    # 生成空dataframe
a = {"x":1, "y":2}    # 新建字典,包含列名和数值
data = data.append(a,ignore_index=True)    # 注意需要赋值操作
print(data)

显示效果:

 

posted on 2023-03-09 07:45  McDelfino  阅读(169)  评论(0)    收藏  举报