Appending a list or series to a pandas DataFrame as a row?

后端 未结 12 1981
一向
一向 2020-12-02 05:22

So I have initialized an empty pandas DataFrame and I would like to iteratively append lists (or Series) as rows in this DataFrame. What is the best way of doing this?

12条回答
  •  不思量自难忘°
    2020-12-02 05:53

    Following onto Mike Chirico's answer... if you want to append a list after the dataframe is already populated...

    >>> list = [['f','g']]
    >>> df = df.append(pd.DataFrame(list, columns=['col1','col2']),ignore_index=True)
    >>> df
      col1 col2
    0    a    b
    1    d    e
    2    f    g
    

提交回复
热议问题