我的问题与这里提出的问题密切相关:使用R从XTS对象拉出本月第一个工作日的回报.
我想提取每个月的第10个数据点,而不是提取每个月的第一天.我怎样才能做到这一点?
我不能在Mavericks 10.9上安装Matplotlib.我有以下错误消息告诉我无法构建freetype:
============================================================================
Edit setup.cfg to change the build options
BUILDING MATPLOTLIB
matplotlib: yes [1.3.1]
python: yes [2.7.6 (default, Apr 9 2014, 11:48:52) [GCC
4.2.1 Compatible Apple LLVM 5.1 (clang-503.0.38)]]
platform: yes [darwin]
REQUIRED DEPENDENCIES AND EXTENSIONS
numpy: yes [version 1.8.1]
dateutil: yes [dateutil was not found. It is required for date
axis support. pip/easy_install may attempt to
install it after matplotlib.]
tornado: yes [tornado was not found. It is required for the
WebAgg backend. pip/easy_install may attempt to
install …Run Code Online (Sandbox Code Playgroud) 我有一个主文件启动多个进程,其中一个进程再次启动多个进程.我在启动嵌套的进程集时遇到问题.
我在一个文件中有以下代码:
# parallel_test.py
import Queue
import multiprocessing
import time
import threading
def worker(q):
while not q.empty():
try:
row = q.get(False)
print row
time.sleep(1)
except Queue.Empty:
break
def main():
print 'creating queue'
q = multiprocessing.Queue()
print 'enqueuing'
for i in range(100):
q.put(i)
num_processes = 15
pool = []
for i in range(num_processes):
print 'launching process {0}'.format(i)
p = multiprocessing.Process(target=worker, args=(q,))
p.start()
pool.append(p)
for p in pool:
p.join()
if __name__ == '__main__':
main()
Run Code Online (Sandbox Code Playgroud)
单独运行此文件python parallel_test.py可正常工作并按预期打印数字.但是从另一个文件作为另一个进程启动它会导致问题.我的主要档案:
# main_loop_test.py
import parallel_test …Run Code Online (Sandbox Code Playgroud) 我正在select()从SQLite数据库做一个,然后是insert():
engine = create_engine('sqlite:///testdb.db')
metadata = MetaData(bind=engine)
test = Table('test', metadata, autoload=True)
# Select all from pending_data
sel = select([test])
res = engine.execute(sel)
print res
# do an insert into pending_data
test.insert()\
.values(info='blah')\
.execute()
Run Code Online (Sandbox Code Playgroud)
当我的代码执行插入行时,我收到此错误:
sqlalchemy.exc.ResourceClosedError: This Connection is closed
Run Code Online (Sandbox Code Playgroud)
但是,如果我将res转换为如下列表:
res = list(engine.execute(sel))
Run Code Online (Sandbox Code Playgroud)
我的代码运行正常.这里发生了什么?
我想生成一系列的回报x,使得回报的标准差为0.03,产品为1 + x = 1.总而言之,回报有两个条件:
1) sd(x) == 0.03
2) prod(1+x) == 1
这是可能的,如果是这样,我怎样才能在R中实现它?
谢谢.
我正在编写一个gensim教程并遇到了一些我不理解的东西.texts是一个嵌套的字符串列表:
In [37]: texts
Out[37]:
[['human', 'machine', 'interface', 'lab', 'abc', 'computer', 'applications'],
['survey', 'user', 'opinion', 'computer', 'system', 'response', 'time'],
['eps', 'user', 'interface', 'management', 'system'],
['system', 'human', 'system', 'engineering', 'testing', 'eps'],
['relation', 'user', 'perceived', 'response', 'time', 'error', 'measurement'],
['generation', 'random', 'binary', 'unordered', 'trees'],
['intersection', 'graph', 'paths', 'trees'],
['graph', 'minors', 'iv', 'widths', 'trees', 'well', 'quasi', 'ordering'],
['graph', 'minors', 'survey']]
Run Code Online (Sandbox Code Playgroud)
并sum(texts,[])给出:
Out[38]:
['human',
'machine',
'interface',
'lab',
'abc',
'computer',
'applications',
'survey',
'user',
'opinion',
'computer',
Run Code Online (Sandbox Code Playgroud)
该列表继续了几行,但我省略了其余的以节省空间.我有两个问题:
1)为什么sum(texts,[])产生结果(即展平嵌套列表)? …
我准备参加考试,这是讲义中的一个问题:
Why Map tasks outputs are written to the local disk and not to HDFS?
Run Code Online (Sandbox Code Playgroud)
这是我的想法:
还有什么其他可能的原因?我的答案合理吗?
我有一个当前位于以下文件夹结构中的应用程序:
myapp/
client/
core/
server/
template_files/
Run Code Online (Sandbox Code Playgroud)
它有一个服务器端和一个客户端组件,当我将代码部署给用户时,我也不想包含服务器端代码。无论client和server需要的core代码运行。
阅读一般 Python 项目结构后,我意识到我应该首先将结构更改为:
myapp/
myapp/
client/
core/
server/
template_files/ (template is only needed by the server)
bin/
setup.py
Run Code Online (Sandbox Code Playgroud)
构建目录和进行代码部署的最佳方法是什么?
我有一个toWords将整数转换为单词的函数
例如toWords(500, tableWords)给fivehundred
我有一个数字数组h = (1..999).to_a,我想通过这个数组并将每个数字转换成一个单词并将其存储在一个新数组中.我目前的尝试是:
h = (1..999).to_a
Lh = h.each do |i| toWords(i, tableWords) end
Run Code Online (Sandbox Code Playgroud)
但是,内容Lh只是从1到999的整数,而不是我的toWords函数的输出.我该怎么做呢?我正在考虑R中的某些内容sapply.
更好的是,如果我的新数组Lh可以有两列,第一列包含数字格式的整数,第二列是单词中的相应数字.
谢谢!
我有这些数字:
login.day$wday
[1] 5 6 7 1 2 3 4
Run Code Online (Sandbox Code Playgroud)
我想将它们映射到:
login.day$wday
[1] 4 5 6 7 1 2 3
Run Code Online (Sandbox Code Playgroud)
每个数字都减 1,如果答案是 0,则将其绕回到 7。这简单得令人尴尬,但我就是想不出来。我的尝试总是给我一个零:
> (login.day$wday + 6) %% 7
[1] 4 5 6 0 1 2 3
Run Code Online (Sandbox Code Playgroud)
更喜欢 R 中的解决方案。是否可以使用模算术,或者我必须使用if statement?
我正在使用 Mac OS X 版本的 Sublime Text 2。函数的自动完成功能非常好 - 但我想知道在调用函数时是否可以有一个参数列表来提醒自己有多少参数和哪些参数需要通过吗?我的功能定义为:
import math
def area_polygon(n, s):
return (0.25 * n * s ** 2) / math.tan(math.pi / n)
Run Code Online (Sandbox Code Playgroud)
如果我在括号内(或作为下拉列表)键入 area_polygon() 后获得参数列表,这将很有用,这样我就知道要传入什么。
谢谢。
python ×6
r ×3
arrays ×1
hadoop ×1
macos ×1
mapreduce ×1
matplotlib ×1
random ×1
ruby ×1
sqlalchemy ×1
sqlite ×1
sublimetext2 ×1
subset ×1
xts ×1