A period of time ago because a business needs to parse a HDF format file. Before that, I don't know what the HDF file is. The explanation of Baidu Encyclopedia is as follows:
HDF is a self-describing, multi-object file format for storing and distributing scientific data. HDF is a new data format for efficient storage and distribution of scientific data, created by the National Centre for Supercomputing Applications NCSA (full name: Nation Center for supercomputing application) in order to meet research needs in a variety of fields. HDF can represent many necessary conditions for the storage and distribution of scientific data.
Using Python parsing will of course use a third-party package, as follows:
import mathimport pandas as pdimport xlwt
The first one is for mathematical calculations math包主要处理数学相关的运算
. For pandas
An introduction please click here. XLWT This package is written in HDF file.
The code for reading the HDF file using Python is as follows:
withas store: df = store[date] # index shoule be end -> region -> group df.reset_index(inplace=True) df.set_index(["end""region""group"], inplace=True) df.sort_index(inplace=True)
In fact, after getting to the data is pandas
the function provided to get the data you need.
slice_df = df.loc[dt] rtt = slice_df.rtt.unstack(level=01000 cwnd = slice_df.cwnd.unstack(level=0) total = slice_df.total.unstack(level=0) rows = rtt.index.tolist() columns = rtt.columns.tolist()
Finally, write to Excel with the following code:
def writexcel(listname, name, time): #将数据写入ExcelSaveurl = Excel_filr_url +'%s_%s_%s.xls '% (Avg_rtt, time, name) Excel_file = XLWT. Workbook () Table = Excel_file.add_sheet (' Tcpinfo ') Index_row =0 forIteminchListName: forItem_key, Item_valueinchItem.items (): Table.write (Index_row,0, str (item_key)) Table.write (Index_row,1, str (item_value[1][0])) Table.write (Index_row,2, str (item_value[1][1])) Table.write (Index_row,3, str (item_value[0]). Decode (' Utf-8 ')) Index_row + =1Excel_file.save (Saveurl)
Python parsing hdf file