我安装pandas和matplotlib使用pip3 install.然后我运行了这个脚本:
import pandas as pd
import matplotlib.pyplot as plt
data = pd.ExcelFile("Obes-phys-acti-diet-eng-2014-tab.xls")
print (data.sheet_names)
Run Code Online (Sandbox Code Playgroud)
并收到此错误:
dhcp-169-233-172-97:Obesity juliushamilton$ python3 ob.py
Traceback (most recent call last):
File "ob.py", line 4, in <module>
data = pd.ExcelFile("Obes-phys-acti-diet-eng-2014-tab.xls")
File "/Library/Frameworks/Python.framework/Versions/3.4/lib/python3.4/site-packages/pandas/io/excel.py", line 169, in __init__
import xlrd # throw an ImportError if we need to
ImportError: No module named 'xlrd'
Run Code Online (Sandbox Code Playgroud)
为什么xlrd缺少必要的?
我想用Python创建一个具有各种属性和方法的类,但是为了继承列表的功能,我可以将对象追加到对象本身,而不是任何属性.我希望能够说' graph[3]',而不是' graph.node_list[3]'.有没有办法做到这一点?
我在全局安装了Python3,然后创建了一个virtualenv。现在我想把里面的python版本改成Python2.7。尝试安装Python2.7时我只能选择安装到我的硬盘上。如何指定 virtualenv 中的版本?
有没有更多的Pythonic方法来编写下面的代码,以便它迭代某些条件但是还保留了迭代的索引?
def TrieMatching(text, trie):
match_locations = []
location = 0
while text:
if PrefixTrieMatching(text, trie):
match_locations.append(location)
text = text[1:]
location += 1
Run Code Online (Sandbox Code Playgroud) 我有一个 Python 程序,其中包含类定义、方法定义,最后还有一个调用这些方法和类的主方法。当我在终端中运行该程序时,它没有输出任何内容,也没有错误消息。我应该改变程序的编写方式吗?
主要方法在底部。
import re
import random
class node:
def __init__(self, parent, daughters, edge):
self.parent = parent
self.daughters = daughters
self.edge = edge
trie.append(self)
self.index = len(trie) - 1
def BruteForcePatternMatching(text, patterns):
indices = []
for pattern in patterns:
pattern = re.compile(pattern)
indices += pattern.finditer(text)
return indices
def TrieConstruction(patterns, trie):
trie.append(node(0, [], 0))
for pattern in patterns:
currentNode = trie[0]
for base in pattern:
for daughter in currentNode.daughters:
if base == daughter.edge:
currentNode = daughter
break
else:
trie.append(node(currentNode, [], …Run Code Online (Sandbox Code Playgroud) node_name是一个字符串.这不应该返回node_list字典中的键列表,可以迭代吗?为什么错误说它不可迭代?
class Graph:
def __init__(self):
self.node_list = {}
self.number = 0
def node(self, node_name):
if node_name in self.node_list.keys:
...
File "PythonProject2.3.py", line 10, in node
if node_name in self.node_list.keys: #returns list of keys
TypeError: argument of type 'builtin_function_or_method' is not iterable
Run Code Online (Sandbox Code Playgroud) 我试过在MATLAB命令行中运行一个脚本,它说
>> run(ex1)
Undefined function or variable 'ex1'.
>> run(exp1.m)
Undefined variable "exp1" or function "exp1.m".
Run Code Online (Sandbox Code Playgroud)