Python 使用另一个pandas数据帧更新存储在Pytable中的pandas数据帧

Python 使用另一个pandas数据帧更新存储在Pytable中的pandas数据帧,python,pandas,hdf5,pytables,dataframe,Python,Pandas,Hdf5,Pytables,Dataframe,我试图创建一个函数,用pandas数据帧中的新数据更新存储在PyTable中的pandas数据帧。我想检查PyTable中是否缺少特定DatetimeIndexes的某些数据(值为NaN或新的时间戳可用),将其替换为给定数据帧中的新值,并将其附加到PyTable中。基本上,只需更新一个Pytable。我可以使用Pandas中的combine_first方法获得组合数据帧。 下面是使用虚拟数据创建的Pytable: 这样就创建了pytable。假设我有另一个数据帧,我想用它更新Pytable: 问

我试图创建一个函数,用pandas数据帧中的新数据更新存储在PyTable中的pandas数据帧。我想检查PyTable中是否缺少特定DatetimeIndexes的某些数据(值为NaN或新的时间戳可用),将其替换为给定数据帧中的新值,并将其附加到PyTable中。基本上,只需更新一个Pytable。我可以使用Pandas中的combine_first方法获得组合数据帧。 下面是使用虚拟数据创建的Pytable:

这样就创建了pytable。假设我有另一个数据帧,我想用它更新Pytable:

问题是PyTable保留原始值,而不更新现有值。我现在有重复的条目(按索引),因为原始值不会被覆盖

总结: 如何使用另一个数据帧更新PyTable

谢谢,
Elv当前不支持此操作
PyTables
支持
update
方法,但未在pandas中实现

最简单的方法是使用
mode='w'
并编写一个新文件,或者

store.remove(键);store.append(…)

HDF5
不是“常规”数据库,更新也不是常见操作,如果需要的话,SQL可能是一个选项


请随时请求
更新
作为一个增强问题。

最后,我自己发现了。在我的例子中,当“combine_first”获得原始值和新值时可以覆盖整个节点时,可以使用

而不是


事实上,这是我暂时的解决办法。谢谢你的信息
import pandas as pd
import numpy as np
import datetime as dt
index = pd.DatetimeIndex(start = dt.datetime(2001,1,1,0,0), periods = 20000,freq='10T')
data_in_pytable = pd.DataFrame(index=index,data=np.random.randn(20000,2),columns=['value_1','value_2'])
data.to_hdf(r'C:\pytable.h5','test',mode='r+',append=True,complevel=9,complib='zlib')
new_index = pd.DatetimeIndex(start = dt.datetime(2001,5,1,0,0), periods = 10000,freq='10T')
data_to_update=pd.DataFrame(index=new_index,data=np.random.randn(10000,2),columns=['value_1','value_2'])
store=pd.HDFStore(r'C:\pytable.h5',mode='r+',complevel=9,complib='zlib')
store.append('test',store.select('test').combine_first(data_to_update))
store.close()
store.put(key,value,table=True,append=False) 
store.append(key,value).