Questions tagged «python»

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

3
Python发送带有标头的POST
我尝试构建一个python脚本,该脚本发送带有用于提取结果的参数的POST。通过提琴手,我提取了我要返回的帖子请求。该网站仅使用https。 POST /Services/GetFromDataBaseVersionned HTTP/1.1 Host: www.mywbsite.fr "Connection": "keep-alive", "Content-Length": 129, "Origin": "https://www.mywbsite.fr", "X-Requested-With": "XMLHttpRequest", "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/536.5 (KHTML, like Gecko) Chrome/19.0.1084.52 Safari/536.5", "Content-Type": "application/json", "Accept": "*/*", "Referer": "https://www.mywbsite.fr/data/mult.aspx", "Accept-Encoding": "gzip,deflate,sdch", "Accept-Language": "fr-FR,fr;q=0.8,en-US;q=0.6,en;q=0.4", "Accept-Charset": "ISO-8859-1,utf-8;q=0.7,*;q=0.3", "Cookie": "ASP.NET_SessionId=j1r1b2a2v2w245; GSFV=FirstVisit=; GSRef=https://www.google.fr/url?sa=t&rct=j&q=&esrc=s&source=web&cd=1&ved=0CHgQFjAA&url=https://www.mywbsite.fr/&ei=FZq_T4abNcak0QWZ0vnWCg&usg=AFQjCNHq90dwj5RiEfr1Pw; HelpRotatorCookie=HelpLayerWasSeen=0; NSC_GSPOUGS!TTM=ffffffff09f4f58455e445a4a423660; GS=Site=frfr; __utma=1.219229010.1337956889.1337956889.1337958824.2; __utmb=1.1.10.1337958824; __utmc=1; __utmz=1.1337956889.1.1.utmcsr=google|utmccn=(organic)|utmcmd=organic|utmctr=(not%20provided)" {"isLeftColumn":false,"lID":-1,"userIpCountryCode":"FR","version":null,"languageCode":"fr","siteCode":"frfr","Quotation":"eu"} …

4
分组数据框并获得总和和计数?
我有一个看起来像这样的数据框: Company Name Organisation Name Amount 10118 Vifor Pharma UK Ltd Welsh Assoc for Gastro & Endo 2700.00 10119 Vifor Pharma UK Ltd Welsh IBD Specialist Group, 169.00 10120 Vifor Pharma UK Ltd West Midlands AHSN 1200.00 10121 Vifor Pharma UK Ltd Whittington Hospital 63.00 10122 Vifor Pharma UK Ltd …

3
python set操作的时间复杂度?
Big O表示法中每个python设置操作的时间复杂度是多少? 我正在将Python的set类型用于对大量项目的操作。我想知道每个操作的性能如何受到集合大小的影响。例如,添加,并测试成员资格: myset = set() myset.add('foo') 'foo' in myset 谷歌搜索并没有占用任何资源,但是合理地考虑了Python的set实现的时间复杂性是合理的。 如果它存在,到一些链接像这将是巨大的。如果那里没有这样的东西,那么也许我们可以解决吗? 用于查找所有设置操作的时间复杂度的额外标记。

1
仅在一侧向tkinter小部件添加填充
我如何在tkinter窗口小部件居中的情况下向tkinter窗口添加填充?我试过了: self.canvas_l = Label(self.master, text="choose a color:", font="helvetica 12") self.canvas_l.grid(row=9, column=1, sticky=S, ipady=30) 和 self.canvas_l = Label(self.master, text="choose a color:", font="helvetica 12") self.canvas_l.grid(row=9, column=1, rowspan=2, sticky=S, pady=30) 我只想在标签顶部填充30像素。

10
如何阻止打印呼叫?
有没有一种方法可以阻止函数调用print? 我正在将pygame.joystick模块用于正在开发的游戏。 我创建了一个pygame.joystick.Joystick对象,并在游戏的实际循环中调用其成员函数get_button以检查用户输入。该功能可以完成我需要做的所有事情,但是问题在于它还会调用print,从而大大降低了游戏速度。 我可以阻止此呼叫print吗?


