나는 각 그룹 내에 여러 그룹과 데이터 세트가있는 중첩 된 hdf5 파일로 팬더 데이터 프레임의 데이터를 쓰려고합니다. 앞으로도 계속 성장할 단일 파일로 유지하고 싶습니다. 나는 중첩 된 구조가 생성팬더 데이터 프레임을 HDF5 데이터 세트에 쓰는 방법
import h5py
import numpy as np
import pandas as pd
file = h5py.File('database.h5','w')
d = {'one' : pd.Series([1., 2., 3.], index=['a', 'b', 'c']),
'two' : pd.Series([1., 2., 3., 4.], index=['a', 'b', 'c', 'd'])}
df = pd.DataFrame(d)
groups = ['A','B','C']
for m in groups:
group = file.create_group(m)
dataset = ['1','2','3']
for n in dataset:
data = df
ds = group.create_dataset(m + n, data.shape)
print ("Dataset dataspace is", ds.shape)
print ("Dataset Numpy datatype is", ds.dtype)
print ("Dataset name is", ds.name)
print ("Dataset is a member of the group", ds.parent)
print ("Dataset was created in the file", ds.file)
print ("Writing data...")
ds[...] = data
print ("Reading data back...")
data_read = ds[...]
print ("Printing data...")
print (data_read)
file.close(
)
이 방법을 달성하고 싶은 무엇의 구조를 보여줍니다 다음 코드를 사용하여 이동을 했어하지만 인덱스와 열을 잃는다. 나는이 사람이 어떤 빛을하시기 바랍니다 있나이 오류
AttributeError: 'Dataset' object has no attribute 'split'
를 얻을 수는
df.to_hdf('database.h5', ds, table=True, mode='a')
을 시도했지만 작동하지 않았다.
key : string
identifier for the group in the store
그래서이 시도 : 많은 감사
처럼 미래 즉 작업에 거대한 될 것입니다 특정 그룹에서 데이터를 검색하는 효율적인 방법인지하지만 궁금'pandas'는 hdf5' 파일'에 데이터 프레임을 작성하는'pytables'를 사용합니다. 'h5py' 파일을 찾는 데는 의문의 여지가 있습니다. 레이아웃은 복잡하지만 따르기가 불가능하지는 않습니다. 'h5py'는'hdf5'에 본질적으로'numpy' iterface입니다. – hpaulj
https://stackoverflow.com/questions/41173254/how-should-i-use-h5py-lib-for-storing-time-series-data – hpaulj