The number of occurrences of each word in the. 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 2.python write generated serialization: __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) to I in range (n )]if __name__ = = ' __main__ ': print Generate (10) 3. Iterate through 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 (): For Col in Xrange (booksheet.ncols): For row in Xrange (booksheet.nrows): Value=book Sheet.cell (row,col). Value PrinT value where xlrd need Baidu download import this module into Python 4. Organize the data in a table into a format of lua type #coding=utf-8__author__ = ' ZCG ' #2017 9/26import Xlrdfileoutput = open (' Configs.lua ', ' W ') writedata= "[email protected]: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 (): W Ritedata = writedata+ ' at ' +booksheet.name+ ' ={\n ' for col in Xrange (booksheet.ncols): For row in xrange (Bookshee T.nrows): value = Booksheet.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 ()
The number of occurrences of each word in the Python statistics text