
Python
文章平均质量分 51
小小白2333
推荐算法方向。欢迎私信问问问题python\R\spss(免费),算法问题可以一起讨论哇~
展开
-
python 安装包报错
python安装包换源原创 2023-02-24 21:57:37 · 426 阅读 · 0 评论 -
精简python代码 ,减少for循环
精简python代码 ,减少for循环原创 2023-02-08 14:29:54 · 482 阅读 · 0 评论 -
sentence_transformers安装成功,但是不能import
sentence_transformers安装成功,但是不能import原创 2023-02-03 12:59:22 · 2913 阅读 · 0 评论 -
python 各种形式之间的文件转换
python 各种形式之间的文件转换原创 2023-02-01 11:33:39 · 1011 阅读 · 0 评论 -
Python基本用法
python数据处理基本操作原创 2023-01-06 20:40:30 · 628 阅读 · 5 评论 -
jupyter notebook生成py文件
在一个jupyter notebook中代码最后写入:并将jupyter notebook的文件名称也改为设定的。,最后执行以下代码即可生成。原创 2022-10-25 11:12:36 · 1634 阅读 · 0 评论 -
Python问题:AttributeError: ‘str‘ object has no attribute ‘decode‘
AttributeError: 'str' object has no attribute 'decode'原创 2022-07-21 11:30:40 · 4203 阅读 · 0 评论 -
Python爬虫问题解决: SyntaxError: invalid syntax
import urllib.requestimport requestsurl = 'https://hz.lianjia.com/zufang/'headers = ( 'User-Agent':'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.102 Safari/537.36')# headers = ('User-Agent':'Mo...原创 2022-03-30 12:07:03 · 2465 阅读 · 0 评论 -
Python问题解决:TypeError: ‘<‘ not supported between instances of ‘float‘ and ‘str‘
出错代码:#按区域得到每组的数据key = df[['区域','产品类别']].apply(tuple,axis=1)gp = df.groupby(key)for key,g in gp: print(f'{key}:{type(g)}')报错:TypeError: '<' not supported between instances of 'float' and 'str'解决方法:key = df[['区域','产品类别']].apply(tupl..原创 2022-03-23 16:37:02 · 15100 阅读 · 1 评论 -
Python问题:SyntaxError: invalid syntax
出错代码:# 中雨或大雨 并且温度高于33度的记录cond = ( '天气状况 in ('中雨','大雨')' #in表示是否存在, and 或or 表示逻辑关系 'and 最高温度 >= 33 ' )df_tmp.query(cond)问题:解决方法:将查询字符串改为双引号...原创 2022-03-17 15:58:07 · 778 阅读 · 0 评论 -
Python问题:UnicodeDecodeError: ‘utf-8‘ codec can‘t decode byte 0xb0 in position 0: invalid start byte
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xb0 in position 0: invalid start byte解决办法原创 2022-03-16 14:21:18 · 4632 阅读 · 1 评论 -
Python问题:UnsortedIndexError: ‘MultiIndex slicing requires the index to be lexsorted: slicing on lev
部分表:代码rows = idx['中山':'珠海','2019-07-02':'2019-07-04']cols = idx['白天',['最高温度','天气状况']]df.loc[rows,cols]问题:UnsortedIndexError: 'MultiIndex slicing requires the index to be lexsorted: slicing on levels [0, 1], lexsort depth 0'解决方法:因为pandas 需要原创 2022-03-16 16:59:04 · 2224 阅读 · 1 评论 -
SQLServer索引与Python索引的区别与联系
SQLServer:索引主要目的是提高了SQL Server系统的性能,加快数据的查询速度与减少系统的响应时间。索引是什么:数据库中的索引类似于一本书的目录,在一本书中使用目录可以快速找到你想要的信息,而不需要读完全书。在数据库中,数据库程序使用索引可以重啊到表中的数据,而不必扫描整个表。书中的目录是一个字词以及各字词所在的页码列表,数据库中的索引是表中的值以及各值存储位置的列表.创建索引: CREATE[UNIQUE][CLUSTERED|NONCLUSTERED]INDEX...原创 2022-03-10 17:09:46 · 1299 阅读 · 0 评论 -
Python问题:EOL while scanning string literal和错误ValueError: Invalid placeholder in string: line
EOL while scanning string literalValueError: Wrong number of items passed 11, placement implies 1ValueError: Invalid placeholder in string: line 1, col 1原创 2022-03-09 11:11:46 · 1118 阅读 · 1 评论 -
Python问题:KeyError: ‘XXX‘
问题代码:note_str_1 = Template('${cwh}(${spr})有${num}条,用印申请审批超24小时,具体为:${detail}') #对字段进行连接 最后形成一句话df['红色预警内容'] = df.apply(lambda line: note_str_1.substitute(cwh=line['cwh'],spr=line['spr'],num=line['审批人超时数'], yysqsj=line['yysqsj'],yylb=line['y原创 2022-03-01 15:08:05 · 1505 阅读 · 0 评论 -
Python函数:rank()
函数形式:DataFrame.rank(axis=0, method='average', numeric_only=NoDefault.no_default, na_option='keep', ascending=True, pct=False)沿轴计算数值数据等级(1到n)。默认情况下,相等的值被分配一个等级,这个等级是这些值的等级的平均值。axis:直接排名索引。...原创 2022-02-28 14:31:52 · 6451 阅读 · 0 评论 -
Python函数:set_index()
用法:DataFrame.set_index(keys, drop=True, append=False, inplace=False, verify_integrity=False)使用现有列设置 DataFrame 索引。使用一个或多个现有的列或数组(具有正确的长度)设置DataFrame索引(行标签)。索引可以替换现有的索引,也可以在其上展开。keys:这个参数可以是单个列键、与调用DataFrame相同长度的单个数组,或者包含列键和数组的任意组合的列表。在这里,数组包括Seri.原创 2022-02-28 11:42:40 · 14911 阅读 · 2 评论 -
Python函数:groupby()
形式:DataFrame.groupby(by=None, axis=0, level=None, as_index=True, sort=True, group_keys=True, squeeze=NoDefault.no_default, observed=False, dropna=True)分组操作涉及到分离对象、应用函数和组合结果的一些组合。这可以用于对大量数据进行分组,并计算对这些分组的操作。by:用于确定 groupby 的组。 如果 by 是一个函数,它会在对象索引的每个值上调原创 2022-02-28 11:13:28 · 10890 阅读 · 0 评论 -
Python函数:sort_values()
sort_values()原创 2022-02-25 16:45:13 · 19410 阅读 · 0 评论 -
Python函数:os.chdir()
os.chdir() 方法用于将当前工作目录切换到指定的路径原创 2022-02-23 17:40:02 · 4777 阅读 · 0 评论 -
Python字符串:Template
Template属于string中的一个类。原创 2022-02-23 16:35:04 · 701 阅读 · 0 评论 -
Python问题:ImportError: cannot import name ‘Template‘ from ‘string‘
首先确保安装了Templatepip install template其次,查找创建的文件名是否有 string.py 的将名字改掉就行了原创 2022-02-23 16:15:15 · 1757 阅读 · 0 评论 -
Python函数:Join()
Python join() 方法用于将序列中的元素以指定的字符连接生成一个新的字符串。原创 2022-02-22 17:49:58 · 390 阅读 · 0 评论 -
python函数:pd.Series()
形式:pandas.Series(data=None,index=None,dtype=None,name=None,copy=False,fastpath=False)Pandas主要的数据结构是Series(一维)与DataFrame(二维)Series是带标签的一维数组,可存储整数、浮点数、字符串、Python 对象等类型的数据,轴标签统称为索引.。Pandas会默然用0到n-1来作为series的index,但也可以自己指定index(可以把index理解...原创 2022-02-22 14:39:09 · 27227 阅读 · 0 评论 -
Python函数:reset_index()
reset_index()函数理解原创 2022-02-21 18:04:43 · 26996 阅读 · 0 评论 -
Python函数:apply()
函数:DataFrame.apply(func, axis=0, broadcast=False, raw=False, reduce=None, args=(), **kwds)apply(func [, args [, kwargs ]]) 函数用于当函数参数已经存在于一个元组或字典中时,间接地调用函数。args是一个包含将要提供给函数的按位置传递的参数的元组。如果省略了args,任何参数都不会被传递,kwargs是一个包含关键字参数的字典。apply()的返回值就是func()的返回.原创 2022-02-21 16:05:54 · 10192 阅读 · 0 评论 -
Python问题:OperationalError: (pymysql.err.OperationalError) (2003, “Can‘t connect to MySQL server on ‘
win10系统 3.7.0python版本在 jupyter notebook中出现以下错误OperationalError: (pymysql.err.OperationalError) (2003, "Can't connect to MySQL server on '#@5*.***.**.***' ([Errno 11003] getaddrinfo failed)")解决方法:简单理解为是无法连接到自己想要的数据库。查看连接语句:密码:Z !@#服务器:5原创 2022-02-21 14:14:25 · 4785 阅读 · 0 评论 -
Python函数: time.strftime()、time.localtime()、time.time()
time.strftime(format[, t])Format必须是字符串。如果t中的任何字段超出允许的范围,则会引发ValueError错误time strftime()函数用于格式化时间,返回以可读字符串表示的当地时间,格式由参数 format 决定。t -- 可选的参数 t 是一个 struct_time 对象。python中时间日期格式化符号:%y 两位数的年份表示(00-99) %Y 四位数的年份表示(000-9999) %m 月份(01-12) %d原创 2022-02-21 13:45:00 · 24347 阅读 · 6 评论 -
Python下载jupyter notebook并修改默认地址
系统:win10 python3.7.0键盘操作:win+R ——弹出运行页面——输入:cmd——跳转页面使用pip进行安装pip install jupyter升级操作pip install --upgrade pip运行jupyter notebookjupyter notebook原创 2022-02-15 10:47:18 · 1013 阅读 · 0 评论 -
python问题:NameError: name ‘DataFrame‘ is not defined
df 中的表,发现没有明确的列名,所以修改列名。下述运行结果是原始表的情况运行下述代码df = DataFrame(df1,columns=['order','Name','Age','Weight','m0006','m0612','m1218','f0006','f0612','f1218'])结果:查阅网络,指定了DataFrame,就是 pd.DataFrame(df1,.....)变为全新的空白表。修改代码列名修改好了...原创 2022-02-14 19:10:31 · 20059 阅读 · 0 评论 -
python问题:FileNotFoundError: [Errno 2] No such file or directory: ‘data_clean.csv‘
做数据清洗时,出现错误FileNotFoundError: [Errno 2] No such file or directory: 'data_clean.csv'#读取csv文件import pandas as pddf = pd.read_csv("data_clean.csv")问题应该是找不到data_clean.csv的文件。解决方法:绝对路径和相对路径把“data_clean.scv文件”放在和现在编写的代码.py文件 相同的文件夹下即可运行成功。就导..原创 2022-02-14 17:24:46 · 5761 阅读 · 0 评论 -
python问题:SyntaxError: future feature annotations is not defined. 将python卸载3.6.8重装为3.7进行解决
有些安装包python3.6不行,所以重装为3.7首先找到python3.6.8所在的文件位置(假装这是3.6.8 安装成功之后删早了 忘写博客了)从官网下载python3.7https://www.python.org/downloads/点击Download跳转下述页面,向下拉,找到python3.7 ——单击跳转页面选择画红线,点击下载——选择下载文件的位置文件位置出现下述情况,删除3.6.8即可双击python3.7.0进行...原创 2022-02-11 22:37:33 · 14454 阅读 · 2 评论 -
Python问题:Original error was: No module named ‘numpy.core._multiarray_umath‘ 且多次出现cannot import name
此前系统背景:win10python从3.6.8卸载重装为python3.7import matplotlib.pyplot as pltimport seaborn as snsimport numpy as npimport pandas as pd#数据准备N= 1000x = np.random.randn(N)y = np.random.randn(N)#用Matplotlib 画散点图plt.scatter(x,y,marker= 'x')plt.sho...原创 2022-02-11 22:07:40 · 20775 阅读 · 1 评论