将列表或系列作为一行附加到pandas DataFrame吗? [英] Appending a list or series to a pandas DataFrame as a row?

查看:112
本文介绍了将列表或系列作为一行附加到pandas DataFrame吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我已经初始化了一个空的pandas DataFrame,我想迭代地将列表(或Series)追加为该DataFrame中的行.最好的方法是什么?

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?

推荐答案

有时候,在熊猫之​​外进行所有附加操作都比较容易,然后,只需一枪即可创建DataFrame.

Sometimes it's easier to do all the appending outside of pandas, then, just create the DataFrame in one shot.

>>> import pandas as pd
>>> simple_list=[['a','b']]
>>> simple_list.append(['e','f'])
>>> df=pd.DataFrame(simple_list,columns=['col1','col2'])
   col1 col2
0    a    b
1    e    f

这篇关于将列表或系列作为一行附加到pandas DataFrame吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