如何将单个项目添加到 pandas 系列 [英] How to add a single item to a Pandas Series
本文介绍了如何将单个项目添加到 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.
这篇关于如何将单个项目添加到 pandas 系列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文