title stringlengths 10 172 | question_id int64 469 40.1M | question_body stringlengths 22 48.2k | question_score int64 -44 5.52k | question_date stringlengths 20 20 | answer_id int64 497 40.1M | answer_body stringlengths 18 33.9k | answer_score int64 -38 8.38k | answer_date stringlengths 20 20 | tags list |
|---|---|---|---|---|---|---|---|---|---|
Get all google knowledge graph instances of a certain type | 37,875,697 | <p>I'm trying to get all instances of a certain type from google knowledge graph, so I'm using the <a href="https://developers.google.com/knowledge-graph/" rel="nofollow">Knowledge Graph Search API</a>. This is the request:</p>
<pre><code>r = requests.get("https://kgsearch.googleapis.com/v1/entities:search",params=dic... | 0 | 2016-06-17T07:34:08Z | 39,026,655 | <p>Where is the 'query' parameter ? The types="TVSeries" is correct.</p>
<p>Please see the API reference <a href="https://developers.google.com/knowledge-graph/reference/rest/v1/" rel="nofollow">https://developers.google.com/knowledge-graph/reference/rest/v1/</a></p>
| 0 | 2016-08-18T20:06:25Z | [
"python",
"rest",
"google-knowledge-graph"
] |
problems in importing theano | 37,875,747 | <p>I am running python on windows but when I import theano, I come across this problem:</p>
<pre><code>import theano
</code></pre>
<blockquote>
<p>WARNING (theano.configdefaults): g++ not detected ! Theano will be
unable to execute optimized C-implementations (for both CPU and GPU)
and will default to Python im... | 0 | 2016-06-17T07:36:58Z | 37,875,925 | <p>This isn't a <strong>problem</strong>, it's a <strong>WARNING</strong> as it very clearly says. It just means that you don't have g++ installed on your system and <code>theano</code> won't be able to apply optimizations. </p>
<p>To remove this, just install <code>g++</code> or do as it very clearly says: </p>
<bl... | 0 | 2016-06-17T07:46:22Z | [
"python",
"theano"
] |
How to iterate over a large text file(906.2MB) in Python? | 37,875,761 | <p>This is the code snippet I am using</p>
<pre><code>tweets_data=[]
with open('/home/surya/tweet2.txt','r') as f:
while True:
next_n_lines= list(islice(f,10000))
if not next_n_lines:
break
for line in next_n_lines:
try:
tweet= json.loads(line)
tweets_da... | 1 | 2016-06-17T07:37:47Z | 37,876,038 | <p>If the memory usage is a problem, iterate over the file itself:</p>
<pre><code>for line in f:
# your code here
</code></pre>
<p>If you have a lot of memory, iterate over the <code>.readlines()</code> list:</p>
<pre><code>for line in f.readlines():
# your code here
</code></pre>
| 2 | 2016-06-17T07:51:49Z | [
"python",
"twitter"
] |
z3py examples do not to work on macOS | 37,875,813 | <p>I can not get any of the z3py examples to work. I was able to install it successful using the instructions from the README on github. I successfully updated my python path to point to the appropriate directory. Furthermore, I was able to successfully import z3, but I get an error every time I declare a variable. The... | 1 | 2016-06-17T07:40:43Z | 37,998,091 | <p>There is something wrong with your local installation, either of Python or Z3.</p>
<p>I just compiled Z3 on my Mac and ran the example <code>test.py</code> you provided with no problems. I'm using OS X 10.9.5 with Python 2.7.11 and the current master version of Z3 (commit 41edf5f). The exact instructions I used w... | 0 | 2016-06-23T17:24:09Z | [
"python",
"z3",
"z3py"
] |
Flawed contour detection in an image python opencv | 37,875,928 | <p>I would like to detect the contour of the giant black blob in the following image:</p>
<p><a href="http://i.stack.imgur.com/aLD8r.png" rel="nofollow"><img src="http://i.stack.imgur.com/aLD8r.png" alt="enter image description here"></a></p>
<p>So I used Canny edge detection to find the edges using the following cod... | 0 | 2016-06-17T07:46:24Z | 37,877,914 | <p>The problem is in your workflow.</p>
<p>Remove the Canny operator from your processing. It will give you an edge image from your blobs. Once you process the Canny image with contourFinder it will treat the edge segments as objects. Your largest contour will be of the longest edge segment.
If you zoom into your Cann... | -1 | 2016-06-17T09:27:14Z | [
"python",
"opencv",
"matplotlib",
"computer-vision",
"edge-detection"
] |
Best practice for rendering data into html with ajax | 37,875,967 | <p>I am trying to load some details of an item on-click of that item in some already defined div. I have 2 ways to do that.</p>
<p>Note: I am using python/django as backend, and jquery in frontend</p>
<p>I. My First way</p>
<p><strong>Views.py</strong></p>
<pre><code>def get_item_data(id):
obj = MyClass.objects... | 4 | 2016-06-17T07:48:16Z | 37,885,432 | <p>I prefer to separate the template, business, and js logic as much as possible. It keeps it more pythonic and more within django design principles. This is indeed quite similar to your first method, but uses an html template, rather than printing html to a string in your view.</p>
<p>views.py</p>
<pre><code>def get... | 0 | 2016-06-17T15:37:14Z | [
"javascript",
"jquery",
"python",
"ajax",
"django"
] |
Best practice for rendering data into html with ajax | 37,875,967 | <p>I am trying to load some details of an item on-click of that item in some already defined div. I have 2 ways to do that.</p>
<p>Note: I am using python/django as backend, and jquery in frontend</p>
<p>I. My First way</p>
<p><strong>Views.py</strong></p>
<pre><code>def get_item_data(id):
obj = MyClass.objects... | 4 | 2016-06-17T07:48:16Z | 37,888,467 | <p>very rough draft, from what I actually use, which is <strong>Handlebar</strong>:</p>
<p>in Django template. <strong>head</strong>:</p>
<pre><code><!--Handlebar templates start-->
{% include "app/mydiv.handlebars.html" %}
<!--Handlebar templates end-->
</code></pre>
<p><strong>app/mydiv.handlebars.html... | 0 | 2016-06-17T18:51:18Z | [
"javascript",
"jquery",
"python",
"ajax",
"django"
] |
Passing Selenium Webdriver in a parameter. Is it possible in Python? | 37,875,976 | <p>I'm new to Python.</p>
<p>The aim of my script is to parse Web page with Selenium Webdriver. There are two subtasks. The first task I've made with no errors. But all script was without any function.</p>
<p>Now I'm trying to solve the second task in a little bit complicated way. I want to use functions.</p>
<p>The... | 1 | 2016-06-17T07:48:43Z | 37,876,156 | <p>Yes you can pass a <code>WebDriver</code> as a parameter to any <code>function</code> or <code>method</code>. The answer on your second question is also yes. A single <code>WebDriver</code> could be shared throughout your entire application if that's what you want to do.
If this wasn't possible a very popular design... | 2 | 2016-06-17T07:58:56Z | [
"python",
"selenium",
"selenium-webdriver",
"automated-tests",
"parameter-passing"
] |
How to know if a variable is in an attribute of an object in a list? | 37,876,007 | <p>To check if a variable is in a list, I know that one can use <code>if variable in list</code>. In my instance, I have a list of objects, all of which have the attribute "id", I want to check if an object in a list has a specific ID, but I'm not sure how I would go about doing that.</p>
<p>I already tried looking th... | 1 | 2016-06-17T07:50:00Z | 37,876,103 | <p>You can use list comprehension to get a list of all ids and the check if your <code>id</code> is <code>in</code> that list:
</p>
<pre><code>if my_id in [o.id for o in my_list]:
do_something()
</code></pre>
<p>Or you can use the <a href="https://docs.python.org/3.5/library/functions.html#any" rel="nofollow"><co... | 1 | 2016-06-17T07:55:32Z | [
"python",
"list",
"object",
"attributes"
] |
How to know if a variable is in an attribute of an object in a list? | 37,876,007 | <p>To check if a variable is in a list, I know that one can use <code>if variable in list</code>. In my instance, I have a list of objects, all of which have the attribute "id", I want to check if an object in a list has a specific ID, but I'm not sure how I would go about doing that.</p>
<p>I already tried looking th... | 1 | 2016-06-17T07:50:00Z | 37,876,309 | <p>it is a way to search an specific object inside a list of same objects. I know you are using python, i dont know python but i wrote it in other code. hope it helps. </p>
<blockquote>
<p>In my instance, I have a list of objects, all of which have the
attribute "id"</p>
</blockquote>
<p>List and Object.getId()<... | 0 | 2016-06-17T08:07:16Z | [
"python",
"list",
"object",
"attributes"
] |
How to know if a variable is in an attribute of an object in a list? | 37,876,007 | <p>To check if a variable is in a list, I know that one can use <code>if variable in list</code>. In my instance, I have a list of objects, all of which have the attribute "id", I want to check if an object in a list has a specific ID, but I'm not sure how I would go about doing that.</p>
<p>I already tried looking th... | 1 | 2016-06-17T07:50:00Z | 37,877,001 | <p>So if you want only to check if there is any item in the list that has a specific attribute you can do this:</p>
<pre><code>if any(hasattr(i, str(variable)) for i in your_list):
do_something()
</code></pre>
<p>And if you want to get the all items that contains this attribute you can do something like that:</p>
... | 1 | 2016-06-17T08:46:23Z | [
"python",
"list",
"object",
"attributes"
] |
What happens when you inherent from a module instead of a class in Python? | 37,876,318 | <p>I recently came across <a href="http://stackoverflow.com/questions/14583761/typeerror-module-init-takes-at-most-2-arguments-3-given">this question</a>.</p>
<blockquote>
<pre><code>import Object
class Visitor(Object):
def __init__(self):
super(Visitor,self).__init__()
def visit(self, obj):
... | 2 | 2016-06-17T08:07:29Z | 37,876,860 | <p>To find out where you've gone wrong, you don't really need to look at the error message in this case, it's pretty clear from the code itself.</p>
<p><code>import foo</code></p>
<p>Always means that foo is a module (as opposed to <code>from foo import bar</code> where <code>bar</code> can be a module, class, functi... | 0 | 2016-06-17T08:38:30Z | [
"python",
"class",
"inheritance",
"module",
"python-internals"
] |
What happens when you inherent from a module instead of a class in Python? | 37,876,318 | <p>I recently came across <a href="http://stackoverflow.com/questions/14583761/typeerror-module-init-takes-at-most-2-arguments-3-given">this question</a>.</p>
<blockquote>
<pre><code>import Object
class Visitor(Object):
def __init__(self):
super(Visitor,self).__init__()
def visit(self, obj):
... | 2 | 2016-06-17T08:07:29Z | 37,878,215 | <p>If you put an object called <code>BaseClass</code> in the inheritance list, then the interpreter will call this internally:</p>
<pre><code>type(BaseClass).__init__(cls, name_of_subclass, (BaseClass,), dict_of_subclass)
# or simpler
type(BaseClass)(name_of_subclass, (BaseClass,), dict_of_subclass)
</code></pre>
<p>... | 3 | 2016-06-17T09:39:28Z | [
"python",
"class",
"inheritance",
"module",
"python-internals"
] |
How to add element to matrix? | 37,876,366 | <p>I saw many posts on the same issue but using <code>numpy.array</code>, whereas here I am talking about <code>numpy.matrix</code>. How can I add an element to a matrix? </p>
<p>For example: </p>
<pre><code>my_matrix = [[1 2 3 4 5]]
</code></pre>
<p>How can I make it: </p>
<pre><code>my_matrix = [[1 2 3 4 5 6]]?
<... | 1 | 2016-06-17T08:10:08Z | 37,876,482 | <p>Since matrices are very constrained in numpy (and probably you would be better off if you avoid them), they are very picky compared to regular numpy arrays. You can use a bit verbose command</p>
<pre><code>np.concatenate((my_matrix,[[6]]),1)
</code></pre>
<p>or use the horzcat</p>
<pre><code>np.c_[my_matrix,[[6]]... | 3 | 2016-06-17T08:17:25Z | [
"python",
"numpy",
"matrix"
] |
How to add element to matrix? | 37,876,366 | <p>I saw many posts on the same issue but using <code>numpy.array</code>, whereas here I am talking about <code>numpy.matrix</code>. How can I add an element to a matrix? </p>
<p>For example: </p>
<pre><code>my_matrix = [[1 2 3 4 5]]
</code></pre>
<p>How can I make it: </p>
<pre><code>my_matrix = [[1 2 3 4 5 6]]?
<... | 1 | 2016-06-17T08:10:08Z | 37,876,754 | <p>So, here's what I did. </p>
<pre><code>>>>n = np.matrix('1,2,3,4,5')
>>> n
matrix([[1, 2, 3, 4, 5]])
>>>np.insert(n,5,6)
matrix([[1, 2, 3, 4, 5, 6]])
</code></pre>
<p>For multidimensional arrays, you'll have to mention the horizontal index as well as the vertical index, otherwise the res... | 0 | 2016-06-17T08:32:50Z | [
"python",
"numpy",
"matrix"
] |
Numpy interfering with namespace | 37,876,397 | <pre><code>import numpy as np
def f(x):
x /= 10
data = np.linspace(0, 1, 5)
print data
f(data)
print data
</code></pre>
<p>Output on my system (debian 8, Python 2.7.9-1, numpy 1:1.8.2-2)</p>
<pre><code>[ 0. 0.25 0.5 0.75 1. ]
[ 0. 0.025 0.05 0.075 0.1 ]
</code></pre>
<p>Normally I would expect <code>... | 3 | 2016-06-17T08:11:46Z | 37,877,900 | <blockquote>
<p>Normally I would expect data to stay untouched when passing it to a function as this has its own separate namespace.</p>
</blockquote>
<p><code>x</code> in the function and <code>data</code> at the module level are two names for the <em>same</em> object. Since that object is mutable, any changes mad... | 3 | 2016-06-17T09:26:42Z | [
"python",
"matplotlib",
"namespaces"
] |
Scrapy process.crawl() to export data to json | 37,876,514 | <p>This might be a subquestion of <a href="http://stackoverflow.com/questions/34382356/passing-arguments-to-process-crawl-in-scrapy-python">Passing arguments to process.crawl in Scrapy python</a> but the author marked the answer (that doesn't answer the subquestion i'm asking myself) as a satisfying one.</p>
<p>Here's... | 3 | 2016-06-17T08:19:12Z | 37,887,227 | <p>You need to specify it on the settings:</p>
<pre><code>process = CrawlerProcess({
'FEED_URI': 'file:///tmp/export.json',
})
process.crawl(MySpider)
process.start()
</code></pre>
| 2 | 2016-06-17T17:34:32Z | [
"python",
"json",
"scrapy",
"web-crawler"
] |
How can I split a column in a specific range? | 37,876,523 | <p>I'm working with proteins trajectory and I've got a long data frame. (File with one column and 600.000 lines. </p>
<p>This is and example: </p>
<pre><code>100
100
0
100
100
...
n=600.000
</code></pre>
<p>What I wish is to split this data every 3000 lines, creating a new column beside like this example: </p>
<pre... | 1 | 2016-06-17T08:19:41Z | 37,876,797 | <p>In R you may just may add a <code>dim</code> attribute:</p>
<pre><code>dim(your_vector) <- c(3000, 600000/3000)
</code></pre>
<p>It will change an object class to <code>matrix</code>, so if you need data frame, you will need:</p>
<pre><code>df <- data.frame(your_vector)
</code></pre>
| 3 | 2016-06-17T08:35:10Z | [
"python",
"bash",
"file",
"shell"
] |
How can I split a column in a specific range? | 37,876,523 | <p>I'm working with proteins trajectory and I've got a long data frame. (File with one column and 600.000 lines. </p>
<p>This is and example: </p>
<pre><code>100
100
0
100
100
...
n=600.000
</code></pre>
<p>What I wish is to split this data every 3000 lines, creating a new column beside like this example: </p>
<pre... | 1 | 2016-06-17T08:19:41Z | 37,876,808 | <p>I am not sure I understand your example, but you should be able to use a combination of split and paste:</p>
<pre><code>$ cat filetosplit
1
2
3
4
5
6
7
8
9
10
$ split filetosplit "split." -l 3 -d ; paste split*
1 4 7 10
2 5 8
3 6 9
</code></pre>
<p>The split command will... | 4 | 2016-06-17T08:35:38Z | [
"python",
"bash",
"file",
"shell"
] |
How can I split a column in a specific range? | 37,876,523 | <p>I'm working with proteins trajectory and I've got a long data frame. (File with one column and 600.000 lines. </p>
<p>This is and example: </p>
<pre><code>100
100
0
100
100
...
n=600.000
</code></pre>
<p>What I wish is to split this data every 3000 lines, creating a new column beside like this example: </p>
<pre... | 1 | 2016-06-17T08:19:41Z | 37,876,902 | <p>With <code>awk</code>:</p>
<pre><code>awk -v n=5 '{data[(NR-1)%n FS int((NR-1)/n)]=$0}
END {cols=NR/n;
for (i=0;i<n;i++) {
for (j=0;j<cols;j++)
printf "%s%s", data[i FS j], FS}
print ""
}
}'
</code><... | 1 | 2016-06-17T08:40:55Z | [
"python",
"bash",
"file",
"shell"
] |
Unchangeable script in Ubuntu | 37,876,618 | <p>My client wants to setup a script/file in Ubuntu in one of my client's contractors system to monitor his work/sites visited etc as long as he is in office.</p>
<p>His contractor will have root access in the system, so how can we make sure that the file cant be changed ? Deleting wont help him as his boss will know ... | -1 | 2016-06-17T08:25:46Z | 37,876,877 | <p>The best solution would be <em>not</em> to do this.</p>
<p>Now I don't know about your country's legislation, but in mine, any solution of this sort would be highly illegal. If the client is worried about the contractor, there would be other means of "monitoring" them.</p>
<ul>
<li>Daily reporting</li>
<li>Set up ... | 0 | 2016-06-17T08:39:43Z | [
"java",
"python",
"ubuntu"
] |
Unchangeable script in Ubuntu | 37,876,618 | <p>My client wants to setup a script/file in Ubuntu in one of my client's contractors system to monitor his work/sites visited etc as long as he is in office.</p>
<p>His contractor will have root access in the system, so how can we make sure that the file cant be changed ? Deleting wont help him as his boss will know ... | -1 | 2016-06-17T08:25:46Z | 37,877,043 | <p>Assuming you have legal issues taken care of, your only hope seem to be <a href="https://en.wikipedia.org/wiki/Encryption" rel="nofollow">Encryption</a> and <a href="https://en.wikipedia.org/wiki/Security_through_obscurity" rel="nofollow">Security through Obscurity</a>.</p>
<p>Go for languages which are tougher to ... | 2 | 2016-06-17T08:48:15Z | [
"java",
"python",
"ubuntu"
] |
Using pandas isin with selecting dates | 37,876,652 | <p>A similar question like mine has been asked before, but unfortunately the answer was unable to help my problem.
I have two sets of data columns: 1. the first is generated as follows:</p>
<pre><code>t = pd.bdate_range(start='2016-05-16', end='2016-06-15')
</code></pre>
<p>This gives: </p>
<pre><code>DatetimeIndex:... | -1 | 2016-06-17T08:27:06Z | 37,876,709 | <p>You are looking for <code>v.weekday < 5</code>.</p>
<pre><code>v = pd.date_range(start='2016-05-16', end='2016-06-15', freq='2H')
v[v.weekday < 5]
DatetimeIndex(['2016-05-16 00:00:00', '2016-05-16 02:00:00',
'2016-05-16 04:00:00', '2016-05-16 06:00:00',
'2016-05-16 08:00:00', '2... | 0 | 2016-06-17T08:30:24Z | [
"python",
"date",
"pandas"
] |
Splitting Nested List at every ['-1'] | 37,876,741 | <p>If I have a nested list like this:</p>
<pre><code>[['01'], ['02'], ['-1'], ['03'], ['04']]
</code></pre>
<p>Is there a way I split this nested list at every <code>['-1']</code>?</p>
<p>So that it looks like this:</p>
<pre><code>[[['01'], ['02']], [['03'], ['04']]]
</code></pre>
<p>Any sort of help would be appr... | 1 | 2016-06-17T08:32:02Z | 37,876,780 | <p>Try this,</p>
<pre><code>lists = [['01'], ['02'], ['-1'], ['03'], ['04'], ['-1'], ['05'], ['-1']]
results = list()
prev_idx = 0
for idx, l in enumerate(lists):
if l == ['-1']:
results.append(lists[prev_idx:idx])
prev_idx = idx+1
if prev_idx <= idx: # the last group might be [] as shown ... | 1 | 2016-06-17T08:34:11Z | [
"python",
"list"
] |
Splitting Nested List at every ['-1'] | 37,876,741 | <p>If I have a nested list like this:</p>
<pre><code>[['01'], ['02'], ['-1'], ['03'], ['04']]
</code></pre>
<p>Is there a way I split this nested list at every <code>['-1']</code>?</p>
<p>So that it looks like this:</p>
<pre><code>[[['01'], ['02']], [['03'], ['04']]]
</code></pre>
<p>Any sort of help would be appr... | 1 | 2016-06-17T08:32:02Z | 37,876,955 | <p>A good old fashioned loop should do it:</p>
<pre><code>l = [['01'], ['02'], ['-1'], ['03'], ['04']]
new = []
current = [] # Build a new list here
for i, item in enumerate(l):
if item != ['-1']:
current.append(item)
if i == len(l) - 1: # If the item is the last in the list
new.app... | 0 | 2016-06-17T08:43:43Z | [
"python",
"list"
] |
Splitting Nested List at every ['-1'] | 37,876,741 | <p>If I have a nested list like this:</p>
<pre><code>[['01'], ['02'], ['-1'], ['03'], ['04']]
</code></pre>
<p>Is there a way I split this nested list at every <code>['-1']</code>?</p>
<p>So that it looks like this:</p>
<pre><code>[[['01'], ['02']], [['03'], ['04']]]
</code></pre>
<p>Any sort of help would be appr... | 1 | 2016-06-17T08:32:02Z | 37,877,040 | <p>Seems like a usecase for <em>groupby</em></p>
<pre><code>>>> from itertools import groupby
>>> l = [['01'], ['02'], ['-1'], ['03'], ['04'], ['-1'], ['05'], ['06']]
>>> [list(g) for k,g in groupby(l, lambda x: x == ['-1']) if not k]
[[['01'], ['02']], [['03'], ['04']], [['05'], ['06']]... | 1 | 2016-06-17T08:48:11Z | [
"python",
"list"
] |
Splitting Nested List at every ['-1'] | 37,876,741 | <p>If I have a nested list like this:</p>
<pre><code>[['01'], ['02'], ['-1'], ['03'], ['04']]
</code></pre>
<p>Is there a way I split this nested list at every <code>['-1']</code>?</p>
<p>So that it looks like this:</p>
<pre><code>[[['01'], ['02']], [['03'], ['04']]]
</code></pre>
<p>Any sort of help would be appr... | 1 | 2016-06-17T08:32:02Z | 37,877,061 | <p>You can use <a href="https://docs.python.org/3.4/library/itertools.html#itertools.groupby" rel="nofollow"><code>itertools.groupby</code></a> to group at every occurrence of your split value (here <code>['-1']</code>). <code>if not k</code> ensures that we leave out the split value itself. </p>
<pre><code>orig = [['... | 2 | 2016-06-17T08:49:05Z | [
"python",
"list"
] |
Trouble with identifying a value in a drop down (Selenium Python) | 37,876,853 | <p>I'm using Selenium (Python) to select a value from a drop down list, but I'm having some problems.</p>
<p>When I use Selenium IDE, it identifies the drop down as a button, as follows :</p>
<pre><code> driver.find_element_by_xpath("(//button[@type='button'])[2]")
</code></pre>
<p>I then tried to select a value ... | 1 | 2016-06-17T08:37:46Z | 37,876,973 | <p>The element you are getting with your <code>Xpath</code> is a <code>button</code>. You cannot use <code>Select</code> with buttons. You want to get the <code>select</code> element.
Try this:</p>
<pre><code>Select(driver.find_element_by_xpath("//select[@ng-model='newAccount.timeZoneId']")).select_by_visible_text("Af... | 2 | 2016-06-17T08:44:43Z | [
"python",
"selenium"
] |
Compare every item of a list to every other item in a list checking if they belong to defined intervals | 37,876,857 | <p>I have two lists a & b, with equal length N and values between [0, 1]. I want to check each pair of the two lists with same index (a[0] with b[0], a[1] with b[1] and so on) and based on their values, measure how many times the belong as pair to one of the following states. </p>
<p>Each element of the list can b... | 0 | 2016-06-17T08:38:05Z | 37,877,121 | <p>If I get this right, given your two lists, you need to find out how many "pairs" contain items from the same interval.</p>
<p>Here's a little trick you could use:
Multiply by ten, then use <code>int()</code>to get rid of the decimal part.</p>
<pre><code>a = [.11, .22, .33, .55]
b = [.16, .28, .38, .60]
pairs = 0
... | 2 | 2016-06-17T08:51:58Z | [
"python",
"list"
] |
Compare every item of a list to every other item in a list checking if they belong to defined intervals | 37,876,857 | <p>I have two lists a & b, with equal length N and values between [0, 1]. I want to check each pair of the two lists with same index (a[0] with b[0], a[1] with b[1] and so on) and based on their values, measure how many times the belong as pair to one of the following states. </p>
<p>Each element of the list can b... | 0 | 2016-06-17T08:38:05Z | 37,878,172 | <p>For the numpy version a similar machinery without an explicit loop.</p>
<pre><code>import numpy as np
a = [.11, .22, .33, .55]
b = [.16, .28, .38, .60]
Ind = (10*np.array([a,b])).astype(int)
State_mat = np.zeros((12,12),dtype=int)
State_mat[Ind[0],Ind[1]] = 1
State_mat.tolist()
</code></pre>
<p>gives the same out... | 0 | 2016-06-17T09:37:29Z | [
"python",
"list"
] |
number lists in Python | 37,876,935 | <p>I am allowing choices to user and if the user's choice isn't a number then the script should show an error message: "Please try again".</p>
<pre><code>def prompt(message, choices):
while True:
choice = input(message)
if choice in choices:
return choice
print("That was not a valid answer. please ... | 0 | 2016-06-17T08:42:59Z | 37,877,117 | <pre><code>import sys
def prompt(message, choices):
while True:
choice = input(message)
if choice in choices and type(choice) == int:
return choice
else:
sys.exit("That was not a valid answer. please retry\n"
"valid answers are: {}".format(choices))
def aORp():... | 0 | 2016-06-17T08:51:42Z | [
"python"
] |
number lists in Python | 37,876,935 | <p>I am allowing choices to user and if the user's choice isn't a number then the script should show an error message: "Please try again".</p>
<pre><code>def prompt(message, choices):
while True:
choice = input(message)
if choice in choices:
return choice
print("That was not a valid answer. please ... | 0 | 2016-06-17T08:42:59Z | 37,877,135 | <p>What you need is to use <code>float</code></p>
<pre><code>float(choice)
</code></pre>
<p>It'll return <code>True</code> if choice is a number. It'll return an error if choice is not a number.</p>
<p>More info there : </p>
<p><a href="http://stackoverflow.com/questions/354038/how-do-i-check-if-a-string-is-a-numbe... | 0 | 2016-06-17T08:52:38Z | [
"python"
] |
number lists in Python | 37,876,935 | <p>I am allowing choices to user and if the user's choice isn't a number then the script should show an error message: "Please try again".</p>
<pre><code>def prompt(message, choices):
while True:
choice = input(message)
if choice in choices:
return choice
print("That was not a valid answer. please ... | 0 | 2016-06-17T08:42:59Z | 37,877,342 | <p>You can write a function which inputs a number and then converts it to an int, but doesn't work if it is anything else. If I understand you right, you only want the user to be able to enter an int but not a string. If you only want to check that, an example is:</p>
<pre><code>def prompt (message):
try:
... | 0 | 2016-06-17T09:01:38Z | [
"python"
] |
Python Graphene Interface + InlineFragment seems doesn't resolve ObjectType fields | 37,876,979 | <p>I try to resolve ObjectType fields with InlineFragment on a ObjectType that inherit from an Interface but it seems doesn't work.</p>
<p>Here is my schema:</p>
<pre><code>@schema.register
class BundleInterface(graphene.Interface):
id = graphene.ID()
identifier = graphene.String()
name = graphene.String(... | 0 | 2016-06-17T08:44:58Z | 37,941,024 | <p>I found the issue. I made a pull request on graphql-core: <a href="https://github.com/graphql-python/graphql-core/pull/68" rel="nofollow">https://github.com/graphql-python/graphql-core/pull/68</a></p>
| 1 | 2016-06-21T09:48:52Z | [
"python",
"interface",
"sqlalchemy",
"graphenedb"
] |
Cannot import QtWebKitWidgets in PyQt5 | 37,876,987 | <p>I've recently upgraded PyQt5 from 5.5.1 to 5.6.0 using the Windows 32-bit installer here: <a href="https://www.riverbankcomputing.com/software/pyqt/download5" rel="nofollow">https://www.riverbankcomputing.com/software/pyqt/download5</a>. I've also upgraded my python from 3.4 to 3.5.</p>
<p>When I run my old code (w... | 2 | 2016-06-17T08:45:23Z | 37,877,273 | <p><code>QtWebKit</code> got deprecated upstream in Qt 5.5 and <a href="http://wiki.qt.io/New_Features_in_Qt_5.6#Removed_Modules" rel="nofollow">removed in 5.6</a>.</p>
<p>You may want to switch to <a href="http://pyqt.sourceforge.net/Docs/PyQt5/introduction.html#module-PyQt5.QtWebEngineWidgets" rel="nofollow">PyQt5.Q... | 4 | 2016-06-17T08:58:55Z | [
"python",
"qt",
"pyqt5"
] |
python function string parameter convert to variable name | 37,877,014 | <p>I'm rather new to Python and programming in general, so I apologise in advance if my terminology is incorrect.</p>
<pre><code>hue_alert_delay = 0
def delays(name, delay):
global hue_alert_delay
if name == 'hue_alert_delay':
for i in range(0, delay):
hue_alert_delay += 1
tim... | 0 | 2016-06-17T08:46:52Z | 37,877,104 | <p>Use a dict:</p>
<pre><code>values = {
'hue_alert_delay': 0
}
def delays(name, delay):
values[name] += 1
</code></pre>
<p>Whenever you feel like using "variable variables", what you most likely really want is a dict storing key-value associations. Yes, there <em>are</em> other ways to do literally what you... | 1 | 2016-06-17T08:50:55Z | [
"python",
"string",
"function",
"variables"
] |
python function string parameter convert to variable name | 37,877,014 | <p>I'm rather new to Python and programming in general, so I apologise in advance if my terminology is incorrect.</p>
<pre><code>hue_alert_delay = 0
def delays(name, delay):
global hue_alert_delay
if name == 'hue_alert_delay':
for i in range(0, delay):
hue_alert_delay += 1
tim... | 0 | 2016-06-17T08:46:52Z | 37,877,124 | <p>Use a dictionary like so. </p>
<pre><code>vars = {'hue_alert_delay':0}
def delays(name, delay):
for i in range(0, delay):
vars[name] += 1
time.sleep(1)
vars[name] = 0
</code></pre>
<p>You can also use <code>globals()[name]</code> but I won't recommend it. </p>
| 0 | 2016-06-17T08:52:12Z | [
"python",
"string",
"function",
"variables"
] |
python function string parameter convert to variable name | 37,877,014 | <p>I'm rather new to Python and programming in general, so I apologise in advance if my terminology is incorrect.</p>
<pre><code>hue_alert_delay = 0
def delays(name, delay):
global hue_alert_delay
if name == 'hue_alert_delay':
for i in range(0, delay):
hue_alert_delay += 1
tim... | 0 | 2016-06-17T08:46:52Z | 37,877,131 | <p>Use a dictionary:</p>
<pre><code>vars = {'hue_alert_delay':0}
def delays(name, delay):
for i in range(delay):
vars[name] += 1
time.sleep(1)
vars[name] = 0
delays('hue_alert_delay', 60)
</code></pre>
| 0 | 2016-06-17T08:52:28Z | [
"python",
"string",
"function",
"variables"
] |
Update current version on AWS Elastic Beanstalk | 37,877,051 | <p>I have a python (Django) application on Amazon AWS using Elastic Beanstalk.</p>
<p>It's all ok, and my server is ok with my last application version.
Now I have to update a file into my application so I followed this steps:</p>
<ul>
<li>I downloaded last app version from Application Versions section. I download th... | 0 | 2016-06-17T08:48:38Z | 37,880,800 | <p>Maybe because an error occurs when it try to run deploy script with the new zip file.</p>
<p>You can see that error in <strong>eb-activity logs</strong> and fixed it and deploy it again I think this problem will be solved. </p>
<p><a href="http://docs.aws.amazon.com/elasticbeanstalk/latest/dg/using-features.loggin... | 0 | 2016-06-17T11:47:36Z | [
"python",
"django",
"amazon-web-services",
"elastic-beanstalk"
] |
Manually Delete Python Package Path | 37,877,146 | <p>I manually removed <code>/Library/Python/2.7/site-packages/google</code> through terminal (rm), however it still seems I can import the package in python 2.7.</p>
<p>I am able to run <code>import google</code> but when I print <code>google.__path__</code> it displays <code>['/Library/Python/2.7/site-packages/google... | 0 | 2016-06-17T08:52:59Z | 37,919,508 | <p>Try starting python in verbose mode. This will show from where packages are imported. Since the output can overflow, write it to a text file.</p>
<pre><code>python -v 2>&1 | tee out.txt
>>import google
>>exit()
</code></pre>
<p>Open <code>out.txt</code> and see from where google package is bein... | 0 | 2016-06-20T09:56:39Z | [
"python",
"python-2.7"
] |
Python multiple files variables and functions | 37,877,251 | <p>I'm trying to split my python code into a few files :</p>
<p><strong><code>file1.py</code></strong></p>
<pre><code>from file2 import *
var1 = 7
func_file2()
</code></pre>
<p><strong><code>file2.py</code></strong></p>
<pre><code>def func_file2():
var2 = var1
</code></pre>
<p>So it says:</p>
<pre><code>Name... | 0 | 2016-06-17T08:57:44Z | 37,877,358 | <p>func_file2 doesn't have visibility of your variable var1 because when it's defined the var1 doesn't exist in any scope so the closure doesn't work.</p>
<p>When you write modules in python, follow the principle of cohesion that means that if a function in a module uses a variable from another module something can be... | 0 | 2016-06-17T09:02:26Z | [
"python"
] |
Python multiple files variables and functions | 37,877,251 | <p>I'm trying to split my python code into a few files :</p>
<p><strong><code>file1.py</code></strong></p>
<pre><code>from file2 import *
var1 = 7
func_file2()
</code></pre>
<p><strong><code>file2.py</code></strong></p>
<pre><code>def func_file2():
var2 = var1
</code></pre>
<p>So it says:</p>
<pre><code>Name... | 0 | 2016-06-17T08:57:44Z | 37,877,375 | <p><code>var1</code> is defined in <code>file1</code> but you are referencing it in <code>file2</code>. You could move <code>var1</code> to <code>file2</code> to fix the error. </p>
<p><strong>file1.py</strong></p>
<pre><code>from file2 import *
func_file2()
</code></pre>
<p><strong>file2.py</strong></p>
<pre><... | 1 | 2016-06-17T09:02:59Z | [
"python"
] |
Python multiple files variables and functions | 37,877,251 | <p>I'm trying to split my python code into a few files :</p>
<p><strong><code>file1.py</code></strong></p>
<pre><code>from file2 import *
var1 = 7
func_file2()
</code></pre>
<p><strong><code>file2.py</code></strong></p>
<pre><code>def func_file2():
var2 = var1
</code></pre>
<p>So it says:</p>
<pre><code>Name... | 0 | 2016-06-17T08:57:44Z | 37,877,476 | <p>I don't suggest you to use global variables however if you want it to work the way it is now, you can do something like this:</p>
<pre><code>first file
global var1
var1 = 7
second file
from first_file_name import var1 #this will make your var1 accessible from the second file
</code></pre>
<p>I hope it helps. ... | 0 | 2016-06-17T09:07:42Z | [
"python"
] |
Replace two random characters by two other random characters in python | 37,877,298 | <p>I need change 2 random characters (or more) in a string (x) by other two random characters in other diferent string (y), using Python, example strings:</p>
<pre><code>x = 'ABCDEF'
y = 'GHIJK'
</code></pre>
<p>The possible solution would be: </p>
<blockquote>
<p>z=AB<strong>I</strong>D<strong>G</strong>F </p>
... | -1 | 2016-06-17T08:59:51Z | 37,877,725 | <p>Here is the implementation.</p>
<p><strong>Code</strong> </p>
<pre><code>import random
def swap_charcter(x,y):
x_list = list(x)
for i in random.sample(range(len(x_list)),2):
x_list[i] = random.choice(y)
return ''.join(x_list)
</code></pre>
<p><strong>Results</strong></p>
<pre><code>In [1]:... | 1 | 2016-06-17T09:18:48Z | [
"python",
"random"
] |
Replace two random characters by two other random characters in python | 37,877,298 | <p>I need change 2 random characters (or more) in a string (x) by other two random characters in other diferent string (y), using Python, example strings:</p>
<pre><code>x = 'ABCDEF'
y = 'GHIJK'
</code></pre>
<p>The possible solution would be: </p>
<blockquote>
<p>z=AB<strong>I</strong>D<strong>G</strong>F </p>
... | -1 | 2016-06-17T08:59:51Z | 37,878,121 | <p>With <code>chain</code> and <code>sample</code> </p>
<pre><code>from itertools import chain
from random import sample
x="ABCDEF"
y="ZYXWVU"
to_replace=3
print("".join(chain(sample(x,to_replace),sample(y,len(y)-to_replace))))
>>>FDAWXY
</code></pre>
| 0 | 2016-06-17T09:35:40Z | [
"python",
"random"
] |
pycharm not using virtualenv from vagrant box when 'go to declaration' instead uses some outdated stuff from its remote_sources | 37,877,325 | <p>I setuup Project Interpreter pointing virtualenv on vagrant virtual machine (Settings / Project Interpreter / Add Remote), but when I click ctrl+B or use 'go to definition' I always end up in location like this: <code>/home/<my_user_name>/.PyCharm50/system/remote_sources/1174787026/154306353/django/...</code><... | 2 | 2016-06-17T09:00:55Z | 39,578,272 | <p>I also had this issue setting up a remote interpreter with Vagrant.</p>
<p>It appears that for a remote interpreter you need to mark Python source root folders as "Source Folders" under Project Structure in Preferences. They should then show up as blue in your Project browser. You don't need to mark all the sub fol... | 0 | 2016-09-19T16:52:37Z | [
"python",
"ubuntu",
"vagrant",
"pycharm",
"virtualenv"
] |
Not sure how to return value from function | 37,877,349 | <p>i have a code which i need to return the values, but i think i am not able to place the <code>return</code> statement properly. I need to return the combined list of IP address to calling function in python</p>
<pre><code>def call_me ():
ACCESS_KEY= "XX"
SECRET_KEY= "XXXX"
regions = ['us-west-2','eu-central-1... | 0 | 2016-06-17T09:01:57Z | 37,877,449 | <p>You can define <code>ip_list</code> before the <code>for</code> loop and <code>extend</code> it with the list of values from each region:</p>
<pre><code>ip_list = []
for region in regions:
instance_information = {}
#
# your code
#
ip_list.extend(i[0] for i in instance_information.values())
... | 0 | 2016-06-17T09:06:25Z | [
"python",
"return"
] |
Not sure how to return value from function | 37,877,349 | <p>i have a code which i need to return the values, but i think i am not able to place the <code>return</code> statement properly. I need to return the combined list of IP address to calling function in python</p>
<pre><code>def call_me ():
ACCESS_KEY= "XX"
SECRET_KEY= "XXXX"
regions = ['us-west-2','eu-central-1... | 0 | 2016-06-17T09:01:57Z | 37,877,633 | <p>Your problem is not in where to place the return statement. The issue is that you redefine <code>ip_list</code> within each iteration of the <code>for</code> loop, so there is no point at which you ever have all the information to return it.</p>
<p>I'm not sure exactly what format you want to return the values in, ... | 0 | 2016-06-17T09:14:15Z | [
"python",
"return"
] |
UnicodeEncode error in python when uploading CSV file to postgres DB | 37,877,396 | <p>I keep getting a UnicodeEncode error when trying to upload a CSV file into a Postgres DB using Python2.7</p>
<p>First I create the file in CSV format. The file has non latin characters that's why I download it and encoding the second column which it has strings:</p>
<pre><code>writer = csv.writer(response, dialect... | 0 | 2016-06-17T09:03:55Z | 37,877,686 | <p>You can try using <a href="https://pypi.python.org/pypi/unicodecsv/0.9.0" rel="nofollow">unicodecsv</a> instead of the built-in <code>csv</code></p>
| 0 | 2016-06-17T09:17:21Z | [
"python",
"postgresql",
"csv",
"encode"
] |
UnicodeEncode error in python when uploading CSV file to postgres DB | 37,877,396 | <p>I keep getting a UnicodeEncode error when trying to upload a CSV file into a Postgres DB using Python2.7</p>
<p>First I create the file in CSV format. The file has non latin characters that's why I download it and encoding the second column which it has strings:</p>
<pre><code>writer = csv.writer(response, dialect... | 0 | 2016-06-17T09:03:55Z | 37,879,833 | <p>After all I have flattened the values before I write them into the CSV.
I used the unidecode module as following:</p>
<pre><code>from unidecode import unidecode
for row in rows:
field_1 = row[0]
field_2 = unidecode(row[1]).encode(encoding='UTF-8') # LINE CHANGED
fields = [field_1, field_2]
... | 0 | 2016-06-17T10:56:18Z | [
"python",
"postgresql",
"csv",
"encode"
] |
HOW TO LABEL the FEATURE IMPORTANCE with forests of trees? | 37,877,542 | <p>I use sklearn to plot the feature importance for forests of trees. The dataframe is named 'heart'. Here the code to extract the list of the sorted features:</p>
<pre><code>importances = extc.feature_importances_
indices = np.argsort(importances)[::-1]
print("Feature ranking:")
for f in range(heart_train.shape[1]):... | 3 | 2016-06-17T09:10:19Z | 37,879,594 | <p>The problem is here:</p>
<pre><code>plt.xticks(range(heart_train.shape[1]), indices)
</code></pre>
<p><code>indices</code> is an array of indices returned from your <code>np.argsort(importances)[::-1]</code>, it doesn't have the <em>feature names</em> you want to appear as ticks on your X axis.</p>
<p>You need so... | 1 | 2016-06-17T10:44:01Z | [
"python",
"numpy",
"matplotlib",
"scikit-learn",
"sklearn-pandas"
] |
file not found error with python, no error in cmd | 37,877,555 | <p>I've made a python script for windows to print each file in a directory. To do that, i use ghostscript and gsprint.</p>
<p>When i launch the script, there is an error <code>WindowsError: [error2] file not found</code></p>
<p>If i launch the same command line in cmd, there is no error and the pdf is printed...</p>
... | 0 | 2016-06-17T09:11:06Z | 37,878,944 | <p>After many tries, i managed to solve the problem : </p>
<p>Gsprint was installed in <code>c:\program files</code> i moved it and installed in <code>c:\GSP</code> so a path without spaces and it worked fine.</p>
| 0 | 2016-06-17T10:15:18Z | [
"python",
"windows",
"python-2.7",
"ghostscript"
] |
Drop rows while iterating through groups in pandas groupby | 37,877,585 | <p>for a dataset like:</p>
<pre><code>te = {'A':[1,1,1,2,2,2],'B':[0,3,6,0,5,7]}
df = DataFrame(te, index = range(6))
vol = 0
</code></pre>
<p>I'd like to groupby <code>A</code> and iter through the groups after the groupby function:</p>
<pre><code>for name, group in df.groupby('A'):
for i, row in group.iterrows... | 0 | 2016-06-17T09:12:03Z | 37,878,398 | <p>If I understand correctly, you can do both operations separately without loop:</p>
<pre><code>vol = df.A[df.B <= 0].sum()
df = df[df.B > 0] # equivalent to drop
</code></pre>
| 0 | 2016-06-17T09:48:04Z | [
"python",
"pandas"
] |
Get view direction relative to scene in vispy? | 37,877,592 | <p>What is the cleanest way to get the view direction relative to your scene in vispy?</p>
<p><code>view.scene.transform</code> contains a whole chain of transforms:</p>
<pre><code>In [88]: view.scene.transform
Out[88]:
<ChainTransform [<STTransform scale=[ 960. -540. 1. 1.] translate=[ 960. 540. 0. ... | 1 | 2016-06-17T09:12:33Z | 37,882,984 | <p>Vispy transformations have a <code>map</code> and <code>imap</code> function you can use to map coordinates between scene and screen coordinates in either direction. I used them on points and threw in a lot of assertions to be safe; there are probably simpler implementations. I tested this for orthographic projectio... | 0 | 2016-06-17T13:34:07Z | [
"python",
"opengl",
"coordinate-systems",
"vispy"
] |
sanitize && build url | 37,877,611 | <p>Is it possible, whith beautifulsoup (python), to extract urls absolute instead of relative urls of a web page ?</p>
<p>For example, when I scrap <a href="http://bing.com" rel="nofollow">http://bing.com</a> and ask a href links :
for link in soup.findAll('a'):</p>
<p>It return as well as relative than absolute ... | 0 | 2016-06-17T09:13:30Z | 37,877,873 | <p>Use <code>filter()</code> and lambdas.</p>
<p><code>urlList = filter(lambda aTag: aTag['href'].startswith('http'), soup('a'))</code></p>
<p>should do the trick.</p>
<p>In short, check the whether the 'href' attribute of your links start with the string 'http'.</p>
<p>If you want to recreate absolute URLs from th... | 0 | 2016-06-17T09:25:27Z | [
"python",
"beautifulsoup"
] |
sanitize && build url | 37,877,611 | <p>Is it possible, whith beautifulsoup (python), to extract urls absolute instead of relative urls of a web page ?</p>
<p>For example, when I scrap <a href="http://bing.com" rel="nofollow">http://bing.com</a> and ask a href links :
for link in soup.findAll('a'):</p>
<p>It return as well as relative than absolute ... | 0 | 2016-06-17T09:13:30Z | 37,882,619 | <p>If you want to only match absolute URLs, the simplest way to do it would be to use a <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/#css-selectors" rel="nofollow">CSS selector</a>:</p>
<pre><code>soup.select("a[href^=http]")
</code></pre>
<p>Here <code>^=</code> means "starts with".</p>
<p>If you ... | 1 | 2016-06-17T13:18:28Z | [
"python",
"beautifulsoup"
] |
calculate angle of rotation image wrt another image | 37,877,626 | <p>I am developing an application which processes cheques for banks. But when the bank's image of a cheque can be skewed or rotated slightly by an angle of maximum value 20 degrees. Before the cheque can be processed, I need to properly align this skewed image. I am stuck here.</p>
<p>My initial idea was that I will f... | 0 | 2016-06-17T09:14:02Z | 37,878,122 | <p>What I would do in your case is to find the check within the image using feature matching with your template check image. Then you only need to find the transformation from one to the other and deduce the angle from this. </p>
<p>Take a look at <a href="http://docs.opencv.org/3.0-beta/doc/py_tutorials/py_feature2d/... | 1 | 2016-06-17T09:35:43Z | [
"python",
"opencv",
"image-processing"
] |
I have a .json file which I can and have opened in python, but how can I extract certain pieces of information from it? | 37,877,636 | <p>I have a .json file which I have opened in python. However I wish to only extract the orderIds from the .json file instead of printing the whole thing. Here is my code so far:</p>
<pre><code>import json
from pprint import pprint
import
with open('data-3.json') as data_file:
data = json.load(data_file)
ppri... | -1 | 2016-06-17T09:14:26Z | 37,877,944 | <p>It is similar to accessing elements of a dictionary.</p>
<pre><code>Json = {'A':
{'B':['C','D','E']
}
}
Json['A']['B'] will give you ['C','D','E']
</code></pre>
| 0 | 2016-06-17T09:28:42Z | [
"python",
"extract",
"package.json"
] |
Why am I getting an empty array with (scrapy shell response.xpath())? | 37,877,690 | <p>I'm wondering why response.xpath() returns an empty array <code>[]</code> in <a href="https://www.amazon.cn/b/2127529051" rel="nofollow">this page</a>, even if I do <code>response.xpath('//div').extract()</code>!
Example:</p>
<pre><code>$ scrapy shell https://www.amazon.cn/b/2127529051
...
>>> response.xpa... | 0 | 2016-06-17T09:17:26Z | 37,878,014 | <blockquote>
<p><code>response.xpath('\\div').execute()</code></p>
</blockquote>
<p>This line is just wrong. First of all you use front-slashes instead of back-slashes here. Also <code>execute()</code> is not a method of <code>Selector</code> or <code>SelectorList</code> objects (those are the values that are return... | 0 | 2016-06-17T09:31:18Z | [
"python",
"xpath",
"scrapy"
] |
How to turn a pandas dataframe row into a comma separated string | 37,877,708 | <p>I need to iterate over each row of a pandas df and turn this into a comma separated string.</p>
<p>example:</p>
<pre><code>df3 = DataFrame(np.random.randn(10, 5),
columns=['a', 'b', 'c', 'd', 'e'])
a b c d e
0 -0.158897 -0.749799 0.268921 0.070035 0.0996... | 1 | 2016-06-17T09:18:04Z | 37,877,750 | <p>You can canvert <code>DataFrame</code> to <code>numpy.array</code> by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.values.html" rel="nofollow"><code>values</code></a> and then generate <code>strings</code>:</p>
<pre><code>b = '\n'.join(','.join('%0.3f' %x for x in y) for y in df.v... | 1 | 2016-06-17T09:19:56Z | [
"python",
"pandas"
] |
How to turn a pandas dataframe row into a comma separated string | 37,877,708 | <p>I need to iterate over each row of a pandas df and turn this into a comma separated string.</p>
<p>example:</p>
<pre><code>df3 = DataFrame(np.random.randn(10, 5),
columns=['a', 'b', 'c', 'd', 'e'])
a b c d e
0 -0.158897 -0.749799 0.268921 0.070035 0.0996... | 1 | 2016-06-17T09:18:04Z | 37,877,882 | <p>You could use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.to_string.html" rel="nofollow"><code>pandas.DataFrame.to_string</code></a> with some optional arguments set to False and then split on newline characters to get a list of your strings. This feels a little dirty though. </p>... | 1 | 2016-06-17T09:25:58Z | [
"python",
"pandas"
] |
How to calculate average value from gridded datasets in python | 37,877,822 | <p>Hello I have a gridded datasets in .nc format. I tried to read .nc file for different combination of latitude and longitude with the code given below, but i know this is not the ideal way to do that.</p>
<pre><code>import netCDF4
from netCDF4 import Dataset
f= Dataset('data.nc')
data1 = f.variables['asa'][:,3,23]... | 0 | 2016-06-17T09:23:15Z | 37,878,284 | <p>I don't know about nc formatting, but I would expect that you should be able to do </p>
<pre><code>import netCDF4
from netCDF4 import Dataset
f= Dataset('data.nc')
Data = np.average(f.variables['asa'][:,3:5,23:26], axis = 0)
</code></pre>
| 1 | 2016-06-17T09:42:35Z | [
"python",
"numpy",
"pandas",
"dataframe",
"netcdf"
] |
Bokeh Gmap hide/unhide background | 37,877,825 | <p>I have a Bokeh image made with patches onto a google map as background.</p>
<p><a href="http://giove.units.it:5000" rel="nofollow">http://giove.units.it:5000</a></p>
<p>Is there a tool (or javascript code) to hide/unhide the background ? and is there way to save in png the background too ?</p>
<p>thanks</p>
| 0 | 2016-06-17T09:23:19Z | 37,882,336 | <p>As of Bokeh <code>0.11.1</code> (and soon to be <code>0.12</code>) there is no mechanism to hide the map portion. It seems like a reasonable feature though, an probably not terribly difficult to implement. I encourage you to submit a feature request on the project's <a href="https://github.com/bokeh/bokeh/issues" re... | 0 | 2016-06-17T13:05:28Z | [
"python",
"google-maps",
"bokeh"
] |
pip install using proxy in a virtual environment | 37,877,871 | <p>I work on a Ubuntu VM in my company's laptop which uses proxy server for connecting to internet.
After some research I found out how to install modules using <code>pip install</code> with proxy. For example, using this command I can install my virtualenv module:</p>
<pre><code>sudo pip install --proxy=http://user:p... | 1 | 2016-06-17T09:25:14Z | 39,208,484 | <p>Meanwhile, I know the solution. <code>pip</code> needs the environment variable <code>HTTP_PROXY</code> and <code>HTTPS_PROXY</code> in capital letters, instead of <code>http_proxy</code>.
So append below text pattern at the end of your your '~/.bashrc' </p>
<pre><code>HTTP_PROXY=http://username:pass@proxyaddress:p... | 1 | 2016-08-29T14:16:46Z | [
"python",
"ubuntu",
"pip",
"virtualenv",
"proxy-server"
] |
How to round a number to a chosen integer | 37,877,895 | <p>In Denmark we have an odd grading system that goes as follows. [-3,00,02,4,7,10,12]
Our assignment is to take a vector with different decimal numbers, and round it to the nearest valid grade. Here is our code so far. </p>
<pre><code>import numpy as np
def roundGrade(grades):
if (-5<grades<-1.5):
... | 16 | 2016-06-17T09:26:29Z | 37,878,226 | <p>Well, even without testing your code, I can see some problems here.<br/><br/>
Your function, <code>roundGrade</code>, takes a number and returns a number, but when you call it, you provide an array to it. Assuming your indentation is ok and the call is not inside the function, I would do something like that:</p>
<p... | 1 | 2016-06-17T09:39:45Z | [
"python",
"rounding"
] |
How to round a number to a chosen integer | 37,877,895 | <p>In Denmark we have an odd grading system that goes as follows. [-3,00,02,4,7,10,12]
Our assignment is to take a vector with different decimal numbers, and round it to the nearest valid grade. Here is our code so far. </p>
<pre><code>import numpy as np
def roundGrade(grades):
if (-5<grades<-1.5):
... | 16 | 2016-06-17T09:26:29Z | 37,878,366 | <p>As for the exception, numpy array is a function , and needed to be called with ()
So your method call should be like:</p>
<pre><code>print(roundGrade(np.array([-2.1,6.3,8.9,9])))
</code></pre>
<p>and not:</p>
<pre><code>print(roundGrade(np.array[-2.1,6.3,8.9,9]))
</code></pre>
<p>As for the function itself, eith... | 0 | 2016-06-17T09:46:18Z | [
"python",
"rounding"
] |
How to round a number to a chosen integer | 37,877,895 | <p>In Denmark we have an odd grading system that goes as follows. [-3,00,02,4,7,10,12]
Our assignment is to take a vector with different decimal numbers, and round it to the nearest valid grade. Here is our code so far. </p>
<pre><code>import numpy as np
def roundGrade(grades):
if (-5<grades<-1.5):
... | 16 | 2016-06-17T09:26:29Z | 37,878,423 | <p>That's how i would do it:</p>
<pre><code>def roundGrade(grades_in):
grades_out = []
for grades in grades_in:
if grades < -5 or grades > 15:
gradesRounded = '??'
print('Grade input out of range ({:})!'.format(grades))
if (-5<grades<-1.5):
grades... | 1 | 2016-06-17T09:49:38Z | [
"python",
"rounding"
] |
How to round a number to a chosen integer | 37,877,895 | <p>In Denmark we have an odd grading system that goes as follows. [-3,00,02,4,7,10,12]
Our assignment is to take a vector with different decimal numbers, and round it to the nearest valid grade. Here is our code so far. </p>
<pre><code>import numpy as np
def roundGrade(grades):
if (-5<grades<-1.5):
... | 16 | 2016-06-17T09:26:29Z | 37,878,425 | <p>You are getting that error because when you print, you are using incorrect syntax:</p>
<pre><code>print(roundGrade(np.array[-2.1,6.3,8.9,9]))
</code></pre>
<p>needs to be</p>
<pre><code>print(roundGrade(np.array([-2.1,6.3,8.9,9])))
</code></pre>
<p>Notice the extra parentheses: <code>np.array(<whatever>)<... | 21 | 2016-06-17T09:49:45Z | [
"python",
"rounding"
] |
How to round a number to a chosen integer | 37,877,895 | <p>In Denmark we have an odd grading system that goes as follows. [-3,00,02,4,7,10,12]
Our assignment is to take a vector with different decimal numbers, and round it to the nearest valid grade. Here is our code so far. </p>
<pre><code>import numpy as np
def roundGrade(grades):
if (-5<grades<-1.5):
... | 16 | 2016-06-17T09:26:29Z | 37,878,494 | <p>I would round by calculating which valid grade it is closest to and returning that one:</p>
<pre><code>import numpy as np
def roundGrade(grade):
validGrades = np.array([-3,0,2,4,7,10,12])
return validGrades[np.argmin((grade-validGrades)**2)]
</code></pre>
<p>This of course only allows you to pass a single ... | 2 | 2016-06-17T09:53:04Z | [
"python",
"rounding"
] |
How to round a number to a chosen integer | 37,877,895 | <p>In Denmark we have an odd grading system that goes as follows. [-3,00,02,4,7,10,12]
Our assignment is to take a vector with different decimal numbers, and round it to the nearest valid grade. Here is our code so far. </p>
<pre><code>import numpy as np
def roundGrade(grades):
if (-5<grades<-1.5):
... | 16 | 2016-06-17T09:26:29Z | 37,878,529 | <p>You could simply take the minimum distance from each grade to each grade group, like so. This assumes you actually want to round to the nearest grade from your grade group, which your current code doesn't do exactly. </p>
<pre><code>grade_groups = [-3,0,2,4,7,10,12]
sample_grades = [-2.1,6.3,8.9,9]
grouped = [min(g... | 17 | 2016-06-17T09:55:08Z | [
"python",
"rounding"
] |
How to round a number to a chosen integer | 37,877,895 | <p>In Denmark we have an odd grading system that goes as follows. [-3,00,02,4,7,10,12]
Our assignment is to take a vector with different decimal numbers, and round it to the nearest valid grade. Here is our code so far. </p>
<pre><code>import numpy as np
def roundGrade(grades):
if (-5<grades<-1.5):
... | 16 | 2016-06-17T09:26:29Z | 37,878,578 | <pre><code>def roundGrade(grade):
d = {x:abs(x - grade) for x in [-3,00,02,4,7,10,12]}
return min(d, key=d.get)
print list(map(roundGrade, [-2.1, 6.3, 8.9, 9]))
</code></pre>
<p>It is less efficient (I think) but is much smaller code<br>
It creates a dictionary where the key is a round grade and the value is t... | 2 | 2016-06-17T09:57:29Z | [
"python",
"rounding"
] |
How to round a number to a chosen integer | 37,877,895 | <p>In Denmark we have an odd grading system that goes as follows. [-3,00,02,4,7,10,12]
Our assignment is to take a vector with different decimal numbers, and round it to the nearest valid grade. Here is our code so far. </p>
<pre><code>import numpy as np
def roundGrade(grades):
if (-5<grades<-1.5):
... | 16 | 2016-06-17T09:26:29Z | 37,879,077 | <p>I think you might be able to do it in a one liner using only lists:</p>
<pre><code>l = [-2.1,6.3,8.9,9]
b = [-3,0,02,4,7,10,12]
a = [b[min(enumerate([abs(j - item) for j in b]), key=lambda p:p[1])[0]] for item in l]
>>> [-3, 7, 10, 10]
</code></pre>
<p>You can break this down as:</p>
<pre><code>min(enum... | 2 | 2016-06-17T10:21:08Z | [
"python",
"rounding"
] |
How to round a number to a chosen integer | 37,877,895 | <p>In Denmark we have an odd grading system that goes as follows. [-3,00,02,4,7,10,12]
Our assignment is to take a vector with different decimal numbers, and round it to the nearest valid grade. Here is our code so far. </p>
<pre><code>import numpy as np
def roundGrade(grades):
if (-5<grades<-1.5):
... | 16 | 2016-06-17T09:26:29Z | 37,880,858 | <p>You are getting that error because of the extra parenthesis in the line</p>
<pre><code>print(roundGrade(np.array([-2.1,6.3,8.9,9])))
</code></pre>
<p>is should be </p>
<pre><code>print(roundGrade(np.array[-2.1,6.3,8.9,9]))
</code></pre>
| 1 | 2016-06-17T11:50:23Z | [
"python",
"rounding"
] |
How to change the string value in multiple places? | 37,877,949 | <p>Let's say I have a string that I used to set a value for a few <code>Kivy</code> widgets. How could I make all the widgets react to the change of that string?<br>
I could make that string a property for each widget, but if I change the property of one widget, the others with the same property aren't going to change ... | 0 | 2016-06-17T09:28:49Z | 37,878,207 | <p>In kivy you can use properties for that (not to be confused with python properties, which are a complete different thing). In kv language you should be able to do the following:</p>
<pre><code>MainWidget:
id: "main"
mystring: "asdf"
widget1:
content: main.mystring
widget2:
content: ... | 0 | 2016-06-17T09:39:06Z | [
"python",
"python-3.x",
"kivy"
] |
BigQuery Python API GET Tables | 37,878,026 | <p>I'm trying to access my data using the BigQuery API Python Library but can't seem to do so. My code is below. The data that I used in the code was also used <a href="https://cloud.google.com/bigquery/docs/reference/v2/tables/get#try-it" rel="nofollow">here</a> and it worked there but in my code throws a <code>TypeEr... | 0 | 2016-06-17T09:31:49Z | 37,897,756 | <p>You are missing <code>.execute()</code> at the end of LN 8: </p>
<pre><code>[..]
response= tables.get(projectId=project_id, datasetId=dataset_id, tableId=table_id).execute()
[..]
</code></pre>
| 1 | 2016-06-18T13:55:23Z | [
"python",
"google-bigquery"
] |
Python script to check server status | 37,878,030 | <p>I want to check some service status (like MySQL, Apache2) using python. I wrote a simple script.</p>
<pre><code>#!/usr/bin/python
from subprocess import call
command = raw_input('Please enter service name : ')
call(["/etc/init.d/"+command, "status"])
</code></pre>
<p>This script will request the user to enter th... | 0 | 2016-06-17T09:32:03Z | 37,878,523 | <p>I think what you want is to capture the output. Something along the lines of:</p>
<pre><code>status = subprocess.check_output("YOUR COMMAND", shell=True)
if ("Active: active (running)" in status):
...
</code></pre>
| 1 | 2016-06-17T09:54:50Z | [
"python",
"mysql",
"server"
] |
How to get Time offset information off datetime64[ns] | 37,878,167 | <p>I am converting a datetime[ns] column to a different timezone and the resulting column looks like this:</p>
<pre><code>0 2011-05-25 20:30:00+02:00
1 2011-05-24 20:30:00+02:00
2 2011-05-20 20:30:00+02:00
3 2011-05-19 20:30:00+02:00
4 2011-05-15 13:30:00+02:00
</code></pre>
<p>I am trying to pull out the o... | 1 | 2016-06-17T09:37:16Z | 37,878,991 | <p>I think you need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.dt.strftime.html" rel="nofollow"><code>strftime</code></a>:</p>
<pre><code>print (df)
date
0 2011-05-25 20:30:00+02:00
1 2011-05-24 20:30:00+02:00
2 2011-05-20 20:30:00+02:00
3 2011-05-19 20:30:00+02... | 1 | 2016-06-17T10:17:41Z | [
"python",
"datetime",
"pandas",
"dataframe",
"timezoneoffset"
] |
Can't get SQLAlchemy func.lower to work with MySQL | 37,878,257 | <p>I am doing some silly mistake with the syntax but cant figure out what.</p>
<p>I am trying to use <strong>sqlalchemy</strong> <code>func</code> to compare a DB field and a variable by turning them both in lower cases, but the output comes null as if the condition isnât satisfying. </p>
<p>The same thing works... | 1 | 2016-06-17T09:41:00Z | 37,881,291 | <p>The issue is that the MySQL functions <code>LOWER()</code> and <code>UPPER()</code> <a href="http://dev.mysql.com/doc/refman/5.7/en/string-functions.html#function_lower" rel="nofollow">cannot handle binary string types</a> and just return the binary string unmodified.</p>
<p>As the column in question</p>
<pre><cod... | 1 | 2016-06-17T12:12:38Z | [
"python",
"flask",
"sqlalchemy",
"flask-sqlalchemy"
] |
Resample with custom month-end frequency | 37,878,332 | <p>I'm looking for an equivalent specification to <code>W-MON</code> (weekly, ending Monday) for monthly data.</p>
<p>Specifically, I have a pandas data frame of daily data, and I want to only take monthly observations, starting with the most recent date and going back monthly. </p>
<p>So if today is 17/06/2016, my d... | 0 | 2016-06-17T09:44:34Z | 37,882,608 | <p>You can create the relevant dates using <code>relativedelta</code> and select using <code>.loc[]</code>:</p>
<pre><code>from datetime import datetime
from dateutil.relativedelta import relativedelta
from pandas_datareader.data import DataReader
</code></pre>
<p>Using daily sample data:</p>
<pre><code>stock_data =... | 0 | 2016-06-17T13:17:55Z | [
"python",
"pandas",
"dataframe",
"time-series",
"frequency"
] |
sql query parser --- how to fetch table_name | 37,878,525 | <p>I have lot of files which have oracle sql statements separated by ;</p>
<p>I want to get table_name from those sql select</p>
<p>essentially sql statment are of 3 types in file</p>
<pre><code> Select * from table1;
select * from ( select * from table9 x inner join table10 y on x.col1=y.col1);
select * from table2... | -1 | 2016-06-17T09:54:55Z | 37,885,195 | <p>Finds a word after <em>from</em> or <em>join</em> and optionaly another word after comma.</p>
<pre><code>>>> for m in re.findall(r'(from|join)\s+(\w+)(,\s*(\w+))?', s):
... print(m[1])
... if m[3]:
... print(m[3])
...
table1
table9
table10
table2
table3
</code></pre>
| 0 | 2016-06-17T15:23:31Z | [
"python",
"regex"
] |
matplotlib animation ArtistAnimation failure due to ffmpeg unavailable | 37,878,769 | <p>I am trying to call matplotlib.animation.ArtistAnimation to make an animation from a series of png images, but I get an error that is connected to the ffmpeg. I have Anaconda installed on my Ubuntu 14.04. The error message that I get is:</p>
<pre><code>UserWarning: Matplotlib is building the font cache using fc-lis... | 0 | 2016-06-17T10:07:22Z | 37,901,870 | <pre><code>conda update conda
conda install --channel https://conda.anaconda.org/conda-forge ffmpeg
</code></pre>
| 1 | 2016-06-18T21:37:27Z | [
"python",
"matplotlib",
"ffmpeg",
"ubuntu-14.04"
] |
Python lambda using for loop to dynamically add parameters | 37,878,794 | <p>I have the following lambda expression:</p>
<pre><code>constraints = lambda values: (
values['volume'] < 10,
values['mass'] < 100,
values['nItems'] <= 10,
values['nItems'] >= 5
... | 3 | 2016-06-17T10:08:20Z | 37,879,646 | <p>You can replace the lambda by a proper function and get some speedups. There is nothing that prevents your lambda from being a function. </p>
<p>Additionally, you cannot add dynamic expressions to a function. The closest approach would be to pass the keys and thresholds as parameters to your function:</p>
<pre><co... | 1 | 2016-06-17T10:46:16Z | [
"python",
"lambda"
] |
Python lambda using for loop to dynamically add parameters | 37,878,794 | <p>I have the following lambda expression:</p>
<pre><code>constraints = lambda values: (
values['volume'] < 10,
values['mass'] < 100,
values['nItems'] <= 10,
values['nItems'] >= 5
... | 3 | 2016-06-17T10:08:20Z | 37,881,401 | <p>First, don't use lambda where you don't need it</p>
<p><a href="https://www.python.org/dev/peps/pep-0008/" rel="nofollow">PEP8</a></p>
<blockquote>
<p>Always use a def statement instead of an assignment statement that
binds a lambda expression directly to an identifier.</p>
<p>Yes:</p>
<p>def f(x): r... | 4 | 2016-06-17T12:18:14Z | [
"python",
"lambda"
] |
How to set the build description via Jenkins REST API or Python? | 37,878,805 | <p>Is there any way (like Jenkins REST API or Python module) to set the existing jenkins build's build description ?</p>
<p>Many thanks :)</p>
| 0 | 2016-06-17T10:08:46Z | 37,934,963 | <p>seems this problem was resolved in the following link</p>
<p><a href="http://stackoverflow.com/questions/25427622/changing-jenkins-build-name-description-through-api-in-java">Changing Jenkins Build Name & Description through API in JAVA</a></p>
<p>curl -u $USER:$PASSWORD --data-urlencode "description=$new_de... | 0 | 2016-06-21T03:13:24Z | [
"python",
"jenkins"
] |
Automatically change def. parameter by using loop | 37,878,815 | <p>I'm trying to change a definition's parameter using while loop.</p>
<p>First, I created a function that calculates a variable, this function requires an input that will change as the while loop holds True. I tried change the input using a "+=" command but python doesn't recognize it as a change of input in formula.... | 0 | 2016-06-17T10:09:07Z | 37,879,391 | <p>You need to pass in the parameter that you want to change per iteration:</p>
<pre><code>def test(x,y,z):
for i in range(12):
x -= z
x *= 1 + y
return x
def main():
gx = 1
gy = 5
gz = 10
# Define a function rerun which binds gx to x, gy to y and leaves one parameter open
... | 0 | 2016-06-17T10:33:58Z | [
"python",
"python-2.7"
] |
Automatically change def. parameter by using loop | 37,878,815 | <p>I'm trying to change a definition's parameter using while loop.</p>
<p>First, I created a function that calculates a variable, this function requires an input that will change as the while loop holds True. I tried change the input using a "+=" command but python doesn't recognize it as a change of input in formula.... | 0 | 2016-06-17T10:09:07Z | 37,880,433 | <p>Your program works except for a couple of things.</p>
<p>You need to set <code>end</code> to the result of <code>rerun()</code>, otherwise if the <code>while end > 0</code> loop is entered, it will run forever because <code>end</code> is never changed. </p>
<p>You also need to return something from <code>rerun<... | 0 | 2016-06-17T11:28:10Z | [
"python",
"python-2.7"
] |
Groupby df column using pandas | 37,878,864 | <p>I have data</p>
<pre><code>1 member_id application_name active_seconds
2 192180 Opera 6
3 192180 Opera 7
4 192180 Chrome 243
5 5433112 Chrome 52
6 5433112 Opera 34
7 5433112 ... | 4 | 2016-06-17T10:11:34Z | 37,878,913 | <p>I think you need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.aggregate.html" rel="nofollow"><code>aggregate</code></a>:</p>
<pre><code>df1 = df.groupby(['member_id', 'application_name'])
.agg({'application_name':len, 'active_seconds':sum})
print (df1)
... | 4 | 2016-06-17T10:14:08Z | [
"python",
"pandas",
"dataframe",
"group-by",
"aggregate"
] |
Refactoring using decorators to reduce code volume | 37,878,872 | <p>i've recently switch to a new project and all our selenium tests are written in Python. I was wondering if i can reduce the code volume by using decorators</p>
<p>what we got right now is :</p>
<pre><code>class BasePage(object):
view_button = ".//a[text()='View']"
create_button = ".//a[text()='Create']"
... | 3 | 2016-06-17T10:11:49Z | 37,879,279 | <p>I'm not sure how you would make it so you can do <code>click.view_button</code>. However, you could give you element its own class. This way you can achieve something like <code>view_button.click()</code>. In my project I am doing this for all my elements.</p>
<pre><code>class BaseElement:
def __init__(self, dr... | 1 | 2016-06-17T10:29:41Z | [
"python",
"selenium",
"nose"
] |
Refactoring using decorators to reduce code volume | 37,878,872 | <p>i've recently switch to a new project and all our selenium tests are written in Python. I was wondering if i can reduce the code volume by using decorators</p>
<p>what we got right now is :</p>
<pre><code>class BasePage(object):
view_button = ".//a[text()='View']"
create_button = ".//a[text()='Create']"
... | 3 | 2016-06-17T10:11:49Z | 37,880,229 | <p>thanks to post from RemcoW i found a solution, see below </p>
<pre><code>class ViewButton():
def __init__(self,driver):
self.driver = driver
self.locator = (".//a[text()='View']")
@property
def click(self):
return self.driver.find_element_by_xpath(self.locator).click()
class B... | 1 | 2016-06-17T11:17:00Z | [
"python",
"selenium",
"nose"
] |
Refactoring using decorators to reduce code volume | 37,878,872 | <p>i've recently switch to a new project and all our selenium tests are written in Python. I was wondering if i can reduce the code volume by using decorators</p>
<p>what we got right now is :</p>
<pre><code>class BasePage(object):
view_button = ".//a[text()='View']"
create_button = ".//a[text()='Create']"
... | 3 | 2016-06-17T10:11:49Z | 37,880,460 | <p>you can also check the following solution; Create new module - navigation.py with :</p>
<pre><code>class Button():
def __init__(self,driver, locator):
self.driver = driver
self.locator = locator
@property
def click(self):
return self.driver.find_element_by_xpath(self.locator).c... | 2 | 2016-06-17T11:29:25Z | [
"python",
"selenium",
"nose"
] |
python matplotlib multiple lines animation | 37,878,896 | <p>I'm trying to create an animation with matplotlib to plot several datasets simultaneously in one animation.
The problem is that two of my datasets have 50 points in them, and the third one has got 70000 points. Therefore, simultaneous plotting (with the same interval between the points) is useless, as the first two... | 0 | 2016-06-17T10:13:22Z | 37,956,651 | <p>Simpler than using separate animation calls is to update all of your lines in the same animation call, but at a different rate. In your case, only update the red and green lines every (70000/50)th call to <code>update</code>.</p>
<p>You can do this by changing your code starting at your <code>update</code> function... | 0 | 2016-06-22T00:20:34Z | [
"python",
"animation",
"matplotlib",
"plot"
] |
sqlalchemy.exc.ProgrammingError: (psycopg2.ProgrammingError) can't adapt type 'property' | 37,878,909 | <p>I'm attempting to query <code>Version</code> where I wish to get objects back where their <code>max_version_number</code> attribute equals the <code>version_number</code>:</p>
<pre><code>latest_versions = \
dbSession.query(Version).filter(Version.max_version_number == Version.number_version)
</code></pre>
<p>T... | 0 | 2016-06-17T10:14:02Z | 37,879,341 | <p>The problem is that you're passing a <code>property</code> descriptor object (<code>Version.max_version_number</code>) to compare, which psycopg2 has no idea about how to adapt. Instead you should use an SQL expression one way or the other.</p>
<p>To get the rows with maximum versions grouped by tasks in project <c... | 1 | 2016-06-17T10:32:12Z | [
"python",
"postgresql",
"sqlalchemy",
"psycopg2"
] |
Indexing one array by another in numpy | 37,878,946 | <p>Suppose I have a matrix <strong>A</strong> with some arbitrary values:</p>
<pre><code>array([[ 2, 4, 5, 3],
[ 1, 6, 8, 9],
[ 8, 7, 0, 2]])
</code></pre>
<p>And a matrix <strong>B</strong> which contains indices of elements in A:</p>
<pre><code>array([[0, 0, 1, 2],
[0, 3, 2, 1],
[3, 2, ... | 4 | 2016-06-17T10:15:22Z | 37,879,017 | <p>You can use <a href="http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html#advanced-indexing"><code>NumPy's advanced indexing</code></a> -</p>
<pre><code>A[np.arange(A.shape[0])[:,None],B]
</code></pre>
<p>One can also use <code>linear indexing</code> -</p>
<pre><code>m,n = A.shape
out = np.take(A,B + n*... | 7 | 2016-06-17T10:18:54Z | [
"python",
"numpy"
] |
Selenium-Debugging: Element is not clickable at point (X,Y) with Firefox driver | 37,879,010 | <p>I try to scrape this <a href="http://www.auchandrive.fr/" rel="nofollow">site</a> by selenium-python
i want to click in "Next Page" buttom, for this i do:</p>
<pre><code> driver.find_element_by_class_name('pagination-r').click()
</code></pre>
<p>it works for many pages but not for all, i got this error</p>
<pre>... | 1 | 2016-06-17T10:18:37Z | 37,880,313 | <p>Another element is covering the element you are to click. You could use <code>execute_script()</code> to click on this.</p>
<pre><code>element = driver.find_element_by_class_name('pagination-r').click()
driver.execute_script("arguments[0].click();", element)
</code></pre>
| 1 | 2016-06-17T11:21:31Z | [
"python",
"selenium",
"selenium-webdriver",
"web-scraping",
"selenium-firefoxdriver"
] |
Selenium-Debugging: Element is not clickable at point (X,Y) with Firefox driver | 37,879,010 | <p>I try to scrape this <a href="http://www.auchandrive.fr/" rel="nofollow">site</a> by selenium-python
i want to click in "Next Page" buttom, for this i do:</p>
<pre><code> driver.find_element_by_class_name('pagination-r').click()
</code></pre>
<p>it works for many pages but not for all, i got this error</p>
<pre>... | 1 | 2016-06-17T10:18:37Z | 37,881,646 | <p>Use explicit wait instead of implicit.</p>
<pre><code> new WebDriverWait(TestingSession.Browser.WebDriver, TimeSpan.FromSeconds(10)).Until(ExpectedConditions.ElementExists((By.ClassName("pagination-r'"))));
</code></pre>
| 0 | 2016-06-17T12:30:12Z | [
"python",
"selenium",
"selenium-webdriver",
"web-scraping",
"selenium-firefoxdriver"
] |
Removing an image in a wx python panel using a button | 37,879,042 | <p>I'm new to python/wxpython.
I have a wxpython frame which is split vertically - displaying 2 panels. On the left panel i have a display window, which displays an image by allowing the user to browse for a file by clicking on a button added onto the right panel. The loading of the image works fine, however i want to... | 0 | 2016-06-17T10:19:35Z | 37,890,734 | <p>You should have a handle on the <code>wx.StaticBitmap</code> widget that you're using to display the image. You can just hide that widget or set it to an <code>wx.EmptyImage</code>. </p>
<p>I wrote a simple image viewer application that you can check out. It might help you figure this out:</p>
<pre><code>import os... | 0 | 2016-06-17T21:38:59Z | [
"python",
"wxpython"
] |
Pulling a file from SFTP server using partial file name | 37,879,067 | <p>To obtain a file from a SFTP server I use the command: </p>
<pre><code>sftp.get("directory/filename.ext", preserve_mtime = True)
</code></pre>
<p>This works fine when I point to the complete filename. However, there are files on the SFTP server that have a random code in their name together with a date. Can I sear... | 0 | 2016-06-17T10:20:39Z | 37,880,050 | <p>You could get a list of all the files in the directory and then check for the date in question:</p>
<pre><code>targetDate = "01-01-2016" # Change to the correct format of course.
possibleFiles = sftp.listdir("directory/")
for i in possibleFiles:
if targetDate in i:
sftp.get("directory/" + i, preserve_mt... | 3 | 2016-06-17T11:07:44Z | [
"python",
"file",
"ssl",
"get",
"sftp"
] |
intercept function calls going out of a function python | 37,879,130 | <p>I would like to intercept the function calls happening inside a function. This is aimed at producing a "mocking" sort of an effect on function calls inside a function.</p>
<p>For example:</p>
<pre><code>def calls_add(a,b):
print "this function calls add"
c = add(a,b)
print "call to add returned",c
</co... | 0 | 2016-06-17T10:23:23Z | 37,879,759 | <p>I think you are looking for <code>unittest.mock.patch</code>:</p>
<blockquote>
<p>patch() acts as a function decorator, class decorator or a context manager. Inside the body of the function or with statement, the target is patched with a new object. When the function/with statement exits the patch is undone.</p>
... | 0 | 2016-06-17T10:52:15Z | [
"python",
"mocking",
"py.test"
] |
intercept function calls going out of a function python | 37,879,130 | <p>I would like to intercept the function calls happening inside a function. This is aimed at producing a "mocking" sort of an effect on function calls inside a function.</p>
<p>For example:</p>
<pre><code>def calls_add(a,b):
print "this function calls add"
c = add(a,b)
print "call to add returned",c
</co... | 0 | 2016-06-17T10:23:23Z | 37,879,873 | <p>You have to use <a href="http://www.voidspace.org.uk/python/mock/patch.html#patch" rel="nofollow"><code>mock.patch</code></a>. You have the following two posiblities:</p>
<ol>
<li><p>If you want to use a decorator:</p>
<pre><code>import mock
def some_other_func(*args, **kwargs):
return "test value"
def add... | 0 | 2016-06-17T10:58:23Z | [
"python",
"mocking",
"py.test"
] |
Unable to import even after installing the packages | 37,879,138 | <p>I have installed numpy, scipy, scikit learn and other required packages. Still when I try to import them in python, it shows no module found.</p>
<pre><code>pip install -U numpy scipy scikit-learn
Requirement already up-to-date: numpy in /usr/lib/python2.7/dist-packages
Collecting scipy
Downloading scipy-0.17.1-c... | 1 | 2016-06-17T10:23:45Z | 37,879,213 | <p>Not sure if related but you are having a <code>permission denied</code> error, try with
<code>sudo pip install -U numpy scipy scikit-learn</code></p>
<p>To double check your installation run <code>pip freeze</code></p>
<pre><code>$ pip freeze | grep numpy
$ numpy==1.9.2
</code></pre>
<p>That way you really chec... | 3 | 2016-06-17T10:26:40Z | [
"python",
"ubuntu",
"numpy",
"scipy",
"scikit-learn"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.