博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Python之pandas模块
阅读量:4962 次
发布时间:2019-06-12

本文共 2311 字,大约阅读时间需要 7 分钟。

pandas

pandas is an open source, BSD-licensed library providing high-performance, easy-to-use data structures and data analysis tools for the  programming language

一、安装

1、pandas

git clone git://github.com/pydata/pandas.git

 

2、Requirements

Cpython

pytz

 

二、例子:

数据内容格式:

dstat命令输出的结果

"epoch","1m","5m","15m","read","writ","read","writ","usr","sys","idl","wai","hiq","siq","recv","send","used","buff","cach","free","util","util"1384246698.290,2.730,1.190,0.940,4316699.658,3074071.976,283.904,131.427,1.172,0.464,96.302,1.858,0.022,0.182,0.0,0.0,6959415296.0,1933697024.0,19159023616.0,22583123968.0,0.155,0.2921384246699.290,2.730,1.190,0.940,4579328.0,880640.0,560.0,27.0,14.518,0.876,82.228,1.877,0.0,0.501,363556.0,2888961.0,6973390848.0,1933697024.0,19159031808.0,22569140224.0,0.0,17.6001384246700.290,2.730,1.190,0.940,3678208.0,516096.0,449.0,18.0,13.965,0.623,83.292,1.621,0.125,0.374,140745.0,1662141.0,6983143424.0,1933697024.0,19159306240.0,22559113216.0,0.0,13.8001384246701.290,2.510,1.170,0.930,4292608.0,667648.0,524.0,49.0,7.644,0.752,89.348,1.629,0.0,0.627,139858.0,1056176.0,6971334656.0,1933697024.0,19159306240.0,22570921984.0,0.0,15.01384246702.290,2.510,1.170,0.930,4104192.0,684032.0,502.0,22.0,3.616,0.748,93.267,1.621,0.0,0.748,126114.0,1135695.0,6983221248.0,1933697024.0,19159592960.0,22558748672.0,0.0,14.800

 

程序:

#!/usr/bin/env python2.7#-*- coding:utf-8 -*-import pandas as pdimport numpy as npf = open("./ssd_dstat.txt")index_list = []flag = Falseall_data_list=[]for line in f.xreadlines():    if "buff" in line:        index_str_list = line.strip('\n').split(',')        index_list = []        for i in index_str_list:            column_name = i.strip('"')            if column_name in index_list:                                                                                                                                    column_name = column_name + '_1'            index_list.append(column_name)        print index_list        flag = True    elif flag:        data_str_list = line.strip('\n').split(',')        data_list = []        for i in data_str_list:            data_list.append(float(i))        all_data_list.append(data_list)data = np.array(all_data_list)df = pd.DataFrame(data,columns=index_list)print df

以上是个初步的例子,还有待优化

转载于:https://www.cnblogs.com/gsblog/p/3424295.html

你可能感兴趣的文章
jQuery 基础学习
查看>>
一个简单的 MVVM 实现
查看>>
CABasicAnimation
查看>>
UML建模——用例图(Use Case Diagram)
查看>>
LINUX诞生
查看>>
大学毕业一个月的微型总结
查看>>
Linuxer-"Linux开发人员自己的媒体"第五月稿件和赠书名单
查看>>
unittest -官网文档学习笔记-TestCase class
查看>>
unbuntu 安装一些常用软件
查看>>
软件工程实践第二次作业
查看>>
ansible入门01
查看>>
Rails 自定义验证的错误信息
查看>>
图论(对偶图):COGS 470. [NOI2010]海拔
查看>>
第三方类AFNetworking
查看>>
Enterprise Library 2.0 -- Cryptography Application Block
查看>>
简单的发邮件功能实现
查看>>
velocity模板引擎学习(3)-异常处理
查看>>
OllyDBG 1.10
查看>>
[svc][op]杀进程
查看>>
linux安装jdk
查看>>