Questions tagged «python»

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

5
TypeError:“ dict_keys”对象不支持索引
def shuffle(self, x, random=None, int=int): """x, random=random.random -> shuffle list x in place; return None. Optional arg random is a 0-argument function returning a random float in [0.0, 1.0); by default, the standard random.random. """ randbelow = self._randbelow for i in reversed(range(1, len(x))): # pick an element in x[:i+1] with …

15
使用nltk.data.load加载english.pickle失败
尝试加载punkt令牌生成器时... import nltk.data tokenizer = nltk.data.load('nltk:tokenizers/punkt/english.pickle') ... LookupError有人提出: > LookupError: > ********************************************************************* > Resource 'tokenizers/punkt/english.pickle' not found. Please use the NLTK Downloader to obtain the resource: nltk.download(). Searched in: > - 'C:\\Users\\Martinos/nltk_data' > - 'C:\\nltk_data' > - 'D:\\nltk_data' > - 'E:\\nltk_data' > - 'E:\\Python26\\nltk_data' > - 'E:\\Python26\\lib\\nltk_data' > - 'C:\\Users\\Martinos\\AppData\\Roaming\\nltk_data' …
144 python  jenkins  nltk 


7
使用Pandas在python中读取Excel文件
我正在尝试以这种方式读取Excel文件: newFile = pd.ExcelFile(PATH\FileName.xlsx) ParsedData = pd.io.parsers.ExcelFile.parse(newFile) 这引发了一个错误,该错误表示预期有两个参数,我不知道第二个参数是什么,而且我在这里想要实现的是将Excel文件转换为DataFrame,我这样做是否正确?或者还有其他方法可以使用熊猫吗?

9
Python中的哈希图
我想在Python中实现HashMap。我想请用户输入。根据他的输入,我正在从HashMap中检索一些信息。如果用户输入HashMap的键,我想检索相应的值。 如何在Python中实现此功能? HashMap<String,String> streetno=new HashMap<String,String>(); streetno.put("1", "Sachin Tendulkar"); streetno.put("2", "Dravid"); streetno.put("3","Sehwag"); streetno.put("4","Laxman"); streetno.put("5","Kohli")
144 python  hashmap 


1
在此Django应用程序教程中,choice_set是什么?
Django教程中的这一行,编写您的第一个Django应用,第1部分: p.choice_set.create(choice='Not much', votes=0) 它是如何choice_set存在的?它是什么? 我想这choice部分是Choice本教程中使用的模型的小写版本,但是什么是choice_set?你能详细说明吗? 更新:根据Ben的回答,我找到了此文档:遵循“向后”关系。
144 python  django  orm 

20
如何删除字符串的左侧部分?
我有一些简单的python代码,可在文件中搜索字符串,例如path=c:\path,其中c:\path部分可能会有所不同。当前代码是: def find_path(i_file): lines = open(i_file).readlines() for line in lines: if line.startswith("Path="): return # what to do here in order to get line content after "Path=" ? 取得文字的简单方法是什么Path=?
144 python  string 


7
首次出现大于当前值的值
我在numpy中有一个1D数组,我想在值超过numpy数组中的值的位置找到索引的位置。 例如 aa = range(-10,10) 查找超出aa值的位置5。
144 python  numpy 

7
熊猫数据框fillna()仅存在一些列
我试图只对某些列子集用0填充Pandas数据框中的任何值。 当我做: import pandas as pd df = pd.DataFrame(data={'a':[1,2,3,None],'b':[4,5,None,6],'c':[None,None,7,8]}) print df df.fillna(value=0, inplace=True) print df 输出: a b c 0 1.0 4.0 NaN 1 2.0 5.0 NaN 2 3.0 NaN 7.0 3 NaN 6.0 8.0 a b c 0 1.0 4.0 0.0 1 2.0 5.0 0.0 2 3.0 0.0 7.0 …
144 python  pandas  dataframe 

18
尝试运行Python脚本时出现“ ImportError:未命名模块”
我正在尝试运行一个脚本,该脚本除其他外将启动python脚本。我收到一个ImportError:没有名为...的模块,但是,如果我启动ipython并通过解释器以相同的方式导入相同的模块,则该模块将被接受。 怎么回事,我该如何解决?我试图了解python如何使用PYTHONPATH,但是我感到非常困惑。任何帮助将不胜感激。

12
从jinja2调用python函数
我正在使用jinja2,并且想使用类似于调用宏的语法来调用python函数作为辅助函数。jinja2似乎旨在阻止我进行函数调用,并坚持要通过将函数复制到模板中作为宏来重复我自己。 有没有简单的方法可以做到这一点?而且,有没有什么方法可以导入整套python函数并使它们从jinja2中进行访问,而无需经历大量的rigamarole(例如编写扩展名)?
144 python  jinja2 



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.