这是可怕的代码块:
import pandas as pd
import numpy as np
from pathlib import Path
import h5py as hdf
def datarray(data):
'''works well for HDF files'''
return pd.DataFrame(np.array(data))
print( 'Modules imported')
print( 'Initialized')
pth=Path(r'C:\Users\open.Sourcerer\Desktop\1DTrimmedStruc')
geo=hdf.File(pth/'DB_RAS.g09.hdf','r')
struc=geo.get('Geometry').get('Structures').get('Attributes')
culs=geo.get('Geometry').get('Structures').get('Culvert Groups').get('Attributes')
brls=geo.get('Geometry').get('Structures').get('Culvert Groups').get('Barrels').get('Attributes')
struc=datarray(struc)
culs=datarray(culs)
brls=datarray(brls)
struc['RSReach']=struc['RS']+struc['Reach']
culs['RSReach']=culs['RS']+culs['Reach']
brls['RSReach']=brls['RS']+brls['Reach']
for df in (struc,culs,brls):
print(df)
我尝试了几种方法将这3个数据集转换为数据框并迭代添加列,但均未成功。不,我不能合并到1个数据集,我曾经将它们提供给excel的单独函数,但是现在我直接从HDF中获取数据集,因此输出需要特别地看起来像这样。我怎么能从这里煮下来呢?谢谢