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 objects created on same day till now
37,945,688
<p>I have a model which contains <code>created_at</code> DateTimeField. I want to filter the model to get all object created on this day, month till now.</p> <p>For Example : Date = 21/06/2016 Now I want to get all objects created on 21/06 till now irrespective of year.</p> <p>Edit: To be precise, I have model which ...
0
2016-06-21T13:22:09Z
37,961,082
<p>Thanks for your comments and answers. I have used <a href="http://stackoverflow.com/a/6130259/4679396">this</a> answer to solve the problem. I have removed the <code>timedelta(days)</code> from the code.</p>
1
2016-06-22T07:19:23Z
[ "python", "django", "datetime", "django-models", "python-datetime" ]
Matplotlib colormap: Maximum number of colors
37,945,708
<p>I noticed some unexpected behaviour of the colormap functions of matplotlib. Consider the following example:</p> <pre><code>from matplotlib.cm import hot c = hot(range(0, 512)) </code></pre> <p>All colors c[255] to c[511] are the same, i.e. white. I would have expected the colormap function to normalize the input ...
1
2016-06-21T13:23:04Z
37,946,344
<p>you could create your own colormap by using:</p> <pre><code>from matplotlib import cm new_map = cm.gray.from_list('whatever', ('white', 'black'), N=512) </code></pre> <p>This would create a grayscale colormap ranging from 0 to 512.</p>
1
2016-06-21T13:50:58Z
[ "python", "matplotlib", "colormap" ]
how to set a variable dynamically - python, pandas
37,945,754
<pre><code>&gt;&gt;&gt;import pandas as pd &gt;&gt;&gt;import numpy as np &gt;&gt;&gt;from pandas import Series, DataFrame &gt;&gt;&gt;rawData = pd.read_csv('wow.txt') &gt;&gt;&gt;rawData time mean 0 0.005 0 1 0.010 258.64 2 0.015 258.4...
1
2016-06-21T13:25:25Z
37,946,590
<pre><code>for i in df.index: if df.mean [i]=0: answer=input ("Do you want to interpolate?") if answer="Y": x1 = df.loc[df.mean &gt; 0].index[1] y1 = df.loc[df.time &gt; 0].index[1] Interpolate eqn else: Process else: x0 = df.ti...
0
2016-06-21T14:01:22Z
[ "python", "csv", "pandas", "dynamic", "dataframe" ]
Instagram API Python error
37,945,823
<p>I'm trying to familiarize with the library <a href="https://github.com/facebookarchive/python-instagram" rel="nofollow">python-instagram</a>.</p> <p>I've done this code:</p> <pre><code>from instagram.client import InstagramAPI clientid = '***' clientsecret = '***' api = InstagramAPI(client_id=clientid, client_secr...
-1
2016-06-21T13:28:02Z
37,992,509
<p>I would suggest you to take a look at this <a href="https://github.com/facebookarchive/python-instagram/blob/master/sample_app.py" rel="nofollow">sample app</a> . You will get to know how to use python-instagram library.</p> <p>In your code , You are passing client Id in <code>InstagramAPI()</code>. But as per thei...
0
2016-06-23T13:04:41Z
[ "python", "instagram-api" ]
Activate Python 2.7
37,945,834
<p><strong>Environment</strong></p> <ul> <li>Default install of python 3.4 via Anaconada 3</li> <li>Installed in default directory of C:\Anaconda3</li> <li>Created 2.7 virtual environment </li> </ul> <p><strong>Issue</strong></p> <p>Using 'activate py27' and then typing command 'spyder' works perfectly. My Spyder I...
0
2016-06-21T13:28:44Z
37,946,473
<p>The python 3.4 environment variable was taking precedence over the 2.7 because of the directory I was in. Even though 2.7 was activated. </p> <p>Changing to the 'envs' directory changed the precedence and correctly booted the 2.7 instance.</p> <p>Big thanks to <a href="http://stackoverflow.com/users/433829/matthe...
0
2016-06-21T13:56:29Z
[ "python", "virtualenv", "anaconda" ]
How do I execute this line of code in a python script as if it were command line?
37,945,934
<p>I'm trying to write a script to duplicate running the line:</p> <pre><code> D:\...\bin&gt;jython.bat D:\...\UploadTest.py </code></pre> <p>in a python script, like it were via cmd. I've tried a variety of subprocess.Popen commands and none of them work (all get the Errno2 file not found). I currently have </p> ...
0
2016-06-21T13:32:57Z
37,946,133
<p>You probably need to use <code>shell=True</code> in the POpen call. But note the warnings about potential security issues found in the <a href="https://docs.python.org/2/library/subprocess.html" rel="nofollow">documentation</a>.</p>
-1
2016-06-21T13:41:47Z
[ "python", "jython" ]
How do I execute this line of code in a python script as if it were command line?
37,945,934
<p>I'm trying to write a script to duplicate running the line:</p> <pre><code> D:\...\bin&gt;jython.bat D:\...\UploadTest.py </code></pre> <p>in a python script, like it were via cmd. I've tried a variety of subprocess.Popen commands and none of them work (all get the Errno2 file not found). I currently have </p> ...
0
2016-06-21T13:32:57Z
37,946,423
<p>I had tried something like this. Let me know if this suits your requirement. Here is the reference <a href="http://stackoverflow.com/questions/20810366/executing-shell-script-using-subprocess-popen-in-python">link</a></p> <pre><code>#!/usr/bin/env python from subprocess import call from textwrap import dedent call...
-1
2016-06-21T13:54:43Z
[ "python", "jython" ]
pyspark. Transformer that generates a random number generates always the same number
37,945,936
<p>I am trying to measure the performance impact on having to copy a <code>dataframe</code> from scala to python and back in a large pipeline. For that purpose I have created this rather artificial transformer:</p> <pre><code>from pyspark.ml.pipeline import Transformer from pyspark.ml.param.shared import HasInputCol, ...
2
2016-06-21T13:33:03Z
37,948,670
<p>Well, expected is rather relative here but it is not something that cannot be explained. In particular the state of the RNG is inherited from the parent process. You can easily prove that by running following simple snippet in the local mode:</p> <pre class="lang-py prettyprint-override"><code>import random def r...
2
2016-06-21T15:31:18Z
[ "python", "random", "apache-spark", "pyspark", "spark-dataframe" ]
can someone confirm that this dosen't work on python 3.5?
37,945,955
<p>it's supposed to add a and b after you type them , example is <code>2</code> ,<code>5</code> ,it should <code>return 7</code>.</p> <pre><code>import sys input = sys.stdin.read() tokens = input.split() a = int(tokens[0]) b = int(tokens[1]) print(a + b) </code></pre> <p>But, when i run it, it's just stuck and it doe...
1
2016-06-21T13:34:25Z
37,946,078
<p>No, <code>sys.stdin.read()</code> will read until the stream ends (you can press Ctrl-D to send the Signal) use <code>input()</code>. (Also, don't use input, or any other keywords or standard methods as a variable name.)</p>
3
2016-06-21T13:39:33Z
[ "python", "python-3.x" ]
How to train a sense2vec model
37,946,008
<p>The documentation of sense2vec mentions 3 primary files - the first of them being merge_text.py. I have tried several types of inputs- txt,csv,bzipped file since merge_text.py tries to open files compressed by bzip2.</p> <p>The file can be found at: <a href="https://github.com/spacy-io/sense2vec/blob/master/bin/me...
5
2016-06-21T13:36:29Z
38,845,362
<p>The input file should be a bzipped json. To use a plain text file just edit the <code>merge_text.py</code> as follow:</p> <pre><code>def iter_comments(loc): with bz2.BZ2File(loc) as file_: for i, line in enumerate(file_): yield line.decode('utf-8', errors='ignore') # yield ujson....
0
2016-08-09T08:10:34Z
[ "python", "word2vec", "spacy" ]
How can I get oembed json for reddit comment?
37,946,019
<p>I'm trying to use <code>python-oembed</code> library to get oembed comment from reddit(<a href="https://github.com/reddit/reddit/wiki/oEmbed" rel="nofollow">https://github.com/reddit/reddit/wiki/oEmbed</a>):</p> <pre><code>import oembed consumer = oembed.OEmbedConsumer() endpoint = oembed.OEmbedEndpoint('https://w...
2
2016-06-21T13:37:00Z
37,949,348
<p>The oembed returned by reddit is invalid.</p> <p>From <a href="http://oembed.com/" rel="nofollow">http://oembed.com/</a>, §2.3.4.4, <code>width</code> and <code>height</code> are required for the <code>rich</code> type.</p> <p>But, from <a href="https://www.reddit.com/oembed?url=https://www.reddit.com/r/Showertho...
1
2016-06-21T16:02:31Z
[ "python", "python-3.x", "reddit", "oembed", "reddit-api" ]
Parallelization/multiprocessing of conditional for loop
37,946,039
<p>I want to use multiprocessing in Python to speed up a while loop.</p> <p>More specifically:<br> I have a matrix (samples*features). I want to select <strong>x</strong> subsets of samples whose values at a random subset of features is unequal to a certain value (-1 in this case). </p> <p>My serial code:</p> <pre><...
1
2016-06-21T13:38:00Z
38,016,516
<p>I found a working solution. I decided to run the while loop in parallel and have the different processes interact over a shared counter. Furthermore, I vectorized the search for suitable samples. </p> <p>The vectorization yielded a ~300x speedup and running on 4 cores speeds up the computation ~twofold.</p> <p>Fir...
0
2016-06-24T15:05:18Z
[ "python", "parallel-processing", "python-multiprocessing" ]
Modify Python global variable inside eval
37,946,054
<p>I have code like this:</p> <pre><code>globals_defined = {'add': my_add_fn, 'divide': my_divide_fn} eval_result = eval(&lt;some code&gt;, {data: {'name_1': 'NAME1', 'name_2': 'NAME2'}, globals_defined) </code></pre> <p>I would like set a global variable inside the eval and then be able to access it afterwards. So l...
2
2016-06-21T13:38:40Z
37,946,147
<p>You should not be using eval to start with. But since you don't show the code you are running in there, there is no way to suggest alternatives.</p> <p>The fact is Python's <code>eval</code> only executes expressions - and assignments in Python are <code>statements</code> - you can't, ordinarily, have an assignmen...
3
2016-06-21T13:42:21Z
[ "python", "eval" ]
Modify Python global variable inside eval
37,946,054
<p>I have code like this:</p> <pre><code>globals_defined = {'add': my_add_fn, 'divide': my_divide_fn} eval_result = eval(&lt;some code&gt;, {data: {'name_1': 'NAME1', 'name_2': 'NAME2'}, globals_defined) </code></pre> <p>I would like set a global variable inside the eval and then be able to access it afterwards. So l...
2
2016-06-21T13:38:40Z
37,946,543
<p>Why try to use a global namespace? Why not construct a specific local namespace to pass the functions to the <code>eval</code>? The problem with passing <code>globals()</code> as the global namespace to <code>eval</code> or <code>exec</code> is that you are giving away control of your namespace to the code you exit,...
0
2016-06-21T13:58:55Z
[ "python", "eval" ]
Run a Python function for x seconds?
37,946,342
<p>I have a data stream that I need parse and extract values from, create a list of those values and append them to a list in a nested list fashion, e.g. mainList[[firstExtractedValue],[SecondExtractedValue]...]. The creation of the mainList must run in 15 minutes segments, after which I iterate over mainList and creat...
-2
2016-06-21T13:50:55Z
37,946,495
<p>You could just periodically check the time, and end after 15-minutes, no? Something like:</p> <pre><code>import datetime def func(maxrt): stop = datetime.datetime.now() + maxrt while datetime.datetime.now() &lt; stop: # do stuff func(datetime.timedelta(minutes=15)) </code></pre>
2
2016-06-21T13:57:07Z
[ "python", "multithreading", "python-2.7" ]
Replacing string characters with characters that are contained within each other
37,946,446
<p>Alright here is the bit in question.</p> <pre><code>if any(char in word for char in ["a", "ā", "e", "ē", "i", "ī", "u", "ū", "o", "ai", "ei", "ui"]): for ch in ["a", "ā", "e", "ē", "i", "ī", "u", "ū", "o", "ai", "ei", "ui"]: if ch in word: word = word.replace(ch, ch + "p" + ch) </code></pre> <p>...
1
2016-06-21T13:55:45Z
37,946,876
<p>You can join those characters to a regular expression using <code>|</code>. Make sure to sort the multi-char parts first, so they are preferred in the match (i.e. it matches <code>ai</code> instead of <code>a</code> and then <code>i</code>). Then use <a href="https://docs.python.org/3/library/re.html#re.sub" rel="no...
2
2016-06-21T14:14:34Z
[ "python", "replace" ]
Replacing string characters with characters that are contained within each other
37,946,446
<p>Alright here is the bit in question.</p> <pre><code>if any(char in word for char in ["a", "ā", "e", "ē", "i", "ī", "u", "ū", "o", "ai", "ei", "ui"]): for ch in ["a", "ā", "e", "ē", "i", "ī", "u", "ū", "o", "ai", "ei", "ui"]: if ch in word: word = word.replace(ch, ch + "p" + ch) </code></pre> <p>...
1
2016-06-21T13:55:45Z
37,948,777
<p>Your code is not python3, but from what I understood from your second example, try this:</p> <pre><code>list1 = ["a", "b", "ay", "by"] state = input("Type a, b, ay or by: ") for char in state: if char in list1: print("k") break </code></pre>
0
2016-06-21T15:36:13Z
[ "python", "replace" ]
Check if a record exists in a Cassandra table using the Python driver
37,946,458
<p>How can be determined whether a record exists in a table? The way I tried was to do a <code>SELECT</code> query and then count the rows of the <code>ResultSet</code> using the following:</p> <pre><code>rows = session.execute("SELECT * FROM test_table WHERE id=%s", ([&lt;id_here&gt;])) if len(rows) == 0: print "...
1
2016-06-21T13:56:02Z
37,947,673
<p>You can simply do one of the following:</p> <pre><code>rows = session.execute("SELECT * FROM test_table WHERE id=%s", ([&lt;id_here&gt;])) if not rows: print "Does not exist" </code></pre> <p>Or, if selecting multiple rows you could iterate over the ResultSet with:</p> <pre><code>for row in rows: do_somet...
2
2016-06-21T14:47:23Z
[ "python", "cassandra" ]
`Warning: Cannot parent components or objects in the underworld.` : adding bend deformer to group
37,946,491
<p>following lines lead to <code>Warning: Cannot parent components or objects in the underworld.</code></p> <p>self.lashesGroup = cmds.group(em=True, name="lashesGroup") cmds.parent(self.benddeformer, self.lashesGroup)</p> <p>benddeformer is a non-linear bend deformer - how can i avoid this warning? because it doesnt...
0
2016-06-21T13:56:58Z
37,956,869
<p>You probably just need to make sure that <code>benddeformer</code> is the transform which owns the deformer handle. You can't parent non-dag nodes. However you can get the handle from the bend node like this:</p> <pre><code>handle = (cmds.listConnections(self.benddeformer + ".matrix") or [None])[0] if handle: c...
0
2016-06-22T00:53:21Z
[ "python", "maya" ]
Solving a permutation and constraint issue
37,946,498
<p>Quick-and-dirty schedule optimization. An example: I have 7 different songs I can practice. I have 30 minutes total practice time. And I can break that into 5 minute windows. So I could practice one song for 30 minutes, or 6 different songs for 5 each, or one for 25 minutes and one for 5 minutes,etc. Separate...
1
2016-06-21T13:57:16Z
37,947,909
<p>edit: As Gassa pointed out, order doesn't seem to matter here. So if I'm understanding the question now, you want <code>itertools.combinations_with_replacement([1,2,3,4,5,6,7], r=6)</code></p> <p><strong>old answer:</strong></p> <p>What you are looking for is all of the permutations (with replacement) of length 6 ...
0
2016-06-21T14:57:29Z
[ "python", "algorithm", "permutation" ]
Python3 connecting to MSSQL
37,946,564
<p>I am writing Python3 and we have a database(mssql). I have some strings and want to put these strings into db table. But I could not handle connecting to DB. Some people suggested using pyodbc but my python version is 3.4.4 and pyodbc is not supporting it. I am writing my codes in PyCharm IDE and I am not using anyo...
0
2016-06-21T13:59:48Z
37,947,193
<p>If you work on a Linux distribution, try to install pip3 (python dependency manager for python 3) then run</p> <pre><code>pip install pymssql </code></pre> <p>Then read the library documention to learn how to use it at <a href="http://pymssql.org/en/latest/" rel="nofollow">http://pymssql.org/en/latest/</a></p>
1
2016-06-21T14:27:57Z
[ "python", "sql-server", "python-3.x", "ide", "connection" ]
Scrapy - externally configurable scraping rules
37,946,588
<p>I'd like to define my scraping rules in an external file so that the core code will not need to change for each web site. The file will have several rules with each coming into effect for different web sites. I have external files for <strong>start_urls</strong> and <strong>allowed_domains</strong>, but would like t...
1
2016-06-21T14:01:18Z
37,947,481
<p>One option for extraction rules is to use <a href="https://github.com/fizx/parsley" rel="nofollow">Parsley DSL</a></p> <p><a href="https://github.com/redapple/parslepy" rel="nofollow">parslepy</a> is an implementation of <a href="https://github.com/fizx/parsley/wiki" rel="nofollow">the language</a> in Python (Discl...
3
2016-06-21T14:40:15Z
[ "python", "xpath", "scrapy" ]
Incrementing IntegerField counter in a database
37,946,663
<p>As beginner at Django, i tried to make a simple application that would give Http response of how many times content was viewed. I have created a new <code>Counter</code> model, and inside, added IntegerField model <code>count</code>.</p> <pre><code>class Counter(models.Model): count = models.IntegerField(defaul...
1
2016-06-21T14:04:46Z
37,946,703
<h2>The problem</h2> <p>Yes but you are creating a new <code>Counter</code> object on each request, which starts again at 0, that's your problem</p> <pre><code>def IndexView(response): counter = Counter() # This creates a new counter each time counter.count = counter.count + 1 counter.save() return Ht...
1
2016-06-21T14:06:59Z
[ "python", "django", "django-models", "models" ]
Python: sort tab-separated key in dict by both columns
37,946,826
<p>I have a dictionary with tab separated keys. </p> <pre><code>d = {} d["1\t1"] = "abc" d["10\t1"] = "def" d["1\t10"] = "ghi" d["2\t5"] = "xyz" d["1\t4"] = 0 </code></pre> <p>How can I sort these keys after first and second column? </p> <p>I cannot use this</p> <pre><code>for s in sorted(d): print s </code></p...
0
2016-06-21T14:12:10Z
37,946,957
<p>i assume the second column means after \t<br></p> <pre><code>sorted(d.items(),key= lambda x: (int(x[0].split('\t')[0]),int(x[0].split('\t')[-1]))) </code></pre> <p>output:<br></p> <pre><code>[('1\t1', 'abc'), ('1\t4', 0), ('1\t10', 'ghi'), ('2\t5', 'xyz'), ('10\t1', 'def')] </code></pre> <p>print out:</p> <pre>...
4
2016-06-21T14:18:14Z
[ "python", "dictionary" ]
Python: sort tab-separated key in dict by both columns
37,946,826
<p>I have a dictionary with tab separated keys. </p> <pre><code>d = {} d["1\t1"] = "abc" d["10\t1"] = "def" d["1\t10"] = "ghi" d["2\t5"] = "xyz" d["1\t4"] = 0 </code></pre> <p>How can I sort these keys after first and second column? </p> <p>I cannot use this</p> <pre><code>for s in sorted(d): print s </code></p...
0
2016-06-21T14:12:10Z
37,947,421
<p>Alternative (and probably much easier solution) for my own problem (thanks Kevin): </p> <pre><code>d = {} d[1,1] = "abc" d[10,1] = "def" d[1,10] = "ghi" d[2,5] = "xyz" d[1,4] = 0 for k in sorted(d): print(k) </code></pre> <p>Only included small revision of input data.</p>
0
2016-06-21T14:37:42Z
[ "python", "dictionary" ]
Numpy.shape has a suffix: optimal way to get rid of it
37,946,828
<p>Having read <a href="http://stackoverflow.com/questions/21284790/what-is-the-l-in-numpy-shape-and-32-in-numpy-type-of-an-array">What is the L in numpy.shape and 32 in numpy.type of an array?</a> I know <em>why</em> the "L" suffix is there. But I want to do some operations that involve knowing the size of my dataset....
1
2016-06-21T14:12:14Z
37,946,927
<p>The <code>L</code> is an artefact of displaying the value, indicating that the value is being stored as a <code>long</code>, rather than as an <code>int</code>: it is not actually <em>part</em> of the value. Therefore, you can just ignore it.</p> <pre><code>&gt;&gt;&gt; num = 123L # create a long for testing &gt;&...
0
2016-06-21T14:16:41Z
[ "python", "numpy" ]
Trying to upsample Pandas to have data for every minute
37,946,847
<p>I have a database, with a mix of minutely,5minutely, and hourly data points: My goal is to have 10min data averages, but hwen I plot this out there is missing datapoints and the written CSV file goes from writing every data point to every hour) </p> <p>The output looks like</p> <pre><code> 2005-03-01 17:00:00,...
1
2016-06-21T14:12:59Z
37,946,974
<p>is that what you want?</p> <pre><code>In [57]: df.resample('T').ffill() Out[57]: Conc Flow SZ SB RZ RB Fraction Attenuation Date 2005-03-01 17:10:00 1.6 7.9 0.0214 1.3536 0.0214 1.6726 1.0 30.567 2005-03-01 17:11:00 1.6 7.9 0.0214 1.3536 0.0214 ...
1
2016-06-21T14:19:10Z
[ "python", "pandas" ]
Trying to upsample Pandas to have data for every minute
37,946,847
<p>I have a database, with a mix of minutely,5minutely, and hourly data points: My goal is to have 10min data averages, but hwen I plot this out there is missing datapoints and the written CSV file goes from writing every data point to every hour) </p> <p>The output looks like</p> <pre><code> 2005-03-01 17:00:00,...
1
2016-06-21T14:12:59Z
37,947,550
<p>Your data is a little sparse to get points every 10min when you only get one reading per hour at the end... Since you get missing points, you either have to use the data you have (using <code>ffill</code> or <code>bfill</code>), or interpolate the missing data.</p> <pre><code>df['Conc'].plot(label='original') df['C...
0
2016-06-21T14:42:33Z
[ "python", "pandas" ]
n-D Trees - calculating the coordinates of hypercubes
37,947,068
<p>I am trying to implement a generic n-dimensional Tree that will hold n-dimensional data. By n-dimensional data I mean data points having 6-7 coordinates in my case. Here is the Tree Node (a compound data type) and the Tree Class:</p> <pre><code>#data = data points (i.e. [x,y,z,k,m,n]) #hypercube = set of tuples; co...
1
2016-06-21T14:22:59Z
37,987,641
<p>I once wrote a k-dimensional quadtree in Java, here is the code:</p> <pre><code>NodeKD(double[] min, double[] max, int maxDepth, NodeKD parent) { this.min = min; this.max = max; this.center = new double[min.length]; for (int i = 0; i &lt; min.length; i++) { this.center[i] = (max[i]+min[i])/2...
1
2016-06-23T09:32:11Z
[ "python", "data-structures", "tree" ]
add headings to rows and columns of matrices in python
37,947,091
<p>I have 2 matrices and I want to add headings to them. How can I add them and call each cell with the headings of rows and columns of them? And also I have to calculate the sum of each element of rows with the elements of columns. I did it but is there a better way (a loop) to do it instead of what I did? and it retu...
2
2016-06-21T14:23:44Z
37,947,891
<p>This is one way to do it:</p> <pre><code>&gt;&gt;&gt; import itertools &gt;&gt;&gt; T = np.array([0,0.012,0.054,0,1,0.03,0.08,0.14,0.02]).reshape(3,3) &gt;&gt;&gt; T array([[ 0. , 0.012, 0.054], [ 0. , 1. , 0.03 ], [ 0.08 , 0.14 , 0.02 ]]) &gt;&gt;&gt; W = np.array([1,0,0.03,0.01,0.099,0....
0
2016-06-21T14:56:57Z
[ "python", "numpy", "matrix" ]
Paho subscriber on_message/on_connect not working
37,947,164
<p>I've installed Mosquitto and used in the terminal without problem, also installed paho for c++, both mosquitto and paho work well. Then installed paho for python via pip. Now i'm trying to test it with this code but the on_message and on_connect functions never get called. I'm doing </p> <p><code>mosquitto_pub -h ...
1
2016-06-21T14:26:49Z
37,947,416
<p>The following is working fine for me.</p> <p>I have removed the <code>self</code> from the callbacks and swapped the loop for <code>mqtt_client.loop_forever()</code> </p> <pre><code>import paho.mqtt.client as mqtt def on_connect(mqtt_client, obj, flags, rc): mqtt_client.subscribe("test") def on_message(mqtt_...
1
2016-06-21T14:37:34Z
[ "python", "mqtt", "mosquitto", "paho" ]
continue creating files from where it stopped
37,947,178
<p>I am using python and I have to write a program to create files of a total of 160 GB. I ran the program overnight and it was able to create files of 100 GB. However, after that it stopped running and gave an error saying "No space left on device". </p> <p>QUESTION : I wanted to ask if it was possible to start runn...
0
2016-06-21T14:27:09Z
37,947,369
<p>Keep track of your position in what you're doing with a <code>currentPosition</code> list, since lists are mutable, you can modify it within your function to keep track.</p> <pre><code>def foo(): currentPosition = 0 while currentPosition &lt; endPosition try: createTonsOfData() # global ...
0
2016-06-21T14:35:29Z
[ "python", "python-2.7", "file" ]
continue creating files from where it stopped
37,947,178
<p>I am using python and I have to write a program to create files of a total of 160 GB. I ran the program overnight and it was able to create files of 100 GB. However, after that it stopped running and gave an error saying "No space left on device". </p> <p>QUESTION : I wanted to ask if it was possible to start runn...
0
2016-06-21T14:27:09Z
37,947,472
<p>More details are required i think. how are these files being created? What are the stop conditions for your function? If you are doing a simple file writer you can change the mode to append and that should help. Anyway, a little more details are required</p> <p>Have a good one</p>
0
2016-06-21T14:39:48Z
[ "python", "python-2.7", "file" ]
Changing line style proportional spacing using matplotlib
37,947,218
<p>With uneven distributed data, the color are too similar for almost all points. For example. the figure below represent too much shallow color corresponding to the <code>value &lt; 12000</code>. </p> <p><a href="http://i.stack.imgur.com/vF330.png" rel="nofollow"><img src="http://i.stack.imgur.com/vF330.png" alt="...
2
2016-06-21T14:29:14Z
37,948,219
<p>I think the "easiest" would be to create a <a href="http://matplotlib.org/users/legend_guide.html" rel="nofollow">proxy artist</a> for your legend.</p> <p>The following works, but it needs to be adjusted to your needs, I'm not sure the normalization of the colormap and the size of the points is quite right.</p> <p...
1
2016-06-21T15:10:52Z
[ "python", "python-2.7", "matplotlib", "visualization", "legend" ]
Update ok in mondb client but KO in Python
37,947,258
<p>Newbie in mongodb/python/pymongo. My mongodb client code works OK. Here it is :</p> <pre><code>db.meteo.find().forEach( function(myDoc) { db.test.update({"contract_name" : myDoc.current_observation.observation_location.city}, { $set: { "temp_c_meteo" : myDoc.current_observation.temp_c , ...
0
2016-06-21T14:30:45Z
37,948,247
<p>Try using an attribute style access instead of dictionary style access?</p> <p>Something like</p> <pre><code>db = MDBClient.test collection = db.infosdb </code></pre>
0
2016-06-21T15:12:33Z
[ "python", "mongodb", "pymongo-3.x" ]
Update ok in mondb client but KO in Python
37,947,258
<p>Newbie in mongodb/python/pymongo. My mongodb client code works OK. Here it is :</p> <pre><code>db.meteo.find().forEach( function(myDoc) { db.test.update({"contract_name" : myDoc.current_observation.observation_location.city}, { $set: { "temp_c_meteo" : myDoc.current_observation.temp_c , ...
0
2016-06-21T14:30:45Z
38,081,640
<p>There is how i made it worked : no update_many but update.</p> <p>[...]</p> <p>saveInDB:</p> <pre><code>#BE connected to MongoDB client MDBClient = MongoClient() db = MDBClient.test collection = db.infosdb collectionMeteo = db.meteo </code></pre> <p>[...]</p> <pre><code> try: meteos = collect...
0
2016-06-28T16:32:12Z
[ "python", "mongodb", "pymongo-3.x" ]
Extract the real part of an array in python
37,947,269
<p>I am loading some data from a file, do a transformation and then extract the real part, however, the np.real function does not seem to work. It prints: </p> <p>[[(0.99023793104890667+0.034016079376604003j) 0.9905214315431583 0.99033818364852688 ..., 0.86609847609098078 0.87048246890045189 None]] </p> <p>where cl...
0
2016-06-21T14:31:15Z
37,947,449
<p>real should be used as numpy array obj function </p> <pre><code>a = numpy.array([1+2j, 3+4j]) print a.real array([ 1., 3.]) </code></pre>
0
2016-06-21T14:38:56Z
[ "python", "arrays", "python-2.7", "numpy" ]
Extract the real part of an array in python
37,947,269
<p>I am loading some data from a file, do a transformation and then extract the real part, however, the np.real function does not seem to work. It prints: </p> <p>[[(0.99023793104890667+0.034016079376604003j) 0.9905214315431583 0.99033818364852688 ..., 0.86609847609098078 0.87048246890045189 None]] </p> <p>where cl...
0
2016-06-21T14:31:15Z
37,948,986
<pre><code>[[(0.99023793104890667+0.034016079376604003j) 0.9905214315431583 0.99033818364852688 ..., 0.86609847609098078 0.87048246890045189 None]] </code></pre> <p>there are several clues that this is not an ordinary array of complex floats, which is what the <code>.real</code> method is meant for.</p> <p>The comp...
0
2016-06-21T15:46:23Z
[ "python", "arrays", "python-2.7", "numpy" ]
How to find elements in a list is consecutive
37,947,363
<p>Hi I have a list <code>[tag1 tag2]</code>, I would like to find out whether the number following tag is incremental. </p> <pre><code>match_atr_value = re.search('(.+)\~(\w+)',each_line) tags = match_atr_value.group(1).split('.') print tag Input: [tag1 tag2] [tag1 tag3] [tag1 tag2 tag4] Output: Incremental Not N...
0
2016-06-21T14:35:12Z
37,947,656
<p>If I were you, I would avoid a regex and do something like below. I get the number from the string, whether it's beginning, end, etc. and then compare it to the previous value and <code>return False</code> if it's not increasing</p> <pre><code>def isIncreasing( listy ): prev = 0 for w in listy: ...
0
2016-06-21T14:46:47Z
[ "python", "list" ]
How to find elements in a list is consecutive
37,947,363
<p>Hi I have a list <code>[tag1 tag2]</code>, I would like to find out whether the number following tag is incremental. </p> <pre><code>match_atr_value = re.search('(.+)\~(\w+)',each_line) tags = match_atr_value.group(1).split('.') print tag Input: [tag1 tag2] [tag1 tag3] [tag1 tag2 tag4] Output: Incremental Not N...
0
2016-06-21T14:35:12Z
37,947,824
<pre><code>tag1val = int(re.search(r'\D*(\d+)', tag1).group(1)) tag2val = int(re.search(r'\D*(\d+)', tag2).group(1)) (tag1val - tag2val) == -1 True tag3val = int(re.search(r'\D*(\d+)', tag3).group(1)) (tag1val - tag3val) == -1 False (tag2val - tag3val) == -1 True </code></pre> <p>If you wanted to stick with regu...
0
2016-06-21T14:53:58Z
[ "python", "list" ]
How to find elements in a list is consecutive
37,947,363
<p>Hi I have a list <code>[tag1 tag2]</code>, I would like to find out whether the number following tag is incremental. </p> <pre><code>match_atr_value = re.search('(.+)\~(\w+)',each_line) tags = match_atr_value.group(1).split('.') print tag Input: [tag1 tag2] [tag1 tag3] [tag1 tag2 tag4] Output: Incremental Not N...
0
2016-06-21T14:35:12Z
37,947,858
<p>You can extract all the digits followed by <code>tag</code> via <a href="https://docs.python.org/2/library/re.html#re.findall" rel="nofollow"><code>re.findall()</code></a> and then use <a href="https://docs.python.org/2/library/functions.html#enumerate" rel="nofollow"><code>enumerate()</code></a> and <a href="https:...
4
2016-06-21T14:55:43Z
[ "python", "list" ]
Pylint import check when directories are not the same than the import
37,947,365
<p>I've an unusual question, and I don't find the answer because no one is doing like that :p</p> <p>I want to use PyLint in order to resolve errors before running the script, especially calling methods from other modules and heritage.</p> <p>Thing is, my python scripts are not organized the same way than the import....
0
2016-06-21T14:35:16Z
37,947,911
<p>There are possibly multiple solutions to this. First, you can try to write a failure import hook, using astroid's API, which might look as this: <a href="https://github.com/PyCQA/astroid/blob/master/astroid/brain/brain_six.py#L273" rel="nofollow">https://github.com/PyCQA/astroid/blob/master/astroid/brain/brain_six.p...
0
2016-06-21T14:57:40Z
[ "python", "import", "pylint" ]
Django: return render not looking for urls.py in sub application
37,947,367
<p>I have a <code>urls.py</code> file in <code>mysite</code>, which points to everything in the <code>shark/</code> folder to the <code>shark/urls.py</code> file:</p> <p><em>mysite/urls.py</em></p> <pre><code>urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^polls/', include ('polls.urls')), url(r'...
0
2016-06-21T14:35:20Z
37,947,476
<p>It would be a match if the url were: <code>shark/target</code> since you specified the <code>shark</code> prefix in the root <code>urls.py</code>. Use an empty string there and it will match <code>target/</code>. e.g.:</p> <p><strong>mysite\urls.py:</strong></p> <pre><code>urlpatterns = [ url(r'^admin/', admin...
0
2016-06-21T14:40:03Z
[ "python", "django" ]
Django: return render not looking for urls.py in sub application
37,947,367
<p>I have a <code>urls.py</code> file in <code>mysite</code>, which points to everything in the <code>shark/</code> folder to the <code>shark/urls.py</code> file:</p> <p><em>mysite/urls.py</em></p> <pre><code>urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'^polls/', include ('polls.urls')), url(r'...
0
2016-06-21T14:35:20Z
37,947,651
<p>The <code>shark/urls.py</code> is only loaded for paths that begin with <code>shark/</code>, because that's what you are specifying in your <code>mysite/urls.py</code>. Therefore, to additionally load the path <code>target/</code> from your "sharks" app, you have to specifically mention it in the main <code>mysite/u...
0
2016-06-21T14:46:30Z
[ "python", "django" ]
replace new line with space only if it isn't followed by another new line (undo hard wrap in text)
37,947,453
<p>I have a bunch of text files with hard line wraps (i.e. new line at around 80 chars). I'd like to undo that and join all of those sentences together but maintain new lines where they are new chapters or paragraphs. </p> <p>i.e I.d like to replace '\n' with ' ' if and only if the following character is not another '...
1
2016-06-21T14:38:59Z
37,947,660
<p>Use <a href="https://docs.python.org/3.5/library/re.html#re.sub" rel="nofollow"><code>re.sub()</code></a> and then you have to play around with negative look-behind and look-ahead assertations. If your input is large this will not be very efficient.</p> <p>The look-behind:</p> <pre><code>(?&lt;!...) Matches ...
0
2016-06-21T14:46:55Z
[ "python", "regex", "sed" ]
replace new line with space only if it isn't followed by another new line (undo hard wrap in text)
37,947,453
<p>I have a bunch of text files with hard line wraps (i.e. new line at around 80 chars). I'd like to undo that and join all of those sentences together but maintain new lines where they are new chapters or paragraphs. </p> <p>i.e I.d like to replace '\n' with ' ' if and only if the following character is not another '...
1
2016-06-21T14:38:59Z
37,947,672
<p>You can use <code>awk</code> for that, like this:</p> <pre><code>awk '{$1=$1}1' RS='' ORS='\n\n' OFS=' ' file </code></pre> <p>Explanation:</p> <ul> <li><p><code>{$1=$1}</code> looks like it won't changed anything. That's true, but still <code>awk</code> will reassemble the record using the new separators (look b...
0
2016-06-21T14:47:23Z
[ "python", "regex", "sed" ]
replace new line with space only if it isn't followed by another new line (undo hard wrap in text)
37,947,453
<p>I have a bunch of text files with hard line wraps (i.e. new line at around 80 chars). I'd like to undo that and join all of those sentences together but maintain new lines where they are new chapters or paragraphs. </p> <p>i.e I.d like to replace '\n' with ' ' if and only if the following character is not another '...
1
2016-06-21T14:38:59Z
37,948,028
<p>You could use a groupby, grouping on whitespace:</p> <pre><code>from itertools import groupby with open("test.txt") as f: print("".join(["".join(v) if k else " ".join(map(str.strip, v))+"\n" for k, v in groupby(f, str.isspace)])) </code></pre> <p>Which would give you:</p> <pre><code>Lorem ipsum dolor sit am...
0
2016-06-21T15:03:00Z
[ "python", "regex", "sed" ]
replace new line with space only if it isn't followed by another new line (undo hard wrap in text)
37,947,453
<p>I have a bunch of text files with hard line wraps (i.e. new line at around 80 chars). I'd like to undo that and join all of those sentences together but maintain new lines where they are new chapters or paragraphs. </p> <p>i.e I.d like to replace '\n' with ' ' if and only if the following character is not another '...
1
2016-06-21T14:38:59Z
37,949,066
<p>I'd try following regex in python:</p> <p>Assuming <code>text</code> variable contains your sample text</p> <pre><code>import re p = re.compile(ur'(?&lt;!^)\n(?=\S)', re.MULTILINE) result = re.sub(p, u" ", text) print(result) </code></pre> <p>It will print following text, replacing single newline with space.</p>...
0
2016-06-21T15:49:43Z
[ "python", "regex", "sed" ]
replace new line with space only if it isn't followed by another new line (undo hard wrap in text)
37,947,453
<p>I have a bunch of text files with hard line wraps (i.e. new line at around 80 chars). I'd like to undo that and join all of those sentences together but maintain new lines where they are new chapters or paragraphs. </p> <p>i.e I.d like to replace '\n' with ' ' if and only if the following character is not another '...
1
2016-06-21T14:38:59Z
37,950,438
<p>Sometimes complicated replacements can be accomplished by passing a function in as the 2nd parameter to <code>re.sub()</code>.</p> <pre><code>import re ipsum = '''Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus porta dui quis aliquet interdum. Sed in pellentesque libero. Quisque tempus nisl nec ni...
0
2016-06-21T17:01:00Z
[ "python", "regex", "sed" ]
pandas: sum two rows of dataframe without rearranging dataframe?
37,947,479
<p>I have a dataframe and I'm trying to sum two rows without messing up the order of the rows.</p> <pre><code>&gt; test = {'counts' : pd.Series([10541,4143,736,18,45690], index=['Daylight','Dawn','Other / unknown','Uncoded &amp; errors','Total']), 'percents' : pd.Series([23.07,9.07,1.61,0.04,100], index=['Daylight','D...
1
2016-06-21T14:40:13Z
37,947,868
<p>use <code>groupby(..., sort=False).sum()</code>:</p> <pre><code>In [84]: (testdf.reset_index() ....: .replace({'index': {'Uncoded &amp; errors':'Other / unknown'}}) ....: .groupby('index', sort=False).sum() ....: ) Out[84]: counts percents index Daylight 10541 2...
2
2016-06-21T14:56:08Z
[ "python", "pandas" ]
pandas: sum two rows of dataframe without rearranging dataframe?
37,947,479
<p>I have a dataframe and I'm trying to sum two rows without messing up the order of the rows.</p> <pre><code>&gt; test = {'counts' : pd.Series([10541,4143,736,18,45690], index=['Daylight','Dawn','Other / unknown','Uncoded &amp; errors','Total']), 'percents' : pd.Series([23.07,9.07,1.61,0.04,100], index=['Daylight','D...
1
2016-06-21T14:40:13Z
37,948,003
<p>Although I prefer MaxU's answer, you can also try summing in-place:</p> <pre><code>testdf.loc['Other / unknown'] += testdf.loc['Uncoded &amp; errors'] </code></pre> <p>And then deleting the row by index:</p> <pre><code>testdf.drop(['Uncoded &amp; errors'], inplace=True) In [28]: testdf Out[28]: ...
1
2016-06-21T15:01:41Z
[ "python", "pandas" ]
pyODBC refuses to look for unixODBC, instead looks for iODBC
37,947,482
<p>Is there a way to get pyODBC v3.0.10 to look for the unixODBC driver, instead of the iODBC driver it seems to want to look for?</p> <p>My understanding is that pyODBC v3.0.10 is supposed to do this by default, while versions prior to v3.0.7 required a manual edit to the setup.py file (see reference <a href="https:/...
0
2016-06-21T14:40:15Z
37,987,728
<p>I believe the reason is you may have compiled pyodbc to use iODBC (or maybe that's the default). If you want tomake sure you build pyodbc against unixODBC, you can specify that just before running <code>setup.py build</code>, as instructed here (look at <a href="http://www.easysoft.com/developer/languages/python/pyo...
1
2016-06-23T09:35:39Z
[ "python", "anaconda", "pyodbc", "unixodbc" ]
pyODBC refuses to look for unixODBC, instead looks for iODBC
37,947,482
<p>Is there a way to get pyODBC v3.0.10 to look for the unixODBC driver, instead of the iODBC driver it seems to want to look for?</p> <p>My understanding is that pyODBC v3.0.10 is supposed to do this by default, while versions prior to v3.0.7 required a manual edit to the setup.py file (see reference <a href="https:/...
0
2016-06-21T14:40:15Z
38,107,050
<p>This is a repost of my answer <a href="http://stackoverflow.com/questions/37933369/error-connecting-to-ms-sql-server-using-pyodbc-unixodbc-and-freetds-on-a-mac/38106959#38106959">here</a>, but this answers this, more-specific formation of the question. Hope I'm not violating any rules, but this took me several week...
0
2016-06-29T18:05:37Z
[ "python", "anaconda", "pyodbc", "unixodbc" ]
How to print like jupyter notebook's default cell output
37,947,496
<p>I faced a problem while printing pandas dataframes in jupyter notebook. If the column names are really long it breaks the dataframe structure in different lines. </p> <p>How can I print it like the way jupyter notebook does it by default(Shown in image - third cell)? As far as I know, only way to print the datafram...
0
2016-06-21T14:40:38Z
37,947,698
<p>You can use IPython's <code>display</code> function to achieve that:</p> <pre><code>from IPython.display import display display(d) </code></pre> <p><a href="http://i.stack.imgur.com/7e9KD.png" rel="nofollow"><img src="http://i.stack.imgur.com/7e9KD.png" alt="display screenshot"></a></p>
2
2016-06-21T14:48:37Z
[ "python", "pandas", "dataframe", "ipython", "jupyter-notebook" ]
Neural Network composed of multiple activation functions
37,947,558
<p>I am using the sknn package to build a neural network. In order to optimize the parameters of the neural net for the dataset I am using I am using an evolutionary algorithm. Since the package allows me to build a neural net where each layer has a different activation function, I was wondering if that is a practical ...
2
2016-06-21T14:42:59Z
37,947,823
<p>A neural network is just a (big) mathematical function. You could even use different activation functions for different neurons in the same layer. Different activation functions allow for different non-linearities which might work better for solving a specific function. Using a sigmoid as opposed to a tanh will only...
1
2016-06-21T14:53:53Z
[ "python", "neural-network", "scikits", "activation-function" ]
Neural Network composed of multiple activation functions
37,947,558
<p>I am using the sknn package to build a neural network. In order to optimize the parameters of the neural net for the dataset I am using I am using an evolutionary algorithm. Since the package allows me to build a neural net where each layer has a different activation function, I was wondering if that is a practical ...
2
2016-06-21T14:42:59Z
37,948,107
<blockquote> <p>I was wondering if [having different activation functions on each layer] is a practical choice, or whether I should just use one activation function per net?</p> </blockquote> <p>Short answer: it depends</p> <p>Longer answer: I'm trying to think of why you <em>would</em> want to have multiple activa...
1
2016-06-21T15:06:18Z
[ "python", "neural-network", "scikits", "activation-function" ]
Pandas: How to sum columns based on conditional of other column values?
37,947,641
<p>I have the following pandas DataFrame.</p> <pre><code>import pandas as pd df = pd.read_csv('filename.csv') print(df) dog A B C 0 dog1 0.787575 0.159330 0.053095 1 dog10 0.770698 0.169487 0.059815 2 dog11 0.792689 0.152043 0.055268 3 dog12 0.785066 ...
2
2016-06-21T14:45:57Z
37,947,677
<p>The following should work, here we mask the df where the condition is met, this will set <code>NaN</code> to the rows where the condition isn't met so we call <code>fillna</code> on the new col:</p> <pre><code>In [67]: df = pd.DataFrame(np.random.randn(5,3), columns=list('ABC')) df Out[67]: A B ...
3
2016-06-21T14:47:36Z
[ "python", "pandas", "dataframe", "conditional" ]
Run python script from VBA
37,947,724
<p>I have tried several solutions to run python script out of VBA.</p> <p>My current solution that still doesnt work</p> <pre><code>Dim wsh As Object Set wsh = VBA.CreateObject("WScript.Shell") Dim windowStyle As Integer: windowStyle = 1 Dim waitOnReturn As Boolean: waitOnReturn = True wsh.Run "C:\Python33\python.ex...
0
2016-06-21T14:49:49Z
37,947,802
<p><a href="http://docs.xlwings.org/en/stable/quickstart.html#call-python-from-excel" rel="nofollow">xlwings</a> claims to make python from excel very easy:</p> <pre><code>Sub RandomNumbers() RunPython ("import mymodule; mymodule.rand_numbers()") End Sub </code></pre> <blockquote> <p>To make this run, just impo...
0
2016-06-21T14:52:53Z
[ "python", "vba" ]
Run python script from VBA
37,947,724
<p>I have tried several solutions to run python script out of VBA.</p> <p>My current solution that still doesnt work</p> <pre><code>Dim wsh As Object Set wsh = VBA.CreateObject("WScript.Shell") Dim windowStyle As Integer: windowStyle = 1 Dim waitOnReturn As Boolean: waitOnReturn = True wsh.Run "C:\Python33\python.ex...
0
2016-06-21T14:49:49Z
37,947,856
<p>Is this what you are looking for? <a href="https://blogs.msdn.microsoft.com/vbfaq/2004/05/30/how-can-i-run-another-application-or-batch-file-from-my-visual-basic-net-code/" rel="nofollow">https://blogs.msdn.microsoft.com/vbfaq/2004/05/30/how-can-i-run-another-application-or-batch-file-from-my-visual-basic-net-code/<...
-1
2016-06-21T14:55:35Z
[ "python", "vba" ]
Run python script from VBA
37,947,724
<p>I have tried several solutions to run python script out of VBA.</p> <p>My current solution that still doesnt work</p> <pre><code>Dim wsh As Object Set wsh = VBA.CreateObject("WScript.Shell") Dim windowStyle As Integer: windowStyle = 1 Dim waitOnReturn As Boolean: waitOnReturn = True wsh.Run "C:\Python33\python.ex...
0
2016-06-21T14:49:49Z
37,987,223
<p>Finally I ended up with creation of .exe files instead of trying to call scripts itself.</p> <p>So, I applied cx_Freeze, created .exe files and then called them as</p> <pre><code>Script_path1 = "C:\Users\" + Environ("Username") &amp; "\Documents\Promo_models\get_sku_data\gui_changed.exe" wsh.Run Script_path1, wind...
0
2016-06-23T09:14:04Z
[ "python", "vba" ]
Run python script from VBA
37,947,724
<p>I have tried several solutions to run python script out of VBA.</p> <p>My current solution that still doesnt work</p> <pre><code>Dim wsh As Object Set wsh = VBA.CreateObject("WScript.Shell") Dim windowStyle As Integer: windowStyle = 1 Dim waitOnReturn As Boolean: waitOnReturn = True wsh.Run "C:\Python33\python.ex...
0
2016-06-21T14:49:49Z
38,296,223
<p>Here are a couple options to try.</p> <pre><code>RetVal = Shell("&lt;full path to python.exe&gt; " &amp; "&lt;full path to your python script&gt;") </code></pre> <p>Or if the python script is in the same folder as the workbook, then you can try :</p> <pre><code>RetVal = Shell("&lt;full path to python.exe&gt; " &a...
0
2016-07-10T20:32:24Z
[ "python", "vba" ]
saving lines to file based on condition pandas python
37,947,741
<p>I have a small sample dataset:</p> <pre><code>import pandas as pd df = {'ID': ['H576','H577','H577','H578','H600', 'H700', 'H700'], 'CD': ['AAAAAAA', 'BBBBB', 'CCCCCC','DDDDDD', 'EEEEEEE','FFFFFFF','GGGGGGG']} df = pd.DataFrame(df) </code></pre> <p>it looks like: </p> <pre><code>df Out[9]: CD ID ...
1
2016-06-21T14:50:33Z
37,948,193
<p>try this:</p> <pre><code>(df.groupby('ID') .filter(lambda g: len(g) &gt; 1) .groupby('ID') .apply(lambda gp: gp.to_csv('ID{}.txt'.format(gp.name), sep='\t', index=False)) ) </code></pre> <p><strong>Output</strong></p> <p>IDH577.txt:</p> <pre><code>CD ID BBBBB H577 CCCCCC H577 </code></pre> <p>IDH70...
1
2016-06-21T15:09:56Z
[ "python", "pandas" ]
Python MYSql.connector will not insert data
37,947,880
<p>I am trying to insert some data into a a database I am making and it will not insert. I literally have used the same insert method on other code and it still seems to work, however this one refuses to. Help!</p> <pre><code>from Bio import Entrez from sys import exit Entrez.email = "A.N.Other@example.com" # Alwa...
0
2016-06-21T14:56:34Z
37,975,169
<p>I ended up just doing it this way and it finally worked. I am unsure why it did not work before but I believe that it had something to do with the formatting of how i typed in the columns.</p> <pre><code>from mysql.connector import MySQLConnection, Error from python_mysql_dbconfig import read_db_config cnx = mysql...
0
2016-06-22T17:57:42Z
[ "python", "mysql", "mysql-python", "bioinformatics" ]
Trouble to change user.is_staff 's value
37,947,912
<p>I create a custom Staff model and ModelForm in my project. By default, A Staff is created without staff permission.In other world,User.is_staff = False. The permission can be set later in updatstaff. In my updatestaff, I try to offer a staff permission by calling user.is_staff = True. However, the user.is_staff is a...
0
2016-06-21T14:57:41Z
37,948,825
<p>You should never assume that <code>request.POST.get(...)</code> could give you right data type. What you get back is an <code>unicode</code>. So, <code>bool('True')</code> is <code>True</code> and <code>bool('False')</code> is also <code>True</code>. In your case it will always <code>True</code>. There is not clear ...
1
2016-06-21T15:38:11Z
[ "python", "django" ]
Trouble to change user.is_staff 's value
37,947,912
<p>I create a custom Staff model and ModelForm in my project. By default, A Staff is created without staff permission.In other world,User.is_staff = False. The permission can be set later in updatstaff. In my updatestaff, I try to offer a staff permission by calling user.is_staff = True. However, the user.is_staff is a...
0
2016-06-21T14:57:41Z
37,949,959
<p>@trantu's answer explains the problem with your code, but you should never check if the user is authorised by checking the POST parameters, as a user can post whatever they want with the form.</p> <p>You should use something like this instead:</p> <pre><code>if request.user.is_staff(): # Or admin, or checking the...
0
2016-06-21T16:33:44Z
[ "python", "django" ]
androidviewclient: store view client dumps
37,947,992
<p>Is there some way to store dumps in a dictionary and use these dumps at a later time so that the dump does not have to be recalculated every time? This is a more a proof of concept question as I'm looking for a way to speed up androidviewclient's slow dump process and make my script quicker in any manner. For instan...
0
2016-06-21T15:01:20Z
37,953,312
<p>This is a <code>culebra</code> generated script slightly modified to do what you are asking for.</p> <pre><code>#! /usr/bin/env python # -*- coding: utf-8 -*- ''' Copyright (C) 2013-2016 Diego Torres Milano Created on 2016-06-21 by Culebra v11.5.9 __ __ __ __ / ...
0
2016-06-21T19:46:51Z
[ "android", "python", "androidviewclient" ]
Help - Web-form Bruteforcing with Python
37,947,994
<p>So, I have this Python script below. What it does, is it basically bruteforces a web-form (login) using itertools. It does what I want, I've got it to work perfectly etc., however I'd like to ask if someone could replace the bruteforce/dictionary generation process with a load-passwords-from-wordlist.txt feature. If...
-1
2016-06-21T11:45:05Z
37,947,995
<p>Something like this could be added so if a password file is present in the command line arguments it will use that instead of the pre-defined list.</p> <p>Example: <em>python script.py password.txt</em></p> <pre><code>import sys import os if len(sys.argv) &gt; 1: if os.path.exists(sys.argv[1]): combos...
1
2016-06-21T13:28:22Z
[ "passwords", "python", "dictionary" ]
Self scheduled Python script
37,948,020
<p>I'm writing an Python script that calls a function that exports and imports spaces from the wiki tool Confluence. It has to run everyday, but we can't use cron so i'm looking for a way to schedule it by her self.</p> <p>I've created the following. I can already schedule it for the next day but not for the following...
0
2016-06-21T15:02:29Z
37,949,013
<p>I would suggest using something a bit simplilar then what you are doing there. There is a simple scheduling library in python called sched, which can be found here: <a href="https://docs.python.org/2/library/sched.html" rel="nofollow">https://docs.python.org/2/library/sched.html</a></p> <p>A simple example of using...
0
2016-06-21T15:47:30Z
[ "python", "scripting", "scheduled-tasks" ]
Self scheduled Python script
37,948,020
<p>I'm writing an Python script that calls a function that exports and imports spaces from the wiki tool Confluence. It has to run everyday, but we can't use cron so i'm looking for a way to schedule it by her self.</p> <p>I've created the following. I can already schedule it for the next day but not for the following...
0
2016-06-21T15:02:29Z
38,296,238
<p>Sorry, but can't you simply use the Windows Task Scheduler for this?</p> <p><a href="http://www.sevenforums.com/tutorials/11949-elevated-program-shortcut-without-uac-prompt-create.html" rel="nofollow">http://www.sevenforums.com/tutorials/11949-elevated-program-shortcut-without-uac-prompt-create.html</a></p>
0
2016-07-10T20:34:40Z
[ "python", "scripting", "scheduled-tasks" ]
Django: Unable to call python function from Javascript
37,948,066
<p>I have a Django project with the following structure. My project name is <em>SimpleWeb</em>. I have an application named <em>query</em>. Now I have an HTML page which has a dropdown menu and a submit button.</p> <p>Here is what I am trying to do. When the user selects an item from the dropdown and hits submit, I wa...
0
2016-06-21T15:04:44Z
37,948,535
<p>You coworker is correct, you are being redundant in you <code>urls.py</code> definitions.</p> <p>For now, only use your main app's <code>SimpleWeb/urls.py</code> and build you URLs from there. Once you got that, you can learn how to separate them into parts and import them.</p> <p>I guess these are the URLs you ar...
1
2016-06-21T15:25:31Z
[ "javascript", "python", "angularjs", "django" ]
Django: Unable to call python function from Javascript
37,948,066
<p>I have a Django project with the following structure. My project name is <em>SimpleWeb</em>. I have an application named <em>query</em>. Now I have an HTML page which has a dropdown menu and a submit button.</p> <p>Here is what I am trying to do. When the user selects an item from the dropdown and hits submit, I wa...
0
2016-06-21T15:04:44Z
37,948,684
<p>You're not defining the URLs correctly so the router can't find the correct method. One way you could define the URLs:</p> <p><strong>SimpleWeb\urls.py</strong></p> <pre><code>from django.conf.urls import include, url from django.contrib import admin urlpatterns = [ url(r'^admin/', admin.site.urls), url(r'',...
1
2016-06-21T15:31:52Z
[ "javascript", "python", "angularjs", "django" ]
How to read text file columns to apply python data frame?
37,948,102
<p>I have a Original <strong>text file</strong>: original.txt</p> <pre><code>tmin, tmax, mean, fmin, fmax, stdev 0, 0.005000, 0, 0, 0, 0 0.005000, 0.010000, 0, 0, 0, 0 </code></pre> <p>For calculating, I read this file as CSV</p> <pre><code>&gt;&gt;&gt;import pandas as pd &...
0
2016-06-21T15:06:10Z
37,948,338
<p>There are spaces in your column names:</p> <pre><code>Index([u'tmin', u' tmax', u' mean', u' fmin', u' fmax', u' stdev'], dtype='object') </code></pre> <p>By default <code>read_csv</code> parses the file using commas as the delimiter between fields. So <code>df</code> ends up with a column named <code>u' tmax'</c...
2
2016-06-21T15:17:01Z
[ "python", "csv", "pandas", "dataframe" ]
How to read text file columns to apply python data frame?
37,948,102
<p>I have a Original <strong>text file</strong>: original.txt</p> <pre><code>tmin, tmax, mean, fmin, fmax, stdev 0, 0.005000, 0, 0, 0, 0 0.005000, 0.010000, 0, 0, 0, 0 </code></pre> <p>For calculating, I read this file as CSV</p> <pre><code>&gt;&gt;&gt;import pandas as pd &...
0
2016-06-21T15:06:10Z
37,948,456
<p>The u' indicates unicode string.</p> <p>To get the values of tmin, tmax etc, just enter</p> <pre><code>df.tmin </code></pre> <p>for entire column or </p> <pre><code>df['tmin'] </code></pre> <p>You can get specific values by doing the following:</p> <pre><code>df.tmin[0] </code></pre> <p>or</p> <pre><code>df[...
0
2016-06-21T15:21:33Z
[ "python", "csv", "pandas", "dataframe" ]
Django not serving admin static files using fastcgi
37,948,141
<p>I am trying to deploy my django app on a subdomain, say example.djangoapp.com, everything works fine, except for my django admin site, when i click on the link that goes to the admin site, it routes to a different url. This happens when i use the admin url template tag, i.e. it routes to djangoapp.com/index instead ...
1
2016-06-21T15:07:44Z
37,993,059
<p>You'll need to add a rewrite rule to redirect the browser request to the actual static files for the admin page. Below your last rewrite rule, add these lines:</p> <pre><code>RewriteCond "%{REQUEST_URI}" ".*/static/admin/.*" RewriteRule "(.*)/cconect/(.*)" "$1/index.fcgi/$2" [R, L] </code></pre> <p>Here, the rewri...
0
2016-06-23T13:28:16Z
[ "python", "django", ".htaccess" ]
How to use Qt designer with a preexisting Python code?
37,948,252
<p>I am currently trying to make GUI in python. For this, the way I found is to use Qt Designer to generate a graphical interface .ui, and to convert it in .py with PyQt4, to edit functions in python.</p> <p>The question I have is then how to modify the graphical interface without having to set up again the whole pyth...
0
2016-06-21T15:12:45Z
37,962,196
<p><strong>Answer</strong>. If you're going to modify code from Qt Designer (via pyuic), understand that the process is one way:</p> <pre><code>.ui file -&gt; pyuic -&gt; .py </code></pre> <p>pyuic (and uic, the Qt/C++ equivalent) are one way code generators. You can't take existing Python code and make a .ui file f...
1
2016-06-22T08:10:26Z
[ "python", "qt", "user-interface", "interface", "qt-designer" ]
assigning bounds to individual independent points within the scipy.optimize.curve_fit function
37,948,271
<p>I am trying to fit a Planck curve to radiance readings. I know the radiance at some known wavelengths (11 data points), the parameter to fit is the temperature.</p> <p>The Planck function that returns the radiance from the wavelength and the temperature:</p> <pre><code>def bbody(lam, T) : lam = 1e-6 * lam # fr...
1
2016-06-21T15:13:44Z
37,954,852
<p>It seems that your "bounds" somehow quantify uncertainties of the readings of the independent variable (wavelengths). </p> <p><code>bounds</code> parameter is definitely not helpful: it's job is to set the allowed bounds for the parameter you're estimating (e.g., you know that the temperature is not negative).</p> ...
2
2016-06-21T21:25:27Z
[ "python", "numpy", "scipy", "curve-fitting" ]
Extract files from zip archive excluding certain filenames
37,948,283
<p>In Python, how do I extract a zip archive while preserving folder structure but excluding certain filenames (file types) from extraction? For example, I want to exclude all the <code>.tif</code> images from being extracted.</p> <p>I'm using Python 3.x and the <code>zipfile</code> module.</p>
-2
2016-06-21T15:14:05Z
37,948,415
<p>Pass a filtered <code>members</code> to <code>extractall()</code>. <code>archive.extractall(members=(member for member in archive.namelist() if not member.endswith('.tif')))</code>.</p> <pre><code>def extractall(self, path=None, members=None, pwd=None): """Extract all members from the archive to the current wor...
1
2016-06-21T15:19:52Z
[ "python", "python-3.x", "zipfile" ]
Extract files from zip archive excluding certain filenames
37,948,283
<p>In Python, how do I extract a zip archive while preserving folder structure but excluding certain filenames (file types) from extraction? For example, I want to exclude all the <code>.tif</code> images from being extracted.</p> <p>I'm using Python 3.x and the <code>zipfile</code> module.</p>
-2
2016-06-21T15:14:05Z
37,949,888
<p>It is been a while since I have used this routine, so I had to dig it out. You may want to test/adapt to your specific need.</p> <p>The exclusion <code>if</code> statement only checks the last three characters of the to be extracted file name, you can change this using a <code>.split('.')</code> to check for the fu...
1
2016-06-21T16:30:19Z
[ "python", "python-3.x", "zipfile" ]
Type Error when sending command through python
37,948,306
<p>I'm trying to use bleualign (<a href="https://github.com/rsennrich/Bleualign" rel="nofollow">https://github.com/rsennrich/Bleualign</a>) to align the sentences of some .txt files. The way this tool works is to send a command in the terminal in the following way:</p> <pre><code>python ../../Bleualign/bleualign.py -s...
0
2016-06-21T15:15:06Z
37,949,428
<p>This appears to be a bug in Bleualign. On the current line of <a href="https://github.com/rsennrich/Bleualign/blob/master/bleualign/align.py#L187" rel="nofollow">https://github.com/rsennrich/Bleualign/blob/master/bleualign/align.py#L187</a> they authors have:</p> <pre><code>return io.StringIO('\n'.join([line.rstri...
0
2016-06-21T16:06:18Z
[ "python", "unicode" ]
How to use monkeypatch in a "setup" method for unit tests using pytest?
37,948,345
<p>I am attempting to mock out a utility class (In this case the python logger utility) in a unit test.</p> <p>While I know how to do it using monkeypatch on a per test level, I was hoping I could simply do it as part of the setup/globally in some way.</p> <p>Here is what I am hoping I can do (but I am getting errors...
2
2016-06-21T15:17:17Z
37,956,445
<p><code>monkeypatch</code> works as a normal pytest fixture. If you want to use it, you need to make your method as a fixture as well.</p> <pre><code>import logging import pytest @pytest.fixture def setup(monkeypatch): class fake_logger(object): def __init__(self, val): pass def s...
0
2016-06-21T23:57:36Z
[ "python", "unit-testing", "py.test", "monkeypatching" ]
Django Form Decimal field initial data with 2 decimal places
37,948,434
<p>I have a form with a <code>DecimalField</code> and I am getting the data from API which I pass as initial input to the form. The <code>DecimalField</code> is defined as below:</p> <pre><code>school_fee = forms.DecimalField(max_digits=6,decimal_places=2,initial=5.00,required=True") </code></pre> <p>So, I am getting...
0
2016-06-21T15:20:44Z
37,966,216
<p>You need to import Decimal.</p> <pre><code>from decimal import Decimal </code></pre> <p>instead of initial write</p> <pre><code>default=Decimal('5.00') </code></pre> <p>may be solved your problem</p>
0
2016-06-22T11:07:10Z
[ "python", "django", "python-2.7", "django-forms" ]
Reference DataFrame name in a function (pandas, python3)
37,948,562
<p>I have a bunch of data frames with sales data for different brands. I want to create a function that ultimately makes excel files from the brand specific data frames. Everything works fine except I need to make uniquely named excel files as the output. Here is what I currently have:</p> <pre><code>def brandOverview...
2
2016-06-21T15:26:37Z
37,949,495
<p>Your attempt is very close. You only need to alter <code>str(b)</code> and replace it with something that returns <code>'Adidas'</code> in this case and whatever the brand is for any other case. You didn't provide any information about the structure of the dataframes. However, in order for this to work, you need ...
2
2016-06-21T16:10:25Z
[ "python", "pandas", "dataframe" ]
codecademy Practice Makes Perfect digit_sum
37,948,737
<p>The purpose is Write a function called digit_sum that takes a positive integer n as input and returns the sum of all that number's digits.</p> <p>For example: digit_sum(1234) should return 10 which is 1 + 2 + 3 + 4.</p> <p>(Assume that the number you are given will always be positive.)</p> <p><a href="https://www...
0
2016-06-21T15:34:12Z
37,949,048
<p>Something like : </p> <pre><code>def digit_sum(n): dig=0 # this is the result os the sum number=str(n) #transform the number into string so we can iterate for i in range(len(number)): dig=dig+int(number[i]) #transform the char to int return dig #return the sum </code></pre> <p>I take the n...
0
2016-06-21T15:49:06Z
[ "python" ]
codecademy Practice Makes Perfect digit_sum
37,948,737
<p>The purpose is Write a function called digit_sum that takes a positive integer n as input and returns the sum of all that number's digits.</p> <p>For example: digit_sum(1234) should return 10 which is 1 + 2 + 3 + 4.</p> <p>(Assume that the number you are given will always be positive.)</p> <p><a href="https://www...
0
2016-06-21T15:34:12Z
37,949,164
<p>So the difference between inside/outside is <strong>locality</strong>. When you put <code>dig</code> outside, you create a global list. From there, you're constantly <em>appending</em> to that- the list is never cleared! So if I run <code>digit_sum(1234)</code>, I properly get 10. If I immediately thereafter run <co...
1
2016-06-21T15:54:23Z
[ "python" ]
codecademy Practice Makes Perfect digit_sum
37,948,737
<p>The purpose is Write a function called digit_sum that takes a positive integer n as input and returns the sum of all that number's digits.</p> <p>For example: digit_sum(1234) should return 10 which is 1 + 2 + 3 + 4.</p> <p>(Assume that the number you are given will always be positive.)</p> <p><a href="https://www...
0
2016-06-21T15:34:12Z
38,136,416
<p>The previous answer is all right. Just to focuse your attention so that you could avoid mistakes in the future: When you write:</p> <pre><code>u=str(n) for i in u: dig.append(i) </code></pre> <p>you don't append the digits of the number to the dig. Instead you add digits 0, 1 ,2 ,3 .. so on. Exactly t...
0
2016-07-01T03:09:29Z
[ "python" ]
Why does this print the memory location of an object rather than what I want?
37,948,820
<p>I'm not sure what's happening when I print my dictionary. </p> <p>In Python 3, I have a dictionary of parse_blast objects called transSwiss. Each object's proteinID is the key with the entire object as the value.</p> <p>I can print transSwiss in it's entirety and I can also print blasto.protein, but not when I com...
-3
2016-06-21T15:37:59Z
37,948,956
<p>Because your object is defined by you, you also need to tell python how you want it to print. You can do this by defining a function called "__str__" that returns how you want to print your object.</p> <p><a href="https://en.wikibooks.org/wiki/Python_Programming/Classes#str" rel="nofollow">https://en.wikibooks.org/...
1
2016-06-21T15:45:34Z
[ "python", "dictionary" ]
Python: how to create a choropleth map out of a shapefile of Canada?
37,948,836
<p>My goal here is to create a <a href="https://en.wikipedia.org/wiki/Choropleth_map" rel="nofollow">choropleth map</a> of Canada in Python. Suppose I have a dictionary with values referring to each Canadian province/territory:</p> <pre><code>myvalues={'Alberta': 1.0, 'British Columbia': 2.0, 'Manitoba': 3.0, 'New ...
5
2016-06-21T15:38:41Z
37,950,172
<p>Request: please rename your <code>values</code> dictionary to something else. That name has made writing this answer much more difficult. :)</p> <p>Haven't tested this, but try:</p> <pre><code>color_numbers = values.values() # assumes the provinces are listed in the same order in values as # they are in ...
1
2016-06-21T16:45:50Z
[ "python", "matplotlib", "patch", "shapefile", "choropleth" ]
Python: how to create a choropleth map out of a shapefile of Canada?
37,948,836
<p>My goal here is to create a <a href="https://en.wikipedia.org/wiki/Choropleth_map" rel="nofollow">choropleth map</a> of Canada in Python. Suppose I have a dictionary with values referring to each Canadian province/territory:</p> <pre><code>myvalues={'Alberta': 1.0, 'British Columbia': 2.0, 'Manitoba': 3.0, 'New ...
5
2016-06-21T15:38:41Z
37,950,227
<p>You mentioned confusion about <code>cccol</code> being a list of lists. It is list of RGBA tuples (red, green, blue, alpha transparency). These represent 13 "equally spaced" colors from orange to red.</p> <p>In your case you don't want equally spaced colors but colors corresponding to <code>myvalues</code>. Do t...
1
2016-06-21T16:48:31Z
[ "python", "matplotlib", "patch", "shapefile", "choropleth" ]
Python: how to create a choropleth map out of a shapefile of Canada?
37,948,836
<p>My goal here is to create a <a href="https://en.wikipedia.org/wiki/Choropleth_map" rel="nofollow">choropleth map</a> of Canada in Python. Suppose I have a dictionary with values referring to each Canadian province/territory:</p> <pre><code>myvalues={'Alberta': 1.0, 'British Columbia': 2.0, 'Manitoba': 3.0, 'New ...
5
2016-06-21T15:38:41Z
37,950,480
<p>This doesn't directly answer your question but hopefully solves your problem just the same. Have you looked at <a href="http://geopandas.org/" rel="nofollow">GeoPandas</a>? It provides a simple API for working with and plotting shapefiles. You can replicate your code, including plotting a choropleth, in just a fe...
2
2016-06-21T17:03:12Z
[ "python", "matplotlib", "patch", "shapefile", "choropleth" ]
python dictionary iteration usage error
37,948,996
<p>Ok here is my code:</p> <pre><code># create variables direction = ('north', 'south', 'east', 'west', 'down', 'up', 'left', 'right', 'back') verb = ('go', 'stop', 'kill', 'eat') stop = ('the', 'in', 'of', 'from', 'at', 'it') noun = ('door', 'bear', 'princess', 'cabinet') number = ('0', '1', '2', '3', '4', '5', '6',...
-1
2016-06-21T15:46:42Z
37,949,144
<p><code>if words in k:</code> is never true so <code>m</code> is never defined, hence the error.</p> <p>You could do something like that:</p> <pre><code>m = "" for k, v in src.items(): if words in k: m = src.get(k) if m: print([(m, w) for w in words if w in direction or verb or stop or noun or nu...
0
2016-06-21T15:53:13Z
[ "python", "python-2.7" ]
python dictionary iteration usage error
37,948,996
<p>Ok here is my code:</p> <pre><code># create variables direction = ('north', 'south', 'east', 'west', 'down', 'up', 'left', 'right', 'back') verb = ('go', 'stop', 'kill', 'eat') stop = ('the', 'in', 'of', 'from', 'at', 'it') noun = ('door', 'bear', 'princess', 'cabinet') number = ('0', '1', '2', '3', '4', '5', '6',...
-1
2016-06-21T15:46:42Z
37,949,617
<p>You logic is all wrong, <em>words</em> is a list and a list could never be in your tuple of words so it <code>m</code> never gets defines. You need to check if the individual <em>word</em> was in the key/tuple. I would use a <em>frozenset</em> of words as keys instead for <code>O(1)</code> lookups:</p> <pre><code>...
0
2016-06-21T16:17:44Z
[ "python", "python-2.7" ]
python dictionary iteration usage error
37,948,996
<p>Ok here is my code:</p> <pre><code># create variables direction = ('north', 'south', 'east', 'west', 'down', 'up', 'left', 'right', 'back') verb = ('go', 'stop', 'kill', 'eat') stop = ('the', 'in', 'of', 'from', 'at', 'it') noun = ('door', 'bear', 'princess', 'cabinet') number = ('0', '1', '2', '3', '4', '5', '6',...
-1
2016-06-21T15:46:42Z
37,949,966
<p>Your design is probably not the best to start, here are my proposals:</p> <pre><code># frozenset are a better option for these static variables... direction = ('north', 'south', 'east', 'west', 'down', 'up', 'left', 'right', 'back') verb = ('go', 'stop', 'kill', 'eat')...
0
2016-06-21T16:34:12Z
[ "python", "python-2.7" ]
LSTM ptb model in tensorflow returns the same word all the time
37,949,044
<p>I applied the same methods described in <a href="http://stackoverflow.com/questions/36286594/predicting-the-next-word-using-the-lstm-ptb-model-tensorflow-example">Predicting the next word using the LSTM ptb model tensorflow example</a> to use tensorflow LSTM and predict the next words in my test document. However, t...
1
2016-06-21T15:48:57Z
37,961,284
<p>Maybe the temperature of the SoftMax is too cold?</p>
0
2016-06-22T07:28:14Z
[ "python", "tensorflow", "lstm" ]
Automatic pytest.mark decoration based on fixture
37,949,078
<p>Let's say I have a pytest fixture established in my conftest.py file that looks like:</p> <pre><code>def live_fixture(): # network access here... pass </code></pre> <p>I use this same fixture in many test functions, say that test_spam.py has some test functions:</p> <pre><code>@pytest.mark.live def test_o...
1
2016-06-21T15:50:13Z
37,952,009
<p>Well, I fooled around with this a bit more and got something very rough working. I define a function like this: </p> <pre><code>import sys, inspect, pytest def mark_live_fixtures(module_name): testfunctions = [obj for name,obj in inspect.getmembers(sys.modules[module_name]) ...
0
2016-06-21T18:31:00Z
[ "python", "py.test", "python-decorators" ]
Automatic pytest.mark decoration based on fixture
37,949,078
<p>Let's say I have a pytest fixture established in my conftest.py file that looks like:</p> <pre><code>def live_fixture(): # network access here... pass </code></pre> <p>I use this same fixture in many test functions, say that test_spam.py has some test functions:</p> <pre><code>@pytest.mark.live def test_o...
1
2016-06-21T15:50:13Z
37,952,276
<p>I found another plausible solution, by trying to dig out how pytest.mark works.</p> <p>I found class Node has a method "add_marker", which should be the exact method which implement feature pytest.mark. And class Item is extended from Node.</p> <p>So my solution is:</p> <ol> <li>Trying to find if the fixture is u...
1
2016-06-21T18:45:56Z
[ "python", "py.test", "python-decorators" ]
Improve performance of elasticsearch signals
37,949,140
<p>I am using system called commonsearch. Particularly for this post, we will be talking about backend part of it, witch is written in python.</p> <p>The backend system streams warc file and indexe's its content to 2 elasticsearch clusters - 1) Text elasticsearch cluster 2) Document elasticsearch cluster.</p> <p>The ...
0
2016-06-21T15:53:09Z
38,077,418
<p>For each question:</p> <p><strong>How could i boost the performance of all of this ?</strong> Several ways are here, try Feature Selection for your text and classes, based on model you use for training(e.g Bag Of Words) or try LSA and LSI, look at this: <a href="http://stackoverflow.com/questions/37969425/text-clas...
1
2016-06-28T13:19:38Z
[ "python", "performance", "amazon-web-services", "filter", "rank" ]
How do I use a variable in a module that is defined in the main program?
37,949,155
<p>I'm writing a program to control a camera connected to two stepper motors from a raspberry pi. I'm writing in python, and I'm having trouble understanding global variables (or names in python, I guess). I've looked up some things about scope and about global variables, but I'm really new to programming with python, ...
3
2016-06-21T15:54:02Z
37,949,408
<p>The <code>global</code> statement is a <strong><em>declaration</em></strong> which holds for the entire current code block. It means that the listed identifiers are to be interpreted as globals. </p> <p>You still need to <strong>define</strong> the identifiers somewhere. This is the error you get: <code>global name...
1
2016-06-21T16:05:12Z
[ "python" ]
'WSGIRequest' object has no attribute 'user' Django admin
37,949,198
<p>When I trying to access the admin page it gives me the following error:</p> <pre><code>System check identified no issues (0 silenced). June 21, 2016 - 15:26:14 Django version 1.9.7, using settings 'librato_chart_sender_web.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-...
5
2016-06-21T15:55:52Z
37,950,161
<p>I found the answer. The variable name on:</p> <pre><code>MIDDLEWARE = [ 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middlewa...
27
2016-06-21T16:45:28Z
[ "python", "django", "admin", "panel", "wsgi" ]
'WSGIRequest' object has no attribute 'user' Django admin
37,949,198
<p>When I trying to access the admin page it gives me the following error:</p> <pre><code>System check identified no issues (0 silenced). June 21, 2016 - 15:26:14 Django version 1.9.7, using settings 'librato_chart_sender_web.settings' Starting development server at http://127.0.0.1:8000/ Quit the server with CONTROL-...
5
2016-06-21T15:55:52Z
39,519,162
<p>To resolve this go to settings.py where there MIDDLEWARE</p> <p>Change that to MIDDLEWARE_CLASSES</p> <p><a href="https://docs.djangoproject.com/ja/1.9/topics/http/middleware/">https://docs.djangoproject.com/ja/1.9/topics/http/middleware/</a></p>
10
2016-09-15T19:44:03Z
[ "python", "django", "admin", "panel", "wsgi" ]
How to identify and label similar rows in a pandas data frame
37,949,199
<p>I am working with a large data set that is composed of two panda data-frames. One of which is the measurements taken from an instrument, the other is the variables present at each measurement. The goal is to use a few supervised learning methods to predict the variables given the measurements. I have not found a ...
-5
2016-06-21T15:55:52Z
37,949,600
<p>Your question really needs clarifications but since they are MIA i will assume ahead.</p> <p><strong>ASSUMPTIONS</strong></p> <ul> <li>The column on the left comes from a list of lists. I will name that "alist_oflists".</li> <li>Every time a unique inner list is found, a new integer-type identifier is attributed t...
0
2016-06-21T16:16:20Z
[ "python", "pandas", "dataframe" ]