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
App Engine serving old version intermittently
38,741,327
<p>I've deployed a new version which contains just one image replacement. After migrating traffic (100%) to the new version I can see that only this version now has active instances. However 2 days later and App engine is still intermittently serving the old image. So I assume the previous version. When I ping the doma...
0
2016-08-03T10:43:17Z
38,788,820
<p>You have multiple layers of caches beyond memcache, </p> <p>Googles edge cache will definitely cache static content especially if you app is referenced by your domain and not appspot.com . </p> <p>You will probably need to use some cache busting techniques. </p> <p>You can test this by requesting the url that i...
0
2016-08-05T12:03:52Z
[ "python", "google-app-engine" ]
Efficient convolution of two images along one axis
38,741,395
<p>I have two large grayscale images. Either PIL.Image or numpy data structure. </p> <p>How do I do 1d convolution of the two images along one axis? </p> <p>The best I come up with is</p> <pre><code>def conv2(im1, im2, *args): res = 0 for l1, l2 in zip(im1, im2): res += np.convolve(l1, l2, *args) ...
0
2016-08-03T10:46:36Z
38,741,470
<p>FFT along one axis, multiply along one axis and inverse FFT. Should be MUCH faster according to <a href="http://www.dspguide.com/ch18/2.htm" rel="nofollow">this explanation</a> Scipy.signal.fftconvolve should do the job.</p>
2
2016-08-03T10:49:50Z
[ "python", "numpy" ]
What happens during a Jupyter notebook evaluation?
38,741,451
<p>I've always thought that Jupyter simply printed out the <code>repr</code> of an object, but that is not the case.</p> <p>Here is an example. If I evaluate this in a notebook:</p> <pre><code>obj = type(2) obj </code></pre> <p>I just get: <code>int</code>.</p> <p>If I do instead</p> <pre><code>print(obj) </code><...
0
2016-08-03T10:48:47Z
38,745,682
<p>Jupyter/IPython uses a rather complex <a href="https://github.com/ipython/ipython/blob/master/IPython/lib/pretty.py" rel="nofollow">pretty printer</a>. Concerning your example of <code>int</code>, it has a <a href="https://github.com/ipython/ipython/blob/master/IPython/lib/pretty.py#L668" rel="nofollow">printer for ...
1
2016-08-03T13:55:35Z
[ "python", "jupyter-notebook" ]
Create JSON tree with unknown root
38,741,507
<p>I have the following data created from a minimum spanning tree algorithm:</p> <pre><code>links = [("Earl","Bob"),("Bob","Sam"),("Bob","Leroy"),("Leroy","Harry")] </code></pre> <p>I need to convert the data into the following json tree:</p> <pre><code>{ "id": "Earl", "name": "Earl", "children": [ ...
0
2016-08-03T10:51:31Z
38,741,619
<pre><code>tree = get_nodes('Root'); tree = tree.children[0]; print(json.dumps(tree, indent=2)); </code></pre>
-1
2016-08-03T10:56:36Z
[ "python", "json", "minimum-spanning-tree" ]
Create JSON tree with unknown root
38,741,507
<p>I have the following data created from a minimum spanning tree algorithm:</p> <pre><code>links = [("Earl","Bob"),("Bob","Sam"),("Bob","Leroy"),("Leroy","Harry")] </code></pre> <p>I need to convert the data into the following json tree:</p> <pre><code>{ "id": "Earl", "name": "Earl", "children": [ ...
0
2016-08-03T10:51:31Z
38,741,774
<p>Isn't this because you've added Earl as a child of Root? With:</p> <pre><code>links.append(('Root', node)) print links # [('Earl', 'Bob'), ('Bob', 'Sam'), ('Bob', 'Leroy'), ('Leroy', 'Harry'), ('Root', 'Earl')] </code></pre> <p>So now when you run <code>children = get_children(node)</code> for <code>node = 'Root'<...
-1
2016-08-03T11:03:25Z
[ "python", "json", "minimum-spanning-tree" ]
How do I get the values of pixels in a certain area?
38,741,551
<p>so since I am relatively new to programming I would need a little help with that problem. I am using SimpleCV with Python 2.7 on a Windows Computer. What I am trying to do is to get a (selfwritten) program to tell me the values of the pixels along a preset line, the most important thing here would be the color of ...
2
2016-08-03T10:53:22Z
38,750,457
<p>Let's say you have the center <code>(x0, y0)</code>. You want to iterate over the pixels on the radius going from <code>(x0, y0)</code> to <code>(x1, y1)</code> which is a point on the circle. </p> <p>In C++, you would be able to use the <a href="http://docs.opencv.org/2.4/modules/core/doc/drawing_functions.html#li...
0
2016-08-03T17:47:33Z
[ "python", "windows", "opencv", "tracking", "simplecv" ]
Sentry django configuration - logger
38,741,620
<p>I am trying to use simple logging and want to send errors/exceptions to Sentry.</p> <p>I configured the Sentry as per the document and run the test successfully on my dev(<code>python manage.py raven test</code>)</p> <p>I added the Logging configuration as in <a href="https://docs.getsentry.com/hosted/clients/pyth...
1
2016-08-03T10:56:38Z
38,751,038
<p>When you call <code>logger = logging.getLogger(__name__)</code> Django <a href="https://docs.djangoproject.com/ja/1.9/topics/logging/#naming-loggers" rel="nofollow">creates a new logger</a>.</p> <p>One option is that if you want to log directly to only Sentry, you could use:</p> <pre><code>logger = logging.getLogg...
0
2016-08-03T18:23:19Z
[ "python", "django", "logging", "sentry" ]
Saving file from post request using Flask only works locally
38,741,699
<p><strong>HMTL:</strong></p> <pre><code>&lt;form action="/uploadimage" method="post" enctype="multipart/form-data"&gt; &lt;input type="file" name="file"&gt;&lt;br&gt; &lt;input type="submit" value="Submit"&gt; &lt;/form&gt; </code></pre> <p><strong>Python (Flask):</strong></p> <pre><code>@app.route('/uploadimag...
1
2016-08-03T11:00:09Z
38,741,854
<p>Openshift have <code>data</code> and that <code>directory can be used for persistent storage</code> | <code><a href="https://developers.openshift.com/managing-your-applications/filesystem.html" rel="nofollow">filesystem</a></code></p> <p>You can get the directory using this environment variable <code>OPENSHIFT_DAT...
1
2016-08-03T11:06:59Z
[ "python", "file", "flask", "openshift" ]
Optimal way for finding 'greatest value less than' in Numpy array
38,741,718
<p>I have a sorted numpy array <code>X</code> and also two constants <code>k</code> and <code>delta</code> that are not in <code>X</code>. I would like to find the index corresponding to, the largest value in <code>X</code> less than or equal to <code>k</code> and the value must be within <code>delta</code> of <code>k<...
2
2016-08-03T11:00:53Z
38,741,916
<p><a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.argmax.html" rel="nofollow"><code>Numpy.argmax</code></a> could be usefull for taking advantage of the sorted list.</p> <pre><code>import numpy as np np.argmax(X &lt;= k) if k-d &lt; np.argmax(X &lt;= k) &lt; k+d else None </code></pre>
0
2016-08-03T11:11:06Z
[ "python", "arrays", "performance", "sorting", "numpy" ]
Optimal way for finding 'greatest value less than' in Numpy array
38,741,718
<p>I have a sorted numpy array <code>X</code> and also two constants <code>k</code> and <code>delta</code> that are not in <code>X</code>. I would like to find the index corresponding to, the largest value in <code>X</code> less than or equal to <code>k</code> and the value must be within <code>delta</code> of <code>k<...
2
2016-08-03T11:00:53Z
38,742,146
<p>One efficient approach to leverage the sorted order would be with <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.searchsorted.html" rel="nofollow"><code>np.searchsorted</code></a> -</p> <pre><code>def largest_within_delta(X, k, delta): right_idx = X.searchsorted(k,'right')-1 if (k - X[ri...
2
2016-08-03T11:21:35Z
[ "python", "arrays", "performance", "sorting", "numpy" ]
Delete row in column when value in column is a string
38,741,814
<p>I have the following dataframe:</p> <pre><code> MATERIAL KW_WERT NETTO_EURO TA 0 B60ETS 0.15 18.9 SDH 1 B60ETS 0.145 18.27 SDH 2 B60ETS 0.145 18.27 SDH 3 B60ETS 0.15 ...
1
2016-08-03T11:05:03Z
38,741,853
<p>You can use mask with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_numeric.html" rel="nofollow"><code>to_numeric</code></a> and <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.notnull.html" rel="nofollow"><code>notnull</code></a> with <a href="http://pandas.py...
1
2016-08-03T11:06:50Z
[ "python", "python-3.x", "pandas" ]
Pickle Key error "Y" using socket
38,741,884
<p>I am trying to send a dictionary to my client and it is fin on the server end but when it gets to unpickling the dictionary it comes up with error <code>KeyError: 'Y'</code>. </p> <p>Why?</p> <p>Here is my code:</p> <p>client.py:</p> <pre><code>import socket, pickle s = socket.socket() s.connect(("localhost", 1...
0
2016-08-03T11:08:59Z
38,742,013
<p>It certainly doesn't help that the "You're connected" message is being concatenated with the pickle in your client. Removing that <code>send</code> from the server code appears to make your program work correctly.</p>
1
2016-08-03T11:15:12Z
[ "python", "sockets", "pickle" ]
Pickle Key error "Y" using socket
38,741,884
<p>I am trying to send a dictionary to my client and it is fin on the server end but when it gets to unpickling the dictionary it comes up with error <code>KeyError: 'Y'</code>. </p> <p>Why?</p> <p>Here is my code:</p> <p>client.py:</p> <pre><code>import socket, pickle s = socket.socket() s.connect(("localhost", 1...
0
2016-08-03T11:08:59Z
38,742,034
<p>The pickle protocol is version dependent. Could it be that you use different Python / pickle versions on client and server? In that case select a low protocol version explicitly as explained in the <a href="https://docs.python.org/3.5/library/pickle.html" rel="nofollow">docs</a>.</p> <p>Alternatively use JSON or so...
-1
2016-08-03T11:16:29Z
[ "python", "sockets", "pickle" ]
Pickle Key error "Y" using socket
38,741,884
<p>I am trying to send a dictionary to my client and it is fin on the server end but when it gets to unpickling the dictionary it comes up with error <code>KeyError: 'Y'</code>. </p> <p>Why?</p> <p>Here is my code:</p> <p>client.py:</p> <pre><code>import socket, pickle s = socket.socket() s.connect(("localhost", 1...
0
2016-08-03T11:08:59Z
38,742,153
<p>Your function <code>userDump()</code> should be corrected as:</p> <pre><code>def userDump(): d = s.recv(1024) s.sendall("userdump") d = s.recv(1024) return pickle.loads(d) </code></pre> <p>In your code you receive <code>"You're Connected"</code> in <code>d</code> and you are trying to unpickle...
0
2016-08-03T11:21:59Z
[ "python", "sockets", "pickle" ]
Calculating the frequency of each row in Pandas DataFrame
38,741,914
<p>Suppose I have given datasets:</p> <pre><code>Sr.No|Query ----- 1. a 2. a 3. b 4. b 5. a </code></pre> <p>I want the following result :</p> <pre><code>Sr.No | Query | Frequency 1. a 3 2. a 3 3. b 2 4. b 2 5. a 3 </code></pre> <p>Please note th...
3
2016-08-03T11:10:53Z
38,741,972
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.transform.html" rel="nofollow"><code>transform</code></a> with <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.size.html" rel="nofollow"><code>size</code></a>:</p> <pre><...
1
2016-08-03T11:13:27Z
[ "python", "pandas", "dataframe" ]
How to convert data of type Panda to Panda.Dataframe?
38,741,952
<p>I have a object of which type is Panda and the print(object) is giving below output</p> <pre><code> print(type(recomen_total)) print(recomen_total) </code></pre> <p>Output is </p> <pre><code>&lt;class 'pandas.core.frame.Pandas'&gt; Pandas(Index=12, instrument_1='XXXXXX', instrument_2='XXXX...
0
2016-08-03T11:12:35Z
38,742,968
<p>Interestingly, it will not convert to a dataframe directly but to a series. Once this is converted to a series use the to_frame method of series to convert it to a DataFrame</p> <pre><code>import pandas as pd df = pd.DataFrame({'col1': [1, 2], 'col2': [0.1, 0.2]}, index=['a', 'b']) for row in...
0
2016-08-03T11:57:17Z
[ "python", "pandas", "dataframe" ]
Update date in Python
38,742,028
<p>so here is my problem, I am trying to do a little program that gives the user the next date when he will have to pay rent.</p> <p>Here is my code:</p> <pre><code>curdate = datetime.date(2015, 01, 01) rent_date = datetime.date(curdate.year, curdate.month+1, 01) one_day = datetime.timedelta(days = 1) one_week = dat...
1
2016-08-03T11:16:07Z
38,742,144
<p>Your code is not altering anything because datetime is an immutable object, and when you call replace on it, it returns a new datetime, instead of modifying the first one.</p> <p>You should <code>return</code> the new object from the function and <code>assign</code> it back to <code>rent_date</code>:</p> <pre><cod...
1
2016-08-03T11:21:34Z
[ "python" ]
Update date in Python
38,742,028
<p>so here is my problem, I am trying to do a little program that gives the user the next date when he will have to pay rent.</p> <p>Here is my code:</p> <pre><code>curdate = datetime.date(2015, 01, 01) rent_date = datetime.date(curdate.year, curdate.month+1, 01) one_day = datetime.timedelta(days = 1) one_week = dat...
1
2016-08-03T11:16:07Z
38,742,424
<p><strong>Your functions have to return a new rent date.</strong> You just need to add the following lines in your code:</p> <ul> <li><strong><em>return cd</em></strong></li> <li><strong><em>new_rent_date = rent_date_calc(curdate, rent_date)</em></strong></li> </ul> <p>===============================================...
0
2016-08-03T11:34:43Z
[ "python" ]
Django channels: Echo example issues
38,742,115
<p>I'm following the sample code provided by the <a href="http://channels.readthedocs.io/en/latest/getting-started.html" rel="nofollow">channels documentation</a> and have run into a issue. The django server successfully accepts a websocket from the browser and sending appears to work. However server-side processing of...
0
2016-08-03T11:20:26Z
38,742,358
<p>You should connect <code>ws_message</code> consumer to <code>websocket.receive</code> not <code>websocket.recieve</code>.</p>
0
2016-08-03T11:31:33Z
[ "javascript", "python", "django", "websocket", "django-channels" ]
boost.python string management
38,742,186
<p>How does boost.python handle std::string member variables? Specifically, if I have a class and its boost.python wrapper</p> <pre><code>class A { public: std::string name; }; class_&lt;A&gt;("AWrapper") .def_readwrite("name", &amp;A::name); </code></pre> <p>how is the correspondence between std::string object ...
0
2016-08-03T11:23:33Z
38,745,570
<p>Short answer: your suspicions and insight about the behaviour is mostly correct, boost-python will interpret your configuration to produce a simple and inefficient behaviour, however it provides support mechanisms to override and extend this. This may be a lot of work.</p> <p>Long answer:</p> <blockquote> <p>is ...
2
2016-08-03T13:50:38Z
[ "python", "boost", "boost-python" ]
linux Environment vars permanently added using python
38,742,207
<p>I am trying to update a linux environment variable using a bash script, loaded from a python script</p> <p>1.- I delete it:</p> <pre><code>del os.environ['USER'] </code></pre> <p>2.- I run sourced the bash script with commands lib:</p> <pre><code>status, output = commands.getstatusoutput('. ' + PATH +'/script.sh...
0
2016-08-03T11:24:50Z
38,742,414
<p>The environment is inherited by a child process from its parent; more specifically a parent process creates an environment for child processes and by default this is the same as the parent's.</p> <p>It is not possible for any process to modify the environment of any other existing process.</p>
1
2016-08-03T11:34:21Z
[ "python", "linux", "environment-variables" ]
linux Environment vars permanently added using python
38,742,207
<p>I am trying to update a linux environment variable using a bash script, loaded from a python script</p> <p>1.- I delete it:</p> <pre><code>del os.environ['USER'] </code></pre> <p>2.- I run sourced the bash script with commands lib:</p> <pre><code>status, output = commands.getstatusoutput('. ' + PATH +'/script.sh...
0
2016-08-03T11:24:50Z
38,742,514
<p><code>os.environ</code> is <em>not</em> your environment, but a representation of it, created when the <code>os</code> module is imported for the first time. According to <a href="https://docs.python.org/2/library/os.html#process-parameters" rel="nofollow">the documentation</a> some platforms will reflect changes to...
1
2016-08-03T11:38:43Z
[ "python", "linux", "environment-variables" ]
MySQL sequential read in a For Loop
38,742,229
<p>I have a database with multiple tables(around 100) with records stored based on category. Each category is a table and , each table holds multiple items. Each item is having multiple transaction records for each day, whenever there is a transaction happened with multiple fields for each row.</p> <p>I need to fetch ...
-1
2016-08-03T11:25:43Z
38,742,381
<p>Before even considering this question, I would urge you to re-examine the structure of your database. If you have 100 tables with the same structure (?), each one representing a different category, it would be MUCH simpler to have a single table with an additional <code>category</code> column that you could then use...
0
2016-08-03T11:32:54Z
[ "php", "python", "mysql", "codeigniter" ]
Howto copy a dask dataframe?
38,742,536
<p>Given a pandas <code>df</code> one can copy it before doing anything via:</p> <pre><code>df.copy() </code></pre> <p>How can I do this with a dask dataframe object?</p>
1
2016-08-03T11:39:36Z
38,743,372
<p>Mutation on dask.dataframe objects is rare, so this is rarely necessary. </p> <p>That being said, you can safely just copy the object</p> <pre><code>from copy import copy df2 = copy(df) </code></pre> <p>No dask.dataframe operation mutates any of the fields of the dataframe, so this is sufficient.</p>
2
2016-08-03T12:14:31Z
[ "python", "dask" ]
Howto copy a dask dataframe?
38,742,536
<p>Given a pandas <code>df</code> one can copy it before doing anything via:</p> <pre><code>df.copy() </code></pre> <p>How can I do this with a dask dataframe object?</p>
1
2016-08-03T11:39:36Z
38,743,529
<p>Write it to a file and read again:</p> <pre><code>import os import dask.dataframe as dd df = &lt;Initial Dask Dataframe to be copied&gt; file = 'sample.csv' df.to_csv(file) df2 = df.read_csv(file) os.remove(file) </code></pre>
0
2016-08-03T12:21:48Z
[ "python", "dask" ]
QTreeView, QTreeWidget, QTableWidget or QTableView for object data?
38,742,557
<p>I have a collection of objects and I want to display their data in rows/columns. However I'm not sure which pyside widget to use. There are a few main features I want to implement which I'm assuming may help decide which widget to use. Each row is an object. Which pyside widget should i use and why?</p> <p>Features...
0
2016-08-03T11:40:27Z
38,782,197
<p>Use a tree if the data is hierarchical. Your data is clearly not so it's better to use a table.</p> <p>The <code>QTableWidget</code> is slightly easier to implement than the <code>QTableView</code> (which also needs a <code>QTableModel</code> as backend) but it has less capabilities. I use a <code>QTableWidget</cod...
0
2016-08-05T06:05:32Z
[ "python", "widget", "pyside" ]
Python path and raw strings
38,742,691
<p>I have some problems with the name of path + file (which is an input for a function) That works:</p> <pre><code>result=r"D:\final\Res.mat" </code></pre> <p>That does not work:</p> <pre><code>result="D:\\final\\Res.mat" </code></pre> <p>What I would like to do is the following (but does also not work "[Errno 22] ...
-2
2016-08-03T11:46:04Z
38,742,780
<p>The <code>r</code> prefix is used to indicate the you want the string to be evaluated as "raw", keeping backslashes as-is.</p> <p>Try this:</p> <pre><code>path = r"D:\final" nameFile = "Res" result = path + '\\' + nameFile + 'mat' </code></pre> <p>As you can see, I added <code>r</code> before the string expressi...
0
2016-08-03T11:50:07Z
[ "python", "rawstring" ]
Python path and raw strings
38,742,691
<p>I have some problems with the name of path + file (which is an input for a function) That works:</p> <pre><code>result=r"D:\final\Res.mat" </code></pre> <p>That does not work:</p> <pre><code>result="D:\\final\\Res.mat" </code></pre> <p>What I would like to do is the following (but does also not work "[Errno 22] ...
-2
2016-08-03T11:46:04Z
38,742,784
<p>You need use a raw string for the path variable, or escape the backslash:</p> <pre><code>path = r"D:\final" </code></pre> <p>You can see the difference here:</p> <pre><code>&gt;&gt;&gt; "D:\final" 'D:\x0cinal' &gt;&gt;&gt; r"D:\final" 'D:\\final' </code></pre> <p>In the first case <code>'\f</code>' is the form f...
0
2016-08-03T11:50:13Z
[ "python", "rawstring" ]
Python path and raw strings
38,742,691
<p>I have some problems with the name of path + file (which is an input for a function) That works:</p> <pre><code>result=r"D:\final\Res.mat" </code></pre> <p>That does not work:</p> <pre><code>result="D:\\final\\Res.mat" </code></pre> <p>What I would like to do is the following (but does also not work "[Errno 22] ...
-2
2016-08-03T11:46:04Z
38,742,794
<blockquote> <p>How do I get the "r" in front of the name without using " "?</p> </blockquote> <p>Just use <code>os.path.join</code>:</p> <pre><code>import os path = r"D:\final" nameFile= "Res.mat" result = os.path.join(path, nameFile) print(result) &gt;&gt; D:\final\Res.mat </code></pre>
0
2016-08-03T11:50:34Z
[ "python", "rawstring" ]
Python path and raw strings
38,742,691
<p>I have some problems with the name of path + file (which is an input for a function) That works:</p> <pre><code>result=r"D:\final\Res.mat" </code></pre> <p>That does not work:</p> <pre><code>result="D:\\final\\Res.mat" </code></pre> <p>What I would like to do is the following (but does also not work "[Errno 22] ...
-2
2016-08-03T11:46:04Z
38,742,827
<p>My interpreter suggests that you are mistaken in your belief that the second example does not work, because</p> <pre><code>&gt;&gt;&gt; r"D:\final\Res.mat" == "D:\\final\\Res.mat" True </code></pre> <p>The correct way to build file paths from components is by using the <code>os.path.join</code> function, which can...
2
2016-08-03T11:51:59Z
[ "python", "rawstring" ]
AffinityPropagation' object has no attribute 'label_'
38,742,707
<p>I am using scikit learn for affinity propogation algo. My input data is a numpy array of size 2303*2303 . It is a similarity matrix. I want to calculate the distance of each element in a cluster to its centroid. When i try to print the labels, i am getting the following error:</p> <p>"AffinityPropagation' object ha...
0
2016-08-03T11:47:08Z
38,742,865
<p>According to the docs of <a href="http://scikit-learn.org/stable/modules/generated/sklearn.cluster.AffinityPropagation.html" rel="nofollow">AffinityPropagation</a> you have to type </p> <p><code>print af.labels_</code></p>
1
2016-08-03T11:53:17Z
[ "python", "machine-learning", "scikit-learn" ]
combining py and sh code in one file
38,742,739
<p>I was wondering how can I combine sh and py code in one file and then execute it. What format should I save it in and commands for executing it?</p> <p>Here is an example script I have written have a look at it and tell me the modifications to it</p> <pre><code>#test Print("hello welcome to test") print("to expl...
1
2016-08-03T11:48:22Z
38,742,853
<p>You could save a Python file and run the shell script with Python code:</p> <pre><code>import os os.system('./script.sh') </code></pre>
1
2016-08-03T11:52:51Z
[ "python", "linux", "bash", "shell", "sh" ]
combining py and sh code in one file
38,742,739
<p>I was wondering how can I combine sh and py code in one file and then execute it. What format should I save it in and commands for executing it?</p> <p>Here is an example script I have written have a look at it and tell me the modifications to it</p> <pre><code>#test Print("hello welcome to test") print("to expl...
1
2016-08-03T11:48:22Z
38,742,863
<p>You can execute unix commands in python using <code>os.system()</code>, which is a bit deprecated. For example:</p> <pre><code>import os os.system("command") </code></pre> <p>or better using <code>subprocess</code> module:</p> <pre><code>import subprocess subprocess.call("command1") subprocess.call(["command1", "...
0
2016-08-03T11:53:13Z
[ "python", "linux", "bash", "shell", "sh" ]
combining py and sh code in one file
38,742,739
<p>I was wondering how can I combine sh and py code in one file and then execute it. What format should I save it in and commands for executing it?</p> <p>Here is an example script I have written have a look at it and tell me the modifications to it</p> <pre><code>#test Print("hello welcome to test") print("to expl...
1
2016-08-03T11:48:22Z
38,742,982
<p>You can't write both intermixed directly, but you can certainly run shell commands from within Python:</p> <pre><code>import subprocess retval = subprocess.call('echo foo', shell=True) </code></pre> <p>See the <a href="https://docs.python.org/3/library/subprocess.html" rel="nofollow"><code>subprocess</code> docs</...
1
2016-08-03T11:57:57Z
[ "python", "linux", "bash", "shell", "sh" ]
combining py and sh code in one file
38,742,739
<p>I was wondering how can I combine sh and py code in one file and then execute it. What format should I save it in and commands for executing it?</p> <p>Here is an example script I have written have a look at it and tell me the modifications to it</p> <pre><code>#test Print("hello welcome to test") print("to expl...
1
2016-08-03T11:48:22Z
38,743,080
<p>You can. You have to import the os module and wrap your shell commands like this: os.system("ls -l"). <a href="http://stackoverflow.com/questions/89228/calling-an-external-command-in-python">Source</a></p> <p>So for your code it would look like this:</p> <pre><code>#test print("hello welcome to test") import os p...
2
2016-08-03T12:02:02Z
[ "python", "linux", "bash", "shell", "sh" ]
How to use a Seafile generated upload-link w/o authentication token from command line
38,742,893
<p>With Seafile one is able to create a public upload link (e.g. <code>https://cloud.seafile.com/u/d/98233edf89/</code>) to upload files via Browser w/o authentication.</p> <p>Seafile webapi does not support any upload w/o authentication token.</p> <p>How can I use such kind of link from command line with curl or fro...
0
2016-08-03T11:54:13Z
38,743,242
<p>needed 2 hours to find a solution with curl, it needs two steps:</p> <ol> <li>make a get-request to the public uplink url with the <code>repo-id</code> as query parameter as follows:</li> </ol> <p><code>curl 'https://cloud.seafile.com/ajax/u/d/98233edf89/upload/?r=f3e30b25-aad7-4e92-b6fd-4665760dd6f5' -H 'Accept: ...
0
2016-08-03T12:08:15Z
[ "python", "curl", "urllib2", "http-upload", "seafile-server" ]
How to make this Block of python code short and efficient
38,742,938
<p>I am total newbie to programming and python. I was solving a problem. I found the solution but it seems like too slow.</p> <pre><code> if n % 2 == 0 and n % 3 == 0 and\ n % 4 == 0 and n % 5 == 0 and\ n % 6 == 0 and n % 7 == 0 and\ n % 8 == 0 and n % 9 == 0 and\ n % 10 == 0 and n % 11 ...
31
2016-08-03T11:56:13Z
38,742,979
<pre><code>if all(n % i == 0 for i in range(2, 21)): </code></pre> <p><code>all</code> accepts an iterable and returns <code>True</code> if all of its elements are evaluated to <code>True</code>, <code>False</code> otherwise. The <code>n % i == 0 for i in range(2, 21)</code> part returns an iterable with 19 <code>True...
46
2016-08-03T11:57:49Z
[ "python", "performance", "python-2.7", "if-statement" ]
How to make this Block of python code short and efficient
38,742,938
<p>I am total newbie to programming and python. I was solving a problem. I found the solution but it seems like too slow.</p> <pre><code> if n % 2 == 0 and n % 3 == 0 and\ n % 4 == 0 and n % 5 == 0 and\ n % 6 == 0 and n % 7 == 0 and\ n % 8 == 0 and n % 9 == 0 and\ n % 10 == 0 and n % 11 ...
31
2016-08-03T11:56:13Z
38,743,005
<p>Built in <a href="https://docs.python.org/2/library/functions.html#all">all </a> will help.</p> <blockquote> <p>Return True if all elements of the iterable are true (or if the iterable is empty).</p> </blockquote> <pre><code>if all(n % i == 0 for i in xrange(2, 21)) </code></pre>
6
2016-08-03T11:58:47Z
[ "python", "performance", "python-2.7", "if-statement" ]
How to make this Block of python code short and efficient
38,742,938
<p>I am total newbie to programming and python. I was solving a problem. I found the solution but it seems like too slow.</p> <pre><code> if n % 2 == 0 and n % 3 == 0 and\ n % 4 == 0 and n % 5 == 0 and\ n % 6 == 0 and n % 7 == 0 and\ n % 8 == 0 and n % 9 == 0 and\ n % 10 == 0 and n % 11 ...
31
2016-08-03T11:56:13Z
38,743,106
<p>There's a trade-off between short and efficient.</p> <p>The <em>Short</em> way is <code>if all(n % i == 0 for i in range(2, 21)):</code></p> <p>The <em>Efficient</em> way is to notice that things like <code>n % 20 == 0</code> also mean that <code>n % f == 0</code> where <code>f</code> is any factor of 20. For exam...
79
2016-08-03T12:02:46Z
[ "python", "performance", "python-2.7", "if-statement" ]
How to make this Block of python code short and efficient
38,742,938
<p>I am total newbie to programming and python. I was solving a problem. I found the solution but it seems like too slow.</p> <pre><code> if n % 2 == 0 and n % 3 == 0 and\ n % 4 == 0 and n % 5 == 0 and\ n % 6 == 0 and n % 7 == 0 and\ n % 8 == 0 and n % 9 == 0 and\ n % 10 == 0 and n % 11 ...
31
2016-08-03T11:56:13Z
38,743,183
<p>You need a condition that evaluates True when all divisions give a zero remainder. The two solutions so far proposed don't appear to do that. I suspect the condition you need is</p> <pre><code>if not any(n % i for i in range(2, 21)): </code></pre>
3
2016-08-03T12:05:44Z
[ "python", "performance", "python-2.7", "if-statement" ]
How to make this Block of python code short and efficient
38,742,938
<p>I am total newbie to programming and python. I was solving a problem. I found the solution but it seems like too slow.</p> <pre><code> if n % 2 == 0 and n % 3 == 0 and\ n % 4 == 0 and n % 5 == 0 and\ n % 6 == 0 and n % 7 == 0 and\ n % 8 == 0 and n % 9 == 0 and\ n % 10 == 0 and n % 11 ...
31
2016-08-03T11:56:13Z
38,743,446
<p>There's a smarter way to do this. If <code>n</code> is divisible by every integer in range(1, 21) then it <em>must</em> be a multiple of the <a href="https://en.wikipedia.org/wiki/Least_common_multiple">least common multiple</a> of those integers. </p> <p>You can calculate the LCM of a set of numbers progressively...
53
2016-08-03T12:17:35Z
[ "python", "performance", "python-2.7", "if-statement" ]
How to make this Block of python code short and efficient
38,742,938
<p>I am total newbie to programming and python. I was solving a problem. I found the solution but it seems like too slow.</p> <pre><code> if n % 2 == 0 and n % 3 == 0 and\ n % 4 == 0 and n % 5 == 0 and\ n % 6 == 0 and n % 7 == 0 and\ n % 8 == 0 and n % 9 == 0 and\ n % 10 == 0 and n % 11 ...
31
2016-08-03T11:56:13Z
38,743,465
<p>It's just a mathematical trick, use something like <code>n % "LCM(1,2,...,20) == 0</code> which could be coded as:</p> <pre><code>if n % 232792560 == 0: #do whatever you want </code></pre>
4
2016-08-03T12:18:35Z
[ "python", "performance", "python-2.7", "if-statement" ]
How to make this Block of python code short and efficient
38,742,938
<p>I am total newbie to programming and python. I was solving a problem. I found the solution but it seems like too slow.</p> <pre><code> if n % 2 == 0 and n % 3 == 0 and\ n % 4 == 0 and n % 5 == 0 and\ n % 6 == 0 and n % 7 == 0 and\ n % 8 == 0 and n % 9 == 0 and\ n % 10 == 0 and n % 11 ...
31
2016-08-03T11:56:13Z
38,751,082
<p>For variety, the way you could have used a loop for this is</p> <pre><code>test = True for modulus in range(2, 21): if n % modulus != 0: test = False break if test: # Do stuff </code></pre> <p>If you are comfortable with <code>for</code>-<code>else</code>, you can improve the brevity by</p>...
4
2016-08-03T18:26:05Z
[ "python", "performance", "python-2.7", "if-statement" ]
How to make this Block of python code short and efficient
38,742,938
<p>I am total newbie to programming and python. I was solving a problem. I found the solution but it seems like too slow.</p> <pre><code> if n % 2 == 0 and n % 3 == 0 and\ n % 4 == 0 and n % 5 == 0 and\ n % 6 == 0 and n % 7 == 0 and\ n % 8 == 0 and n % 9 == 0 and\ n % 10 == 0 and n % 11 ...
31
2016-08-03T11:56:13Z
38,751,170
<p>I'm a very light python user myself, and I didn't know about all. Those solutions are pretty cool (and probably more efficient than the one I'm about to post). But just if you want to see another way to do it, here is another option:</p> <pre><code>def IsDivUpTo20(n): for i in range(2, 21): if n % i != 0...
2
2016-08-03T18:31:15Z
[ "python", "performance", "python-2.7", "if-statement" ]
How to make this Block of python code short and efficient
38,742,938
<p>I am total newbie to programming and python. I was solving a problem. I found the solution but it seems like too slow.</p> <pre><code> if n % 2 == 0 and n % 3 == 0 and\ n % 4 == 0 and n % 5 == 0 and\ n % 6 == 0 and n % 7 == 0 and\ n % 8 == 0 and n % 9 == 0 and\ n % 10 == 0 and n % 11 ...
31
2016-08-03T11:56:13Z
38,753,310
<p>Similar to previous answers:</p> <pre><code>import operator x = 232792560 if reduce(operator.__and__, [x % n == 0 for n in xrange(2, 21, 2)]): print("ok") </code></pre>
2
2016-08-03T20:46:25Z
[ "python", "performance", "python-2.7", "if-statement" ]
How to make this Block of python code short and efficient
38,742,938
<p>I am total newbie to programming and python. I was solving a problem. I found the solution but it seems like too slow.</p> <pre><code> if n % 2 == 0 and n % 3 == 0 and\ n % 4 == 0 and n % 5 == 0 and\ n % 6 == 0 and n % 7 == 0 and\ n % 8 == 0 and n % 9 == 0 and\ n % 10 == 0 and n % 11 ...
31
2016-08-03T11:56:13Z
38,759,211
<p>Many of the above code examples are shorter, but (probably) not efficient enough:</p> <pre><code>n%2 == 0 =&gt; n%4 6 8... ==0 n%3 == 0 =&gt; n%3 6 9... ==0 </code></pre> <p>We can use only primes to check within the range:</p> <pre><code>if all(n % i == 0 for i in [2,3,5,7,11,13,17,19]) </code></pre> <...
3
2016-08-04T05:38:12Z
[ "python", "performance", "python-2.7", "if-statement" ]
How to make this Block of python code short and efficient
38,742,938
<p>I am total newbie to programming and python. I was solving a problem. I found the solution but it seems like too slow.</p> <pre><code> if n % 2 == 0 and n % 3 == 0 and\ n % 4 == 0 and n % 5 == 0 and\ n % 6 == 0 and n % 7 == 0 and\ n % 8 == 0 and n % 9 == 0 and\ n % 10 == 0 and n % 11 ...
31
2016-08-03T11:56:13Z
38,813,932
<p>I don't know if answering your own question is good or not.</p> <p>Since I need to check. if a number is divisible by numbers from 1 to 20 or not. So it gonna take long time to check. But if I could make checklist shorter then it will efficient.</p> <p>Like, if a number is divisible by <code>18</code> then it also...
0
2016-08-07T12:01:42Z
[ "python", "performance", "python-2.7", "if-statement" ]
Python async transactions psycopg2
38,742,954
<p>It is possible to do async i/o with psycopg2 (which can be <a href="http://initd.org/psycopg/docs/advanced.html#async-support" rel="nofollow">read here</a>) however I'm not sure how to do async transactions. Consider this sequence of things:</p> <ul> <li>Green Thread 1 starts transaction T</li> <li>GT1 issues updat...
2
2016-08-03T11:56:49Z
38,744,541
<p>Actually you can use BEGIN; and COMMIT; with async. What you need is a connection pool setup and make sure each green thread gets its own connection (Just like a real thread would in a multithreaded application).</p> <p>You cannot use psycopg2's builtin transaction handling.</p>
0
2016-08-03T13:05:06Z
[ "python", "postgresql", "asynchronous", "psycopg2", "python-db-api" ]
python imap4 extract subject mails
38,743,027
<p>i have this python code :</p> <pre><code>import imaplib import email, sys imaplib._MAXLINE = 40000 mail = imaplib.IMAP4('imapmail.libero.it') mail.login('username@libero.it', 'password') mail.list() mail.select('inbox') result, data = mail.search(None, 'All') out = open('output.txt', 'a', 0) for latest_email_uid ...
1
2016-08-03T12:00:01Z
38,744,582
<p>When you do...</p> <pre><code>result, data = mail.search(None, 'All') </code></pre> <p>...<code>data</code> holds <code>message sequence numbers</code>, not <code>uids</code>. Message sequence numbers and UIDs are not the same. </p> <p>So, to fix your code, replace the above line with:</p> <pre><code>result, dat...
0
2016-08-03T13:07:40Z
[ "python" ]
Pandas Converter on Data strptime()
38,743,079
<p>I am trying to plot this points, however I am getting that error. Do I need another converter for the date data? The x-axis should be the date, and y axis should be the time value. Thank you.</p> <p>TypeError: strptime() argument 1 must be str, not Timestamp</p> <pre><code>df = pd.read_csv('file.csv', sep=',', par...
1
2016-08-03T12:02:00Z
38,743,431
<p>The problem seems to be that you assume <code>df['Date']</code> is a string column and you're trying to convert it to date with <code>[date_to_days(d) for d in dates]</code>, but since you read the file with the <code>parse_dates=[0]</code> option, pandas already parsed it.</p>
0
2016-08-03T12:17:06Z
[ "python" ]
Pandas Converter on Data strptime()
38,743,079
<p>I am trying to plot this points, however I am getting that error. Do I need another converter for the date data? The x-axis should be the date, and y axis should be the time value. Thank you.</p> <p>TypeError: strptime() argument 1 must be str, not Timestamp</p> <pre><code>df = pd.read_csv('file.csv', sep=',', par...
1
2016-08-03T12:02:00Z
38,743,457
<p><code>datetime.strptime()</code> is for <em>parsing</em> strings into <code>datetime.datetime</code> objects. As such it makes no sense to apply it to a <code>pandas.tslib.Timestamp</code> object, which is what would be passed in by <code>[date_to_days(d) for d in dates]</code> because <code>dates</code> contains th...
0
2016-08-03T12:18:09Z
[ "python" ]
why use sqlalchemy declarative api?
38,743,100
<p>New to sqlalchemy and somewhat novice with programing and python. I had wanted to query a table. It seems I can use the all() function when querying but cannot filter without creating a class.</p> <p>1.) Can I filter without creating a class and using the declarative api? Is the filtering example stated below in...
0
2016-08-03T12:02:39Z
38,743,594
<p>Filter using declarative api this way:</p> <pre><code>session.query(files).filter(files.file_name == 'test.json').all() </code></pre> <p>You can also use raw sql queries (<a href="http://docs.sqlalchemy.org/en/latest/core/connections.html#basic-usage" rel="nofollow">docs</a>).</p> <p>Whether using declarative api...
1
2016-08-03T12:24:42Z
[ "python", "postgresql", "sqlalchemy" ]
why use sqlalchemy declarative api?
38,743,100
<p>New to sqlalchemy and somewhat novice with programing and python. I had wanted to query a table. It seems I can use the all() function when querying but cannot filter without creating a class.</p> <p>1.) Can I filter without creating a class and using the declarative api? Is the filtering example stated below in...
0
2016-08-03T12:02:39Z
38,750,610
<p>If you want to filter by a <code>Table</code> construct, it should be:</p> <pre><code>session.query(files).filter(files.c.file_name == 'test.json') </code></pre> <p>You need to create mapped classes if you want to use the ORM features of SQLAlchemy. For example, with the code you currently have, in order to do an ...
1
2016-08-03T17:56:27Z
[ "python", "postgresql", "sqlalchemy" ]
My code with truncate() appends new data instead of replacing old data
38,743,152
<p>This code below is supposed to delete the content of the file and write the new strings that user enters through terminal, but in reality it only appends new line to what is already there. I can't seem to make it fully erase the content with <code>truncate()</code>. How do I do this?</p> <p><strong>Note</strong>: i...
0
2016-08-03T12:04:38Z
38,743,210
<p><a href="https://docs.python.org/3/library/io.html#io.IOBase.truncate" rel="nofollow"><code>truncate()</code></a> without any arguments truncates at the current position. Pass a size to make it truncate the file to that size.</p>
2
2016-08-03T12:07:04Z
[ "python", "python-3.x" ]
My code with truncate() appends new data instead of replacing old data
38,743,152
<p>This code below is supposed to delete the content of the file and write the new strings that user enters through terminal, but in reality it only appends new line to what is already there. I can't seem to make it fully erase the content with <code>truncate()</code>. How do I do this?</p> <p><strong>Note</strong>: i...
0
2016-08-03T12:04:38Z
38,743,218
<p>The <a href="https://docs.python.org/2/library/stdtypes.html#file.truncate" rel="nofollow"><code>truncate</code></a> method has an optional <code>size</code> argument which defaults to the current position of the file pointer. Since you've already called <code>read</code> on the file, <code>truncate</code> isn't doi...
1
2016-08-03T12:07:22Z
[ "python", "python-3.x" ]
django.core.validators is not a package
38,743,262
<p>I've been struggling with this issue for a couple of days and still can't figure out why this is happening. I'm trying to at least access a shell via manage.py or perform a migration. (django 1.9.8, python 3.5.2)</p> <pre><code> Traceback (most recent call last): File "gris/gris/manage.py", line 14, in &lt;mod...
0
2016-08-03T12:09:16Z
38,743,444
<p>According to the <a href="https://docs.djangoproject.com/en/1.9/ref/validators/" rel="nofollow">Django documentation</a> and indeed the <a href="https://docs.djangoproject.com/en/1.9/_modules/django/core/validators/" rel="nofollow">source code</a> <code>django.core.validators</code> is a module, and does not contain...
0
2016-08-03T12:17:34Z
[ "python", "django", "debian", "importerror" ]
django.core.validators is not a package
38,743,262
<p>I've been struggling with this issue for a couple of days and still can't figure out why this is happening. I'm trying to at least access a shell via manage.py or perform a migration. (django 1.9.8, python 3.5.2)</p> <pre><code> Traceback (most recent call last): File "gris/gris/manage.py", line 14, in &lt;mod...
0
2016-08-03T12:09:16Z
38,743,608
<p>That error would perhaps be raised if <code>django.core.validators</code> was in your <code>INSTALLED_APPS</code> setting. </p> <p>If it is in your <code>INSTALLED_APPS</code> setting, then it shouldn't be there because it's not an app. Remove it.</p>
1
2016-08-03T12:25:14Z
[ "python", "django", "debian", "importerror" ]
Elastic doesn't find the word with the apostrophe (')
38,743,274
<p>I try to find the sentence that consists the word with the apostrophe. So, in the text </p> <blockquote> <p>If you ask foreigners to name some typically English dishes, they will probably say fish and chips and then stop. It is disappointing, but true, that there is no tradition in Britain of eating in rest...
1
2016-08-03T12:09:44Z
38,745,845
<blockquote> <p>“The hardest thing of all is to find a black cat in a dark room, especially if there is no cat.”</p> <p>― Confucius</p> </blockquote> <p>Elasticsearch perform <a href="https://www.elastic.co/guide/en/elasticsearch/guide/current/analysis-intro.html#_built_in_analyzers" rel="nofollow">stan...
0
2016-08-03T14:02:03Z
[ "python", "elasticsearch" ]
A better code to make an empty square with using numbers
38,743,349
<p>hi i want to make an empty square with numbers and i have the code like this:</p> <pre><code>L = input ('input your numbers = ') M = (L-2) * ' ' P = L - 1 x = "" y = "" for a in range(1,L+1): x = x + str(a) print x for b in range(2,L): print str(b) + M + str(P) P-=1 for c in range(L,0,-1): y = y +...
0
2016-08-03T12:13:28Z
38,743,894
<p>Not exactly the same output as yours (due to <code>print</code> placing space after each digit), but example how to accomplish the same by detecting edge and calculating value:</p> <pre><code>n = input('&gt; ') m = n-1 for i in range(n): for j in range(n): if i == 0 or j == 0: # top or left edge ...
1
2016-08-03T12:36:34Z
[ "python", "python-3.x" ]
A better code to make an empty square with using numbers
38,743,349
<p>hi i want to make an empty square with numbers and i have the code like this:</p> <pre><code>L = input ('input your numbers = ') M = (L-2) * ' ' P = L - 1 x = "" y = "" for a in range(1,L+1): x = x + str(a) print x for b in range(2,L): print str(b) + M + str(P) P-=1 for c in range(L,0,-1): y = y +...
0
2016-08-03T12:13:28Z
38,744,804
<pre><code>string = map(str,range(1,L+1)) print ''.join(string) print '\n'.join([ i+M+j for i,j in zip(string[1:-1],string[1:-1][::-1])]) print ''.join(string[::-1]) </code></pre>
0
2016-08-03T13:17:59Z
[ "python", "python-3.x" ]
Best way to create a Day model in Django
38,743,403
<p>I want to create an object called Day and in that I want to store other object instances called Meeting.</p> <p>My question is: What is the best way to create the object Day with datetime reference. Is there a built in model structure or something that lets me use days as objects or should I simply create the model...
0
2016-08-03T12:15:40Z
38,743,810
<p>I would structure your database like this:</p> <pre><code>class DayModel(models.Model): date = models.DateField() class MeetingModel(models.Model): day = models.ForeignKey(DayModel, related_name="meetings") time = models.TimeField() </code></pre>
0
2016-08-03T12:33:19Z
[ "python", "django", "django-models" ]
How to find the median in Apache Spark with Python Dataframe API?
38,743,476
<p>Pyspark API provides many aggregate functions except the median. Spark 2 comes with approxQuantile which gives approximate quantiles but exact median is very expensive to calculate. Is there a more Pyspark way of calculating median for a column of values in a Spark Dataframe?</p>
0
2016-08-03T12:19:01Z
38,743,477
<p>Here is an example implementation with Dataframe API in Python (Spark 1.6 +).</p> <pre><code>import pyspark.sql.functions as F import numpy as np </code></pre> <p>Let's assume we have monthly salaries for customers in "salaries" spark dataframe such as: </p> <p><strong>month | customer_id | salary</strong></p> <...
0
2016-08-03T12:19:01Z
[ "python", "apache-spark", "pyspark", "median" ]
How to perform mean subtraction and normalization with Tensorflow
38,743,506
<p>On <a href="http://cs231n.github.io/neural-networks-2/" rel="nofollow">http://cs231n.github.io/neural-networks-2/</a> it is mentioned that for convolutional neural networks it is preferred to preprocess data using mean subtraction and normalization techniques.</p> <p>I was just wondering how would it be best approa...
0
2016-08-03T12:20:49Z
38,744,527
<p>You're looking for <a href="https://www.tensorflow.org/versions/master/api_docs/python/image.html#per_image_whitening" rel="nofollow"><code>tf.image.per_image_whitening(image)</code></a>:</p> <blockquote> <p>Linearly scales image to have zero mean and unit norm.</p> <p>This op computes (x - mean) / adjusted_...
0
2016-08-03T13:04:35Z
[ "python", "tensorflow" ]
How to perform mean subtraction and normalization with Tensorflow
38,743,506
<p>On <a href="http://cs231n.github.io/neural-networks-2/" rel="nofollow">http://cs231n.github.io/neural-networks-2/</a> it is mentioned that for convolutional neural networks it is preferred to preprocess data using mean subtraction and normalization techniques.</p> <p>I was just wondering how would it be best approa...
0
2016-08-03T12:20:49Z
39,831,856
<p>Looking in the source code for <a href="https://github.com/tensorflow/tensorflow/blob/master/tensorflow/contrib/layers/python/layers/feature_column.py" rel="nofollow">feature columns</a> I noticed for real_valued_column types there is a keyword argument normalizer that can take as an argument a default normalization...
0
2016-10-03T12:36:48Z
[ "python", "tensorflow" ]
How to fetch specific rows from a tensor in Tensorflow?
38,743,538
<p>I have a tensor defined as follows:</p> <pre><code>temp_var = tf.Variable(initial_value=np.asarray([[1, 2, 3],[4, 5, 6],[7, 8, 9],[10, 11, 12]])) </code></pre> <p>I also have an array of indexes of rows to be fetched from tensor:</p> <pre><code>idx = tf.constant([0, 2]) </code></pre> <p>Now I want to take a subs...
0
2016-08-03T12:22:07Z
38,746,778
<p>The <a href="https://www.tensorflow.org/versions/r0.10/api_docs/python/array_ops.html#gather" rel="nofollow"><code>tf.gather()</code></a> op does exactly what you need: it selects rows from a matrix (or in general (N-1)-dimensional slices from an N-dimensional tensor). Here's how it would work in your case:</p> <pr...
1
2016-08-03T14:41:28Z
[ "python", "tensorflow" ]
Debug behavior differ from normal execution in python
38,743,551
<p>I am trying to figure out why my code behavior differs from normal execution. I have seen this, but it is not my case:</p> <blockquote> <p><a href="http://stackoverflow.com/questions/1108246/what-to-do-if-debug-behaviour-differs-from-normal-execution">What to do, if debug behaviour differs from normal execution?<...
0
2016-08-03T12:22:37Z
38,743,642
<p>You are repeatedly adding the <em>same dictionary</em> to the list. Python containers store <em>references</em>, not copies, so any alteration you make to that dictionary is going to be visible through all those references.</p> <p>Yes, printing that dictionary before you altered it in a next loop iteration won't sh...
2
2016-08-03T12:26:20Z
[ "python", "pandas" ]
Graphviz: write result to file
38,743,578
<p>I have dataframe</p> <pre><code>ID domain search_term 111 vk.com вконтакте 111 twitter.com фэйсбук 111 facebook.com твиттер 222 avito.ru купить машину 222 vk.com вконтакте 333 twitter.com твиттер 333 apple.com купить айфон 333 rbk.ru новÐ...
0
2016-08-03T12:24:00Z
38,743,987
<p>Do not put <code>f = Digraph(...)</code> and <code>f.render(...)</code> inside the <code>if-statement</code>. The code inside the <code>if-statement</code> should get executed once for every edge. You do not want to create a new <code>Digraph</code> and render it for every edge.</p> <p>So instead, you could use <co...
2
2016-08-03T12:40:54Z
[ "python", "pandas", "matplotlib", "graphviz" ]
EOF Error Pickle
38,743,646
<p>I am looping through a list of Pickled files and some of my files have EOF Errors, which means they did not write properly. Is there a way to loop around the files that have these errors and continue to the next file instead of the entire script stopping?</p>
-2
2016-08-03T12:26:35Z
38,743,699
<p>Use <code>try/except</code>:</p> <pre><code>for pkl_file in pkls: try: obj = pickle.load(..) # or however you load the file except EOFError: continue # rest of code, handling obj </code></pre>
1
2016-08-03T12:28:46Z
[ "python", "pickle" ]
EOF Error Pickle
38,743,646
<p>I am looping through a list of Pickled files and some of my files have EOF Errors, which means they did not write properly. Is there a way to loop around the files that have these errors and continue to the next file instead of the entire script stopping?</p>
-2
2016-08-03T12:26:35Z
38,743,923
<p>First of all, ensure that you are opening the pickle files in <em>binary</em> mode as this is a potential cause of EOF errors when reading/writing pickle data.</p> <p>When you are reading the pickle files use <code>rb</code> mode when calling <a href="https://docs.python.org/3/library/functions.html?highlight=open#...
0
2016-08-03T12:38:18Z
[ "python", "pickle" ]
how to use pandas dataframe after splitting my test set?
38,743,888
<p>i have recently learned how to do validation split on my pandas dataframe , but after spliting i noticed that i am not able to slice my columns . </p> <pre><code>print(my_data['column name']) </code></pre> <p>it throwing an error , please help . </p> <p>my code goes like this :</p> <pre><code>import pandas as p...
1
2016-08-03T12:36:21Z
38,744,020
<p><a href="http://scikit-learn.org/stable/modules/generated/sklearn.cross_validation.train_test_split.html" rel="nofollow"><code>train_test_split</code></a> returns a list of the splits, you're supposed to use these to index the df:</p> <pre><code>X_train, X_test, y_train, y_test =train_test_split(data , train_size =...
3
2016-08-03T12:42:20Z
[ "python", "validation", "pandas", "numpy", "scikit-learn" ]
how to use pandas dataframe after splitting my test set?
38,743,888
<p>i have recently learned how to do validation split on my pandas dataframe , but after spliting i noticed that i am not able to slice my columns . </p> <pre><code>print(my_data['column name']) </code></pre> <p>it throwing an error , please help . </p> <p>my code goes like this :</p> <pre><code>import pandas as p...
1
2016-08-03T12:36:21Z
38,744,439
<p>If we input simple numpy arrays the output are numpy arrays too. See an example <a href="http://scikit-learn.org/stable/modules/generated/sklearn.cross_validation.train_test_split.html" rel="nofollow">here</a> :</p> <pre><code>&gt;&gt;&gt; import numpy as np &gt;&gt;&gt; from sklearn.cross_validation import train_t...
0
2016-08-03T13:01:16Z
[ "python", "validation", "pandas", "numpy", "scikit-learn" ]
See current logging config in Python (Django)
38,744,092
<p>I am setting up logging in Django, but for some reason I see no logs appear. Django uses Python's <code>logging</code> module (I use Python 2.7).</p> <p>Is there a way I can see the currently configured logging setup, something like a <code>logging.getConfigDict()</code> or so?</p>
1
2016-08-03T12:45:12Z
38,765,453
<p>There's the <code>logging_tree</code> module for that:</p> <p><code>pip install logging_tree</code></p> <p>and then (via <code>./manage.py shell</code>)</p> <pre><code>import logging_tree logging_tree.printout() </code></pre> <p>More infos: <a href="http://rhodesmill.org/brandon/2012/logging_tree/" rel="nofollow...
1
2016-08-04T10:57:40Z
[ "python", "django", "logging" ]
glob error <_io.TextIOWrapper name='...' mode='r' encoding='cp1252'> reading text file error
38,744,244
<p>I am trying to make a social program where the profiles are stored in .txt files here is part of the code:</p> <pre><code>XX = [] pl = glob.glob('*.txt') for a in pl: if ' pysocial profile.txt' in a: ...
-3
2016-08-03T12:52:30Z
38,744,973
<p>The <code>open</code> method opens the file and returns a <code>TextIOWrapper</code> object but does not read the files content.</p> <p>To actually get the content of the file, you need to call the <code>read</code> method on that object, like so:</p> <pre><code>G = open(P, 'r') print(G.read()) </code></pre> <p>H...
0
2016-08-03T13:26:08Z
[ "python" ]
format date 'Fri Apr 15 04_01_33 2016' and '2015-12-16 22-39-28' Using python datetime format date
38,744,270
<p>Here is Simples way to format date using datetime</p> <pre><code>from datetime import datetime date = '2016-04-07 04-54-53' date1 = 'Fri Apr 15 04_01_33 2016' format = "%Y-%m-%d %H-%M-%S" format1 = "%a %b %d %H_%M_%S %Y" datetime = datetime.strptime(date, format) datetime1 = datetime.strptime(date1, format1) print(...
-5
2016-08-03T12:53:41Z
38,744,299
<p><strong>Simples way to format date using datetime</strong></p> <pre><code>from datetime import datetime date = '2016-04-07 04-54-53' date1 = 'Fri Apr 15 04_01_33 2016' format = "%Y-%m-%d %H-%M-%S" format1 = "%a %b %d %H_%M_%S %Y" datetime = datetime.strptime(date, format) datetime1 = datetime.strptime(date1, format...
0
2016-08-03T12:55:13Z
[ "python", "django", "datetime" ]
Django URLs error: view must be a callable or a list/tuple in the case of include()
38,744,285
<p>After upgrading to Django 1.10, I get the error:</p> <pre><code>TypeError: view must be a callable or a list/tuple in the case of include(). </code></pre> <p>My urls.py is as follows:</p> <pre><code>urlpatterns = [ url(r'^$', 'myapp.views.home'), url(r'^contact$', 'myapp.views.contact'), url(r'^login/...
6
2016-08-03T12:54:34Z
38,744,286
<p>Django 1.10 no longer allows you to specify views as a string (e.g. <code>'myapp.views.home'</code>) in your URL patterns.</p> <p>The solution is to update your <code>urls.py</code> to include the view callable. This means that you have to import the view in your <code>urls.py</code>. If your URL patterns don't hav...
20
2016-08-03T12:54:34Z
[ "python", "django", "django-urls", "django-1.10" ]
Django URLs error: view must be a callable or a list/tuple in the case of include()
38,744,285
<p>After upgrading to Django 1.10, I get the error:</p> <pre><code>TypeError: view must be a callable or a list/tuple in the case of include(). </code></pre> <p>My urls.py is as follows:</p> <pre><code>urlpatterns = [ url(r'^$', 'myapp.views.home'), url(r'^contact$', 'myapp.views.contact'), url(r'^login/...
6
2016-08-03T12:54:34Z
38,837,787
<p>This error just means that <code>myapp.views.home</code> is not something that can be called, like a function. It is a string in fact. While your solution works in django 1.9, nevertheless it throws a warning saying this will deprecate from version 1.10 onwards, which is exactly what has happened. The previous solut...
1
2016-08-08T20:16:22Z
[ "python", "django", "django-urls", "django-1.10" ]
Custom serializer issue in django with json data
38,744,349
<p>I cant get my serializer to work correctly on a foreign key field any help would be greatly appreciated. </p> <p>Here is the error </p> <p>dim_json = DimensionSerializer(dim_data) </p> <p>print dim_json </p> <p>DimensionSerializer([, , , , , ]): </p> <pre><code>id = IntegerField(label='ID', read_only=True) ...
-1
2016-08-03T12:57:04Z
38,747,901
<p>I figured it out instead of using my custom serializer I just used the django.core one and presto it works. </p> <pre><code>dim_json = serializer.serialize('json', Dimension.objects.all()) print dim_json </code></pre>
0
2016-08-03T15:31:14Z
[ "python", "json", "django", "django-serializer" ]
Numpy array 15min values - hourly mean values
38,744,353
<p>I have the following situation:</p> <p>A numpy array</p> <pre><code>x = np.array([12,3,34,5...,]) </code></pre> <p>where every entry corresponds to a simulation result (time-step 15min).</p> <p>Now I need the mean hourly value (mean value of first 4 elements, then next 4, etc.) stored in a new numpy array. Is th...
2
2016-08-03T12:57:16Z
38,744,446
<pre><code>N = 4 mod_ = x.size % N x1 = np.pad(x.astype(float), (0, (mod_ &gt; 0) * (N - mod_)), 'constant', constant_values=(np.nan,)) x2 = np.reshape(x1, (int(x1.size/4), 4)) x3 = np.nanmean(x2, axis=1) print(x3) </code></pre>
1
2016-08-03T13:01:35Z
[ "python", "numpy" ]
Numpy array 15min values - hourly mean values
38,744,353
<p>I have the following situation:</p> <p>A numpy array</p> <pre><code>x = np.array([12,3,34,5...,]) </code></pre> <p>where every entry corresponds to a simulation result (time-step 15min).</p> <p>Now I need the mean hourly value (mean value of first 4 elements, then next 4, etc.) stored in a new numpy array. Is th...
2
2016-08-03T12:57:16Z
38,744,742
<p>To handle arrays whose size may not be a multiple of 4, copy <code>x</code> into a new array, <code>tmp</code>, whose size is a multiple of 4:</p> <pre><code>tmp = np.full((((x.size-1) // 4)+1)*4, dtype=float, fill_value=np.nan) tmp[:x.size] = x </code></pre> <p>Empty values are represented by <code>nan</code>. T...
2
2016-08-03T13:14:54Z
[ "python", "numpy" ]
Numpy array 15min values - hourly mean values
38,744,353
<p>I have the following situation:</p> <p>A numpy array</p> <pre><code>x = np.array([12,3,34,5...,]) </code></pre> <p>where every entry corresponds to a simulation result (time-step 15min).</p> <p>Now I need the mean hourly value (mean value of first 4 elements, then next 4, etc.) stored in a new numpy array. Is th...
2
2016-08-03T12:57:16Z
38,746,311
<p>Here is another solution:</p> <p>your input:</p> <pre><code>In [11]: x = np.array([12, 3, 34, 5, 1, 2, 3]) </code></pre> <p>taking every 4 elements in b</p> <pre><code>In [12]: b = [x[n:n+4] for n in range(0, len(x), 4)] </code></pre> <p>create new empty list to append results</p> <pre><code>In [13]: l = [] I...
1
2016-08-03T14:22:09Z
[ "python", "numpy" ]
Tkinter Text widget: Configure font
38,744,394
<p>I have <code>Text</code> widget that I can configure the font families by:</p> <pre><code>textwidget.config(font=(Consolas,13)) </code></pre> <p>That would configure the whole <code>text</code> Widget. I only want to tell <code>Tkinter</code> I want to make every input after the <code>Text</code> widget has been c...
0
2016-08-03T12:59:10Z
38,781,382
<p>Have a look at the <code>tag</code> commands. You can change the selected text using this code:</p> <pre><code>number=0 def fontchange(): textwidget.tag_add(str(number), SEL_FIRST, SEL_LAST) textwidget.tag_config(str(number), font=(Consolas,13)) number += 1 </code></pre> <p>Obviously this is a very bas...
1
2016-08-05T04:54:39Z
[ "python", "text", "fonts", "tkinter", "configuration" ]
How to test `@authenticated` handler using tornado.testing?
38,744,453
<p>I am new to unit testing using script. I tried to verify login with arguments in post data, but I am getting login page as response and not get logged in.Because of <code>@tornado.web.authenticated</code> i can't access other functions without login and it responding to login page</p> <pre><code>import tornado from...
0
2016-08-03T13:01:55Z
38,778,310
<p>To test code that uses <code>@authenticated</code> (unless you are testing the redirection to the login page itself), you need to pass a cookie (or whatever form of authentication you're using) that will be accepted by your <code>get_current_user</code> method. The details of this will vary depending on how exactly ...
0
2016-08-04T22:20:14Z
[ "python", "unit-testing", "web-applications", "tornado" ]
AssertionError: negative sum of square deviations
38,744,648
<p>As part of a larger project, I am writing a function that takes in a dict of dicts of ints and returns a dict with each "outer" key linked to a tuple of the mean and standard deviation of that sub dictionary (i.e. <code>(mean(dict[key1]), stdev(dict[key1]))</code> ). I am operating on a large dataset (the source fi...
1
2016-08-03T13:10:28Z
38,745,780
<p>The code in <code>statiscs.py</code> is pure Python - you seem to be a victim of a weird overflow error in the Fraction class, when processing the internal "sum of quares) <code>statistics._ss</code> function. </p> <p>I think the best thing you can do now is to isntrument the<code>_ss</code> function in the <code>...
2
2016-08-03T13:59:57Z
[ "python", "python-3.x", "dictionary", "statistics", "standard-deviation" ]
How do I search for a specific Outlook email in python
38,744,747
<p>I have the following code which works, it can read the most recent Email in my outlook inbox and print the body of that message. However, I want to be able to specify a static Email address, and return all of the messages from that person. How would I change the code to do that?</p> <pre class="lang-python prettypr...
0
2016-08-03T13:15:19Z
38,746,159
<p>You have already a script that allow you to obtain the list of message in a folder :</p> <pre><code>outlook = win32com.client.Dispatch("Outlook.Application").GetNamespace("MAPI") inbox = outlook.GetDefaultFolder(6) messages = inbox.Items </code></pre> <p>Once you got all the messages, you just have to check if the...
0
2016-08-03T14:15:55Z
[ "python", "email", "outlook", "python-2.x" ]
django add foreign key value after form submit
38,744,752
<p>After a <code>ModelForm</code> has been submitted, how can I add a foreign key relation so that it validates?</p> <p><code>models.py</code></p> <pre><code>class Comment(models.Model): id = models.AutoField(primary_key=True) activity = models.ForeignKey(Activity) submitter = models.ForeignKey(User) ...
1
2016-08-03T13:15:28Z
38,744,948
<p>I think you are mixing up form instance with model instance. your <code>newComment</code> is a form, assigning other objects as a form attribute will not make the form saving the foreign key(not sure where did you find this usage), because all form data is saved in <code>form.data</code>, which is a dict like data s...
4
2016-08-03T13:25:02Z
[ "python", "django" ]
Django server crashes with exit codes 139, 77
38,744,818
<h2>Foreword</h2> <p>Okay, I have a really complex perfomance issue. I'm building a content managment system and one of the features should be generating tons of <code>.docx</code> files with different templates. I started with <a href="https://pythonhosted.org/django-webodt/quickstart.html" rel="nofollow">Webodt</a> ...
1
2016-08-03T13:18:48Z
38,749,701
<p>Okay, that was a bug in <code>templated_docs</code>. I was right, it happens because <code>templated_docs</code> is trying to start LibreOffice twice. As it said in <code>pylokit</code> <a href="https://github.com/xrmx/pylokit#examples" rel="nofollow">documentation</a>:</p> <blockquote> <p>The use of _exit() inst...
1
2016-08-03T17:03:04Z
[ "python", "django", "libreoffice" ]
Python imaplib doesnt mark messages as unseen
38,744,885
<p>I am working on a function that collects data from email and has a switch to mark messages as unseen. During development it started to fail I don't know why. I've looked it up in documentation, I've searched stackoverflow (got to <a href="http://stackoverflow.com/questions/17367611/python-imaplib-mark-email-as-unrea...
1
2016-08-03T13:21:50Z
38,745,198
<p>I believe you want</p> <pre><code>mail.store(uid, '+FLAGS', '(\\Seen)') </code></pre> <p>I think what you're doing right now is <em>removing</em> the seen flag. But I'll look in the RFC to be sure.</p> <p><strong>Edit:</strong> Yup. That's what the <a href="https://tools.ietf.org/html/rfc3501#page-59" rel="nofoll...
1
2016-08-03T13:34:39Z
[ "python", "imaplib" ]
Preserve formatting when modifying an Excel (xlsx) file with Python
38,744,952
<p>Is there any Python module out there that can be used to create an Excel XLSX file replicating the format from a template?</p>
-2
2016-08-03T13:25:27Z
38,745,135
<p>You can use openpyxl to open a template file and then populate it with data and save it as something else to preserve the original template for use later. Check out this answer: <a href="http://stackoverflow.com/questions/38616207/store-data-which-is-an-output-of-python-program-in-excel-file/38616604#38616604">Worki...
0
2016-08-03T13:32:23Z
[ "python", "excel" ]
Preserve formatting when modifying an Excel (xlsx) file with Python
38,744,952
<p>Is there any Python module out there that can be used to create an Excel XLSX file replicating the format from a template?</p>
-2
2016-08-03T13:25:27Z
38,745,156
<p>As far as I understood <code>openpyxl</code> supports this. This is example from <a href="http://openpyxl.readthedocs.io/en/default/usage.html#write-a-workbook-from-xltx-as-xlsx" rel="nofollow">docs</a>:</p> <pre><code>from openpyxl import load_workbook wb = load_workbook('sample_book.xltx') ws = wb.active ws['D...
0
2016-08-03T13:33:12Z
[ "python", "excel" ]
Wrap image around a circle
38,745,020
<p>What I'm trying to do in this example is wrap an image around a circle, like below.</p> <p><a href="http://i.stack.imgur.com/0vWEI.png"><img src="http://i.stack.imgur.com/0vWEI.png" alt="original"></a></p> <p><a href="http://i.stack.imgur.com/B63uj.png"><img src="http://i.stack.imgur.com/B63uj.png" alt="wrapped"><...
8
2016-08-03T13:27:57Z
38,745,222
<p>I think what you need is a noise filter. There are many implementations from which I think Gaussian filter would give a good result. You can find a list of filters <a href="http://pillow.readthedocs.io/en/3.1.x/reference/ImageFilter.html" rel="nofollow">here</a>. If it gets blurred too much:</p> <ul> <li>keep your ...
4
2016-08-03T13:35:31Z
[ "python", "python-3.x", "python-imaging-library" ]
Wrap image around a circle
38,745,020
<p>What I'm trying to do in this example is wrap an image around a circle, like below.</p> <p><a href="http://i.stack.imgur.com/0vWEI.png"><img src="http://i.stack.imgur.com/0vWEI.png" alt="original"></a></p> <p><a href="http://i.stack.imgur.com/B63uj.png"><img src="http://i.stack.imgur.com/B63uj.png" alt="wrapped"><...
8
2016-08-03T13:27:57Z
38,819,423
<p>You are having problems filling up your circle because you are approaching this from the wrong way – quite literally.</p> <p>When mapping <em>from</em> a source <em>to</em> a target, you need to fill your <em>target</em>, and map each translated pixel from this into the <em>source</em> image. Then, there is no ch...
4
2016-08-07T23:13:30Z
[ "python", "python-3.x", "python-imaging-library" ]
Using Models in Django-Rest Framework
38,745,067
<p>I am new to Django-Rest Framework and I wanted to develop API calls. I am currently using Mysql database so if I have to make changes in the database, do I have to write models in my project or Can I execute the raw data operation onto my database.</p> <p>Like: This is my urls.py file which contains a list of URLs ...
0
2016-08-03T13:29:40Z
38,746,370
<p>you don't <em>need</em> to use models, but you really should. django's ORM (the way it handles reading/writing to databases) functionality is fantastic and really useful. </p> <p>if you're executing raw sql statements all the time, you either have a highly specific case where django's functions fail you, or you're ...
2
2016-08-03T14:24:39Z
[ "python", "django", "django-rest-framework" ]
Using Models in Django-Rest Framework
38,745,067
<p>I am new to Django-Rest Framework and I wanted to develop API calls. I am currently using Mysql database so if I have to make changes in the database, do I have to write models in my project or Can I execute the raw data operation onto my database.</p> <p>Like: This is my urls.py file which contains a list of URLs ...
0
2016-08-03T13:29:40Z
38,750,038
<p>Django REST Framework is designed to work with Django Framework. And Django ORM is an integral part of Django Framework. Granted, that it is possible to use Django and DRF without using ORM, but you will be basically fighting against the framework instead of using the framework to help you. So, you have three basic ...
0
2016-08-03T17:21:45Z
[ "python", "django", "django-rest-framework" ]
Using Models in Django-Rest Framework
38,745,067
<p>I am new to Django-Rest Framework and I wanted to develop API calls. I am currently using Mysql database so if I have to make changes in the database, do I have to write models in my project or Can I execute the raw data operation onto my database.</p> <p>Like: This is my urls.py file which contains a list of URLs ...
0
2016-08-03T13:29:40Z
38,750,758
<p>Why would you use Django without hitting the database with the ORM? Most of the times the ORM works as you'd expect, and even allow you to perform searches like this:</p> <pre><code>class Foo(models.Model): code = models.CharField(max_length=10, ...) class Bar(models.Model): code = models.CharField(max_len...
0
2016-08-03T18:05:45Z
[ "python", "django", "django-rest-framework" ]
Web Scraping a Forum Post in Python Using Beautiful soup and lxml Cannot get all posts
38,745,080
<p>Im having an issue that is driving me absolutely crazy. I am a newbie to web scraping, and I am practicing web scraping by trying to scrape the contents of a forum post, namely the actual posts people made. I have isolated the posts to what i think contains the text which is div id="post message_ 2793649 (see attach...
0
2016-08-03T13:30:18Z
38,745,900
<p>There's nothing with the id <code>post_message</code>, so <code>link.find_all</code> returns an empty list. You'll first want to grab all of the ids within all the <code>div</code>s, and then filter that list of ids with a regex (e.g.) to get only those that start with <code>post_message_</code> and then a number. T...
0
2016-08-03T14:04:51Z
[ "python", "web-scraping", "beautifulsoup", "lxml" ]
Web Scraping a Forum Post in Python Using Beautiful soup and lxml Cannot get all posts
38,745,080
<p>Im having an issue that is driving me absolutely crazy. I am a newbie to web scraping, and I am practicing web scraping by trying to scrape the contents of a forum post, namely the actual posts people made. I have isolated the posts to what i think contains the text which is div id="post message_ 2793649 (see attach...
0
2016-08-03T13:30:18Z
38,747,669
<p>You have a couple of issues, the first being you have multiple spaces in the url so you are not going to the page you think you are:</p> <pre><code>In [50]: import requests In [51]: r.url # with spaces Out[51]: 'http://www.catforum.com/forum/43-forum-fun/350938-count-one-billion-2016-a-120.html' Out[49]: 'http://...
0
2016-08-03T15:21:20Z
[ "python", "web-scraping", "beautifulsoup", "lxml" ]
How can I make a plot appear in a new window, such that I can inspect it (zoom in etc.)?
38,745,103
<p><img src="http://i.stack.imgur.com/5XoHV.png" alt="Codeplot"> I wrote the code above and it is showing my plot in the Ipython console. However, I want to inspect the plot i.e. be able to zoom in/out and have coordinates displayed when moving my cursor. </p> <p>I know I can do this with executing the file from the l...
0
2016-08-03T13:31:09Z
38,745,347
<p>I see that you have <code>pyplot</code> already imported. Run the following in your console:</p> <pre><code>plt.switch_backend('qt4agg') </code></pre> <p>If this does not work because the name <code>plt</code> is not recognized, import it in the console:</p> <pre><code>from matplotlib import pyplot as plt </code>...
0
2016-08-03T13:40:50Z
[ "python", "plot", "show", "interactive" ]
Match identical words in two prints
38,745,163
<p>I am using os to list the filenames within a directory. I am also using pandas to list the contents of one column in a CSV file. I have printed the results of both and now I want to match the names that appear in both prints and also identify which names are exclusive to one print. Below is my code which gets the na...
2
2016-08-03T13:33:19Z
38,745,667
<p>So as I understand it you have two lists. One from the directory and another from a column in Pandas. You want the elements that are in both lists as well as the elements that are unique to each list. Lets say your lists are like this:</p> <pre><code>List1 = ['a' , 'b' , 'c' , 'd', 'e', 'f'] List2 = ['c' , 'd' , 'e...
1
2016-08-03T13:55:01Z
[ "python", "csv", "pandas" ]
Match identical words in two prints
38,745,163
<p>I am using os to list the filenames within a directory. I am also using pandas to list the contents of one column in a CSV file. I have printed the results of both and now I want to match the names that appear in both prints and also identify which names are exclusive to one print. Below is my code which gets the na...
2
2016-08-03T13:33:19Z
38,745,723
<p>Instead of</p> <pre><code>for file in dirs: print file </code></pre> <p>Build a list:</p> <pre><code>files = [file for file in dirs] </code></pre> <p>Then use the DataFrame to check:</p> <pre><code>df.Column.isin(files) # this will check elementwise Out: 0 True 1 True 2 True 3 True Name: Colum...
2
2016-08-03T13:57:08Z
[ "python", "csv", "pandas" ]
XML parsing in python while retaining link to position in original file
38,745,263
<p>I need to extract certain data from XML files, but also know the position where the extracted element was located in the original XML file - as a character offset from file beginning, or a line number + position in that line.</p> <p>The commonly used python XML libraries don't seem to provide any such functionality...
0
2016-08-03T13:37:02Z
38,745,434
<p>I don't think such things exists. Most parsers do the parsing first (manipulate the text stream into tokens and then parse it into a tree). By that time, they usually have a good knowledge of where they are in the original stream (this is required to output parsing errors). However once the object tree has been buil...
0
2016-08-03T13:45:00Z
[ "python", "xml", "elementtree" ]