Python reads and writes Excel

Source: Internet
Author: User

#-*-Coding:utf-8-*-
Import xlrd
Import Codecs

Def read_excel ():
#save the Resultitem like (Key,value)
FW = Codecs.open (' Result.txt ', ' w ', ' Utf-8 ')
Workbook = Xlrd.open_workbook (R ' D:\work1\word2vec_noquery_avn_sorted_unique_xiao.xlsx ')
# Get all Sheet
Print workbook.sheet_names () # [u ' Word2vec_noquery_avn_sorted_unique_xiao ']
#获取sheet2
# get sheet content based on sheet index or name
Sheet2 = Workbook.sheet_by_name (' Word2vec_noquery_avn_sorted_unique_xiao ')
# sheet name, number of rows, number of columns
Print Sheet2.name,sheet2.nrows,sheet2.ncols

#开始按行遍历
sum = 0
For I in Range (sheet2.nrows):
s = []
Sum_per_row = 0
Result_per_row = 0.0
j = 1
S.append (Sheet2.cell (i,0). Value) #获取每一行的key
For j in Range (Len (Sheet2.row (i))):
if (j%2==0):
Sum_per_row + = Sheet2.cell (i,j)
n = (len (sheet2.row (i))-1) * 2
Result_per_row = SUM_PER_ROW/2
S.append (Result_per_row)
Fw.write (s)
Sum + = Result_per_row
sum = sum/sheet2.rows
Print (sum)


Read_excel ()

Http://www.cnblogs.com/ZHANG576433951/p/6821945.html

Http://jingyan.baidu.com/article/e2284b2b754ac3e2e7118d41.html

Python reads and writes Excel

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.