Python解析HDF文件 分类: Python 2015-06-25 00:16 743人阅读 评论(0) 收藏
前段时间因为一个业务的需求需要解析一个HDF格式的文件。在这之前也不知道到底什么是HDF文件。百度百科的解释如下:
HDF是用于存储和分发科学数据的一种自我描述、多对象文件格式。HDF是由美国国家超级计算应用中心NCSA(全称:National Center for Supercomputing Application)创建的,为了满足各种领域研究需求而研制的一种能高效存储和分发科学数据的新型数据格式。HDF可以表示出科学数据存储和分布的许多必要条件。
使用Python解析当然会用到第三方的包,如下:
import math
import pandas as pd
import xlwt
第一个是用来做数学计算的math包主要处理数学相关的运算。至于关于pandas的介绍请点击这里。xlwt这个包是写HDF文件的。
使用Python读取HDF文件的代码如下:
with closing(pd.HDFStore(HDF_FILR_URL)) as 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)
其实这样获取到数据之后就是pandas提供的函数,获取自己需要的数据。
slice_df = df.loc[dt]
rtt = slice_df.rtt.unstack(level=0) / 1000
cwnd = slice_df.cwnd.unstack(level=0)
total = slice_df.total.unstack(level=0)
rows = rtt.index.tolist()
columns = rtt.columns.tolist()
最后写入Excel,代码如下:
def writexcel(listname, name, time):
#将数据写入Excel
saveurl = EXCEL_FILR_URL + '%s_%s_%s.xls' % (AVG_RTT, time, name)
excel_file = xlwt.Workbook()
table = excel_file.add_sheet('tcpinfo')
index_row = 0
for item in listname:
for item_key, item_value in item.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 += 1
excel_file.save(saveurl)
版权声明:本文为博主原创文章,未经博主允许不得转载。
Python解析HDF文件 分类: Python 2015-06-25 00:16 743人阅读 评论(0) 收藏的更多相关文章
- TinyXML2读取和创建XML文件 分类: C/C++ 2015-03-14 13:29 94人阅读 评论(0) 收藏
TinyXML2是simple.small.efficient C++ XML文件解析库!方便易于使用,是对TinyXML的升级改写!源码见本人上传到CSDN的TinyXML2.rar资源:http: ...
- IOS之按钮控件--Button全解析及使用 分类: ios技术 2015-01-17 17:09 169人阅读 评论(0) 收藏
IOS开发中伴随我们始终的 最常用的几个空间之一 -- UIButton 按钮,对于button今天在此做一些浅析,并介绍下主流用法以及常见问题解决办法. 首先是继承问题,UIButton继承于UIC ...
- C/C++中const的用法 分类: C/C++ 2015-07-05 00:43 85人阅读 评论(0) 收藏
const是C语言的关键字,经C++进行扩充,变得功能强大,用法复杂.const用于定义一个常变量(只读变量),当const与指针,引用,函数等结合起来使用时,情况会变得复杂的多.下面将从五个方面总结 ...
- 浅谈new operator、operator new和placement new 分类: C/C++ 2015-05-05 00:19 41人阅读 评论(0) 收藏
浅谈new operator.operator new和placement new C++中使用new来产生一个存在于heap(堆)上对象时,实际上是调用了operator new函数和placeme ...
- Hdu 1506 Largest Rectangle in a Histogram 分类: Brush Mode 2014-10-28 19:16 93人阅读 评论(0) 收藏
Largest Rectangle in a Histogram Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 ...
- cf 61E. Enemy is weak 树状数组求逆序数(WA) 分类: Brush Mode 2014-10-19 15:16 104人阅读 评论(0) 收藏
#include <iostream> #include <algorithm> #include <cstdio> #include <cstring> ...
- short-path problem (Spfa) 分类: ACM TYPE 2014-09-02 00:30 103人阅读 评论(0) 收藏
#include <cstdio> #include <iostream> #include <cstring> #include <queue> #i ...
- HTTP 错误 500.19- Internal Server Error 错误解决方法 分类: Windows服务器配置 2015-01-08 20:16 131人阅读 评论(0) 收藏
1.第一种情况如下: 解决方法如下: 经过检查发现是由于先安装Framework组件,后安装iis的缘故,只需重新注册下Framework就可以了,具体步骤如下 1 打开运行,输入cmd进入到命令提示 ...
- Monthly Expense(二分) 分类: 二分查找 2015-06-06 00:31 10人阅读 评论(0) 收藏
Description Farmer John is an astounding accounting wizard and has realized he might run out of mone ...
随机推荐
- The Moon and Sixpence摘抄
I had not yet learnt how contradictory is human nature; I did not know how much pose there is in the ...
- 528. Random Pick with Weight index的随机发生器
[抄题]: Given an array w of positive integers, where w[i] describes the weight of index i, write a fun ...
- 动态添加 SqlParameter 参数
List<SqlParameter> paras = new List<SqlParameter>(); paras.Add(new SqlParameter("@m ...
- [leetcode]98. Validate Binary Search Tree验证二叉搜索树
Given a binary tree, determine if it is a valid binary search tree (BST). Assume a BST is defined as ...
- Django实现微信消息推送
一 所需准备条件 微信公众号的分类 微信消息推送 公众号 已认证公众号 服务号 已认证服务号 企业号 基于:微信认证服务号 主动推送微信消息.前提:关注服务号环境:沙箱环境 沙箱环境地址: https ...
- Python程序中的进程操作
之前我们已经了解了很多进程相关的理论知识,了解进程是什么应该不再困难了,刚刚我们已经了解了,运行中的程序就是一个进程.所有的进程都是通过它的父进程来创建的.因此,运行起来的python程序也是一个进程 ...
- [SoapUI] 检查测试步骤的类型或者或者某种特定类型的步骤列表
SoapUI Groovy : Check if test step is of specific type, such as : Wsdl, Rest, Jdbc, HTTP, Groovy etc ...
- 【Git】 GitLab简单使用
本例介绍简单实用GitLab,安装请参照[Git] GitLab服务器社区版安装与配置 1.用户和组的管理 a.创建组,在首页点击Create a group b.创建用户,在首页点击Add peop ...
- HQL数据查询基础
HQL定义 1.Hibernate Query Language, Hibernate查询语言 2.HQL是面向对象的查询语言(HQL查询的主体是映射配置的持久化类及其属性而SQL查询主体是数据库表) ...
- ABP框架系列之二十七:(Feature-Management-特征管理)
Introduction Most SaaS (multi-tenant) applications have editions (packages) those have different fea ...