13
将蛇皮套转换成小驼峰皮套(lowerCamelCase)
my_string在python 2.7中从蛇格()转换为小驼峰(myString)的好方法是什么? 显而易见的解决方案是用下划线分隔,将第一个单词以外的每个单词大写,然后重新组合在一起。 但是,我对其他更惯用的解决方案或RegExp实现此目的的方式感到好奇(带有一些大小写修饰符?)

4
如何解压缩pkl文件?
我有一个来自MNIST数据集的pkl文件,其中包含手写数字图像。 我想看一下每个数字图像,因此我需要解压缩pkl文件,除非我不知道怎么做。 有没有办法解压缩/解压缩pkl文件?


18
ImportError:没有名为tensorflow的模块
请帮我解决这个错误 我已经在服务器上安装了tensorflow模块,下面是它的信息 15IT60R19@cpusrv-gpu-109:~$ pip show tensorflow Name: tensorflow Version: 1.0.0 Summary: TensorFlow helps the tensors flow Home-page: http://tensorflow.org/ Author: Google Inc. Author-email: opensource@google.com License: Apache 2.0 Location: /home/other/15IT60R19/anaconda2/lib/python2.7/site-packages Requires: mock, numpy, protobuf, wheel, six 但是当我尝试导入tensorflow时出现以下错误 >>> import tensorflow as tf Traceback (most recent call last): File "<stdin>", line 1, in …


12
VSCode:在所选环境中没有可用的Pip安装程序
我正在尝试在VSCode中的Python文件上运行autopep8 linter。 我已按照以下说明进行操作:https ://code.visualstudio.com/docs/python/environments并选择了我的解释器(⇧⌘P):/usr/local/bin/python 然后,我尝试格式化我的代码,VSCode表示未安装autopep8,可以通过Pip进行安装。但是,当我尝试通过Pip安装时,显示There is no Pip installer available in the selected environment。 然后,我尝试通过选择“ Python:从命令面板创建终端”在当前环境中启动终端。 终端可以正常打开,pip存在,甚至可以pip install autopep8在VSCode中打开终端,但是当我尝试运行Format Document命令时,却遇到了相同的错误,autopep8并且pip在环境中不可用。

7
带标签的sklearn图混淆矩阵
我想绘制一个混淆矩阵以可视化分类器的性能,但它仅显示标签的数字,而不显示标签本身: from sklearn.metrics import confusion_matrix import pylab as pl y_test=['business', 'business', 'business', 'business', 'business', 'business', 'business', 'business', 'business', 'business', 'business', 'business', 'business', 'business', 'business', 'business', 'business', 'business', 'business', 'business'] pred=array(['health', 'business', 'business', 'business', 'business', 'business', 'health', 'health', 'business', 'business', 'business', 'business', 'business', 'business', 'business', 'business', 'health', 'health', 'business', 'health'], dtype='|S8') …

3
如何从Python请求中读取响应?
我有两个Python脚本。一种使用Urllib2库,另一种使用Requests库。 我发现请求更容易实现,但是找不到urlib2的等效read()函数。例如: ... response = url.urlopen(req) print response.geturl() print response.getcode() data = response.read() print data 建立完发布网址后,请data = response.read()给我内容-我正尝试连接到vcloud Director api实例,并且响应显示了我有权访问的端点。但是,如果我按以下方式使用请求库:..... .... def post_call(username, org, password, key, secret): endpoint = '<URL ENDPOINT>' post_url = endpoint + 'sessions' get_url = endpoint + 'org' headers = {'Accept':'application/*+xml;version=5.1', \ 'Authorization':'Basic '+ base64.b64encode(username + "@" …

9
Python Pandas用顶部行替换标题
我目前有一个数据框,看起来像这样: Unnamed: 1 Unnamed: 2 Unnamed: 3 Unnamed: 4 0 Sample Number Group Number Sample Name Group Name 1 1.0 1.0 s_1 g_1 2 2.0 1.0 s_2 g_1 3 3.0 1.0 s_3 g_1 4 4.0 2.0 s_4 g_2 我正在寻找一种删除标题行并使第一行成为新标题行的方法,因此新数据框将如下所示: Sample Number Group Number Sample Name Group Name 0 1.0 1.0 …
79 python  pandas  header  row 

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.