number of occurrences of each word in 1.python statistics text:
#coding =utf-8__author__ = ' zcg ' Import collectionsimport oswith open (' Abc.txt ') as File1: #打开文本文件 str1=file1.read () . Split (') #将文章按照空格划分开print "original text: \ n%s"% str1print "\ n the number of occurrences of each word: \ n%s"% collections. Counter (str1) print collections. Counter (STR1) [' A '] #以字典的形式存储, the key value corresponding to each character is the number of occurrences in the text
__author__ = ' ZCG ' #endcoding utf-8import string,randomfield=string.letters+string.digitsdef getrandom (): Return "". Join (Random.sample (field,4)) def concatenate (group): return "-". Join ([Getrandom () for I in Range (group)] ) def generate (n): return [CONCATENATE (4) for I in range (n)]if __name__ = = ' __main__ ': print generate (10)
3. Traverse all the data in the Excel table:
__author__ = ' Administrator ' Import xlrdworkbook = Xlrd.open_workbook (' Config.xlsx ') print "There is {} sheets in the workbook". Format (workbook.nsheets) for Booksheet in Workbook.sheets (): FO R col in Xrange (booksheet.ncols): As row in Xrange (booksheet.nrows): Value=booksheet.cell (row,col). Valu e print value where xlrd need Baidu download import this module into Python
#coding =utf-8__author__ = ' ZCG ' #2017 9/26import xlrdfileoutput = open (' Configs.lua ', ' W ') writedata= "--@author: zcg\n\n\n" workbook = Xlrd.open_workbook (' config.xlsx ') print "There is {} Sheets in the workbook ". Format (workbook.nsheets) for Booksheet in Workbook.sheets (): WriteData = writedata+ ' at ' +bookshe Et.name+ ' ={\n ' for col in Xrange (booksheet.ncols): For row in Xrange (booksheet.nrows): value = books Heet.cell (row,col). value if row ==0:writedata = writedata+ ' \ t ' + ' ["' +value+ '"] ' + ' = ' + ' {' else:writedata=writedata+ ' "' +str (Booksheet.cell (row,col). Value) + '", ' else:writedata =writedata+ '},\n ' else:writedata=writedata+ '}\n\n ' Else:fileOutput.write (writedata) fileoutput.close ()