java中的接口是类吗
520
2022-09-06
Python使用pandas库读取csv文件,并分组统计的一个例子(pandas处理csv数据)
代码:
# coding=gbk# 从HostWrites.csv读取数据并分组统计import pandasimport datetimeprint "\r\n从 HostWrites.csv 读取数据并分组统计\r\n"excel = pandas.read_csv("D:\Program Files\CrystalDiskInfo8_2_0\Smart\KXG6AZNV512G TOSHIBA39HS1002TMFQ\HostWrites.csv", header=None)dates = []kv = {}# for row in excel.iterrows():for row in excel.tail(100).values: time = pandas.to_datetime(row[0]) value = row[1] date = datetime.datetime.strftime(time, "%Y-%m-%d") if date not in kv: dates.append(date) kv[date] = valuelast = Nonedelta = 0lst = []for date in dates: if last is not None: delta = kv[date] - last last = kv[date] today = datetime.datetime.strftime(datetime.datetime.now(), "%Y-%m-%d") yesterday = datetime.datetime.strftime(datetime.datetime.now() + datetime.timedelta(-1), "%Y-%m-%d") if delta > 50 or date == today or date == yesterday: lst.append((date, kv[date], delta))print "日期".ljust(12, " "), "固态硬盘写入量".ljust(16, " "), "增量"index = 0for item in lst: index += 1 if len(lst) - index < 20: print str(item[0]).ljust(13, " "), str(item[1]).ljust(15, " "), item[2]raw_input("输入任意字符退出:")
View Code
输出:
版权声明:本文内容由网络用户投稿,版权归原作者所有,本站不拥有其著作权,亦不承担相应法律责任。如果您发现本站中有涉嫌抄袭或描述失实的内容,请联系我们jiasou666@gmail.com 处理,核实后本网站将在24小时内删除侵权内容。
发表评论
暂时没有评论,来抢沙发吧~