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

后端 未结 12 1989
一向
一向 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:31

    Converting the list to a data frame within the append function works, also when applied in a loop

    import pandas as pd
    mylist = [1,2,3]
    df = pd.DataFrame()
    df = df.append(pd.DataFrame(data[mylist]))
    

提交回复
热议问题