![](https://img-blog.csdnimg.cn/20201014180756918.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
python
coagenth
Try not to become a man of success. Rather become a man of value.
展开
-
让终端输出五颜六色
在vscode中编写运行代码时,终端用cmd或powershell输出时是黑白的,看得有时视觉疲劳,用下面的小代码,可以改变字符的颜色。import randomcolors={}colors['red'] = '\x1b[1;31m'colors['green'] = '\x1b[1;32m'colors['yellow'] = '\x1b[1;33m'colors['cyan'] = '\x1b[1;36m'colors['reset'] = '\x1b[0m'print(random.原创 2021-03-08 18:58:29 · 1800 阅读 · 0 评论 -
用nltk对文本分词
用nltk对文本分词在对有标注的文本进行分词时,要用到nltk库中的WordPunctTokenizer和WhitespaceTokennizer,例子如下:import nltkfrom nltk.tokenize import WordPunctTokenizer,WhitespaceTokenizertxt = 'red foxes <emotion>scare</...原创 2020-01-15 22:42:37 · 3182 阅读 · 0 评论 -
解方程组
通过使用scipy.optimize中的fsolve函数或broyden1函数,解三元方程组的解,并将解代入原方程验证(f1,f2,f3均接近于0),程序代码:import scipy.optimize as optfrom numpy import expimport timeitst1 = timeit.default_timer()def f(variables): (...原创 2020-01-17 22:16:54 · 286 阅读 · 0 评论 -
将Excel表格数据转换成XML格式文件
将Excel表格数据转换成XML格式文件读取Excel文件,将其表中的列名作为名称,行列值作为属性值,转换成xml格式文件。代码如下:import xml.etree.ElementTree as ETimport xlrd#read data from a xlsx'file and assign them to a listExcelFileName = 'F:\\2019sh\\m...原创 2020-02-06 02:53:08 · 3998 阅读 · 0 评论