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 |
|---|---|---|---|---|---|---|---|---|---|
Tilted loss in theano | 38,497,955 | <p>I am trying to calculate the tilted loss, which in turn will be used in Keras. However, I must be doing something wrong since I am getting negative loss values (which ought to be impossible). Can anyone point out what I've done wrong. I'm assuming it's the theano syntax that I have got wrong.</p>
<p>The loss is def... | 0 | 2016-07-21T07:40:16Z | 38,501,057 | <p>You can not slice like this. <a href="http://stackoverflow.com/questions/37425401/theano-tensor-slicing-how-to-use-boolean-to-slice/37425475#37425475">see this answer</a></p>
<p>You need to change your loss function as follows:</p>
<pre><code>def tilted_loss2(y,f):
q = 0.05
e = (y-f)
return (q*tt.sum(e... | 2 | 2016-07-21T10:00:58Z | [
"python",
"theano",
"keras"
] |
PyFann data format for list described dataset | 38,498,119 | <p>I am working on detection of regions of specific tree in an aerial image and my approach is using texture detection. I have 4 descriptors/features and I want to use FANN to create a machine learning environment that would detect properly the regions.</p>
<p>My question is,
is the format I am reading, regarding ... | 0 | 2016-07-21T07:48:35Z | 39,946,524 | <p>Each input neuron can only take a single input - this is the case for all neural networks, irrespective of the library you use. I would suggest using each element in each of your lists as an input to the neural network, e.g. inputs 1-5 are your first list and then 6-10 are your second list. If you have variable leng... | 0 | 2016-10-09T17:37:06Z | [
"python",
"neural-network",
"fann"
] |
Accessing original function variables in decorators | 38,498,159 | <p>I'm making a logging module in python which reports every exception that happens in run-time to a server, so in every function I have to write:</p>
<pre><code>def a_func():
try:
#stuff here
pass
except:
Logger.writeError(self.__class__.__name__, inspect.stack()[1][3],\
t... | 0 | 2016-07-21T07:50:29Z | 38,498,394 | <p>You don't need to use <code>vars()</code>. The <em>traceback</em> of an exception has everything you need:</p>
<pre><code>import sys
def flog(func):
def flog_wrapper(self, *args, **kwargs):
try:
return func(self, *args, **kwargs)
except Exception:
exc_type, exc_value, tb = s... | 0 | 2016-07-21T08:02:42Z | [
"python",
"python-2.7",
"python-decorators"
] |
How do I get all values from one position in a tuple in a pandas dataframe column? | 38,498,239 | <p>I have a pandas dataframe where several columns are filled with tuples with two values each, mixed types.</p>
<p>Example:</p>
<pre><code>import pandas as pd
D = [{'A':1,'B':'Test1','C':('C1',True)},\
{'A':2,'B':'Test2','C':(77,u'orz')},\
{'A':3,'B':'Test3','C':(u'ASDFG',[1,2,3])}]
F = pd.DataFrame.from... | 1 | 2016-07-21T07:54:28Z | 38,498,294 | <p>One way is to use a list comprehension and extract the second item in the tuple pair.</p>
<pre><code>>>> [tup[1] for tup in F.C]
[True, u'orz', [1, 2, 3]]
</code></pre>
| 2 | 2016-07-21T07:57:09Z | [
"python",
"numpy",
"pandas"
] |
How do I get all values from one position in a tuple in a pandas dataframe column? | 38,498,239 | <p>I have a pandas dataframe where several columns are filled with tuples with two values each, mixed types.</p>
<p>Example:</p>
<pre><code>import pandas as pd
D = [{'A':1,'B':'Test1','C':('C1',True)},\
{'A':2,'B':'Test2','C':(77,u'orz')},\
{'A':3,'B':'Test3','C':(u'ASDFG',[1,2,3])}]
F = pd.DataFrame.from... | 1 | 2016-07-21T07:54:28Z | 38,499,436 | <p>If you prefer to stay in the pandas DafaFrame / Series domain:</p>
<pre><code>F.C.apply(lambda x: x[-1])
</code></pre>
<p>Returns:</p>
<pre><code>>>> F.C.apply(lambda x: x[-1])
0 True
1 orz
2 [1, 2, 3]
Name: C, dtype: object
</code></pre>
| 1 | 2016-07-21T08:51:23Z | [
"python",
"numpy",
"pandas"
] |
How can I map an ontology components to a relational database? | 38,498,290 | <p>I already have an owl ontology which contains classes, instances and object properties. How can I map them to a relational data base such as MYSQL using a Python as a programming language(I prefer Python) ?<br>
<strong>For example</strong>, an ontology can contains the classes: "Country and city" and instances like... | 0 | 2016-07-21T07:56:54Z | 38,498,458 | <p>If I understand you well, I think you could use SQLite with python. SQLite is great because you have just to import the library with :</p>
<pre><code>import sqlite3
</code></pre>
<p>And then, there is no need for a server. Things are stored in a file, gerenaly ending with : <code>.db</code></p>
<p>Have a look at ... | 0 | 2016-07-21T08:06:13Z | [
"python",
"mysql",
"relational-database",
"semantic-web",
"ontology"
] |
How can I map an ontology components to a relational database? | 38,498,290 | <p>I already have an owl ontology which contains classes, instances and object properties. How can I map them to a relational data base such as MYSQL using a Python as a programming language(I prefer Python) ?<br>
<strong>For example</strong>, an ontology can contains the classes: "Country and city" and instances like... | 0 | 2016-07-21T07:56:54Z | 38,534,519 | <p>Use the right tool for the job. You're using RDF, that it's OWL axioms is immaterial, and you want to store and query it. Use an RDF database. They're optimized for storing and querying RDF. It's a waste of your time to homegrow storage & query in MySQL when other folks have already figured out how best to do th... | 0 | 2016-07-22T20:08:00Z | [
"python",
"mysql",
"relational-database",
"semantic-web",
"ontology"
] |
How to column_stack a numpy array with a scipy sparse matrix? | 38,498,299 | <p>I have the following matrices:</p>
<pre><code>A.toarray()
array([[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
...,
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0]], dtype=int64)
type(A)
scipy.sparse.csr.csr_matrix
... | 0 | 2016-07-21T07:57:38Z | 38,498,421 | <p>Did you try the following? </p>
<pre><code>C=np.vstack((A.T,B)).T
</code></pre>
<p>With sample values:</p>
<pre><code>A = array([[1, 2, 3], [4, 5, 6]])
>>>> A.shape
(2, 3)
B = array([7, 8])
>>> B.shape
(2,)
C=np.vstack((A.T,B)).T
>>> C.shape
(2, 4)
</code></pre>
<p>If A is a sparse ... | 1 | 2016-07-21T08:04:15Z | [
"python",
"python-2.7",
"python-3.x",
"numpy",
"scipy"
] |
How to column_stack a numpy array with a scipy sparse matrix? | 38,498,299 | <p>I have the following matrices:</p>
<pre><code>A.toarray()
array([[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
...,
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0],
[0, 0, 0, ..., 0, 0, 0]], dtype=int64)
type(A)
scipy.sparse.csr.csr_matrix
... | 0 | 2016-07-21T07:57:38Z | 38,518,846 | <p>2 issues </p>
<ul>
<li>there isn't a <code>sparse.column_stack</code></li>
<li>you are mixing a sparse matrix and dense array</li>
</ul>
<p>2 smaller examples:</p>
<pre><code>In [129]: A=sparse.csr_matrix([[1,0,0],[0,1,0]])
In [130]: B=np.array([1,2])
</code></pre>
<p>Using <code>np.column_stack</code> gives you... | 1 | 2016-07-22T05:30:27Z | [
"python",
"python-2.7",
"python-3.x",
"numpy",
"scipy"
] |
Unexpected behaviour of border: * no_line | 38,498,392 | <p>I am trying to create cells without borders, but somehow that default thin border is always there.</p>
<pre class="lang-python prettyprint-override"><code>from xlwt import Workbook,easyxf
tl = easyxf('border: top thick, right no_line, bottom no_line, left thick')
tr = easyxf('border: top thick, right thick, bottom... | 0 | 2016-07-21T08:02:40Z | 39,062,012 | <p>Use top_color <em>color</em> , bottom_color <em>color</em> , left_color <em>color</em> , right_color <em>color</em> which in your case it should be white. </p>
<p>Where ever you dont want border for example in <strong>tl</strong> you dont want border at right and bottom so set right_color white, bottom_color white... | 0 | 2016-08-21T07:48:09Z | [
"python",
"xlwt"
] |
Read csv to dict of dicts | 38,498,419 | <p>Lets say I have this csv file:</p>
<pre><code>Header1, Header2, Header3
key1, 1, 2
key2, 3, 4
</code></pre>
<p>I'd like to convert it to the following dict:</p>
<pre><code>{Header2: {key1: 1, key2: 3}, Header3: {key1: 2, key2: 4}}
</code></pre>
<p>Is there a simple way to do this?
I tried using... | 2 | 2016-07-21T08:04:11Z | 38,498,744 | <p>You can use <code>to_dict</code> method of pandas' DataFrame instance. For example:</p>
<pre><code>import pandas as pd
df = pd.read_csv('file.csv', delimiter=r',\s+', index_col=0)
print(df.to_dict())
</code></pre>
| 2 | 2016-07-21T08:19:06Z | [
"python",
"csv",
"dictionary"
] |
Read csv to dict of dicts | 38,498,419 | <p>Lets say I have this csv file:</p>
<pre><code>Header1, Header2, Header3
key1, 1, 2
key2, 3, 4
</code></pre>
<p>I'd like to convert it to the following dict:</p>
<pre><code>{Header2: {key1: 1, key2: 3}, Header3: {key1: 2, key2: 4}}
</code></pre>
<p>Is there a simple way to do this?
I tried using... | 2 | 2016-07-21T08:04:11Z | 38,498,891 | <p>You can do this with <code>csv</code> module:</p>
<pre><code>import csv
f = open(csv_file_path)
reader = csv.DictReader(f)
fieldnames = reader.fieldnames
result = {fieldname:{} for fieldname in fieldnames[1:]}
for row in reader:
for fieldname in fieldnames[1:]:
result[fieldname][row['Header1'].strip(... | 0 | 2016-07-21T08:26:25Z | [
"python",
"csv",
"dictionary"
] |
Merge two data frames on multiple values | 38,498,453 | <p>I have two data frames which look like this</p>
<p><strong>df1</strong></p>
<pre><code> name ID abb
0 foo 251803 I
1 bar 376811 R
2 baz 174254 Q
3 foofoo 337144 IRQ
4 barbar 306521 IQ
</code></pre>
<p><strong>df2</strong></p>
... | 1 | 2016-07-21T08:05:55Z | 38,498,580 | <p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.join.html" rel="nofollow"><code>join</code></a>:</p>
<pre><code>print (df1)
name ID abb
0 foo 251803 I
1 bar 376811 R
2 baz 174254 Q
3 foofoo 337144 IRQ
4 barbar 306521 IQ
#each character t... | 2 | 2016-07-21T08:11:50Z | [
"python",
"pandas"
] |
Merge two data frames on multiple values | 38,498,453 | <p>I have two data frames which look like this</p>
<p><strong>df1</strong></p>
<pre><code> name ID abb
0 foo 251803 I
1 bar 376811 R
2 baz 174254 Q
3 foofoo 337144 IRQ
4 barbar 306521 IQ
</code></pre>
<p><strong>df2</strong></p>
... | 1 | 2016-07-21T08:05:55Z | 38,499,036 | <p>See this <a href="http://stackoverflow.com/a/38432346/2336654">answer</a> for various ways to explode on a column</p>
<pre><code>rows = []
for i, row in df1.iterrows():
for a in row.abb:
rows.append([row['ID'], a, row['name']])
df11 = pd.DataFrame(rows, columns=df1.columns)
df11.merge(df2)
</code></pr... | 1 | 2016-07-21T08:32:26Z | [
"python",
"pandas"
] |
Write numpy structured array using savetxt | 38,498,477 | <p>I faced a problem with writing structured array in txt file.
Having an output file (<em>outfile</em>) opened, I use the following numpy function:</p>
<pre><code>np.savetxt(*outfile*, ***recarray***, fmt=['%s','%-7.4f','%-7.4f','%-7.4f'])
</code></pre>
<p>The <strong><em>recarray</em></strong> is like [ (b'H', 0.94... | 0 | 2016-07-21T08:06:58Z | 38,498,626 | <p>I assume that you are using Python 3.0. In this case, you have to specify before <code>'%s'</code> the letter b like this : <code>b'%s'</code></p>
<p>In Python3, the default string type is unicode, so you have use the extra b to mark byte strings.</p>
<p>Your script should be : </p>
<pre><code>np.savetxt(*outfile... | 0 | 2016-07-21T08:13:51Z | [
"python",
"numpy"
] |
Error when creating Database Tables - CKAN | 38,498,590 | <p>i'm trying to install CKAN 2.5.2 on Centos 6.8</p>
<p>When i run paster db init -c /etc/ckan/default/development.ini</p>
<p>i get error </p>
<pre><code>Traceback (most recent call last):
File "/usr/lib/ckan/default/bin/paster", line 9, in <module>
load_entry_point('PasteScript==2.0.2', 'console_script... | 2 | 2016-07-21T08:12:06Z | 38,505,591 | <p>It looks like you have 2 copies of html5lib installed. When you did help(html5lib) it is showing a copy that is installed in your user's python directory (/usr/lib/python2.6/site-packages/) not the virtualenv that you have ckan (and bleach) installed (/usr/lib/ckan/default/lib/python2.6/site-packages/). So get rid o... | 1 | 2016-07-21T13:27:41Z | [
"python",
"centos",
"virtualenv",
"ckan",
"paster"
] |
Extracting portions of low-dimensional numpy array into final axes of higher-dimensional array | 38,498,654 | <p>I have a static shape-<code>(l,l)</code> array <code>C</code>. I want to extract portions of it into some other array <code>K</code>, which has shape <code>(m,m,n,n)</code>. The starting index of what I want to extract from <code>C</code> is given in array <code>i0</code>, which has shape <code>(m,m)</code>.</p>
<p... | 1 | 2016-07-21T08:15:08Z | 38,499,028 | <p>One way would be with <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.meshgrid.html" rel="nofollow"><code>np.meshgrid</code></a> to create <code>2D</code> indexing meshes corresponding to the window of <code>(n,n)</code> shape, adding those with <code>i0</code> that's extended with two new axes al... | 1 | 2016-07-21T08:32:09Z | [
"python",
"arrays",
"numpy"
] |
Data Mining: Clustering of nominal attributes through DBSCAN algo | 38,498,686 | <p>I want to perform clustering on a data set with DBSCAN algorithm. The problem is that the data has nominal attributes like zipcode and currency. Any idea how to handle these values?</p>
| -1 | 2016-07-21T08:16:32Z | 38,520,177 | <p>Two options:</p>
<ol>
<li><p>Define a custom distance function that handles these attributes as desired. For example with zip codes, you will want to look up proximity.</p></li>
<li><p>Use Generalized DBSCAN and define a custom neighbor predicate. It could require e.g. zip codes to be neighbors <em>and</em> attribu... | 0 | 2016-07-22T07:03:11Z | [
"python",
"cluster-analysis",
"data-mining"
] |
execute script from within python3 interpreter and show interpreter results | 38,498,690 | <p>I am working inside the python 3 interpreter, and I want to use it for homework.</p>
<p>first, I have a library called <code>mylibrary.py</code> like this</p>
<pre><code>from math import pi
def area_circle(r):
return(r*r*pi))
</code></pre>
<p>Second, I have a script called <code>homework.py</code> like this</p... | -1 | 2016-07-21T08:16:45Z | 38,499,370 | <p>You can"t show the content without using 'print' if you're not using python prompt .... </p>
<p>You can modify your function, so it prints if a second argument is given, and doesn't print otherwise : </p>
<pre><code>def area_circle(r, do_print=False):
a=r*r*pi
if do_print:
print(a)
return a
</... | 0 | 2016-07-21T08:48:11Z | [
"python",
"python-3.x",
"exec",
"interpreter"
] |
Split pandas column and add last element to a new column | 38,498,718 | <p>I have a pandas dataframe containing (besides other columns) full names:</p>
<pre><code> fullname
martin master
andreas test
</code></pre>
<p>I want to create a new column which splits the fullname column along the blank space and assigns the last element to a new column. The result should look like:</p>
<pre><... | 3 | 2016-07-21T08:18:14Z | 38,498,755 | <p>You need another <code>str</code> to access the last splits for every row, what you did was essentially try to index the series using a non-existent label:</p>
<pre><code>In [31]:
df['lastname'] = df['fullname'].str.split().str[-1]
df
Out[31]:
fullname lastname
0 martin master master
1 andreas test... | 4 | 2016-07-21T08:19:40Z | [
"python",
"pandas",
"split"
] |
Split pandas column and add last element to a new column | 38,498,718 | <p>I have a pandas dataframe containing (besides other columns) full names:</p>
<pre><code> fullname
martin master
andreas test
</code></pre>
<p>I want to create a new column which splits the fullname column along the blank space and assigns the last element to a new column. The result should look like:</p>
<pre><... | 3 | 2016-07-21T08:18:14Z | 38,499,006 | <p>If need create 2 new columns, use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.rsplit.html" rel="nofollow"><code>str.rsplit</code></a> with parameter <code>n=1</code>. If need only last column, <a href="http://stackoverflow.com/a/38498755/2901002"><code>EdChum</code></a> solution ... | 1 | 2016-07-21T08:30:55Z | [
"python",
"pandas",
"split"
] |
read_sql_query returns far more records than actual table rows | 38,498,960 | <p>I am trying to get the a postgresql table in to python data frame. But the dataframe size is extremely larger than the actual number of table records even though I specified an index column. What's causing this issue? Single quotes/ commas in the database table?</p>
<pre><code>import psycopg2 as pg
import pandas.io... | 0 | 2016-07-21T08:29:11Z | 38,499,155 | <p><a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.size.html" rel="nofollow">df.size</a> shows you the number of elements (cells) in the DF</p>
<p>Demo:</p>
<pre><code>In [134]: df
Out[134]:
A B
0 3 11
1 0 2
In [135]: df.size
Out[135]: 4
In [136]: df.shape
Out[136]: (2, 2)
... | 0 | 2016-07-21T08:37:41Z | [
"python",
"postgresql",
"pandas"
] |
Matplotlib custom style error | 38,498,981 | <p>I am trying to set the plotting style in matplotlib:</p>
<blockquote>
<p>import pandas as pd</p>
<p>import matplotlib</p>
<p>print matplotlib.<strong>version</strong></p>
<p>matplotlib.style.use('ggplot')</p>
</blockquote>
<p>Output:</p>
<blockquote>
<p>1.5.1</p>
<p>AttributeError: 'module... | 0 | 2016-07-21T08:23:59Z | 38,499,121 | <p>Try this:</p>
<pre><code>%matplotlib inline
import pandas as pd
import matplotlib
print matplotlib.version
matplotlib.style.use('ggplot')
</code></pre>
| 0 | 2016-07-21T08:36:16Z | [
"python"
] |
--debug command line argument in Python | 38,499,158 | <p>When I introduce to the command line "--debug" argument I need to set variable "debug", from my python script, to the value 1.</p>
<p>I've tried something, but I have to write "--debug=1" to the command line to set variable.</p>
<pre><code>parser = argparse.ArgumentParser()
parser.add_argument("--debug", default=2... | 0 | 2016-07-21T08:37:47Z | 38,499,244 | <p>If you're interested to know whether a certain command line flag has been passed to your script, you'd set the <a href="https://docs.python.org/3/library/argparse.html#action" rel="nofollow"><code>action</code></a> argument of <code>Argument.add_argument</code> to <code>store_true</code>.</p>
<pre><code>parser.add_... | 0 | 2016-07-21T08:42:13Z | [
"python",
"command",
"argparse"
] |
Best way to prevent sql "injection" when using column as variable | 38,499,201 | <p>I'm using pymssql to Update, Drop, and Add columns to a MS SQL server. the columns are sadly variables set by external sources such as reading the database, reading from another database. Now i'm trying to prevent "bad" sql to get through as i don't know exactly what the other database gives me. </p>
<pre><code>'AL... | 0 | 2016-07-21T08:40:13Z | 38,499,740 | <p>Transact-SQL has a function to turn a SQL string into a safe object name: <a href="https://msdn.microsoft.com/en-us/library/ms176114.aspx" rel="nofollow"><code>QUOTENAME()</code></a>. Use it around a bind parameter to have the database driver provide a properly quoted SQL object:</p>
<pre><code>cursor.execute('SELE... | 1 | 2016-07-21T09:06:55Z | [
"python",
"sql-server",
"sql-injection",
"pymssql"
] |
How to block and wait for async, callback based Python function calls | 38,499,261 | <p>I have a Python script makes many async requests. The API I'm using takes a callback.</p>
<p>The main function calls run and I want it to block execution until all the requests have come back.</p>
<p>What could I use within Python 2.7 to achieve this?</p>
<pre><code>def run():
for request in requests:
... | 1 | 2016-07-21T08:42:55Z | 38,502,488 | <p>I found that the simplest, least invasive way is to use <code>threading.Event</code>, available in 2.7.</p>
<pre><code>import threading
import functools
def run():
events = []
for request in requests:
event = threading.Event()
callback_with_event = functools.partial(callback, event)
... | 1 | 2016-07-21T11:01:32Z | [
"python",
"asynchronous",
"callback"
] |
How can I pull information from Excel into PowerPoint using Python and keep the format? | 38,499,294 | <p>I've written a script with python's xlrd and pptx to read each workbook in a directory and pull information from each sheet into a table in a PowerPoint slide. It works okay if the excel table is small but I don't know what will be in these excel files. It becomes illegible when there is too many rows and columns. M... | 0 | 2016-07-21T08:44:35Z | 38,515,889 | <p>Well, you've chosen a hard problem. Certainly all the times I've attempted this sort of thing I've ended up abandoning the effort.</p>
<p>The fundamental explanation I formed was that Excel (and Word) are "flowed" document environments. That is, when you run out of room on one page, it flows to the next. PowerPoint... | 0 | 2016-07-21T23:21:22Z | [
"python",
"excel",
"powerpoint"
] |
python Bluetooth error - No module named _bluetooth | 38,499,342 | <p>I am trying an example code in python which works as a bluetooth server. This code gives following error..</p>
<p>Traceback (most recent call last):
File "/var/lib/cloud9/examples/Sa/rfcomm-server_py", line 7, in
from bluetooth import *
File "/var/lib/cloud9/examples/Sa/bluetooth/<strong>init</strong>.py",... | 0 | 2016-07-21T08:47:14Z | 38,501,457 | <p>I didn't turn on the bluetooth on Beaglebone green wireless board, but after running the following command, the code above worked perfectly:</p>
<pre><code>$ bb-wl18xx-bluetooth
</code></pre>
| 0 | 2016-07-21T10:17:10Z | [
"python",
"bluetooth",
"cloud9-ide",
"beagleboard"
] |
How to display a binary state (ON/OFF) in Matplotlib? | 38,499,347 | <p>I have built a GUI with matplotlib and it contains several plots of values versus time. Now I need a special plot which just shows if a value is on or off (binary state).</p>
<p>Kinda like a control lamp on an analog control panel. I have 5 of those on/off values and I dont know how to do it the best way. </p>
<p>... | 0 | 2016-07-21T08:47:23Z | 38,500,368 | <p>Instead of passing via bar charts I would directly plot a number of rectangles and then dynamically change their color.</p>
<p>You can find the documentation for rectangular patches here: <a href="http://matplotlib.org/api/patches_api.html#matplotlib.patches.Rectangle" rel="nofollow">http://matplotlib.org/api/patch... | 0 | 2016-07-21T09:32:13Z | [
"python",
"matplotlib"
] |
How can Apache use Py3 instesd of Py2? | 38,499,444 | <p>How can Apache use Python/3.x instesd of Python/2.x ?</p>
<p>I'm now trying to set up Django application on server with Py3.
The command <code>python manage.py runserver</code> was successful.
Then I tried to use <code>Apache</code> and <code>mod_wsgi</code> but I got <code>Internal Server Error</code>.</p>
<p>The... | 1 | 2016-07-21T08:51:49Z | 38,540,742 | <p>If you're using compiled <strong>mod_wsgi</strong>, you need to compile it against the appropriate Python binary for the version you want to use, or it'll default to the system Python version (still typically 2.x, unfortunately). For example:</p>
<pre><code>wget -q "https://github.com/GrahamDumpleton/mod_wsgi/archi... | 0 | 2016-07-23T10:28:48Z | [
"python",
"django",
"apache",
"mod-wsgi"
] |
how to retrieve every section by 3X3? | 38,499,475 | <p>any one know how to retrieve section from this array:</p>
<pre><code>a=[[1, 3, 2, 5, 7, 9, 4, 6, 8],
[4, 9, 8, 2, 6, 1, 3, 7, 5],
[7, 5, 6, 3, 8, 4, 2, 1, 9],
[6, 4, 3, 1, 5, 8, 7, 9, 2],
[5, 2, 1, 7, 9, 3, 8, 4, 6],
[9, 8, 7, 4, 2, 6, 5, 3, 1],
[2, 1, 4, 9, 3, 5, 6, 8, 7],
[3, 6, 5, 8, 1, 7, 9, 2, 4]... | 0 | 2016-07-21T08:53:18Z | 38,499,659 | <p>Here is the answer, using list comprehension</p>
<pre><code>>>> [x[:3] for x in a[:3]]
[[1, 3, 2], [4, 9, 8], [7, 5, 6]]
</code></pre>
<p>Left section :</p>
<pre><code>[x[0:3] for x in a[0:3]]
[x[0:3] for x in a[3:6]]
[x[0:3] for x in a[6:9]]
</code></pre>
<p>Middle section :</p>
<pre><code>[x[3:6] for... | 1 | 2016-07-21T09:03:14Z | [
"python",
"list",
"numpy"
] |
how to retrieve every section by 3X3? | 38,499,475 | <p>any one know how to retrieve section from this array:</p>
<pre><code>a=[[1, 3, 2, 5, 7, 9, 4, 6, 8],
[4, 9, 8, 2, 6, 1, 3, 7, 5],
[7, 5, 6, 3, 8, 4, 2, 1, 9],
[6, 4, 3, 1, 5, 8, 7, 9, 2],
[5, 2, 1, 7, 9, 3, 8, 4, 6],
[9, 8, 7, 4, 2, 6, 5, 3, 1],
[2, 1, 4, 9, 3, 5, 6, 8, 7],
[3, 6, 5, 8, 1, 7, 9, 2, 4]... | 0 | 2016-07-21T08:53:18Z | 38,499,913 | <p>Here's a vectorized approach using <code>reshaping</code> and permuting dimensions -</p>
<pre><code>a.reshape(3,3,3,3).transpose(2,0,1,3).reshape(9,3,3)
</code></pre>
<p>Sample run -</p>
<pre><code>In [197]: a
Out[197]:
array([[1, 3, 2, 5, 7, 9, 4, 6, 8],
[4, 9, 8, 2, 6, 1, 3, 7, 5],
[7, 5, 6, 3, 8... | 3 | 2016-07-21T09:14:15Z | [
"python",
"list",
"numpy"
] |
how to retrieve every section by 3X3? | 38,499,475 | <p>any one know how to retrieve section from this array:</p>
<pre><code>a=[[1, 3, 2, 5, 7, 9, 4, 6, 8],
[4, 9, 8, 2, 6, 1, 3, 7, 5],
[7, 5, 6, 3, 8, 4, 2, 1, 9],
[6, 4, 3, 1, 5, 8, 7, 9, 2],
[5, 2, 1, 7, 9, 3, 8, 4, 6],
[9, 8, 7, 4, 2, 6, 5, 3, 1],
[2, 1, 4, 9, 3, 5, 6, 8, 7],
[3, 6, 5, 8, 1, 7, 9, 2, 4]... | 0 | 2016-07-21T08:53:18Z | 38,500,002 | <p>You can use similar this:</p>
<pre><code>for i in range(0, len(a), 3):
left_section = []
middle_section = []
right_section = []
left_section.append(a[i][:3])
left_section.append(a[i+1][:3])
left_section.append(a[i+2][:3])
middle_section.append(a[i][3:6])
middle_section.append(a[i+1][... | 0 | 2016-07-21T09:17:41Z | [
"python",
"list",
"numpy"
] |
how to retrieve every section by 3X3? | 38,499,475 | <p>any one know how to retrieve section from this array:</p>
<pre><code>a=[[1, 3, 2, 5, 7, 9, 4, 6, 8],
[4, 9, 8, 2, 6, 1, 3, 7, 5],
[7, 5, 6, 3, 8, 4, 2, 1, 9],
[6, 4, 3, 1, 5, 8, 7, 9, 2],
[5, 2, 1, 7, 9, 3, 8, 4, 6],
[9, 8, 7, 4, 2, 6, 5, 3, 1],
[2, 1, 4, 9, 3, 5, 6, 8, 7],
[3, 6, 5, 8, 1, 7, 9, 2, 4]... | 0 | 2016-07-21T08:53:18Z | 38,501,887 | <p><strong>Pure python way without the use of numpy:</strong></p>
<p>As you need the lists flattened we use this function (as already mentioned):</p>
<pre><code>def flatten_list(li):
return [el for sub_li in li for el in sub_li]
</code></pre>
<p>We know we can retrieve the first section like this:</p>
<pre><cod... | 0 | 2016-07-21T10:34:11Z | [
"python",
"list",
"numpy"
] |
How do you convert a CSV file into a 2d array in a .js file? | 38,499,489 | <p>I have this csv file that looks a bit like this: </p>
<pre><code>1,2,3
3,4,5
5,6,7
</code></pre>
<p>and I need to convert it (preferably in python) to a .js file array that looks more like this: </p>
<pre><code>var variable1 = [
[1,2,3],
[3,4,5],
[5,6,7],
];
</code></pre>
<p>I'm very new to programming, so any g... | 0 | 2016-07-21T08:54:04Z | 38,499,542 | <p>You have to open your csv file, then read the lines and write them in your js file.</p>
<p>Basically:<br/>
-> Open csv file<br/>
-> Create js file<br/>
-> Write 'var variable1 = [' in your js file<br/>
-> Iterate on csv lines<br/>
-> Write them in your js file<br/>
-> Write '];' in your js file<br/>
-> Close the fi... | 0 | 2016-07-21T08:57:23Z | [
"javascript",
"python",
"arrays",
"csv"
] |
fatal error: 'mymodule.h' file not found - Cython compile fails to find header | 38,499,517 | <p>so I've been trying to get a simple script running, where I incorporate C-code into my python project using Cython 0.24 under MacOS 10.11.5 (El Capitan). I edit the code with PyCharm with Python Version 2.7.10. My setup.py looks like this</p>
<pre><code>from distutils.core import setup
from distutils.extension impo... | 1 | 2016-07-21T08:56:14Z | 38,505,376 | <p>I solved it on my own. The problem was actually not in the code I posted here but in the code calling the function.
I had the lines</p>
<pre><code>import pyximport
pyximport.install()
</code></pre>
<p>still in the code before calling the function in hello_world. This seems to have caused the problem. When I remove... | 0 | 2016-07-21T13:18:08Z | [
"python",
"c",
"osx",
"pycharm",
"cython"
] |
How to store missing date(15 min interval) points from csv into new file (15 minutes interval) -python 3.5 | 38,499,546 | <p>I am new to python so some ideas to move forward would be much appreciated</p>
<p>Problem: I have 44 locations with production data per day (15 mins interval) for the months for dec to june. The total data points for one day should be 4224(44 [locations]*4 [15 intervals]*24 [hrs in day]), but that is not the case a... | -10 | 2016-07-21T08:57:42Z | 38,501,900 | <p>try this:</p>
<pre><code>In [16]: df.ix[df.groupby(df['datetime'].dt.date)['production'].transform('nunique') < 44 * 4 * 24, 'datetime'].dt.date.unique()
Out[16]: array([datetime.date(2015, 12, 7)], dtype=object)
</code></pre>
<p>this will give you all rows for the "problematic" days:</p>
<pre><code>df[df.grou... | 0 | 2016-07-21T10:34:39Z | [
"python",
"pandas",
"dataframe"
] |
Converting all occurrence of True/False to 1/0 in a dataframe with mixed datatype | 38,499,747 | <p>I have a dataframe that has about 100 columns, There are some boolean columns and some chars. I want to replace all boolean having values True/False and also -1 with 1/0. I want to apply it on whole dataframe instead of single column.</p>
<p>I saw some solutions here, like converting the column to integer. But I wa... | 0 | 2016-07-21T09:07:12Z | 38,499,855 | <p><code>applymap</code> is not in-place by default, it will return a new dataframe.</p>
<p>The correct way:</p>
<pre><code>test = test.applymap(lambda x: 1 if x == True else x)
test = test.applymap(lambda x: 0 if x == False else x)
</code></pre>
<p>or</p>
<pre><code>test = test.applymap(lambda x: 1 if x == True el... | 1 | 2016-07-21T09:11:30Z | [
"python",
"data-manipulation"
] |
How to use pandas apply function on all columns of some rows of data frame | 38,499,890 | <p>I have a <code>dataframe</code>. I want to replace values of all columns of some rows to a default value. Is there a way to do this via <code>pandas apply</code> function</p>
<p>Here is the dataframe</p>
<pre><code>import pandas as pd
temp=pd.DataFrame({'a':[1,2,3,4,5,6],'b':[2,3,4,5,6,7],'c':['p','q','r','s','t',... | 1 | 2016-07-21T09:12:45Z | 38,499,928 | <p>Use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.isin.html" rel="nofollow"><code>isin</code></a> to create a boolean mask and use <code>loc</code> to set the rows that meet the condition to the desired new value:</p>
<pre><code>In [37]:
temp.loc[temp['c'].isin(mylist),['a','b']] = 0
... | 2 | 2016-07-21T09:14:44Z | [
"python",
"pandas",
"data-manipulation"
] |
How to use pandas apply function on all columns of some rows of data frame | 38,499,890 | <p>I have a <code>dataframe</code>. I want to replace values of all columns of some rows to a default value. Is there a way to do this via <code>pandas apply</code> function</p>
<p>Here is the dataframe</p>
<pre><code>import pandas as pd
temp=pd.DataFrame({'a':[1,2,3,4,5,6],'b':[2,3,4,5,6,7],'c':['p','q','r','s','t',... | 1 | 2016-07-21T09:12:45Z | 38,500,147 | <p>NumPy based method would be to use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.in1d.html" rel="nofollow"><code>np.in1d</code></a> to get such a mask and use it like so -</p>
<pre><code>mask = np.in1d(temp.c,mylist)
temp.ix[mask,temp.columns!='c'] = 0
</code></pre>
<p>This will replace in all... | 1 | 2016-07-21T09:23:52Z | [
"python",
"pandas",
"data-manipulation"
] |
Flask Socket IO encryption | 38,499,954 | <p>How to encrypt everything that passes through socket between my server and clients? I'm using Flask's socket.io on server and Swift socket.io on clients.</p>
| -3 | 2016-07-21T09:15:59Z | 38,502,220 | <p>You should use the secure <code>wss://</code> (WebSockets over SSL/TLS) protocol instead of <code>ws://</code>. Just like <code>https://</code> it is also encrypted. If you are using <code>https://</code> by default you can only use <code>wss://</code>.</p>
| 0 | 2016-07-21T10:49:05Z | [
"python",
"swift",
"encryption",
"flask",
"socket.io"
] |
Python Tkinter buttons - no text | 38,499,965 | <p>I'm having a bit of a play with tkinter buttons. Im wanting to insert some buttons into a clock script I have.</p>
<p>Inserting the button Exit (3rd line from bottom) inserts a button ok, and the button works, but it refuses to show any text on the button.</p>
<p>How can I show text on this button?</p>
<pre><code... | 0 | 2016-07-21T09:16:28Z | 38,510,629 | <p>Sort of solved it. The button was showing text - it was just off the screen. Solved it by adjusting the width of the tkinter text window and the buttons.</p>
| 1 | 2016-07-21T17:23:36Z | [
"python",
"tkinter"
] |
Python Tkinter buttons - no text | 38,499,965 | <p>I'm having a bit of a play with tkinter buttons. Im wanting to insert some buttons into a clock script I have.</p>
<p>Inserting the button Exit (3rd line from bottom) inserts a button ok, and the button works, but it refuses to show any text on the button.</p>
<p>How can I show text on this button?</p>
<pre><code... | 0 | 2016-07-21T09:16:28Z | 38,515,364 | <p>The value of <code>w</code> (<code>clock.winfo_screenwidth()</code>) is too wide for a button width. It just slides the name of the button too much to the left. So change the width of the button to a smaller number (200), and add <code>sticky=W</code> to the <code>grid</code>, so it won't slide too much anymore. Mea... | 0 | 2016-07-21T22:26:42Z | [
"python",
"tkinter"
] |
Webcam Iris Detection with Hough Circles in Python OpenCV | 38,499,981 | <p>I have managed to isolate a very specific bounding region for an eye with the help of dlib's facial landmark detector. However, I am not completely stumped on how to create a circular border around the iris itself. I have tried canny edge detection followed by hough circles but hough circles does not seem to be able... | -1 | 2016-07-21T09:17:03Z | 38,500,350 | <p>You could use a threshold on the region before using the edge detector. Then you could use the hough circle transformation. If this does not work, an alternativ emay be to find contours and analyse the contour with cvFitEllipse</p>
| 0 | 2016-07-21T09:31:33Z | [
"python",
"opencv",
"image-processing",
"hough-transform",
"canny-operator"
] |
How to add new column to existing csv file | 38,500,090 | <p>For instance, <strong>x</strong> is my data and <strong>r</strong> is supposed to be new data to be added.</p>
<pre><code>import numpy as np
x = np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]], np.int32)
np.savetxt("test.csv", x, fmt='%d', delimiter=',')
r = [1,2,3]
</code></pre>
<p>how co... | 0 | 2016-07-21T09:21:41Z | 38,500,749 | <p>You can insert a new column by using the <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.insert.html" rel="nofollow">insert function</a> in numpy like so</p>
<pre><code>np.insert(x, 3, [r], axis=1)
</code></pre>
| 1 | 2016-07-21T09:48:45Z | [
"python",
"csv",
"numpy",
"append"
] |
How to add new column to existing csv file | 38,500,090 | <p>For instance, <strong>x</strong> is my data and <strong>r</strong> is supposed to be new data to be added.</p>
<pre><code>import numpy as np
x = np.array([[1, 2, 3],
[4, 5, 6],
[7, 8, 9]], np.int32)
np.savetxt("test.csv", x, fmt='%d', delimiter=',')
r = [1,2,3]
</code></pre>
<p>how co... | 0 | 2016-07-21T09:21:41Z | 38,518,607 | <p>Isn't this just about adding a column to an existing 2d array. Writing it to a csv file is just a further step and isn't affected by this addition.</p>
<pre><code>In [96]: x = np.array([[1, 2, 3],
...: [4, 5, 6],
...: [7, 8, 9]], np.int32)
In [97]: r = [1,2,3]
</code></pre>
<p>... | 1 | 2016-07-22T05:09:47Z | [
"python",
"csv",
"numpy",
"append"
] |
Implementation of `Exception.__str__()` in Python | 38,500,098 | <p>I've never fully understood exception handling in Python (or any language to be honest). I was experimenting with custom exceptions, and found the following behaviour.</p>
<pre><code>class MyError(Exception):
def __init__(self, anything):
pass
me = MyError("iiiiii")
print(me)
</code></pre>
<p>Output:<... | 0 | 2016-07-21T09:21:55Z | 38,500,203 | <p>In Python 3, the <code>BaseException</code> class has a <code>__new__</code> method that stores the arguments in <code>self.args</code>:</p>
<pre><code>>>> me.args
('iiiiii',)
</code></pre>
<p>You didn't override the <code>__new__</code> method, only <code>__init__</code>. You'd need to override <strong>b... | 1 | 2016-07-21T09:25:41Z | [
"python",
"python-3.x",
"exception"
] |
How do I pass a string variable with apostrophe (') in a Xpath for Python-Selenium? | 38,500,189 | <p>I have a web table where I need to <code>click</code> the edit template icon (the one that looks like a notepad in the image below) for each row. The table looks like this.</p>
<p><a href="http://i.stack.imgur.com/gkZqk.png" rel="nofollow"><img src="http://i.stack.imgur.com/gkZqk.png" alt=""></a></p>
<p>My code ch... | 2 | 2016-07-21T09:25:13Z | 38,500,656 | <p>You should use <code>\</code> to escape <code>""</code> char as below :-</p>
<pre><code>form_titles = ["3.08 Incident Estimates", "3.09 Quotation by the Consultant", "3.10 Employer's Assessment"]
for form in form_titles:
try:
WebDriverWait(browser, 60).until(EC.presence_of_element_located((By.XPATH... | 2 | 2016-07-21T09:44:38Z | [
"python",
"selenium",
"xpath"
] |
Django seems to escape HTML characters (but is not supposed to) | 38,500,192 | <p>After upgrading Django from 1.8 to 1.9.8 (and also upgrading a bunch of modules in the process), I've got an issue with my translations inside templates.</p>
<p>With the <code>Foobar</code> key associated with the <code>foo<br>bar</code> string, the code:</p>
<pre><code><p>{% i18n 'Foobar' %}</p>... | 0 | 2016-07-21T09:25:16Z | 38,500,881 | <p>OK, thanks to Bestasttung's comment, I solved my problem with this:</p>
<pre><code>{% autoescape off %}
<p>{% i18n 'Foobar' %}</p>
{% endautoescape %}
</code></pre>
<p>But that wasn't very satisfying since I had multiple templates to update.
So, I simply changed my <code>i18n</code> method from:</p>
<... | 1 | 2016-07-21T09:54:18Z | [
"python",
"django",
"localization",
"translation"
] |
Strange result of re.match() | 38,500,330 | <p>`</p>
<pre><code>t='1111 si debiteur'
import re
re.match(r"si débiteur",t) is None #gives back True as a result
re.match(r"1111 si débiteur",t) is None #gives back True as a result
re.match(r"1111 si débiteur",t) is not None #gives back False as a result
t='8588'
re.match(r"1111 si débiteur",t) is None #gives b... | -1 | 2016-07-21T09:30:50Z | 38,500,484 | <p>The value of t: <code>1111 si debiteur</code> does not have an <em>accent</em>. Where <code>re.match(r"1111 si débiteur",t)</code> does.</p>
| 1 | 2016-07-21T09:37:27Z | [
"python"
] |
Python and Neo4j first 10 Elements | 38,500,384 | <p>Is it Possible to select first 10 entries of Neo4j graph just like we do in a Document oriented Database? </p>
| 0 | 2016-07-21T09:32:55Z | 38,500,561 | <p>When using a Cypher query, you can use the <a href="http://neo4j.com/docs/developer-manual/3.0/#query-limit" rel="nofollow"><code>LIMIT</code></a> <a href="http://neo4j.com/docs/cypher-refcard/3.0/" rel="nofollow">clause</a> to complement <code>RETURN</code>:</p>
<pre><code>MATCH (n:SomeLabel)
RETURN n
LIMIT 10
</c... | 1 | 2016-07-21T09:40:42Z | [
"python",
"neo4j"
] |
New origin of imshow after set_data() | 38,500,415 | <p>i have a very strange problem. After setting the data of my imshow instace, the origin is changed from 'upper' to 'lower' and i did not manage to reverse it again. Any ideas?</p>
<p>Here is my code:</p>
<pre><code>im = ax.imshow(data)
ax.set_xlim(0, new_data.shape[1])
ax.set_ylim(0, new_data.shape[0])
im.set_exten... | 0 | 2016-07-21T09:34:35Z | 38,501,842 | <p>I solved it myself. Just swap the values in set_extent() and leave out the set_xim and set_ylim :</p>
<pre><code>im = ax.imshow(data)
im.set_extent((0, new_data.shape[1], new_data.shape[0], 0))
im.set_data(new_data)
</code></pre>
| 0 | 2016-07-21T10:32:18Z | [
"python",
"matplotlib",
"rotation",
"imshow"
] |
Replace word between two substrings (keeping other words) | 38,500,616 | <p>I'm trying to replace a word (e.g. <code>on</code>) if it falls between two substrings (e.g. <code><temp></code> & <code></temp></code>) however other words are present which need to be kept.</p>
<pre><code>string = "<temp>The sale happened on February 22nd</temp>"
</code></pre>
<p>The ... | 2 | 2016-07-21T09:42:51Z | 38,501,144 | <pre><code>re.sub('(<temp>.*?) on (.*?</temp>)', lambda x: x.group(1)+" <replace> "+x.group(2), string, flags=re.DOTALL)
</code></pre>
<p>Output:</p>
<pre><code><temp>The sale happened <replace> February 22nd</temp>
</code></pre>
<p><strong>Edit:</strong></p>
<p>Changed the regex... | 0 | 2016-07-21T10:04:29Z | [
"python",
"regex"
] |
Replace word between two substrings (keeping other words) | 38,500,616 | <p>I'm trying to replace a word (e.g. <code>on</code>) if it falls between two substrings (e.g. <code><temp></code> & <code></temp></code>) however other words are present which need to be kept.</p>
<pre><code>string = "<temp>The sale happened on February 22nd</temp>"
</code></pre>
<p>The ... | 2 | 2016-07-21T09:42:51Z | 38,501,158 | <p>Try <a href="http://lxml.de/tutorial.html" rel="nofollow"><code>lxml</code></a>:</p>
<pre><code>from lxml import etree
root = etree.fromstring("<temp>The sale happened on February 22nd</temp>")
root.text = root.text.replace(" on ", " {replace} ")
print(etree.tostring(root, pretty_print=True))
</code></... | 0 | 2016-07-21T10:05:11Z | [
"python",
"regex"
] |
Wrong python packages path for opencv cmake installation | 38,500,617 | <p>I've been trying to follow the opencv installation steps from <a href="http://www.pyimagesearch.com/2015/06/15/install-opencv-3-0-and-python-2-7-on-osx/" rel="nofollow">pyimagesearch.com</a> with virtualenv. Everything works fine except for the packages path: it should be <code>/Users/JLee/Envs/cv/lib/python2.7/site... | 0 | 2016-07-21T09:42:52Z | 38,524,888 | <p>For some reason it looks like CMake didn't automatically determine your <code>site-packages</code> directory for your virtual environment. That's not an issue though, because all you need to do is sym-link in the <code>cv2.so</code> file.</p>
<p>Find your <code>cv2.so</code> file on disk (based on your output, it s... | 1 | 2016-07-22T11:06:06Z | [
"python",
"opencv",
"virtualenv",
"opencv3.0",
"virtualenvwrapper"
] |
Access column name for a specific value in GREL/Open Refine (or R, Python) | 38,500,634 | <p>I'm trying to access the value of a column name for a specific cell in Open Refine, so I can replace the value of the cell with the column name. I'm aware of the variable <code>row.columnNames</code> that returns ALL column names but is there a way to return just the one for the current cell?</p>
<p>I'm trying to c... | 2 | 2016-07-21T09:43:22Z | 38,502,862 | <p>Try columnName</p>
<p>if(value != NULL, columnName, NULL)</p>
<p>This does not seem to be documneted or available under the help tab. I found it by looking at: <a href="https://github.com/OpenRefine/OpenRefine/blob/c103cdcbff49cde90409855d45f4e50b5a8349d1/main/src/com/google/refine/expr/ExpressionUtils.java#L84" r... | 1 | 2016-07-21T11:18:54Z | [
"python",
"openrefine"
] |
Why when I compare the int values of an RDDpipeline i get both int and none values? | 38,500,739 | <p>I have a csv file that contains fields with the values <code>1</code> and <code>0</code>. Using pyspark I want to capture only those values with <code>1</code> in a specific field. When I convert the fields I transform them to <code>int</code>. When I use an <code>if</code> statement to check if the value is <code>1... | 0 | 2016-07-21T09:48:21Z | 38,501,019 | <p>Your method <code>vehA</code> returns <code>None</code> when <code>ddsA</code> is not equal to <code>1</code> as you are not returning anything in case of <code>else</code> python implicitly returns <code>None</code>. </p>
<p>In order to capture only <code>ddsA</code> with one you could use filter instead of map. <... | 2 | 2016-07-21T09:59:21Z | [
"python",
"apache-spark",
"rdd",
"nonetype"
] |
Check if there is any mail in an outlook folder received yesterday | 38,501,047 | <p>I need to check and verify if there is any mail received in a specific outlook folder on the day before using python code.</p>
<p>I am able to access folder and read mails. But somehow, latest mail is not read when I tried GetLast() method. I use win32com module and Outlook MAPI object to do this.</p>
<p>Is there ... | -1 | 2016-07-21T10:00:28Z | 38,512,170 | <p>Use <code>Items.Restrict</code>:</p>
<pre><code>yesterdaysItems = MAPIFolder.Items.Restrict("@SQL=(ReceivedTime < '7/21/2016') AND (ReceivedTime > '7/20/2016') ")
</code></pre>
| 1 | 2016-07-21T18:49:23Z | [
"python",
"email",
"outlook",
"pywin32",
"win32com"
] |
How to use selenium sending keys to this hideNameInput? | 38,501,099 | <p>here is the elements,i want input something into the nameNoteId.</p>
<pre><code><span class="table_n_abs" onclick="hideNameInput()" id="nameNoteId" style="top: 10px; font-size: 14px; font-family: 微软é
é»; display: block;">é®ç®±/ææºå·/å¸å·</span>
</code></pre>
<p>here is the codes:</p>
<pre... | 1 | 2016-07-21T10:02:27Z | 38,501,623 | <p><code>send_keys()</code> does not work here because it is <code>span</code> element. If you want to change <code>span</code> content you should try using <code>execute_script()</code> as below :-</p>
<pre><code>not_work_elem = driver.find_element_by_id('nameNoteId')
driver.execute_script("arguments[0].textContent =... | 1 | 2016-07-21T10:23:22Z | [
"python",
"selenium",
"input"
] |
Want to extract Text from HTML Document | 38,501,119 | <p>I want to scape some information from <a href="https://www.kickstarter.com/discover/categories/technology?ref=discover_index" rel="nofollow">the Kickstarter website</a>. The information is structured and every Kickstarter project code looks the same:</p>
<pre class="lang-html prettyprint-override"><code><div cla... | -1 | 2016-07-21T10:03:22Z | 38,501,182 | <p>Simply get text from the first "a" tag you've found.</p>
<pre><code>text = project1[0].text
print(text)
</code></pre>
<p>Result would be:</p>
<pre><code>Mine Kafon Drone
</code></pre>
<p>To get data from every :</p>
<pre><code>data = []
for div in soup.find('div', class_='project-card-content'):
data.append... | 1 | 2016-07-21T10:05:54Z | [
"python",
"html",
"beautifulsoup"
] |
FieldDoesNotExist error on Django production server | 38,501,187 | <p>After pushing my Django app to my production server I have got this error :</p>
<pre><code>FieldDoesNotExist at /
Class_B has no field named <function DO_NOTHING at 0x7f5993ed3440>
</code></pre>
<p>The error seems to come from a query to my databse (the same PostgreSQL database that I use for my development... | 0 | 2016-07-21T10:06:00Z | 38,502,744 | <p>Here :</p>
<pre><code>field2 = models.ForeignKey('Class_A', models.DO_NOTHING,
db_column='field1', db_index=True,
related_name='+', blank=True, null=True)
</code></pre>
<p>you're passing <code>models.DO_NOTHING</code> as positional argument instead of a named a... | 2 | 2016-07-21T11:13:23Z | [
"python",
"django",
"postgresql"
] |
How to merge fields row-wise in a tab-delimited file with python | 38,501,217 | <p>These are two example rows of my tab-delimited file:</p>
<pre><code>id reference_rc_001 alternative_rc_001 reference_rc_002 alternative_rc_002 reference_rc_003 alternative_rc_003
id1 0 433 0 0 69
</code></pre>
<p>I would like to merge fields every two columns. The example output should look like ... | 0 | 2016-07-21T10:06:48Z | 38,504,538 | <p>This looks really horrible, is probably the worst way to do this and might be about as efficient as a donkey, but.....
I think it works.</p>
<p>You'll need to open the file, preferably using a <code>with</code> so you can iterate across the lines in the file. (Many other SO articles will deomstrate doing that with ... | 0 | 2016-07-21T12:39:32Z | [
"python",
"merge",
"tab-delimited"
] |
How does python debugger work? | 38,501,245 | <p>I have a basic understanding of how a debugger work but that is in context of compiled languages. How does a debugger like <code>pdb</code> work?
At a very high level, I am looking for something that can explain internals of <code>pdb</code> or in general "debugging interpreted languages"</p>
<p>I googled up but co... | -1 | 2016-07-21T10:07:49Z | 38,501,376 | <p>From <a href="https://docs.python.org/2/library/pdb.html" rel="nofollow">Python 2.7 Documentation</a>:</p>
<blockquote>
<p>It supports setting (conditional) breakpoints and single stepping at
the source line level, inspection of stack frames, source code
listing, and evaluation of arbitrary Python code in the... | 1 | 2016-07-21T10:13:00Z | [
"python",
"debugging"
] |
Getting âpika.exceptions.ConnectionClosedâ error while using rabbitmq in python | 38,501,394 | <p>I am trying to use rabbitmq in python.
My code is:</p>
<pre><code>import pika
if __name__ == '__main__':
connection = pika.BlockingConnection(pika.ConnectionParameters(host='localhost'))
</code></pre>
<p>I am running this file using:</p>
<pre><code>python3 test.py
</code></pre>
<p>Error Signature:</p>
<pre... | 0 | 2016-07-21T10:13:56Z | 38,503,831 | <p>The issue was with rabbitmqctl. Reconfigured it, Restarted service, and issue is fixed.</p>
<ol>
<li>Make sure rabbitmqctl is installed(if installed, uninstall it and re-install;when you just enter rabbitmqctl, it should display the help) </li>
<li>rabbitmqctl start_app </li>
</ol>
<p>TIP: I tried installing first... | 0 | 2016-07-21T12:05:36Z | [
"python",
"rabbitmq"
] |
ioerror errno 13 permission denied: 'C:\\pagefile.sys' | 38,501,476 | <p>Below is my code, what I am trying to achieve is walking through the OS generating a MD5 hash of every file the code is functional, however, I receive the error in the title "ioerror errno 13 permission denied: 'C:\pagefile.sys'" when I try to run the file from C:\ is there a way i can run this as an admin? Even whe... | -1 | 2016-07-21T10:17:52Z | 38,504,398 | <p>As mentioned in error - Permission denied - since file need to be read for getting md5 of its content. There will be always a case when we don't have read permission .</p>
<pre><code>import os, hashlib
def md5_chk(current_file):
try:
md5 = ''
err = ''
H = hashlib.md5()
with open... | 0 | 2016-07-21T12:31:21Z | [
"python",
"os.walk"
] |
Forcing requests library to use TLSv1.1 or TLSv1.2 in Python | 38,501,531 | <p>I am trying to send a POST call using requests library in python to a server. Earlier I was able to successfully send POST calls but recently, the server deprecated TLSv1.0 and now only supports TLSv1.1 and TLSv1.2. Now the same code throws me a "requests.exceptions.SSLError: EOF occurred in violation of protocol (_... | 0 | 2016-07-21T10:19:41Z | 38,502,727 | <p>The TLS stack will use the best version available automatically. If it does not work any longer when TLS 1.0 support is disabled at the server it usually means that your local TLS stack simply does not support newer protocol version like TLS 1.2. This is often the case on Mac OS X since it ships with a rotten old ve... | 0 | 2016-07-21T11:12:30Z | [
"python",
"ssl"
] |
how can i struct.unpack use domain name in place of ip in socket.connect remotely | 38,501,536 | <p>I have the following code, when i use it using an the external ip directly it works just fine but when i change the ip to a domain provided by dyndns it fails and throws the error listed below.</p>
<pre><code>import socket,struct
# Connect with hostname
# dgts = socket.gethostbyname('chxxxmaz.dyndns.biz')
# s = so... | 0 | 2016-07-21T10:19:49Z | 38,501,958 | <p>There is no need to manually resolve the hostname, you can simply use it when connecting the socket.</p>
<p>Your problem comes from the quotes that you add when you connect (why <code>"'" + dgts + "'"</code>?)</p>
<pre><code>import socket, struct
# Connect
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.c... | 0 | 2016-07-21T10:37:18Z | [
"python",
"sockets",
"static",
"dns",
"ip"
] |
create new pandas dataframe column based on if-else condition with a lookup | 38,501,685 | <p>I have a pandas dataframe and I need to create a new column based on an if-else condition. This question already came up here multiple times (e.g., <a href="http://stackoverflow.com/questions/21702342/creating-a-new-column-based-on-if-elif-else-condition">Creating a new column based on if-elif-else condition</a>).</... | 1 | 2016-07-21T10:25:27Z | 38,502,414 | <p>Although this question is very similar to the question: <a href="http://stackoverflow.com/questions/38499890/how-to-use-pandas-apply-function-on-all-columns-of-some-rows-of-data-frame">How to use pandas apply function on all columns of some rows of data frame</a></p>
<p>I think here it's worth showing a couple meth... | 1 | 2016-07-21T10:58:01Z | [
"python",
"pandas",
"conditional",
"condition"
] |
connecting mysql to flask - No module named 'flaskext' | 38,501,772 | <p>I want to connect Mysql to Flask.</p>
<p>Before adding this configuration part:</p>
<pre><code>app = Flask(__name__)
mysql = MySQL()
app.config['MYSQL_DATABASE_USER'] = 'username'
app.config['MYSQL_DATABASE_PASSWORD'] = 'password'
app.config['MYSQL_DATABASE_DB'] = 'dbname'
app.config['MYSQL_DATABASE_HOST'] = 'loca... | 0 | 2016-07-21T10:29:20Z | 38,506,557 | <p>The '.' is missing, try <code>from flask.ext.mysql import MySQL</code>. But if you are using Flask 0.11, extension imports of the form <code>flask.ext.foo</code> have been <a href="http://flask.pocoo.org/docs/0.11/upgrading/#extension-imports" rel="nofollow">deprecated</a> you should use <code>from flask_foo</code>.... | 0 | 2016-07-21T14:09:40Z | [
"python",
"mysql",
"flask"
] |
Matplotlib: combine legend with same color and name | 38,501,822 | <p>If I repeat the plot with same color and label name, the label would appear multiple times:</p>
<pre><code>from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.gca(projection='3d')
x_labels = [10,20,30]
x = [1,2,3,4]
y = [3,1,5,1]
for label in x_labels:
x_3d = label*np.ones_like(x)
ax.plot(... | 3 | 2016-07-21T10:31:34Z | 38,502,062 | <p>You should only show the label for one of the three sets of data. The can be done by adding an if/else statement in the <code>label = ...</code> in <code>ax.plot()</code>. Below is an example:</p>
<pre><code>from mpl_toolkits.mplot3d import Axes3D
fig = plt.figure()
ax = fig.gca(projection='3d')
x_labels = [10,20,... | 2 | 2016-07-21T10:42:25Z | [
"python",
"matplotlib"
] |
How to ping rethinkdb in python,to check whether db server aint down? | 38,501,961 | <pre><code>import rethinkdb as r
con=r.connect(host='localhost')
</code></pre>
<p>How do i ping? How do i used existing connection to ping DB server</p>
| -3 | 2016-07-21T10:37:24Z | 38,513,196 | <p>If you want to check that the connection is still healthy and running queries, you could do something like <code>r.expr(0).run(conn) == 0</code>.</p>
| 0 | 2016-07-21T19:51:03Z | [
"python",
"rethinkdb"
] |
pandas DataFrame reset_index for columns? | 38,502,084 | <p>Is there any equivalent of pandas.DataFrame.reset_index which operates on the columns and is able to handle the case of duplicate column names?</p>
<p>Obviously I could simply assign new values to columns, what I want to know if there is a method like df.reset_index to do that.</p>
<p>Sample Input </p>
<pre><code... | 4 | 2016-07-21T10:43:27Z | 38,502,106 | <p>Use <code>range</code> with length of columns by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.shape.html" rel="nofollow"><code>shape</code></a>:</p>
<pre><code>df.columns = range(df.shape[1])
print (df)
0 1 2
0 0.228080 0.884450 0.753401
1 0.176790 0... | 2 | 2016-07-21T10:44:22Z | [
"python",
"pandas",
"dataframe",
"duplicates",
"reindex"
] |
pandas DataFrame reset_index for columns? | 38,502,084 | <p>Is there any equivalent of pandas.DataFrame.reset_index which operates on the columns and is able to handle the case of duplicate column names?</p>
<p>Obviously I could simply assign new values to columns, what I want to know if there is a method like df.reset_index to do that.</p>
<p>Sample Input </p>
<pre><code... | 4 | 2016-07-21T10:43:27Z | 38,502,767 | <p>you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.set_axis.html" rel="nofollow">set_axis()</a> method:</p>
<pre><code>In [54]: df
Out[54]:
A A B
0 0.934900 0.817182 0.166270
1 0.064543 0.139431 0.249576
2 0.709349 0.731913 0.965048
3 0.28... | 2 | 2016-07-21T11:14:31Z | [
"python",
"pandas",
"dataframe",
"duplicates",
"reindex"
] |
How to modify the seq2seq cost function for padded vectors? | 38,502,366 | <p>Tensorflow supports dynamic length sequence by use of the parameter: 'sequence_length' while constructing the RNN layer, wherein the model does not learn the sequence after the sequence size = 'sequence_length' i.e, returns zero vector. </p>
<p>However, how can the cost function at <a href="https://github.com/tenso... | 0 | 2016-07-21T10:55:56Z | 38,502,547 | <p>This function already supports calculating costs for dynamic sequence lengths through the use of weights. As long as you ensure the weights are 0 for the "padding targets", the cross entropy will be pushed to 0 for those steps:</p>
<pre><code>log_perp_list.append(crossent * weight)
</code></pre>
<p>and the total s... | 1 | 2016-07-21T11:04:30Z | [
"python",
"dynamic",
"tensorflow",
"deep-learning",
"lstm"
] |
For loop did't working in view.py Django? | 38,502,382 | <p>in view.py</p>
<pre><code>Id = [2,3,4,5,6,7,8]
for w in Id:
A = w
Pending = pending(A)
data = {
'Pending': Pending,
}
return render_to_response('dialer_campaign/campaign/list.html', data, context_instance=RequestContext(request))
def pending(campaign_id):
A = Campaign_phoneb... | -3 | 2016-07-21T10:56:41Z | 38,502,820 | <p>Take your data object in list and render to the template</p>
<p>Refer following code</p>
<pre><code>Id = [2,3,4,5,6,7,8]
pending_list = []
for w in Id:
pending = pending(w)
pending_list.append({'pending': pending})
return render_to_response('dialer_campaign/campaign/list.html', pending_list, context_in... | 1 | 2016-07-21T11:17:08Z | [
"python",
"django",
"django-views"
] |
How can I parse long web pages with beatiful soup? | 38,502,390 | <p>I have been using following code to parse web page in the link <a href="https://www.blogforacure.com/members.php" rel="nofollow">https://www.blogforacure.com/members.php</a>. The code is expected to return the links of all the members of the given page.</p>
<pre><code> from bs4 import BeautifulSoup
import ur... | 1 | 2016-07-21T10:57:00Z | 38,512,338 | <p>The results are dynamically loaded by making AJAX requests to the <code>https://www.blogforacure.com/site/ajax/scrollergetentries.php</code> endpoint.</p>
<p>Simulate them in your code with <a href="http://docs.python-requests.org/en/master/" rel="nofollow"><code>requests</code></a> <a class='doc-link' href="http:/... | 1 | 2016-07-21T18:58:33Z | [
"python",
"html",
"web-scraping",
"beautifulsoup"
] |
Pandas DatetimeIndex NonExistentTimeError only when creating MultiIndex | 38,502,474 | <p>I have a <code>list</code> of data that has been read from MongoDB. A subset of the data can be found in <a href="https://gist.githubusercontent.com/philipobrien/280aa38cf024949d33c88fa903ffcb00/raw/1baad587704dfad32b539343b1ab2bffe9ccd9ab/Pandas%2520DatetimeIndex%2520Sample%2520Data" rel="nofollow">this gist</a>. I... | 2 | 2016-07-21T11:00:52Z | 38,502,878 | <p>You need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.sort_index.html" rel="nofollow"><code>sort_index</code></a> first and then append column <code>ID</code> to <code>index</code>:</p>
<pre><code>frame = frame.sort_index()
frame.set_index('ID', append=True, inplace=True)
print (f... | 1 | 2016-07-21T11:19:42Z | [
"python",
"datetime",
"pandas",
"dataframe"
] |
Alter the width of an annotate arrow in matplotlib | 38,502,594 | <p>I am plotting an arrow in <code>matplotlib</code> using <code>annotate</code>. I would like to make the arrow fatter. The effect I am after is a two-headed arrow with a thin edge line where I can control the arrow width i.e. not changing <code>linewidth</code>. I have tried <code>kwargs</code> such as <code>width</... | 0 | 2016-07-21T11:06:31Z | 38,517,497 | <p>The easiest way to do this will be by using <a href="http://matplotlib.org/api/patches_api.html#matplotlib.patches.FancyBboxPatch" rel="nofollow"><code>FancyBboxPatch</code></a> with the darrow (double arrow) option. The one tricky part of this method is that the arrow will not rotate around its tip but rather the e... | 0 | 2016-07-22T03:06:01Z | [
"python",
"python-2.7",
"matplotlib"
] |
python printing the path names of .c files from a directory tree | 38,502,657 | <p>I'm a beginner in Python.
I am trying to work with a directory tree that contains test cases (. files) at variable depth, say, test (top directory) has 2 children test1 and test 2. test1 has further branches t1 and t2 which contain t1.c and t2.c respectively. Similary, test2 has 2 children test21 and test22. test 21... | 1 | 2016-07-21T11:09:18Z | 38,502,879 | <p>It's better to use your own way to practice python. But the efficient way would be :</p>
<pre><code>>>> PATH = '/home/sijan/Desktop/'
>>> import os
>>> from glob import glob
>>> result = [y for x in os.walk(PATH) for y in glob(os.path.join(x[0], '*.py'))]
</code></pre>
<p>It wil... | 1 | 2016-07-21T11:19:54Z | [
"python",
"recursion",
"tree",
"directory"
] |
pause and resume Selenium execution | 38,502,842 | <p>I am looking for an option to pause and resume Selenium execution.</p>
<ol>
<li>start the selenium execution</li>
</ol>
<p><strong>2. pause at a certain step explicitly by some means (commandline/in-line code/manually)</strong></p>
<ol start="3">
<li>continue execution</li>
</ol>
<p>I know that we can keep</p>
... | 0 | 2016-07-21T11:18:05Z | 38,503,006 | <p>Use an IDE, set breakpoints, and debug your script.</p>
| 0 | 2016-07-21T11:25:38Z | [
"java",
"python",
"selenium"
] |
pause and resume Selenium execution | 38,502,842 | <p>I am looking for an option to pause and resume Selenium execution.</p>
<ol>
<li>start the selenium execution</li>
</ol>
<p><strong>2. pause at a certain step explicitly by some means (commandline/in-line code/manually)</strong></p>
<ol start="3">
<li>continue execution</li>
</ol>
<p>I know that we can keep</p>
... | 0 | 2016-07-21T11:18:05Z | 38,503,856 | <p>For Python, use can use <code>pdb</code> for debugging. Just drop the following line at the step where you want to pause and it will drop you into the debugger.
You might have to get a little familiar with <a href="https://docs.python.org/2/library/pdb.html" rel="nofollow">pdb</a> </p>
<pre><code>import pdb; pdb.se... | 0 | 2016-07-21T12:06:45Z | [
"java",
"python",
"selenium"
] |
Asyncio coroutines | 38,502,885 | <p>I thought I had grokked coroutines with David Beazley's very good <a href="http://www.dabeaz.com/coroutines/" rel="nofollow">presentation</a> but I can't reconcile it fully with the new syntax described in <a href="https://www.python.org/dev/peps/pep-0492/" rel="nofollow">PEP-492</a>. </p>
<p>In the presentation, h... | 1 | 2016-07-21T11:20:10Z | 38,503,429 | <p>What you have there is not a coroutine in the sense of the <code>asyncio</code> module and/or PEP-492. As the PEP itself says:</p>
<blockquote>
<p>[This PEP] is relevant only to the kind of coroutine that uses <code>yield</code> as a signal to the scheduler, indicating that the coroutine will be waiting until an ... | 1 | 2016-07-21T11:46:36Z | [
"python",
"python-3.x",
"coroutine",
"python-asyncio"
] |
Python Re-ordering the lines in a dat file by string | 38,502,906 | <p>Sorry if this is a repeat but I can't find it for now. </p>
<p>Basically I am opening and reading a <code>dat</code> file which contains a load of paths that I need to loop through to get certain information. </p>
<p>Each of the lines in the <code>base.dat</code> file contains <code>m.somenumber</code>. For exampl... | 0 | 2016-07-21T11:20:56Z | 38,503,870 | <p>Assuming that the number part of your line has the form of a float you can use a regular expression to match that part and convert it from string to float.</p>
<p>After that you can use this information in order to sort all the lines read from your file. I added a invalid line in order to show how invalid data is h... | 0 | 2016-07-21T12:07:33Z | [
"python",
"file",
"order",
"file.readalllines"
] |
calculate linear regression slope matrix (analogous to correlation matrix) - Python/Pandas | 38,502,916 | <p>Pandas has a really nice function that gives you a correlation matrix Data Frame for your data DataFrame, <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.corr.html" rel="nofollow">pd.DataFrame.corr()</a>.</p>
<p>The r of a correlation, however, isn't always that informative. Dependin... | 0 | 2016-07-21T11:21:33Z | 38,504,303 | <p>Slope of a regression line y=b<sub>0</sub> + b<sub>1</sub> * x can also be calculated using the correlation coefficient: b<sub>1</sub> = corr(x, y) * Ï<sub>x</sub> / Ï<sub>y</sub></p>
<p>Using numpy's newaxis to create the Ï<sub>x</sub> / Ï<sub>y</sub> matrix:</p>
<pre><code>df.corr() * (df.std().values / df.s... | 2 | 2016-07-21T12:27:40Z | [
"python",
"pandas",
"linear-regression",
"correlation"
] |
python pandas assigning to existing dataframe in iteration | 38,503,056 | <p>I have a long list of files that I want to load into separate data frames. However pandas seems to do nothing like that in line, so I am struggling to do this. In my example below, file_map would actually be imported so I can't have a static mapping between variable and file_name. The example does not achieve what i... | 0 | 2016-07-21T11:28:10Z | 38,503,314 | <p>Here's an approach that works well in practice:</p>
<pre><code>import glob
import os
dataframes = {}
for fn in glob('/path/to/files/<pattern>.csv'):
df = pd.read_csv(fn, ...)
dataframes[os.path.basename(fn)] = df
</code></pre>
<p>Here <code>dataframes</code> is a dictionary of dataframes. I'm using ... | 1 | 2016-07-21T11:40:39Z | [
"python",
"pandas"
] |
Get intersection elements of nested dictionaries in Python | 38,503,084 | <p>Let's say I have a list of dicts.
For example, the list contains the following dicts:</p>
<pre><code>{'david': {'status': 'available', 'type': 'human, 'location': [2, 3, 4]}, 'kuka': {'type': 'robot'}}
{'david': {'status': 'available', 'location': [2, 3, 4]}, 'kuka': {'status': 'available', 'type': 'robot'}}
</cod... | 0 | 2016-07-21T11:29:55Z | 38,504,949 | <p>I don't quite understand what you mean by 'intersection'.
If you want to get the common attributes of each dictionary item, you can use a <code>set</code> to get all common keys with following codes.</p>
<pre><code>common_keys = reduce(set.intersection, [set(i.keys()) for i in d.values()])
</code></pre>
<p>Then y... | 0 | 2016-07-21T12:58:46Z | [
"python",
"dictionary",
"nested"
] |
Get intersection elements of nested dictionaries in Python | 38,503,084 | <p>Let's say I have a list of dicts.
For example, the list contains the following dicts:</p>
<pre><code>{'david': {'status': 'available', 'type': 'human, 'location': [2, 3, 4]}, 'kuka': {'type': 'robot'}}
{'david': {'status': 'available', 'location': [2, 3, 4]}, 'kuka': {'status': 'available', 'type': 'robot'}}
</cod... | 0 | 2016-07-21T11:29:55Z | 38,506,628 | <p>You can recursively iterate over all dictionary keys. The most compact way of writing this is probably</p>
<pre><code>def common_items(d1, d2):
return {k: common_items(d1[k], d2[k]) if isinstance(d1[k], dict) else d1[k]
for k in d1.viewkeys() & d2.viewkeys()}
</code></pre>
<p>I'd recommend to ... | 0 | 2016-07-21T14:13:10Z | [
"python",
"dictionary",
"nested"
] |
Using groupby() together with filter in list comprehensions | 38,503,159 | <p>Why is it that</p>
<pre><code>>>> [ ( { k: len(list(g)) } ) for k, g in groupby(sorted('ABABAABBAC')) ]
[{'A': 5}, {'B': 4}, {'C': 1}]
</code></pre>
<p>but</p>
<pre><code>>>> [ ( { k: len(list(g)) } ) for k, g in groupby(sorted('ABABAABBAC')) if len(list(g)) > 1 ]
[{'A': 0}, {'B': 0}]
</code>... | 2 | 2016-07-21T11:33:24Z | 38,503,255 | <p>You have consumed the iterator when you called <code>len(list(g))</code> in your <em>if statement</em> so your <code>len(list(g))</code> returns 0 as there is nothing left to iterate over. </p>
<pre><code>In [1]: it = iter([1,2,3])
In [2]: list(it) # call list once consumes
Out[2]: [1, 2, 3]
In [3]: list(it) #... | 3 | 2016-07-21T11:37:50Z | [
"python",
"grouping",
"list-comprehension"
] |
Django user signup / registration form not working | 38,503,189 | <p>I made a sign up form following a tutorial.</p>
<p>what im trying to do as you can see here is to have the data transferred and get an error or success message to the targeted div in response without refreshing the page.</p>
<p>i have set the 3 forms : email ,email2 and password in the index.html</p>
<p>but the s... | 0 | 2016-07-21T11:34:47Z | 38,503,774 | <p>As correctly pointed out by <a href="http://stackoverflow.com/questions/38503189/django-user-signup-registration-form-not-working/38503774#comment64405258_38503189">Nikhil</a>, you are trying to serialize a form instance. Instead, you should serialize the form data.</p>
<p>From the <a href="https://docs.djangoproje... | 1 | 2016-07-21T12:02:52Z | [
"jquery",
"python",
"django"
] |
How to emit same signal for 2 classess from QThread | 38,503,592 | <p>I want to do that:
There is a class called as 'Main'. There is another class called as 'aClass'. And there is a thirth class called as 'Thread'. It is our thread class.
'Main' is our main class and we start our Thread class from Main class.
When our Thread class is started, it emits a signal from run() function...
'... | 0 | 2016-07-21T11:54:40Z | 38,503,890 | <p>What you are doing is creating a second <code>Thread</code> in the <code>aClass</code> object which is not the same <code>Thread</code> as in the <code>Main</code>. You need to connect the signal from the <code>self.thread</code> in <code>Main</code> to the Slot <code>write</code> in your <code>self.aClass</code> ob... | 0 | 2016-07-21T12:08:33Z | [
"python",
"pyqt4",
"qthread"
] |
Send request on webservice from URL | 38,503,703 | <p>I have SOAP webservice written in python with Spyne module..</p>
<p>This is it:</p>
<pre><code>class Function(spyne.Service):
__service_url_path__ = '/soap';
__in_protocol__ = Soap11(validator='lxml');
__out_protocol__ = Soap11();
@spyne.srpc(Unicode, _returns=Iterable(Unicode))
def Function(A... | 0 | 2016-07-21T11:59:31Z | 38,542,891 | <p>So,
now, I have it.</p>
<p><strong>This is correct way:</strong></p>
<pre><code>class Function(spyne.Service):
__service_url_path__ = '/soap';
__in_protocol__ = HttpRpc(validator='soft'); #this is it
__out_protocol__ = Soap11();
</code></pre>
<p>Now, I can <strong>call web service from URL</strong> l... | 0 | 2016-07-23T14:31:13Z | [
"python",
"web-services",
"post",
"get",
"spyne"
] |
Parsing default arguments in python functions without executing the function | 38,503,937 | <p>I need to pass a function (without calling it) to another function, but I need to specify a different value for a default argument.</p>
<p>For example:</p>
<pre><code>def func_a(input, default_arg=True):
pass
def func_b(function):
pass
func_b(func_a(default_arg=False))
</code></pre>
<p>This, however, <e... | 1 | 2016-07-21T12:10:44Z | 38,503,995 | <p>Use a <a href="https://docs.python.org/3/library/functools.html#functools.partial" rel="nofollow"><code>functools.partial()</code> object</a>:</p>
<pre><code>from functools import partial
func_b(partial(func_a, default_arg=False))
</code></pre>
<p>The <code>partial()</code> object is a callable too, when called i... | 4 | 2016-07-21T12:13:41Z | [
"python",
"function",
"python-3.x",
"default-arguments"
] |
Parsing default arguments in python functions without executing the function | 38,503,937 | <p>I need to pass a function (without calling it) to another function, but I need to specify a different value for a default argument.</p>
<p>For example:</p>
<pre><code>def func_a(input, default_arg=True):
pass
def func_b(function):
pass
func_b(func_a(default_arg=False))
</code></pre>
<p>This, however, <e... | 1 | 2016-07-21T12:10:44Z | 38,504,255 | <p>Use a lambda-function. Like this:</p>
<pre><code>func_b(lambda input: func_a(input, default_arg=False))
</code></pre>
<p>In <code>func_b</code> you will have a callable <code>function</code> which accepts argument input and executes <code>func_a</code> with previously specified <code>default_arg</code> argument.</... | 2 | 2016-07-21T12:25:50Z | [
"python",
"function",
"python-3.x",
"default-arguments"
] |
What does a comma mean in python? | 38,503,941 | <p>I stumbled upon this piece of code:</p>
<pre><code>from gensim import corpora, models, similarities
import numpy as np
corpus = corpora.BleiCorpus('/home/edward/ap/ap.dat', '/home/edward/ap/vocab.txt')
model = models.ldamodel.LdaModel(corpus, id2word = corpus.id2word, alpha=1)
topics = [model[a] for a in corpus]
... | -8 | 2016-07-21T12:10:53Z | 38,504,009 | <p>In this case it creates the tuple <code>(ti, tj)</code> and passes it to <code>dense.__getitem__()</code>. As to what that accomplishes, you will need to see the documentation and/or source for <code>dense</code>'s type.</p>
| 0 | 2016-07-21T12:14:17Z | [
"python"
] |
What does a comma mean in python? | 38,503,941 | <p>I stumbled upon this piece of code:</p>
<pre><code>from gensim import corpora, models, similarities
import numpy as np
corpus = corpora.BleiCorpus('/home/edward/ap/ap.dat', '/home/edward/ap/vocab.txt')
model = models.ldamodel.LdaModel(corpus, id2word = corpus.id2word, alpha=1)
topics = [model[a] for a in corpus]
... | -8 | 2016-07-21T12:10:53Z | 38,504,042 | <p>The code <code>dense[ti, tj]</code> calls <code>dense.__getitem__((ti, tj))</code>. The comma in this case constructs a tuple. This doesn't work with lists, but it could work with a dictionary if the keys are tuples.</p>
<pre><code>>>> [1,2,3][1, 2]
Traceback (most recent call last):
File "<stdin>"... | 0 | 2016-07-21T12:15:56Z | [
"python"
] |
Python - socket.recvfrom() get entire IP/UDP packet? | 38,503,982 | <p>Is there a way to use <code>socket.recvfrom(buf)</code> to get all IP and UPD data?
specifically, I want to know the udp header (source port, dest port, length, application data) as well as the ip specifics : what ip did it come from, what address was it sent to?</p>
<p>Snippet:</p>
<pre><code>addrinfo = socket.ge... | 0 | 2016-07-21T12:13:08Z | 38,505,198 | <p>Using</p>
<pre><code>sock = socket.socket(socket.AF_INET6, socket.SOCK_RAW)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
sock.bind(('', DEST_PORT))
sock.setsockopt(socket.IPPROTO_IPV6, socket.IP_HDRINCL, 1)
</code></pre>
<p>before joining multicast grp seems to work! </p>
| 0 | 2016-07-21T13:09:57Z | [
"python",
"sockets",
"udp",
"ipv6"
] |
Pandas/Python multiply columns by row | 38,504,025 | <p>Apologies if this is a simple question. </p>
<p>I have two dataframes each with the same columns. I need to multiply each row in the second dataframe by the only row in the first. </p>
<p>Eventually there will be more columns of different ages so I do not want to just multiply by a scalar. </p>
<p>I have used df.... | 0 | 2016-07-21T12:15:09Z | 38,504,133 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.mul.html" rel="nofollow"><code>mul</code></a> by first row of <code>df1</code> selected by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.iloc.html" rel="nofollow"><code>iloc</code></a>:</p>
... | 0 | 2016-07-21T12:20:41Z | [
"python",
"pandas",
"dataframe",
"multiplication"
] |
HDFStore: Select if column is in array | 38,504,273 | <p>I have a table with among others, the following columns:</p>
<pre><code>>>> hdf.select('foo').columns
Out[22]:
Index(['bar', 'units'],
dtype='object')
</code></pre>
<p>Now I wanted to select those where <code>bar</code> has one of two values:</p>
<pre><code>myBar = ['1500013010', '1500002071']
hdf... | 0 | 2016-07-21T12:26:39Z | 38,504,517 | <p>your column(s) are not indexed, hence not searchable, so you can't use them in the <code>where</code> parameter.</p>
<p>Demo:</p>
<pre><code>In [131]: df = pd.DataFrame(np.random.randint(0,20,size=(5, 3)), columns=list('ABC'))
In [132]: df
Out[132]:
A B C
0 19 4 18
1 4 14 16
2 17 13 9
3 19 ... | 2 | 2016-07-21T12:38:30Z | [
"python",
"pandas",
"dataframe",
"hdf",
"hdf5storage"
] |
Python + OpenCV, change brightness/darkness outside a sliding window? | 38,504,350 | <p>I'm working with Python and OpenCV and I'm a newbie in both.
For my project, I need to move a sliding window over a picture; for each position of the window the area outside the window must be shown darker than the area inside the window.</p>
<p>This is the part of my code that takes care of the picture and window ... | 1 | 2016-07-21T12:29:34Z | 38,507,263 | <p>In general, you can preserve the content inside the window and lower the intensity of the entire image. Then replace the area inside the window with original content. That trick should work. This part of the code may look like</p>
<pre><code>clone = image.copy()
windowArea = clone[y:y + winH, x:x + winW].copy()
clo... | 0 | 2016-07-21T14:40:09Z | [
"python",
"opencv",
"brightness"
] |
How to read dictionary in different manner? | 38,504,377 | <p>I'm having one dictionary which key is number and value is one or many lists. I want to read this dictionary so that I can separate key and value. </p>
<p><strong>Dictionary-</strong> </p>
<pre><code>{
1468332424064000: '[80000,2]',
1468332423282000: '[30000,6]',
1468332421081000: '[40000,2]',
1468332424121000... | 0 | 2016-07-21T12:30:34Z | 38,504,637 | <p>Assuming that you expect your result to look like</p>
<pre><code>[80000,2]
[30000,2]
[40000,2]
[60000,2]
[30000,6]
[40000,2]
[30000,6]
[30000,2]
[40000,2]
[40000,2]
[70000,6]
[60000,2]
[30000,6]
[60000,2]
[40000,2]
[40000,2]
[30000,6]
</code></pre>
<p>I suggest splitting each value on <code>[</code>, like so:</p>
... | 0 | 2016-07-21T12:44:59Z | [
"python",
"list",
"dictionary"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.