我想补充一些数据,实时,一个空数据帧:追加数据实时到一个空大熊猫据帧
import pandas as pd
import time
df = pd.DataFrame(columns=['time', 'price']) # this is a simple example
# but in my code, I have more
# columns: 'volume', etc.
for i in range(5): # here it lasts one day in my real use case
time.sleep(2)
t = pd.datetime.now()
df[t] = 5 + i
# here I need to have access to the latest updates of df
print df
输出是:
Empty DataFrame
Columns: [time, price, 2015-12-27 01:55:29.812000, 2015-12-27 01:55:31.812000, 2015-12-27 01:55:33.812000, 2015-12-27 01:55:35.812000, 2015-12-27 01:55:37.812000]
Index: []
,而我想:
time price
2015-12-27 01:55:29.812000 5
2015-12-27 01:55:31.812000 6
2015-12-27 01:55:33.812000 7
...
如何向这样的数据框添加数据?
谢谢,但我真的需要一个DataFrame(因为我有几列) – Basj
添加了一个例子。使用索引追加单个行。 –