这个主题暂时没有在这里或其他地方得到解决.有没有将SQLAlchemy <Query object>
转换为pandas DataFrame 的解决方案?
Pandas有能力使用,pandas.read_sql
但这需要使用原始SQL.我有两个理由想要避免它:1)我已经拥有使用ORM的一切(这本身就是一个很好的理由)和2)我使用python列表作为查询的一部分(例如:我的模型类.db.session.query(Item).filter(Item.symbol.in_(add_symbols)
在哪里Item
并且add_symbols
是一个列表).这相当于SQL SELECT ... from ... WHERE ... IN
.
有可能吗?
让我的系统准备好自制软件并pip install matplotlib
在成功安装numpy和scipy后使用,我正在成功安装.然后,跑步
$ python
Python 2.7.6 (default, Jan 30 2014, 20:19:23)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.2.79)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> import matplotlib
>>> matplotlib.__version__
'1.1.1'
Run Code Online (Sandbox Code Playgroud)
这是一个非常过时的版本,没有我的程序运行它.我使用pip uninstall matplotlib
并重做它,pip install 'the url for 1.3.1'
它仍然读取版本1.1.1.有没有办法我可以手动删除所有python库,甚至是python本身,并从头开始重启?或者这是一个明显的解决方案吗?
编辑:我正在运行Mac OS X版本10.9.我刚刚通过macports重新安装了python 2.7和scipy,numpy和matplotlib.有没有一种非常基本的方法可以看到,当我import matplotlib
从python环境中调用它时,在哪里?喜欢which
在终端?我开始使用自制软件,但切换到macports以获得更多控制权.这可能是个问题吗?我需要完全删除自制软件吗?
我一开始确实收到了这条消息:
Warning: Error parsing file /Applications/MacPorts/Python 2.7/Python Launcher.app/Contents/MacOS/Python Launcher: Error opening or reading file
但是在运行$ sudo port -f deactivate python27 …
我有一个list
的awaitables
,我想传递给asyncio.AbstractEventLoop
,但我需要节流请求第三方API.
我想避免一些等待传递future
到循环的东西,因为在此期间我阻止我的循环等待.我有什么选择?Semaphores
并ThreadPools
会限制多少并发运行,但是这不是我的问题.我需要将请求限制为100 /秒,但完成请求所需的时间并不重要.
这是一个使用标准库的非常简洁(非)工作示例,它演示了这个问题.这应该以100 /秒的速度节流,但节流速度为116.651 /秒.在asyncio中限制异步请求调度的最佳方法是什么?
工作代码:
import asyncio
from threading import Lock
class PTBNL:
def __init__(self):
self._req_id_seq = 0
self._futures = {}
self._results = {}
self.token_bucket = TokenBucket()
self.token_bucket.set_rate(100)
def run(self, *awaitables):
loop = asyncio.get_event_loop()
if not awaitables:
loop.run_forever()
elif len(awaitables) == 1:
return loop.run_until_complete(*awaitables)
else:
future = asyncio.gather(*awaitables)
return loop.run_until_complete(future)
def sleep(self, secs) -> True:
self.run(asyncio.sleep(secs))
return True
def get_req_id(self) -> int:
new_id = …
Run Code Online (Sandbox Code Playgroud) 有没有办法使用PIL和matplotlib放置EPS或SVG(或任何可缩放矢量格式)的徽标,以便将徽标放在图表上并将最终文件输出为EPS.现在我得到一个非常渲染的图形,因为有一个.png
文件试图转换为EPS格式,其目标是将图像保存为.eps
或.svg
.
我认为这可能是由于后端的限制,我愿意改变我使用的那个.
这是行不通的:
ax1.set_axis_bgcolor('#fafafa')
img = image.imread('./static/images/logo.png')
image_axis = fig.add_axes(ax1.get_position())
image_axis.patch.set_visible(False)
image_axis.yaxis.set_visible(False)
image_axis.xaxis.set_visible(False)
image_axis.set_xlim(0,19.995)
image_axis.set_ylim(0,11.25)
image_axis.imshow(img, extent=(11.79705,18.99525,.238125,1.313625), zorder=-1, alpha=0.15) #need to keep a 5.023 x by y ratio (.4 x .079)
fig.savefig('static/images/graphs/'+filename+'.eps', format='eps', bbox_inches='tight')
Run Code Online (Sandbox Code Playgroud)
任何更新?
我试图在python中使用两个numpy数据数组进行二阶导数.
例如,有问题的数组如下所示:
import numpy as np
x = np.array([ 120. , 121.5, 122. , 122.5, 123. , 123.5, 124. , 124.5,
125. , 125.5, 126. , 126.5, 127. , 127.5, 128. , 128.5,
129. , 129.5, 130. , 130.5, 131. , 131.5, 132. , 132.5,
133. , 133.5, 134. , 134.5, 135. , 135.5, 136. , 136.5,
137. , 137.5, 138. , 138.5, 139. , 139.5, 140. , 140.5,
141. , 141.5, 142. , 142.5, 143. , 143.5, 144. , …
Run Code Online (Sandbox Code Playgroud) 我使用d3-3d插件来绘制3d条形图,但我想在保持旋转的同时添加平移和缩放功能.只是添加d3.zoom()
似乎与d3.drag()
行为冲突- 它似乎是随机的,哪一个优先,并添加了很多"抖动".
var origin = [100, 85], scale = 5, j = 10, cubesData = [];
var alpha = 0, beta = 0, startAngle = Math.PI/6;
var svg = d3.select('svg')
.call(d3.drag()
.on('drag', dragged)
.on('start', dragStart)
.on('end', dragEnd))
.append('g');
var color = d3.scaleOrdinal(d3.schemeCategory20);
var cubesGroup = svg.append('g').attr('class', 'cubes');
var mx, my, mouseX, mouseY;
var cubes3D = d3._3d()
.shape('CUBE')
.x(function(d){ return d.x; })
.y(function(d){ return d.y; })
.z(function(d){ return d.z; })
.rotateY( startAngle)
.rotateX(-startAngle)
.origin(origin)
.scale(scale); …
Run Code Online (Sandbox Code Playgroud)我在这个问题上遇到了很大的问题 - 关于SO的另一个问题是没有解决它的问题:发送原始电子邮件(带附件)到多个收件人
我的代码(有效)很简单:
def send_amazon_email_with_attachment(html, subject, now, pre):
dummy = 'test@example.com'
recipients = ['test1@exampl.ecom', 'test2@example.com', 'test3@example.com']
connS3 = S3Connection('IDENTIFICATION','PASSWORD')
b = connS3.get_bucket('BUCKET_NAME')
key = b.get_key('FILE_NAME.pdf')
temp = key.get_contents_as_string()
msg = MIMEMultipart('alternative')
msg['Subject'] = subject
msg['From'] = 'My Name <test@example.com>'
msg.preamble = 'Multipart message.\n'
part1 = MIMEText(u"Attached is the report", 'plain')
part2 = MIMEText(html, 'html')
msg.attach(part1)
msg.attach(part2)
part = MIMEApplication(temp) #read binary
part.add_header('Content-Disposition', 'attachment', filename='FILE_NAME.pdf')
msg.attach(part)
conn = boto.ses.connect_to_region('us-east-1', aws_access_key_id='AUTH_ID', aws_secret_access_key='AUTH_PW')
for recipient in recipients:
print recipient
msg['To'] = …
Run Code Online (Sandbox Code Playgroud) 我这里有一个JSFiddle.我已经path
使用了一个元素的绘制动画,walkway.js
并且效果很好,但是在绘制完成之后,我想为动画填充svg
路径元素.我试过给路径下面的CSS:
path {
transition: fill 2.0s linear !important;
}
Run Code Online (Sandbox Code Playgroud)
并且在回调函数上(在.draw()
完成时执行)我fill
通过应用类来改变路径的值,testClass
如下所示:
.testClass {
fill:black;
}
Run Code Online (Sandbox Code Playgroud)
这不起作用 - 转换没有被应用,当回调被调用时,它立即"轻弹"黑色 - 根本没有淡入.这种方法适用于普通的html元素,不涉及SVG.我感谢任何帮助.
在一个时间序列(有序元组)中,找到第一次满足标准的最有效方法是什么?
特别是,对于pandas数据框中的列值,确定值何时超过100的最有效方法是什么?
我希望有一个聪明的矢量化解决方案,而不必使用df.iterrows()
.
例如,对于价格或计数数据,当值超过100.即df ['col']> 100.
price
date
2005-01-01 98
2005-01-02 99
2005-01-03 100
2005-01-04 99
2005-01-05 98
2005-01-06 100
2005-01-07 100
2005-01-08 98
Run Code Online (Sandbox Code Playgroud)
但对于潜在的非常大的系列.是迭代(慢)还是有矢量化解决方案更好?
一个df.iterrows()
解决办法是:
for row, ind in df.iterrows():
if row['col'] > value_to_check:
breakpoint = row['value_to_record'].loc[ind]
return breakpoint
return None
Run Code Online (Sandbox Code Playgroud)
但我的问题更多的是关于效率(可能是一个可以很好地扩展的矢量化解决方案).
D3js数据文件大小的限制因素是什么?是文件从服务器加载到客户端需要多长时间?
我正在尝试创建芝加哥的路线图,在那里你可以将鼠标悬停在路上以获得它的名字并突出显示它.该文件的大小为125 MB.我通过删除不必要的信息将其剥离到30 MB,然后将其转换为TopoJSON文件,将其降至5.1 MB.这是一个不守规矩的文件大小?
python ×7
d3.js ×2
matplotlib ×2
pandas ×2
svg ×2
amazon-ses ×1
arrays ×1
boto ×1
css ×1
email ×1
eps ×1
html ×1
javascript ×1
jquery ×1
json ×1
mime-types ×1
numpy ×1
python-3.x ×1
scipy ×1
sqlalchemy ×1
throttling ×1
topojson ×1