One - One Code All

Blog Content

pandas追加行append

Python 统计学-科学计算   2011-04-17 19:31:24

方法一:通过dict做中转。


首先创建空的list,对原有的Dataframe进行逐行筛选,筛选出的行转化为dict类型,append进list中。全部添加完毕后,再将整个list转化为Dataframe格式。

a = []
for line in insert_lines:
    line = dict(line)
    a.append(line)
a = pandas.Dataframe(a)



方法二:datafram.append

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

用法

将其他行添加到此DataFrame的末尾,返回一个新对象。 不在此DataFrame中的列将作为新列添加。

参数
other:DataFrame或Series / dict-like对象,或者这些要附加的数据的列表
ignore_index: 布尔值,默认False。如果为真,就不会使用索引标签。

df1 = df1.append(df_min)


方法三:直接定位索引:dataframe.loc[i] = []



上一篇:python中pickle 模块的使用
下一篇:pandas dataframe 整列置为零和全部统一置为零

The minute you think of giving up, think of the reason why you held on so long.