如何将单个项目添加到 pandas 系列

问题描述:

如何将单个项目添加到序列化的熊猫系列中.我知道这不是内存管理的最有效方法,但是我仍然需要这样做.

How Do I add a single item to a serialized panda series. I know it's not the most efficient way memory wise, but i still need to do that.

发生的事情:

>> x = Series()
>> N = 4
>> for i in xrange(N):
>>     x.some_appending_function(i**2)    
>> print x

0 | 0
1 | 1
2 | 4
3 | 9

另外,如何将单个行添加到pandas DataFrame?

also, how can i add a single row to a pandas DataFrame?

如何添加单个项目.这不是很有效,但是遵循您的要求:

How to add single item. This is not very effective but follows what you are asking for:

x = p.Series()
N = 4
for i in xrange(N):
   x = x.set_value(i, i**2)

产生x:

0    0
1    1
2    4
3    9

显然,有更好的方法可以只拍摄一张照片.

Obviously there are better ways to generate this series in only one shot.

对于第二个问题,请检查答案以及对SO问题的引用在其中添加一行一个pandas.DataFrame .

For your second question check answer and references of SO question add one row in a pandas.DataFrame.