English 中文(简体)
添加新价值的最佳方式
原标题:Best way to insert a new value

我想利用一个邮资数据框架来跟踪一些市场数据,我将在交易日下载现场。

我要说的是,我要标出AAPL和GOOG的价格。 首先,我建立了一个数据框架:

prices = DataFrame(columns = [ AAPL ,  GOOG ]) 

请允许我说,AAPL的第一份数据点当时为t1和555.0。 之后,几秒以图2计算,全球测验组的价格为430 000美元。

当然可以做到:

prices[ AAPL ][t1] = 555.0
prices[ GOOG ][t2] = 430.0

Is there an easy/fast way in pandas to accomplish this though besides pulling the index, modifying it, reindexing the dataframe and then inserting each scalar price as it comes in?

问题回答

列出<代码>_数值方法(如果大小改动,可检索新物体)。 但并不指望它会很快(与一条nes子相比):

In [7]: prices
Out[7]: 
Empty DataFrame
Columns: array([AAPL, GOOG], dtype=object)
Index: array([], dtype=object)

In [8]: prices = prices.set_value(t1,  AAPL , 5)

In [9]: prices
Out[9]: 
                            AAPL  GOOG
2012-04-12 18:02:28.178331     5   NaN

在某个时候添加一种方法,以便更高效地利用数据框架(NumPy确实有这方面的设施)。





相关问题
Can Django models use MySQL functions?

Is there a way to force Django models to pass a field to a MySQL function every time the model data is read or loaded? To clarify what I mean in SQL, I want the Django model to produce something like ...

An enterprise scheduler for python (like quartz)

I am looking for an enterprise tasks scheduler for python, like quartz is for Java. Requirements: Persistent: if the process restarts or the machine restarts, then all the jobs must stay there and ...

How to remove unique, then duplicate dictionaries in a list?

Given the following list that contains some duplicate and some unique dictionaries, what is the best method to remove unique dictionaries first, then reduce the duplicate dictionaries to single ...

What is suggested seed value to use with random.seed()?

Simple enough question: I m using python random module to generate random integers. I want to know what is the suggested value to use with the random.seed() function? Currently I am letting this ...

How can I make the PyDev editor selectively ignore errors?

I m using PyDev under Eclipse to write some Jython code. I ve got numerous instances where I need to do something like this: import com.work.project.component.client.Interface.ISubInterface as ...

How do I profile `paster serve` s startup time?

Python s paster serve app.ini is taking longer than I would like to be ready for the first request. I know how to profile requests with middleware, but how do I profile the initialization time? I ...

Pragmatically adding give-aways/freebies to an online store

Our business currently has an online store and recently we ve been offering free specials to our customers. Right now, we simply display the special and give the buyer a notice stating we will add the ...

Converting Dictionary to List? [duplicate]

I m trying to convert a Python dictionary into a Python list, in order to perform some calculations. #My dictionary dict = {} dict[ Capital ]="London" dict[ Food ]="Fish&Chips" dict[ 2012 ]="...

热门标签