嗨,我正在学习线性代数与python与Edx课程.(http://nbviewer.ipython.org/github/ULAFF/notebooks/tree/may-14-2014/).
在"02.4.2.10用矩阵向量乘法练习"的第一个框中,代码为:
import generate_problems as gp
print("What is the result of the matrix vector product below?")
p = gp.Problem()
p.new_problem()
Run Code Online (Sandbox Code Playgroud)
generate_problems是Edx教授创建的模块.但是,导入sympy时出错了.
我收到以下错误:
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
<ipython-input-10-79d56e0988cb> in <module>()
----> 1 import generate_problems as gp
2 print("What is the result of the matrix vector product below?")
3
4 p = gp.Problem()
5
/Users/user/Desktop/Course/Python/ipython/notebooks-master/generate_problems.py in <module>()
2 from numpy import matrix
3
----> 4 from sympy import init_printing, Matrix, MatMul, latex, Rational, zeros
5 from IPython.display …Run Code Online (Sandbox Code Playgroud) 我试图添加字典,其中列表中的每个元素都有一个键,列表中的一个后续元素的值和字典格式的后续次数的计数.例如,如果我们有单词列表,['The', 'cat', 'chased', 'the', 'dog']如果键是"the",我希望值为{'dog':1,'cat':1}.整个输出应该是{‘the’: {‘dog’: 1, ‘cat’: 1}, ‘chased’: {‘the’: 1}, ‘cat’: {‘chased’: 1}}.
到目前为止,我的代码可以生成键和值,但不能以字典格式生成字典.有人可以帮忙吗?
我的代码:
line = ['The', 'cat', 'chased', 'the', 'dog']
output = {}
for i, item in enumerate(line):
print(i, item, len(line))
if i != len(line) - 1:
output[item] = line[i+1]=i
print(output)
Run Code Online (Sandbox Code Playgroud)
输出:
{'The': 'cat', 'chased': 'the', 'the': 'dog', 'cat': 'chased'}
Run Code Online (Sandbox Code Playgroud) 嗨,我正在学习数据科学,正在尝试从各个行业的公司列表中制作大数据公司列表。
我有一个大数据公司的行号列表,名为 comp_rows。现在,我正在尝试根据行号使用过滤后的公司创建一个新的数据框。在这里,我需要向现有数据帧添加行,但出现错误。有人可以帮忙吗?
我的数据帧看起来像这样。
company_url company tag_line product data
0 https://angel.co/billguard BillGuard The fastest smartest way to track your spendin... BillGuard is a personal finance security app t... New York City · Financial Services · Security ...
1 https://angel.co/tradesparq Tradesparq The world's largest social network for global ... Tradesparq is Alibaba.com meets LinkedIn. Trad... Shanghai · B2B · Marketplaces · Big Data · Soc...
2 https://angel.co/sidewalk Sidewalk Hoovers (D&B) for the social era Sidewalk helps companies close more sales to …Run Code Online (Sandbox Code Playgroud)