Questions tagged «python»

Python是一种多范式,动态类型的多用途编程语言。它旨在快速学习,理解和使用并强制使用干净统一的语法。请注意,Python 2自2020年1月1日起已不再受支持。不过,对于特定于版本的Python问题,请添加[python-2.7]或[python-3.x]标签。使用Python变体或库(例如Jython,PyPy,Pandas,Numpy)时,请将其包含在标签中。


7
python标准库中的装饰器(@deprecated)
我需要将例程标记为已弃用,但显然没有用于弃用的标准库装饰器。我知道它的配方和警告模块,但是我的问题是:为什么没有用于此(常见)任务的标准库装饰器? 附加问题:标准库中是否有标准装饰器?
127 python  decorator 

3
如何在Flask-SQLAlchemy中按ID删除记录
我users在MySql数据库中有表。这个表有id,name而且age领域。 如何删除某些记录id? 现在,我使用以下代码: user = User.query.get(id) db.session.delete(user) db.session.commit() 但是我不想在删除操作之前进行任何查询。有什么办法吗?我知道,我可以使用db.engine.execute("delete from users where id=..."),但是我想使用delete()方法。



8
使用.corr获取两列之间的相关性
我有以下熊猫数据框Top15: 我创建了一个估计每人可引用文件数量的列: Top15['PopEst'] = Top15['Energy Supply'] / Top15['Energy Supply per Capita'] Top15['Citable docs per Capita'] = Top15['Citable documents'] / Top15['PopEst'] 我想知道人均引用文件数量与人均能源供应之间的相关性。因此,我使用了.corr()方法(皮尔逊相关性): data = Top15[['Citable docs per Capita','Energy Supply per Capita']] correlation = data.corr(method='pearson') 我想返回一个数字,但是结果是:

13
sklearn错误ValueError:输入包含NaN,无穷大或对于dtype('float64')而言太大的值
我正在使用sklearn,并且亲和力传播存在问题。我建立了一个输入矩阵,并且不断收到以下错误。 ValueError: Input contains NaN, infinity or a value too large for dtype('float64'). 我跑了 np.isnan(mat.any()) #and gets False np.isfinite(mat.all()) #and gets True 我尝试使用 mat[np.isfinite(mat) == True] = 0 删除无限值,但这也不起作用。我该怎么做才能摆脱矩阵中的无限值,以便可以使用亲和力传播算法? 我正在使用anaconda和python 2.7.9。

4
如何使用Python请求伪造浏览器访问?
我想从下面的网站获取内容。如果使用Firefox或Chrome这样的浏览器,则可以获取所需的真实网站页面,但是如果使用Python request软件包(或wget命令)进行获取,则它将返回完全不同的HTML页面。我以为网站的开发人员为此做了一些阻碍,所以问题是: 如何使用python请求或命令wget伪造浏览器访问? http://www.ichangtou.com/#company:data_000008.html

3
使用pandas GroupBy.agg()对同一列进行多次聚合
是否有熊猫内置的方法将两个不同的聚合函数f1, f2应用于同一列df["returns"],而无需agg()多次调用? 示例数据框: import pandas as pd import datetime as dt pd.np.random.seed(0) df = pd.DataFrame({ "date" : [dt.date(2012, x, 1) for x in range(1, 11)], "returns" : 0.05 * np.random.randn(10), "dummy" : np.repeat(1, 10) }) 语法上错误但直观上正确的方法是: # Assume `f1` and `f2` are defined for aggregating. df.groupby("dummy").agg({"returns": f1, "returns": f2}) 显然,Python不允许重复的键。还有其他表达方式agg()吗?也许元组列表[(column, …

4
使用boto3连接到CloudFront时如何选择AWS配置文件
我正在使用Boto 3 python库,并想连接到AWS CloudFront。我需要指定正确的AWS Profile(AWS凭证),但是在查看官方文档时,我看不到指定它的方法。 我正在使用代码初始化客户端: client = boto3.client('cloudfront') 但是,这导致它使用默认配置文件进行连接。我找不到可以指定要使用的配置文件的方法。


13
Python3:ImportError:使用模块多处理中的值时,没有名为“ _ctypes”的模块
我正在使用Ubuntu,并已安装Python 2.7.5和3.4.0。在Python 2.7.5中,我能够成功分配变量x = Value('i', 2),但在3.4.0中却不能。我正进入(状态: Traceback (most recent call last): File "<stdin>", line 1, in <module> File "/usr/local/lib/python3.4/multiprocessing/context.py", line 132, in Value from .sharedctypes import Value File "/usr/local/lib/python3.4/multiprocessing/sharedctypes.py", line 10, in < module> import ctypes File "/usr/local/lib/python3.4/ctypes/__init__.py", line 7, in <module> from _ctypes import Union, Structure, Array ImportError: No …


16
安装psycopg2时出错,找不到用于-lssl的库
我跑 sudo pip install psycopg2 我得到了一堆看起来像这样的输出: cc -DNDEBUG -g -fwrapv -Os ..... ..... cc -DNDEBUG -g -fwrapv -Os ..... ..... 最后,它说: ld: library not found for -lssl clang: error: linker command failed with exit code 1 (use -v to see invocation) error: command 'cc' failed with exit status 1 ---------------------------------------- …

14
如何在pandas数据框上显示所有列名称?
我有一个包含数百列的数据框,我需要查看所有列名称。 我做了什么: In[37]: data_all2.columns 输出为: Out[37]: Index(['customer_id', 'incoming', 'outgoing', 'awan', 'bank', 'family', 'food', 'government', 'internet', 'isipulsa', ... 'overdue_3months_feature78', 'overdue_3months_feature79', 'overdue_3months_feature80', 'overdue_3months_feature81', 'overdue_3months_feature82', 'overdue_3months_feature83', 'overdue_3months_feature84', 'overdue_3months_feature85', 'overdue_3months_feature86', 'loan_overdue_3months_total_y'], dtype='object', length=102) 如何显示所有列,而不是截断的列表?
127 python  pandas  dataframe  show 

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.