python 使用pandas,完成对excel的操作: 遍历,求偏度(skew)的小程序

excel有针对偏度的计算函数 skew(), 但是不清楚怎么使用excel进行遍历, 数据量很大。

尝试使用python进行解决。

第一次学习python,没想到了在克服安装各种包的难过之后,居然成功实现了。

python3.3:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
#this is a test case
 
# -*- coding: gbk -*-
print("hello python!中文")
 
#env config
import xlrd
import os
import xlwt3
import numpy
 
import pandas as pd
#from pandas import Series,DataFrame
#import pandas
 
data = xlrd.open_workbook("E:\\data.xlsx")
table = data.sheets()[0]   #this need to be verify more
 
 
#print ("check")
print (table.nrows)
print (table.name)
print ("############################")
 
#total line num
line_num=table.nrows
 
cell_sectionA=table.cell(1,0).value
cell_sectionB=table.cell(1,1).value
#print (cell_sectionA)
#print (cell_sectionB)
 
start_value=cell_sectionA
 
#we need to recode the start value ,but not the end.
sectionB_each_time_start=0
#sectionB_each_time_end=i is ok.
 
for i in range(1,line_num):
    if start_value != table.cell(i,0).value:
        cacu_num=i-sectionB_each_time_start;
        #print (cacu_num)
        #print ("********************************")
        data={}
        for j in range(0,(cacu_num-1)):
            data[j]= table.cell((sectionB_each_time_start+j+1),1).value
            #print (data[j])
 
        df = pd.Series(data)
        #print("skew\t")
        #print("skew: %d  %f" %(table.cell(sectionB_each_time_start+1,0).value,df.skew()))
        print("%d"%table.cell(sectionB_each_time_start+1,0).value)
        #print("%f" %df.skew())
         
        #after caculate ,update the variable.
        sectionB_each_time_start=i-1
        start_value=table.cell(i,0).value
 
#file=xlwt3.Workbook()
#table_for_wt=file.add_sheet("test1");
 
 
#table_for_wt.write(0,0,cell_b)
#table_for_wt.write(1,1,cell_b)
#file.save('E:\\wtest.xls')

  

posted @   xichen  阅读(14507)  评论(0)    收藏  举报
编辑推荐:
· 解锁.NET 9性能优化黑科技:从内存管理到Web性能的最全指南
· 通过一个DEMO理解MCP(模型上下文协议)的生命周期
· MySQL下200GB大表备份,利用传输表空间解决停服发版表备份问题
· 记一次 .NET某固高运动卡测试 卡慢分析
· 微服务架构学习与思考:微服务拆分的原则
阅读排行:
· 解锁.NET 9性能优化黑科技:从内存管理到Web性能的最全指南
· .NET周刊【3月第5期 2025-03-30】
· .net clr 8年才修复的BUG,你让我损失太多了
· 即时通信SSE和WebSocket对比
· 一个神奇的JS代码,让浏览器在新的空白标签页运行我们 HTML 代码(createObjectURL
点击右上角即可分享
微信分享提示