字符串转字节 字符串转换为字节类型: s ="apple" bytes(s,encoding='utf-8') b'apple' 转为字符串 字符类型、数值型等转换为字符串类型 i =100 str(i) '100' 十转ASCII 十进制整数对应的 ASCII 字符 chr(65) 'A' ASCII转十 ASCII字符对应的十进制数 ord('A') 65 生...
python 生成 exe 文件的方法:首先安装 pyinstaller,代码为【pip install pyinstaller】;然后使用 pyinstaller 命令打包成 exe【pyinstaller -F --icon=my.ico…】。 一、安装 pyinstaller pip install pyinstaller 二、使用 pyinstaller 命令 pyinstaller -...
pymysql是 python中 操作MySQL的工具包 python代码中导入pymysql import pymysql 创建连接 语法:conn = pymysql.connect(host=‘127.0.0.1’, port=端口号, user=‘数据库用户名’, passwd=‘密码’, db=‘数据库名’) conn = pymysql.connect(host='127.0.0....
Jupyter介绍 Jupyter Notebook 是一个在浏览器中使用的交互式的笔记本,可以实现将代码、文字完美结合起来,它的受众群体大多数是一些从事数据科学领域相关(机器学习、数据分析等)的人员。 Jupyter Notebook是一个开源的Web应用程序,允许用户创建和共享包含代码、方程式、可视化和文本的文档。它的用途包括:数据清理和转换、数值模拟、统计建模、数据可视化、机器学习等等 Ju...
python中函数或者方法可以返回多个值,定义方法如下: 函数定义方法: def test(): #todo something r1 = '第一个值' r2 = '第二个值' return r1,r2 执行调用方法: res = test() #接收方法一 print(res[0]) print(res[1]) #接收方法二(推荐使用) res1,res2 = tes...
在字符串字符校验里 判断中文字符会经常遇到,这里介绍python校验中文字符串的代码 def check_is_chinese(kw): for ch in kw: if '\u4e00' > ch or ch > '\u9fff': return False return True 测试: kw1 = '老王爱小王' kw2 ...
Python setattr() 函数对应函数 getattr(),用于设置属性值,该属性不一定是存在的。 setattr() 语法: setattr(object, name, value) 参数: object -- 对象。 name -- 字符串,对象属性。 value -- 属性值。 无返回值 setattr() 函数的使用方法: 对已存在的属性进行赋值: >>>c...
any() 函数用于判断给定的可迭代参数 iterable 是否全部为 False,则返回 False,如果有一个为 True,则返回 True。 any() 方法的语法: any(iterable) 参数iterable -- 元组或列表。 返回值如果都为空、0、false,则返回false,如果不都为空、0、false,则返回true。 函数等价于: def any(iterable): ...
在python的 Series结构中无reshape方法,就会报该异常 AttributeError: 'Series' object has no attribute 'reshape' 处理方法:先使用Series的valuse方法将Series对象转化为numpy的ndarray,再用ndarray的reshape方法 ...
测试数据 这里分析1992年到200年 国内生产总值x和财政收入y的数据 分析代码: #!/usr/bin/env python # -*- coding: utf-8 -*- import pandas as pd from sklearn import linear_model import matplotlib.pyplot as plt data = pd.read_excel('F...