我有以下pandas数据帧:
| id | LocTime |ZPos | XPos
datetime |
2017-01-02 00:14:39 |20421902611| 12531245409231| 0 | -6
2017-01-02 00:14:40 |30453291020| 28332479673070| 0 | -2
Run Code Online (Sandbox Code Playgroud)
我想将datetime索引转换为数据框的列.我试过df.reset_index(level=['datetime'])但结果没有改变.任何的想法?
我想只读取HDF5文件中的特定列并在这些列上传递条件.我担心的是我不想将所有HDF5文件作为内存中的数据帧获取.我想只根据他们的条件得到我必要的专栏.
columns=['col1', 'col2']
condition= "col2==1"
groupname='\path\to\group'
Hdf5File=os.path.join('path\to\hdf5.h5')
with pd.HDFStore(Hdf5File, mode='r', format='table') as store:
if groupname in store:
df=pd.read_hdf(store, key=groupname, columns=columns, where=["col2==1"])
Run Code Online (Sandbox Code Playgroud)
我收到一个错误:
TypeError:读取固定格式存储时无法传递列规范.必须完整选择此商店
然后我使用下面的行只返回特定的列:
df=store[groupname][columns]
Run Code Online (Sandbox Code Playgroud)
但我不知道如何通过条件.