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
How to Query from salesforce the OpportunityFieldHistory with python
39,043,710
<p>I am having an issue figuring out how to start a query on the OpportunityFieldHistory from Salesforce.</p> <p>The code I usually use and works for querying Opportunty or Leads work fine, but I do not know how should be written for the FieldHistory. </p> <p>When I want to query the opportunity or Lead I use the fol...
1
2016-08-19T16:21:59Z
39,045,357
<p>Looking at the <a href="https://github.com/simple-salesforce/simple-salesforce/blob/master/simple_salesforce/api.py" rel="nofollow">simple-salesforce API</a>, it appears that the <code>get</code> method accepts an ID which you are passing correctly. However, a quick search in the <a href="https://developer.salesforc...
0
2016-08-19T18:10:25Z
[ "python", "salesforce" ]
Use WTForms QuerySelectField with Pyramid 1.7's db session
39,043,798
<p>I use wtforms_sqlalchemy in my pyramid apps and define several <code>QuerySelectField</code>s. The query factory uses the imported <code>DBSession</code> object to make the query.</p> <pre><code>from wtforms.form import Form from wtforms_sqlalchemy.fields import QuerySelectField from myapp.models import DBSession,...
2
2016-08-19T16:27:14Z
39,067,122
<p>You can try something like this (although it's not the cleanest solution)</p> <pre><code>from myapp.models import MyModel from pyramid import threadlocal def mymodel_choices(request=None): request = request or threadlocal.get_current_request() choices = request.DBSession.query(MyModel) return choices <...
1
2016-08-21T17:46:59Z
[ "python", "sqlalchemy", "pyramid", "wtforms" ]
Use WTForms QuerySelectField with Pyramid 1.7's db session
39,043,798
<p>I use wtforms_sqlalchemy in my pyramid apps and define several <code>QuerySelectField</code>s. The query factory uses the imported <code>DBSession</code> object to make the query.</p> <pre><code>from wtforms.form import Form from wtforms_sqlalchemy.fields import QuerySelectField from myapp.models import DBSession,...
2
2016-08-19T16:27:14Z
39,171,644
<p><code>query_factory</code> only specifies the <em>default</em> query to use, but <a href="https://github.com/wtforms/wtforms-sqlalchemy/blob/master/wtforms_sqlalchemy/fields.py#L98" rel="nofollow"><code>QuerySelectField</code> will prefer the <code>query</code> property if it is set.</a> This is useful for Pyramid,...
1
2016-08-26T17:22:08Z
[ "python", "sqlalchemy", "pyramid", "wtforms" ]
python regex find match that spans multiple lines
39,043,801
<p>So I am trying to grab the string from a BibTex using regex in python. Here is part of my string:</p> <pre><code>a = '''title = {The Origin ({S}, {Se}, and {Te})- {TiO$_2$} Photocatalysts}, year = {2010}, volume = {114},''' </code></pre> <p>I want to grab the string for the title, which is:</p> <pre...
2
2016-08-19T16:27:25Z
39,043,864
<p>A quick solution would be to modify your regex pattern</p> <pre><code>pattern = re.compile('title\s*=\s*{(.*|\n?)},\s*\n', re.DOTALL|re.I) </code></pre>
1
2016-08-19T16:31:34Z
[ "python", "regex" ]
python regex find match that spans multiple lines
39,043,801
<p>So I am trying to grab the string from a BibTex using regex in python. Here is part of my string:</p> <pre><code>a = '''title = {The Origin ({S}, {Se}, and {Te})- {TiO$_2$} Photocatalysts}, year = {2010}, volume = {114},''' </code></pre> <p>I want to grab the string for the title, which is:</p> <pre...
2
2016-08-19T16:27:25Z
39,043,891
<p>Depends on how general you want your regex to be. I guess you want your string to be able to contain { and }, so using that to mark the ending of the pattern will cause issues. Also there could be multiple brackets.</p> <p>Here's an idea, what if you look for the word year at the end of the regex, assuming that's c...
1
2016-08-19T16:33:32Z
[ "python", "regex" ]
python regex find match that spans multiple lines
39,043,801
<p>So I am trying to grab the string from a BibTex using regex in python. Here is part of my string:</p> <pre><code>a = '''title = {The Origin ({S}, {Se}, and {Te})- {TiO$_2$} Photocatalysts}, year = {2010}, volume = {114},''' </code></pre> <p>I want to grab the string for the title, which is:</p> <pre...
2
2016-08-19T16:27:25Z
39,043,962
<p><a href="https://docs.python.org/2/library/textwrap.html" rel="nofollow">textwrap</a> can be useful:</p> <pre><code>import textwrap a = '''title = {The Origin ({S}, {Se}, and {Te})- {TiO$_2$} Photocatalysts}, year = {2010}, volume = {114},''' indent = " " print(textwrap.dedent(indent + a)) </code>...
0
2016-08-19T16:38:14Z
[ "python", "regex" ]
python regex find match that spans multiple lines
39,043,801
<p>So I am trying to grab the string from a BibTex using regex in python. Here is part of my string:</p> <pre><code>a = '''title = {The Origin ({S}, {Se}, and {Te})- {TiO$_2$} Photocatalysts}, year = {2010}, volume = {114},''' </code></pre> <p>I want to grab the string for the title, which is:</p> <pre...
2
2016-08-19T16:27:25Z
39,045,425
<p>Use the newer <a href="https://pypi.python.org/pypi/regex" rel="nofollow"><strong><code>regex module</code></strong></a>:</p> <pre><code>import regex as re rx = re.compile(r''' (?(DEFINE) (?&lt;part&gt;\w+\ =\ \{) (?&lt;end&gt;\},) (?&lt;title&gt;title\ =\ \{) ) ...
1
2016-08-19T18:15:30Z
[ "python", "regex" ]
python pandas groupby about categorial variables
39,043,832
<p>Here is what my dataframe looks like:</p> <pre><code>df = pd.DataFrame([ ['01', 'aa', '1+', 1200], ['01', 'ab', '1+', 1500], ['01', 'jn', '1+', 1600], ['02', 'bb', '2', 2100], ['02', 'ji', '2', 785], ['03', 'oo', '2', 5234], ['04', 'hg', '5-', 1231], ...
1
2016-08-19T16:29:38Z
39,044,741
<p>You can apply different functions by column in a groupby using dictionary syntax.</p> <pre><code>df.groupby('faculty_id').agg({'default_grade': 'first', 'sum': 'sum'}) </code></pre>
1
2016-08-19T17:30:13Z
[ "python", "python-2.7", "pandas", "dataframe", "group-by" ]
Python 3 __getattribute__ vs dot access behaviour
39,043,912
<p>I read a bit on python's object attribute lookup (here: <a href="https://blog.ionelmc.ro/2015/02/09/understanding-python-metaclasses/#object-attribute-lookup" rel="nofollow">https://blog.ionelmc.ro/2015/02/09/understanding-python-metaclasses/#object-attribute-lookup</a>).</p> <p>Seems pretty straight forward, so I...
0
2016-08-19T16:35:23Z
39,044,897
<p>It's easy to get the impression that <code>__getattribute__</code> is responsible for more than it really is. <code>thing.attr</code> doesn't directly translate to <code>thing.__getattribute__('attr')</code>, and <code>__getattribute__</code> is not responsible for calling <code>__getattr__</code>.</p> <p>The fallb...
3
2016-08-19T17:40:28Z
[ "python", "python-3.x" ]
Convert curl to python request
39,043,938
<p>This works on my system:</p> <pre><code>curl https://api.serverpilot.io/v1/servers -u KEY </code></pre> <p>I'm trying to convert it to Python and have tried several variations on this code.</p> <pre><code>params = {"u" :KEY} # params = {"u" :json.dumps(KEY)} restUrl = "https://api.serverpilot.io/v1/servers" resp...
-2
2016-08-19T16:36:48Z
39,044,025
<p>If you response header is really 'application/json; charset=utf8' (or other charset),</p> <pre><code>assert response.headers['content-type'] == 'application/json; charset=utf8' </code></pre> <p>you can use:</p> <pre><code>parsed = response.json() </code></pre>
-1
2016-08-19T16:41:38Z
[ "python", "curl", "python-requests" ]
Convert curl to python request
39,043,938
<p>This works on my system:</p> <pre><code>curl https://api.serverpilot.io/v1/servers -u KEY </code></pre> <p>I'm trying to convert it to Python and have tried several variations on this code.</p> <pre><code>params = {"u" :KEY} # params = {"u" :json.dumps(KEY)} restUrl = "https://api.serverpilot.io/v1/servers" resp...
-2
2016-08-19T16:36:48Z
39,044,076
<p>If you check the documentation for curl, you'll see that -u specifies a user. <a href="http://linux.die.net/man/1/curl" rel="nofollow">http://linux.die.net/man/1/curl</a></p> <p>You can use the verbose options of curl to get a printout of the request being made.</p> <p>If you checkout the requests documentation, y...
1
2016-08-19T16:44:50Z
[ "python", "curl", "python-requests" ]
How to max out bandwidth using concurrent requests?
39,043,948
<p>I want to send approximately 6e6 post requests to a web server. Content is fetched only in the absence of a redirect status code. The problem arises when traversing a stretch of data giving redirects; the bandwidth use is very low!(Like 10 % of the available bandwidth.)</p> <p>I was using <code>multiprocessing.dumm...
0
2016-08-19T16:37:15Z
39,044,081
<p>Oh, it may be even not connected with programming. 6e6 is really much, so it could be limited even because of poor network card. The solution is to try stress-test utility to determine if your hardware could send that number of requests per second. For example, use <code>ab</code> ApacheBench utility, like: <code>ab...
1
2016-08-19T16:45:06Z
[ "python", "python-3.5", "python-multithreading", "python-asyncio", "aiohttp" ]
Django - Looping through two queries for the same data, and adding cost field for each
39,044,020
<p>Its likely the title could be worded better but im struggling with it.</p> <p>Basically i am trying to tally up the cost of circuits per site from my models. the circuit model inherts the site model as per below:</p> <p>models:</p> <pre><code>class ShowroomConfigData(models.Model): location = models.CharField...
0
2016-08-19T16:41:20Z
39,044,320
<p>The most efficient way to do this is using queries. This can be accomplished using <a href="https://docs.djangoproject.com/en/1.10/topics/db/aggregation/" rel="nofollow">annotations</a>, in the following way:</p> <pre><code>from django.db.models import Sum CircuitInfoData.objects.values("showroom_config_data__locat...
1
2016-08-19T17:00:46Z
[ "python", "django" ]
Django - Looping through two queries for the same data, and adding cost field for each
39,044,020
<p>Its likely the title could be worded better but im struggling with it.</p> <p>Basically i am trying to tally up the cost of circuits per site from my models. the circuit model inherts the site model as per below:</p> <p>models:</p> <pre><code>class ShowroomConfigData(models.Model): location = models.CharField...
0
2016-08-19T16:41:20Z
39,044,448
<p>What if you just used a dictionary? Each circuit will have access to the showroom right? So If you built a dictionary and simply pulled out the value at a particular site if that is already being used as a key, you could simply add the value and store it again. Here is an example of this being done.</p> <pre><co...
0
2016-08-19T17:09:08Z
[ "python", "django" ]
Pass a closure from Cython to C++
39,044,063
<p>I have a C++ function that accepts a callback, like this:</p> <pre><code>void func(std::function&lt;void(A, B)&gt; callback) { ... } </code></pre> <p>I want to call this function from Cython by giving it a closure, i.e. something I would have done with a lambda if I was calling it from C++. If this was a C functio...
2
2016-08-19T16:44:15Z
39,052,204
<p>What I believe you're aiming to do is pass a callable Python object to something accepting a <code>std::function</code>. You need to do create a bit of C++ code to make it happen, but it's reasonably straightforward.</p> <p>Starting by defining "accepts_std_function.hpp" as simply as possible to provide an illustra...
1
2016-08-20T08:40:09Z
[ "python", "c++", "cython" ]
How to create a SkewNormal stochastic in pymc3?
39,044,126
<p>How would one use <code>DensityDist</code> to create a SkewNormal distribution for pymc3? There are several dead links to github pages explaining how to create custom Stochastic that are floating around.</p> <p><code>exp</code> is implemented in theano, but I don't think the Normal Cumulative distribution or the <c...
0
2016-08-19T16:47:34Z
39,098,684
<p>The <code>erf</code> function is implemented in Theano. Try this </p> <pre><code>skn = pm.DensityDist('skn', lambda value: tt.log(1 + tt.erf(((value - mu) * tt.sqrt(tau) * alpha)/tt.sqrt(2))) + (-tau * (value - mu)**2 + tt.log(tau / np.pi / 2.)) / 2. ) </code></pre> <p>where: </p> <pre><code>tau = sd**-2 </code><...
1
2016-08-23T10:29:44Z
[ "python", "theano", "pymc", "pymc3" ]
Coding style (PEP8) - Module level "dunders"
39,044,343
<p><em>Definition of "Dunder" (<strong>D</strong>ouble <strong>under</strong>score): <a href="http://www.urbandictionary.com/define.php?term=Dunder" rel="nofollow">http://www.urbandictionary.com/define.php?term=Dunder</a></em></p> <hr> <p>I have a question according the placement of module level "dunders" (like <code...
12
2016-08-19T17:01:55Z
39,044,408
<p>PEP 8 recently was <em>updated</em> to put the location before the imports. See <a href="https://hg.python.org/peps/rev/cf8e888b9555">revision cf8e888b9555</a>, committed on June 7th, 2016:</p> <blockquote> <p>Relax <code>__all__</code> location.</p> <p>Put all module level dunders together in the same locat...
13
2016-08-19T17:06:14Z
[ "python", "pycharm", "pep8", "pep" ]
Why is AWS telling me BucketAlreadyExists when it doesn't?
39,044,362
<p>I'm in the process of automating the setup of some AWS services using AWS SDK for Python (boto3) and running into a very simple problem of creating an S3 bucket. </p> <p>I've double-checked the following:</p> <ul> <li>In <code>~/.aws/credentials</code>, I have an Access Key ID and Secret Access Key set.</li> <li><...
0
2016-08-19T17:03:21Z
39,044,418
<p>A bucket name is global to region and not specific to your account. So you need to choose a name that doesnt exist at all. I recommend using a prefix</p>
4
2016-08-19T17:07:10Z
[ "python", "amazon-web-services", "amazon-s3", "boto3" ]
How does one refresh subplots created using Python(x,y) QT Designer Matplotlib Widget?
39,044,402
<p>I am using the MPL widget that comes with QT in the Python(x,y) package. I am attempting to refresh or redraw my plot with new data. The method fig.canvas.draw() refreshes the main plot only. The subplots are where my issue lies. The previous subplots and everything associated with them (axes scale, annotations, etc...
0
2016-08-19T17:05:44Z
39,053,082
<p>From the example it is not clear how <code>self.mpl_widget.axes</code> is created. It is not used and as explained below, drawing to an old reference of an axes instance might cause the problem.</p> <p>Because <code>mpl_widget.axes</code> is not used at all I would suggest to not hold a reference on the axes. Then ...
1
2016-08-20T10:31:21Z
[ "python", "python-2.7", "matplotlib", "matplotlib-widget" ]
List comprehension works but not for loop––why?
39,044,403
<p>I'm a bit annoyed with myself because I can't understand why one solution to a problem worked but another didn't. As in, it points to a deficient understanding of (basic) pandas on my part, and that makes me mad!</p> <p>Anyway, my problem was simple: I had a list of 'bad' values ('bad_index'); these corresponded to...
5
2016-08-19T17:05:46Z
39,044,503
<p><strong>EDIT: it turns out this is not your problem ... but if you did not have the problem mentioned in the other answer by Deepspace then you would have this problem</strong></p> <pre><code>for i in bad_index: dataclean2 = dataclean1.drop([i]).reset_index(level = 0, drop = True) </code></pre> <p>imagine your...
1
2016-08-19T17:12:39Z
[ "python", "pandas", "for-loop", "indexing", "list-comprehension" ]
List comprehension works but not for loop––why?
39,044,403
<p>I'm a bit annoyed with myself because I can't understand why one solution to a problem worked but another didn't. As in, it points to a deficient understanding of (basic) pandas on my part, and that makes me mad!</p> <p>Anyway, my problem was simple: I had a list of 'bad' values ('bad_index'); these corresponded to...
5
2016-08-19T17:05:46Z
39,044,516
<p><code>data_clean1.drop([x for x in bad_index]).reset_index(level = 0, drop = True)</code> is equivalent to simply passing the <code>bad_index</code> list to <code>drop</code>:</p> <p><code>data_clean1.drop(bad_index).reset_index(level = 0, drop = True)</code></p> <p><code>drop</code> accepts a list, and drops ever...
8
2016-08-19T17:13:29Z
[ "python", "pandas", "for-loop", "indexing", "list-comprehension" ]
Use qcut pandas for multiple valuable categorizing
39,044,434
<p>I am trying to use two values from two columns from a dataframe and perform <code>qcut</code> categorization. </p> <p>single value categorizing it quite simple. But two variables as pairs and vs is something I am trying get. </p> <p>Input: </p> <pre><code>date,startTime,endTime,day,c_count,u_count 2004-01-05,22:0...
1
2016-08-19T17:08:07Z
39,045,050
<p>You can create a Series for each quantile group:</p> <pre><code>q = df[['c_count', 'u_count']].apply(lambda x: pd.qcut(x, np.linspace(0, 1, 6), labels=np.arange(5))) q Out: c_count u_count 0 4 4 1 3 3 2 3 2 3 4...
1
2016-08-19T17:50:22Z
[ "python", "validation", "csv", "pandas" ]
I get 'ImportError: No module named web' despite the fact that it is installed
39,044,472
<p>I would like to run a simple 'Hello world' app. Every time I run it I get </p> <pre><code>'ImportError: No module named web' </code></pre> <p>I installed web.py using pip and using easy_install several times. I tried uninstalling it and installing again. I tried installing it a as sudo. Nothing seems to work. I us...
0
2016-08-19T17:10:41Z
39,046,428
<p>According to the output of your <code>sys.path</code>, you are probably using OSX Python to run your script (<code>app.py</code>) but using Homebrew Python to execute PIP command. The solution is pretty simple:</p> <pre class="lang-sh prettyprint-override"><code>brew link --overwrite python </code></pre> <p>This w...
0
2016-08-19T19:29:35Z
[ "python", "web", "module", "importerror", "web.py" ]
Convert Buffer to Desired Array?
39,044,487
<p>I'm using <a href="https://github.com/copitux/python-github3" rel="nofollow"><code>pygithub3</code></a> to call an api to receive an organization's repositories, but am getting this result:</p> <pre><code>&lt;pygithub3.core.result.smart.Result object at 0x7f97e9c03d50&gt; </code></pre> <p>I believe this is a buffe...
0
2016-08-19T17:11:21Z
39,044,565
<p>If you look at the docstring of <a href="https://github.com/copitux/python-github3/blob/master/pygithub3/core/result/smart.py" rel="nofollow">the <code>Result</code> class</a>, you'll see that one can obtain a list by calling <code>your_result.all()</code>. </p> <p>If you type <code>help(pygithub3.core.result.smart...
1
2016-08-19T17:16:24Z
[ "python", "pygithub" ]
.any()/.all() when checking array elements in list
39,044,501
<p>Hi I'm currently stuck trying to solve this problem:</p> <pre><code>a = [array([1,3]),array([11,3])] b = [array([1,7]),array([1,9])] c = [[array([1,3]),array([11,3])], [array([2,6]),array([9,9])]] if b not in c: c.append(b) if a not in c: c.append(a) </code></pre> <p>I'm keep getting an error message telli...
-2
2016-08-19T17:12:34Z
39,045,850
<p>You should provide a <a href="http://stackoverflow.com/help/mcve">mcve</a>, in any case, here's a starting point so you can continue experimenting by yourself:</p> <pre><code>a = [[1, 3], [11, 3]] b = [[1, 7], [1, 9]] c = [[[1, 3], [11, 3]], [[2, 6], [9, 9]]] print a in c print b in c print all([a in c, b in c]) p...
0
2016-08-19T18:43:32Z
[ "python" ]
PuLP-OR: Can you delete variables already created?
39,044,577
<p>My question is very simple. Is it possible to delete a variable that I have already created?</p> <p>Or my only hope is to not create the variable to begin with?</p> <p>I guess if you can print a variable then using:</p> <pre><code>del prob.variable </code></pre> <p>would delete it. But I can't find it exactly, P...
0
2016-08-19T17:17:48Z
39,045,254
<p><code>del</code> will delete your variable. To simply clear, or unset your variable, use <code>None</code>.</p> <h1>Using <code>del</code></h1> <pre><code>&gt;&gt;&gt; variable = "Hello World!" &gt;&gt;&gt; print variable Hello World! &gt;&gt;&gt; del variable &gt;&gt;&gt; print variable ...
0
2016-08-19T18:03:30Z
[ "python", "optimization", "integer-programming", "pulp", "operations-research" ]
Computing the least distance between coordinate pairs
39,044,599
<p>First dataframe df1 contains id and their corresponding two coordinates. For each coordinate pair in the first dataframe, i have to loop through the second dataframe to find the one with the least distance. I tried taking the individual coordinates and finding the distance between them but it does not work as expect...
1
2016-08-19T17:19:27Z
39,044,999
<p>The code below creates a new column in <code>df1</code> showing the Id of the nearest point in <code>df2</code>. (I can't tell from the question if this is what you want.) I'm assuming the coordinates are in a Euclidean space, i.e., that the distance between points is given by the Pythagorean Theorem. If not, you co...
1
2016-08-19T17:46:51Z
[ "python", "dataframe" ]
Computing the least distance between coordinate pairs
39,044,599
<p>First dataframe df1 contains id and their corresponding two coordinates. For each coordinate pair in the first dataframe, i have to loop through the second dataframe to find the one with the least distance. I tried taking the individual coordinates and finding the distance between them but it does not work as expect...
1
2016-08-19T17:19:27Z
39,045,028
<p>Given you can get your points into a list like so...</p> <pre><code>df1 = [[30.371353, -95.384010], [39.497448, -119.789623]] df2 = [[40.914585, -73.892456], [34.760395, -77.999260]] </code></pre> <p>Import math then create a function to make finding the distance easier:</p> <pre><code>import math def distan...
1
2016-08-19T17:48:36Z
[ "python", "dataframe" ]
How to pass argument to scoring function in scikit-learn's LogisticRegressionCV call
39,044,686
<p><strong>Problem</strong></p> <p>I am trying to use <em>scikit-learn</em>'s <a href="http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegressionCV.html" rel="nofollow"><code>LogisticRegressionCV</code></a> with <a href="http://scikit-learn.org/stable/modules/generated/sklearn.metrics.roc...
2
2016-08-19T17:26:16Z
39,045,082
<p>I found a way to solve this problem!</p> <p><em>scikit-learn</em> offers a <code>make_scorer</code> function in its <code>metrics</code> module that allows a user to create a scoring object from one of its native scoring functions <strong>with arguments specified to non-default values</strong> (see <a href="http://...
0
2016-08-19T17:52:36Z
[ "python", "function", "arguments", "scikit-learn", "scoring" ]
How to pass argument to scoring function in scikit-learn's LogisticRegressionCV call
39,044,686
<p><strong>Problem</strong></p> <p>I am trying to use <em>scikit-learn</em>'s <a href="http://scikit-learn.org/stable/modules/generated/sklearn.linear_model.LogisticRegressionCV.html" rel="nofollow"><code>LogisticRegressionCV</code></a> with <a href="http://scikit-learn.org/stable/modules/generated/sklearn.metrics.roc...
2
2016-08-19T17:26:16Z
39,047,049
<p>You can use <code>make_scorer</code>, e.g.</p> <pre class="lang-py prettyprint-override"><code>from sklearn.linear_model import LogisticRegressionCV from sklearn.metrics import roc_auc_score, make_scorer # some example data X, y = make_classification() # little hack to filter out Proba(y==1) def roc_auc_score_pro...
1
2016-08-19T20:16:06Z
[ "python", "function", "arguments", "scikit-learn", "scoring" ]
Django Rest Framework - Getting a model instance after serialization
39,044,759
<p>I've made a serializer, and I'm trying to create a <code>Booking</code> instance from the booking field in the serializer, after I've validated the POST data. However, because the <code>Booking</code> object has foreign keys, I'm getting the error: <code>ValueError: Cannot assign "4": "Booking.activity" must be a "A...
0
2016-08-19T17:31:34Z
39,047,676
<p><code>serializer.validated_data</code> should be used, not <code>serializer.data</code></p>
0
2016-08-19T21:06:17Z
[ "python", "django", "django-rest-framework" ]
Executing a python script via php
39,044,876
<p>So Im trying to execute a python script from php using this code</p> <pre><code>exec('C:\Python27\python.exe C:\WEBSITE_DATA\script.py'); </code></pre> <p>or with double backspace...</p> <pre><code>exec('C:\\Python27\\python.exe C:\\WEBSITE_DATA\\script.py'); </code></pre> <p>the script is functional and g...
0
2016-08-19T17:39:16Z
39,045,033
<p>That is very bad thing to do. That is very hacky and unsafe solution. Keep this in mind.</p> <p>With this said, you should be looking for php <code>system</code> function that executes the command in console, not <code>exec</code>.</p> <p>There are multiple ways to transfer variables from php script to Python. You...
1
2016-08-19T17:48:54Z
[ "php", "python" ]
Confusion about django.shortcuts.render() method signature in 1.10
39,044,909
<p>The Django 1.10 release notes (<a href="https://docs.djangoproject.com/en/1.10/releases/1.10/#features-removed-in-1-10" rel="nofollow">https://docs.djangoproject.com/en/1.10/releases/1.10/#features-removed-in-1-10</a>) say:</p> <ul> <li>The dictionary and context_instance parameters for the following functions are ...
2
2016-08-19T17:41:21Z
39,045,070
<p>You are confusing <code>context</code> and <code>context_instance</code>, which are two separate arguments. The <code>context_instance</code> argument has been removed in Django 1.10, but <code>context</code> remains.</p> <p>As the docs say, <code>context</code> should be a <em>dictionary</em> of values. You are ge...
3
2016-08-19T17:51:54Z
[ "python", "django", "dictionary" ]
Filtering out row in Pyspark when there is a word from other table in any column
39,044,993
<p>I am new to pyspark and I want to write a query something like,</p> <p><code>select * from table1 where column like '%word1%'</code> which we write in sql or hive.</p> <p>I am writing the following command,</p> <pre><code>data = sqlCtx.sql('select * from table1 where column like '%word1%') </code></pre> <p>But I...
0
2016-08-19T17:46:35Z
39,059,728
<p>Well, "like" function works in pyspark just fine and just like in SQL. With DataFrame API and with SQL API. Examples:</p> <pre><code>import statsmodels.api as sm duncan_prestige = sm.datasets.get_rdataset("Duncan", "car") df = sqlContext.createDataFrame(duncan_prestige.data.reset_index()) index type incom...
0
2016-08-21T00:01:09Z
[ "python", "sql", "apache-spark", "dataframe", "pyspark" ]
Python SQL Object selecting data by dictionary and date
39,045,017
<p>I am using SQLObject, a wrapper for python to manage SQL Queries, with Python 2.7. I know I can select data by using a dictionary such as:</p> <pre><code>restrictions = { ... } selection = sql_table.selectBy(**restrictions).orderBy('-createdtime') </code></pre> <p>I can also query for date by doing:</p> <pre><cod...
0
2016-08-19T17:47:57Z
39,151,432
<p>Fixed the issue. In case you are here facing the same problem, here is the solution:</p> <p>Since the SQLObject wrapper for python supports entering straight SQL queries, I opted to build it myself. First, I unpack all the restrictions as a query</p> <pre><code>select_string = " AND ".join(str(key) + "=" + str(res...
0
2016-08-25T17:31:33Z
[ "python", "mysql", "python-2.7", "dictionary", "sqlobject" ]
Arcpy, select features based on part of a string
39,045,084
<p>So for my example, I have a large shapefile of state parks where some of them are actual parks and others are just trails. However there is no column defining which are trails vs actual parks, and I would like to select those that are trails and remove them. I DO have a column for the name of each feature, that usua...
-1
2016-08-19T17:52:42Z
39,060,971
<p>Although using the Select tool is a good choice, the syntax for the SQL expression can be a challenge. Consider using an <a href="http://resources.arcgis.com/en/help/main/10.2/index.html#//018w00000014000000" rel="nofollow">Update Cursor</a> to tackle this problem.</p> <pre><code>import arcpy stateparks = r"C:\pat...
0
2016-08-21T05:02:17Z
[ "python", "string", "select", "arcpy" ]
scipy.io.loadmat reads MATLAB (R2016a) structs incorrectly
39,045,089
<p>Instead of loading a MATLAB struct as a dict (as described in <a href="http://docs.scipy.org/doc/scipy/reference/tutorial/io.html" rel="nofollow">http://docs.scipy.org/doc/scipy/reference/tutorial/io.html</a> and other related questions), scipy.io.loadmat is loading it as a strange ndarray, where the values are an a...
-2
2016-08-19T17:53:01Z
39,059,775
<p>This is expected behavior. Numpy is just showing you have MATLAB is storing your data under-the-hood.</p> <p>MATLAB structs are 2+D cell arrays where one dimension is mapped to a sequence of strings. In Numpy, this same data structure is called a "record array", and the dtype is used to store the name. And since...
0
2016-08-21T00:11:39Z
[ "python", "matlab" ]
Python AttributeError: module 'runAnalytics' has no attribute 'run'
39,045,091
<p>I am trying to grab an input from my main.py file using tkinter and then use that input in runAnalytics.py</p> <p>main.py</p> <pre><code>import runAnalytics import tkinter import os import centerWindow loadApplication = tkinter.Tk() loadApplication.title("Stock Analytics") loadApplication.geometry("1080x720") la...
1
2016-08-19T17:53:14Z
39,045,161
<p>Try adding () to the end of runAnalytics.run. You are currently telling it to look for a <code>run</code> attribute which it doesn't have instead of a function</p> <pre><code>loadAnalytics = tkinter.Button(loadApplication, text = "Load Analytics", command = runAnalytics.run()) </code></pre>
-2
2016-08-19T17:58:35Z
[ "python", "input", "tkinter", "python-3.5", "attributeerror" ]
Python AttributeError: module 'runAnalytics' has no attribute 'run'
39,045,091
<p>I am trying to grab an input from my main.py file using tkinter and then use that input in runAnalytics.py</p> <p>main.py</p> <pre><code>import runAnalytics import tkinter import os import centerWindow loadApplication = tkinter.Tk() loadApplication.title("Stock Analytics") loadApplication.geometry("1080x720") la...
1
2016-08-19T17:53:14Z
39,045,216
<pre><code>from runAnalytics import run loadAnalytics = tkinter.Button(loadApplication, text="Load Analytics", command=run) </code></pre> <p>You don't want to start another <code>mainloop</code> of <code>tk</code>. Instead you should pass the <code>root</code> and create a toplevel window.</p> <pre><code>def run(roo...
1
2016-08-19T18:01:42Z
[ "python", "input", "tkinter", "python-3.5", "attributeerror" ]
Python AttributeError: module 'runAnalytics' has no attribute 'run'
39,045,091
<p>I am trying to grab an input from my main.py file using tkinter and then use that input in runAnalytics.py</p> <p>main.py</p> <pre><code>import runAnalytics import tkinter import os import centerWindow loadApplication = tkinter.Tk() loadApplication.title("Stock Analytics") loadApplication.geometry("1080x720") la...
1
2016-08-19T17:53:14Z
39,045,286
<p>You have a circular import:</p> <pre><code>import runAnalytics # .. from main import input1 </code></pre> <p>By the time <code>main</code> is being imported again, <code>runAnalytics</code> has not yet had a chance to execute the <code>def run():</code>.. section.</p> <p>Resolve this by <em>removing</em> the <cod...
3
2016-08-19T18:05:33Z
[ "python", "input", "tkinter", "python-3.5", "attributeerror" ]
Access file system from Python on boot-up cron
39,045,143
<p>Please consider the following problem:</p> <p>I have a Python script that runs on a linux machine (Raspberry pi 3, running Rasbian Jessie) on boot. This script has been added to <code>sudo crontab -e</code></p> <p>The script itself starts with no problem but is unable to load in a certain file that is in the same ...
0
2016-08-19T17:57:32Z
39,047,268
<p>Whenever you execute a script via crontab be ready for environment variables to be different. In this case you can simply use the whole path in the file you are trying to reference.</p> <p>To see what the current environment variables are from within Python, use:</p> <pre><code> import os os.environ </code>...
1
2016-08-19T20:34:52Z
[ "python", "linux", "cron", "x11" ]
OpenCV 3.0 installation error
39,045,256
<p>While trying to install OpenCV 3.0 on a Ubuntu 16.04 machine I get the following errors:</p> <pre><code>/home/isenses/Documents/opencv-3.0.0-rc1/modules/videoio/src/cap_gstreamer.cpp:53:21: fatal error: gst/gst.h: No such file or directory compilation terminated modules/videoio/CMakeFiles/opencv_videoio.dir/build....
-2
2016-08-19T18:03:54Z
39,045,299
<p>you're missing gstreamer includes. You have to install GStreamer SDK first</p> <p><a href="http://gstreamer.com/" rel="nofollow">from here</a></p>
0
2016-08-19T18:06:42Z
[ "python", "c++", "opencv", "ubuntu-16.04" ]
Where does the performance boost of map or list comprehension implementations over calling a function over a loop come from?
39,045,396
<p>I understand that you could be more efficient with memory in the implementation of map than in how you might do it over a loop. However, I see that using a map function over calling a function iterating over a loop has a speed boost as well.</p> <p>Is this coming from some optimization in where to store the memory?...
2
2016-08-19T18:13:41Z
39,045,648
<p>The difference is due to append, not map. Try this:</p> <pre><code>res = [] res = [square2(foo) for foo in foobar] </code></pre>
0
2016-08-19T18:30:45Z
[ "python", "algorithm", "performance", "functional-programming" ]
Where does the performance boost of map or list comprehension implementations over calling a function over a loop come from?
39,045,396
<p>I understand that you could be more efficient with memory in the implementation of map than in how you might do it over a loop. However, I see that using a map function over calling a function iterating over a loop has a speed boost as well.</p> <p>Is this coming from some optimization in where to store the memory?...
2
2016-08-19T18:13:41Z
39,046,254
<p>So, the issue with function-calls in loops, in a dynamic language like Python, is that the interpreter has to evalute the refernces each time, and that is costly, especially for global variables. However, notice what happens when you make things local:</p> <pre><code>import time def square(x): return x*x def t...
2
2016-08-19T19:15:07Z
[ "python", "algorithm", "performance", "functional-programming" ]
How do I group lat-lon pairings in a Pandas DataFrame?
39,045,481
<p>I have a dataframe that looks like:</p> <pre><code>lon lat -77.487 39.044 -77.487 39.044 -122.031 37.354 -77.487 39.044 </code></pre> <p>I want to group these lon-lat pairings with a resulting count, like so:</p> <pre><code>lon lat count -77.487 39.044 3 -122.031 37.354 1 </...
2
2016-08-19T18:20:10Z
39,045,543
<p>Please find the documentation from the following link </p> <p><a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html" rel="nofollow">http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html</a></p> <pre><code>df_data=df_data.groupby(['lon','lat']).si...
1
2016-08-19T18:24:03Z
[ "python", "pandas", "dataframe" ]
How do I group lat-lon pairings in a Pandas DataFrame?
39,045,481
<p>I have a dataframe that looks like:</p> <pre><code>lon lat -77.487 39.044 -77.487 39.044 -122.031 37.354 -77.487 39.044 </code></pre> <p>I want to group these lon-lat pairings with a resulting count, like so:</p> <pre><code>lon lat count -77.487 39.044 3 -122.031 37.354 1 </...
2
2016-08-19T18:20:10Z
39,045,790
<p>You could use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.size.html" rel="nofollow"><code>groupby.size</code></a> and rename the column created followed by <code>reset_index</code> to get back the desired <code>dataframe</code>.</p> <pre><code>print(df.groupby(['lon', ...
4
2016-08-19T18:39:22Z
[ "python", "pandas", "dataframe" ]
Feature engineering using PostgreSQL on a large dataset (~3M entries)
39,045,544
<p>I have a dataset of ~3 million chess games (existing columns include names of players, date, result and tournament name). I want to use Random Forest to predict results of chess games.</p> <p>To this end, I want to do some feature engineering. There are several variables that I believe would be strong predictors, e...
-2
2016-08-19T18:24:11Z
39,045,626
<p>if you want speed up executing query you can create index of columns use to joining (foreign keys and columns using where clausule). But added index cause slow down inserting and updtating, and increase required to space disc.</p>
1
2016-08-19T18:29:17Z
[ "python", "sql", "postgresql", "machine-learning", "bigdata" ]
Feature engineering using PostgreSQL on a large dataset (~3M entries)
39,045,544
<p>I have a dataset of ~3 million chess games (existing columns include names of players, date, result and tournament name). I want to use Random Forest to predict results of chess games.</p> <p>To this end, I want to do some feature engineering. There are several variables that I believe would be strong predictors, e...
-2
2016-08-19T18:24:11Z
39,045,725
<p>Not sure know why you use that IN. I thnk you try to simplify your query and lost more of the logic.</p> <p>I belive that is equivalent to</p> <pre><code>SELECT sum(result) INTO temp FROM chess_data2 t1 </code></pre> <p>You probably want </p> <pre><code>SELECT tournament, namew, sum(result) FROM chess_data2 t...
1
2016-08-19T18:35:22Z
[ "python", "sql", "postgresql", "machine-learning", "bigdata" ]
How can I only replace some of the specific characters in a python string?
39,045,594
<p>I want to replace characters in a string but not all of the characters at once. For example:</p> <pre><code>s = "abac" </code></pre> <p>I would like to replace the string with all these options</p> <pre><code>"Xbac" "abXc" "XbXc" </code></pre> <p>I only know the normal s.replace() function that would replace al...
-2
2016-08-19T18:26:57Z
39,045,702
<pre><code>string.replace(s, old, new[, maxreplace]) </code></pre> <p>Return a copy of string s with all occurrences of substring old replaced by new. If the optional argument maxreplace is given, the first maxreplace occurrences are replaced. So, if <code>maxreplace=1</code> only the first character is replaced.</p>
0
2016-08-19T18:34:19Z
[ "python", "string", "replace" ]
How can I only replace some of the specific characters in a python string?
39,045,594
<p>I want to replace characters in a string but not all of the characters at once. For example:</p> <pre><code>s = "abac" </code></pre> <p>I would like to replace the string with all these options</p> <pre><code>"Xbac" "abXc" "XbXc" </code></pre> <p>I only know the normal s.replace() function that would replace al...
-2
2016-08-19T18:26:57Z
39,045,740
<p><a href="https://docs.python.org/2/library/string.html#string.replace" rel="nofollow">You can still use <code>replace()</code></a> to only replace the first <em>k</em> occurrences of a character, rather than all of them at once.</p> <blockquote> <p><em>string.replace(s, old, new[, maxreplace])</em> </p> <p>R...
0
2016-08-19T18:36:14Z
[ "python", "string", "replace" ]
How can I only replace some of the specific characters in a python string?
39,045,594
<p>I want to replace characters in a string but not all of the characters at once. For example:</p> <pre><code>s = "abac" </code></pre> <p>I would like to replace the string with all these options</p> <pre><code>"Xbac" "abXc" "XbXc" </code></pre> <p>I only know the normal s.replace() function that would replace al...
-2
2016-08-19T18:26:57Z
39,045,746
<blockquote> <p>Does anyone have any clever code that would replace all the possible options of characters in the string?</p> </blockquote> <p>Take a look at <a href="https://docs.python.org/3.4/library/re.html" rel="nofollow">regular expressions</a> in Python.</p> <p>Here's an example:</p> <pre><code>import re ...
0
2016-08-19T18:36:25Z
[ "python", "string", "replace" ]
How can I only replace some of the specific characters in a python string?
39,045,594
<p>I want to replace characters in a string but not all of the characters at once. For example:</p> <pre><code>s = "abac" </code></pre> <p>I would like to replace the string with all these options</p> <pre><code>"Xbac" "abXc" "XbXc" </code></pre> <p>I only know the normal s.replace() function that would replace al...
-2
2016-08-19T18:26:57Z
39,047,992
<p>I have managed to replace all the character in the string with all the different combinations. Although the code isnt the most efficient it does what I wanted it to</p> <pre><code>def replaceall(s, n): occurence = s.count(n) alt = [] temp = s for i in range(occurence): temp2 = temp ...
0
2016-08-19T21:35:23Z
[ "python", "string", "replace" ]
RDD basics about partitions
39,045,609
<p>I am reading <a href="http://spark.apache.org/docs/1.6.2/programming-guide.html#rdd-operations" rel="nofollow">Spark: RDD operations</a> and I am executing:</p> <pre><code>In [7]: lines = sc.textFile("data") In [8]: lines.getNumPartitions() Out[8]: 1000 In [9]: lineLengths = lines.map(lambda s: len(s)) In [10]: ...
0
2016-08-19T18:28:08Z
39,046,070
<p><code>len(lineLengths.collect())</code> or <code>lineLengths.count()</code> tells you the number of rows in your rdd. <code>lineLengths.getNumPartitions()</code>, as you noted, is the number of partitions your rdd is distributed over. Each partition of the rdd contains many rows of the dataframe. </p>
2
2016-08-19T19:00:28Z
[ "python", "apache-spark", "distributed-computing", "partitioning", "rdd" ]
Jupyter Notebook: need to review all cells in a data frame
39,045,754
<p>I am using Jupyter notebook, having a python data frame of 100 columns and 200 rows. I need to manually review every cell in the data frame, but on the browser, it just show "..." when the row or column numbers are large. Can I force it to show every row and column instead of just showing "..."?</p> <p>Thanks!</p>
1
2016-08-19T18:36:43Z
39,045,775
<p>You need to specify how many rows you want shown. You can configure those options in a notebook like this...</p> <pre><code>pd.set_option('display.max_column', 999) pd.set_option('display.max_row', 999) </code></pre> <p>where 999 is the number of rows/columns to be shown</p>
1
2016-08-19T18:38:10Z
[ "python", "dataframe", "jupyter-notebook" ]
Jupyter Notebook: need to review all cells in a data frame
39,045,754
<p>I am using Jupyter notebook, having a python data frame of 100 columns and 200 rows. I need to manually review every cell in the data frame, but on the browser, it just show "..." when the row or column numbers are large. Can I force it to show every row and column instead of just showing "..."?</p> <p>Thanks!</p>
1
2016-08-19T18:36:43Z
39,045,787
<p>You must configure the <code>display.max_rows</code> and/or <code>display.max_columns</code>using <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.set_option.html" rel="nofollow"><code>pd.set_option()</code></a>.</p> <p>I.e.:</p> <pre><code>def print_all(x): pd.set_option('display.max_rows...
1
2016-08-19T18:39:02Z
[ "python", "dataframe", "jupyter-notebook" ]
PyDev Interactive console not initiating
39,045,762
<p>When I try to start an interactive console in Eclipse PyDev, I get the following error:</p> <blockquote> <p>'Create Interactive Console' has encountered a problem.</p> <p>Error Initialising console.</p> <p>Error initializing console. Unexpected error connecting to console. Failed to recive suitable ...
0
2016-08-19T18:37:01Z
39,050,045
<p>Make sure your python path is set in Window>Preferences>Interpreters>Python Interpreter </p> <p>Make sure your java is 64bit</p>
0
2016-08-20T03:01:00Z
[ "python", "eclipse", "python-2.7", "64bit", "pydev" ]
PyDev Interactive console not initiating
39,045,762
<p>When I try to start an interactive console in Eclipse PyDev, I get the following error:</p> <blockquote> <p>'Create Interactive Console' has encountered a problem.</p> <p>Error Initialising console.</p> <p>Error initializing console. Unexpected error connecting to console. Failed to recive suitable ...
0
2016-08-19T18:37:01Z
39,086,455
<p>For anyone struggling with the same issue, I ended up reinstalling everything from scratch. This was the most useful link.</p> <p><a href="http://halfanhour.blogspot.ca/2010/05/setting-up-pydev-on-eclipse-for-64-bit.html" rel="nofollow">http://halfanhour.blogspot.ca/2010/05/setting-up-pydev-on-eclipse-for-64-bit.ht...
0
2016-08-22T18:34:25Z
[ "python", "eclipse", "python-2.7", "64bit", "pydev" ]
Why use tuples when inserting vars into strings in Python?
39,045,778
<p>I feel like this would have been asked before, but could not find anything.</p> <p>In python, if you want to insert a var into a string, there are (at least) two ways of doing so.</p> <p>Using the <code>+</code> operator</p> <pre><code>place = "Alaska" adjective = "cold" sentence = "I live in "+place+"! It's very...
2
2016-08-19T18:38:25Z
39,045,824
<p>For a lot of reasons. One good reason is that not always you can or want to use separated strings, because they are already neatly arranged in a list or tuple:</p> <pre><code>strings = ["one", "two", "three"] print "{}, {} and {}".format(*strings) &gt; one, two and three </code></pre>
4
2016-08-19T18:41:54Z
[ "python", "string", "tuples", "readability" ]
Why use tuples when inserting vars into strings in Python?
39,045,778
<p>I feel like this would have been asked before, but could not find anything.</p> <p>In python, if you want to insert a var into a string, there are (at least) two ways of doing so.</p> <p>Using the <code>+</code> operator</p> <pre><code>place = "Alaska" adjective = "cold" sentence = "I live in "+place+"! It's very...
2
2016-08-19T18:38:25Z
39,045,837
<p>The <code>string % (value, value, ..)</code> syntax is called a <a href="https://docs.python.org/2/library/stdtypes.html#string-formatting" rel="nofollow"><em>string formatting operation</em></a>, and you can also apply a <em>dictionary</em>, it is not limited to just tuples. These days you'd actually want to use th...
4
2016-08-19T18:42:46Z
[ "python", "string", "tuples", "readability" ]
Conditional assignment of tensor values in TensorFlow
39,045,797
<p>I want to replicate the following <code>numpy</code> code in <code>tensorflow</code>. For example, I want to assign a <code>0</code> to all tensor indices that previously had a value of <code>1</code>.</p> <pre><code>a = np.array([1, 2, 3, 1]) a[a==1] = 0 # a should be [0, 2, 3, 0] </code></pre> <p>If I write sim...
2
2016-08-19T18:40:02Z
39,047,066
<p><a href="https://www.tensorflow.org/versions/r0.10/api_docs/python/control_flow_ops.html#comparison-operators" rel="nofollow">Several comparison operators</a> are available within TensorFlow API. </p> <p>However, there is nothing equivalent to the concise NumPy syntax when it comes to manipulating the tensors direc...
3
2016-08-19T20:18:14Z
[ "python", "numpy", "tensorflow" ]
Conditional assignment of tensor values in TensorFlow
39,045,797
<p>I want to replicate the following <code>numpy</code> code in <code>tensorflow</code>. For example, I want to assign a <code>0</code> to all tensor indices that previously had a value of <code>1</code>.</p> <pre><code>a = np.array([1, 2, 3, 1]) a[a==1] = 0 # a should be [0, 2, 3, 0] </code></pre> <p>If I write sim...
2
2016-08-19T18:40:02Z
39,047,590
<p>I'm also just starting to use tensorflow Maybe some one will fill my approach more intuitive</p> <pre><code>import tensorflow as tf conditionVal = 1 init_a = tf.constant([1, 2, 3, 1], dtype=tf.int32, name='init_a') a = tf.Variable(init_a, dtype=tf.int32, name='a') target = tf.fill(a.get_shape(), conditionVal, name...
0
2016-08-19T20:59:59Z
[ "python", "numpy", "tensorflow" ]
mplayer - How can I detect EOF in Python
39,045,892
<p>I have a playlist that changes during play, Mplayer doesn't reload the playlist at the end of the first track so what I need to do is capture the EOF, then reload mplayer to carry on playing. How can I detect EOF using mplayer and popen? Or is there an easier way that I'm missing? I've checked the suggested 'duplica...
0
2016-08-19T18:46:32Z
39,095,699
<p>Well I couldn't fix this issue, there must be a way of getting the mplayer status and then doing some code around the state. As it stands I couldn't get mplayer to reload the playlist once it had a new track added and when I did it started back at the beginning - Not very often I let something beat me! </p> <p>For ...
0
2016-08-23T08:09:14Z
[ "python", "mplayer" ]
Python program that crawls for external IP address
39,045,946
<p>I created a basic program to try and crawl a website for my external IP address with <code>BeautifulSoup 4</code>. Although, I keep getting an Attribute Error for my program because it can't obtain the string of a div class or whatever. It would appear as the specific div class does not exists and that it cannot the...
1
2016-08-19T18:51:07Z
39,047,945
<p>It has nothing to do with Javascript, if you look at the source returned you can see:</p> <pre><code>&lt;html style="height:100%"&gt;&lt;head&gt;&lt;META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW"&gt;&lt;meta name="format-detection" content="telephone=no"&gt;&lt;meta name="viewport" content="initial-scale=1.0"&gt;&l...
2
2016-08-19T21:30:53Z
[ "python", "python-3.x", "beautifulsoup", "ip", "web-crawler" ]
Python program that crawls for external IP address
39,045,946
<p>I created a basic program to try and crawl a website for my external IP address with <code>BeautifulSoup 4</code>. Although, I keep getting an Attribute Error for my program because it can't obtain the string of a div class or whatever. It would appear as the specific div class does not exists and that it cannot the...
1
2016-08-19T18:51:07Z
39,050,273
<p>As explained above that have bot detection mechanism placed on there servers and if you try to do requests.get then it return "Request unsuccessful. Incapsula incident ID: 415000500153648966-193432437842182947" and since source code is not loaded that you cannot find the required info. If you want to do it with be...
1
2016-08-20T03:48:22Z
[ "python", "python-3.x", "beautifulsoup", "ip", "web-crawler" ]
Pandas: get multiindex level as series
39,045,948
<p>I have a dataframe with multiple levels, eg:</p> <pre><code>idx = pd.MultiIndex.from_product((['foo', 'bar'], ['one', 'five', 'three' 'four']), names=['first', 'second']) df = pd.DataFrame({'A': [np.nan, 12, np.nan, 11, 16, 12, 11, np.nan]}, index=idx).dropna().astype(int) ...
4
2016-08-19T18:51:11Z
39,046,141
<pre><code>df['B'] = idx.to_series().str[1] </code></pre>
2
2016-08-19T19:06:11Z
[ "python", "pandas", "multi-index" ]
Pandas: get multiindex level as series
39,045,948
<p>I have a dataframe with multiple levels, eg:</p> <pre><code>idx = pd.MultiIndex.from_product((['foo', 'bar'], ['one', 'five', 'three' 'four']), names=['first', 'second']) df = pd.DataFrame({'A': [np.nan, 12, np.nan, 11, 16, 12, 11, np.nan]}, index=idx).dropna().astype(int) ...
4
2016-08-19T18:51:11Z
39,046,145
<pre><code>df['B'] = df.index.get_level_values(level=1) # Zero based indexing. # df['B'] = df.index.get_level_values(level='second') # This also works. &gt;&gt;&gt; df A B first second foo one 12 one two 11 two bar one 16 one two 12 two ...
4
2016-08-19T19:06:33Z
[ "python", "pandas", "multi-index" ]
Numpy: improve fancy indexing on arrays
39,045,976
<p>Looking for faster fancy indexing for numpy, the code I am running slows down, at <code>np.take()</code>. I tried <code>order=F/C</code> with <code>np.reshape()</code>, no improvement. Python <code>operator</code> works well without the double <code>transpose</code>, but with them is equal to <code>np.take().</code>...
0
2016-08-19T18:53:13Z
39,046,433
<p>A test of several options:</p> <pre><code>In [3]: p[rows][:,cols].shape Out[3]: (3500, 16) In [4]: p[rows[:,None],cols].shape Out[4]: (3500, 16) In [5]: p[:,cols].shape Out[5]: (3500, 16) In [6]: p.take(cols,axis=1).shape Out[6]: (3500, 16) </code></pre> <p>time tests - plain <code>p[:,cols]</code> is fastest. Us...
2
2016-08-19T19:29:58Z
[ "python", "numpy", "optimization", "slice" ]
Adding up Random int as it it created
39,045,980
<p>I'm trying to get the computer to save it's random outputs then add them.</p> <p>Example: </p> <pre><code>ran_num = 1 ; ran_total = 1 ran_num = 3 ; ran_total = 4 </code></pre> <p>And so on... </p> <p>This is all in a <code>while</code> loop. </p> <p>So until the <code>ran_total</code> reaches a certain number...
-2
2016-08-19T18:53:26Z
39,046,020
<p>Your problem is most likely on this line (line 5):</p> <pre><code>computer_choice_total =+computer_choice </code></pre> <p><code>=+</code> isn't a valid Python operator. Instead, use <code>+=</code>, like this:</p> <pre><code>computer_choice_total += computer_choice </code></pre> <p>Also, you'll want to make sur...
2
2016-08-19T18:56:42Z
[ "python", "random" ]
OpenCV Identify rows in Table of variable size
39,046,011
<p>I have a bunch of scans of forms that all look like this:</p> <p><a href="http://i.stack.imgur.com/PqyPq.png" rel="nofollow"><img src="http://i.stack.imgur.com/PqyPq.png" alt="enter image description here"></a></p> <p>I'm trying to take out each row to make each on its own image (a row being the box with 10 all th...
0
2016-08-19T18:55:51Z
39,046,108
<p><code>HoughLines</code> helps you find the lines in the image. After that you need to filter out all the non-horizontal ones. You can use the remaining ones to find out where you need to split the image.</p>
2
2016-08-19T19:03:37Z
[ "python", "opencv", "image-processing", "scikit-image" ]
PyQt - Location of the window
39,046,059
<pre><code>def location_on_the_screen(self): fg = self.frameGeometry() sbrp = QDesktopWidget().availableGeometry().bottomRight() fg.moveBottomRight(sbrp) self.move(fg.topLeft()) </code></pre> <p>I can't place the window in the bottom right corner of the screen. frameGeometry() not working as it should....
0
2016-08-19T18:59:51Z
39,052,495
<p>I assume that your 'window' is a subclass of <code>QWidget</code>. If so, the following should fit your needs:</p> <pre><code>import sys from PyQt5.QtWidgets import QApplication, QWidget, QDesktopWidget class MyWidget(QWidget): def __init__(self): super().__init__() self.setFixedSize(400, 30...
0
2016-08-20T09:23:18Z
[ "python", "python-3.x", "user-interface", "pyqt", "pyqt5" ]
PyQt - Location of the window
39,046,059
<pre><code>def location_on_the_screen(self): fg = self.frameGeometry() sbrp = QDesktopWidget().availableGeometry().bottomRight() fg.moveBottomRight(sbrp) self.move(fg.topLeft()) </code></pre> <p>I can't place the window in the bottom right corner of the screen. frameGeometry() not working as it should....
0
2016-08-19T18:59:51Z
39,064,225
<p>Here's a possible solution for windows:</p> <pre><code>import sys from PyQt5.QtWidgets import QApplication, QWidget, QDesktopWidget class MyWidget(QWidget): def __init__(self): super().__init__() self.setFixedSize(400, 300) def location_on_the_screen(self): ag = QDesktopWidget()...
0
2016-08-21T12:33:06Z
[ "python", "python-3.x", "user-interface", "pyqt", "pyqt5" ]
Use scikit-image to read in an image buffer
39,046,106
<p>I already have an in-memory file of an image. I would like to use skimage's io.imread (or equivalent) to read in the image. However, skimage.io.imread() take a file not a buffer</p> <p>example buffer:</p> <pre><code> &lt;Buffer ff d8 ff e0 00 10 4a 46 49 46 00 01 01 00 00 01 00 01 00 00 ff db 00 43 00 03 02 02 02 ...
0
2016-08-19T19:03:31Z
39,046,359
<p>Try converting the buffer into StringIO and then read it using <code>skimage.io.imread()</code></p> <pre><code>import cStringIO img_stringIO = cStringIO.StringIO(buf) img = skimage.io.imread(img_stringIO) </code></pre> <p>You can also read it as :</p> <pre><code>from PIL import Image img = Image.open(img_stringI...
2
2016-08-19T19:22:49Z
[ "python", "numpy", "io", "buffer", "scikit-image" ]
Sublist to number
39,046,121
<p>I'm working on the solution to a fun problem I found. The code I have gives a bunch of sublists, like (1, 2, 3, 0, 0). Is there a way to turn that sublist into the number 12300 and append it to a new list, <code>perm2</code>? I would have to do this for quite a few sublists, so preferably it would be a function I co...
1
2016-08-19T19:04:28Z
39,046,161
<pre><code>digits = [1,2,3,0,0] int(''.join([str(x) for x in digits])) </code></pre>
0
2016-08-19T19:07:46Z
[ "python", "list", "function" ]
Sublist to number
39,046,121
<p>I'm working on the solution to a fun problem I found. The code I have gives a bunch of sublists, like (1, 2, 3, 0, 0). Is there a way to turn that sublist into the number 12300 and append it to a new list, <code>perm2</code>? I would have to do this for quite a few sublists, so preferably it would be a function I co...
1
2016-08-19T19:04:28Z
39,046,212
<p>You here are a few different ways to solve this:</p> <p><strong>1.</strong> <code>perm2 = [int(''.join(str(i) for i in sublist)) for sublist in perm]</code></p> <p><strong>2.</strong> <code>perm2 = [int(''.join(map(str, sublist))) for sublist in perm]</code></p> <p>A more <strong>performant</strong> mathematical ...
3
2016-08-19T19:11:25Z
[ "python", "list", "function" ]
Sublist to number
39,046,121
<p>I'm working on the solution to a fun problem I found. The code I have gives a bunch of sublists, like (1, 2, 3, 0, 0). Is there a way to turn that sublist into the number 12300 and append it to a new list, <code>perm2</code>? I would have to do this for quite a few sublists, so preferably it would be a function I co...
1
2016-08-19T19:04:28Z
39,046,230
<p>Here is a function that creates an integer out of a list of numbers. The advantage of this function is that it does not convert the list of integers into a list of strings, which is a rather costly operation:</p> <pre><code>def list_to_int(ls): num = 0 for digit in ls: num *= 10 num += digit...
5
2016-08-19T19:12:44Z
[ "python", "list", "function" ]
Nested for loops and data analysis across multiple data files
39,046,193
<p>I have wrote the following code and am just having some last little issues that I could use some help with and once this is polished up, I figured this could be really useful to people doing data analysis on point proximity in the future. </p> <p>The purpose of this code is to read in two separate lists of data as ...
0
2016-08-19T19:10:01Z
39,046,948
<p>First, a suggestion: I have had great experiences with pandas.read_csv() to read large ASCII-files (Gigabyte size, 15 million datapoints). Fastest I've come across, close to harddisk read speed and much faster than genfromtxt.</p> <p>Regarding your nested loops: I think your entire loop can be replaced entirely. Th...
0
2016-08-19T20:07:36Z
[ "python", "numpy", "pycharm", "nested-loops", "data-analysis" ]
Nested for loops and data analysis across multiple data files
39,046,193
<p>I have wrote the following code and am just having some last little issues that I could use some help with and once this is polished up, I figured this could be really useful to people doing data analysis on point proximity in the future. </p> <p>The purpose of this code is to read in two separate lists of data as ...
0
2016-08-19T19:10:01Z
39,150,299
<p>After a little more research and getting some advice from colleagues about how to best test my code with different variables, I realized that the code I wrote is actually doing exactly what I want it to. And it seems (for now at least) everything is doing great. All I did was restrict my proximity search to a much s...
0
2016-08-25T16:22:39Z
[ "python", "numpy", "pycharm", "nested-loops", "data-analysis" ]
Python: base case of a recursive function
39,046,311
<p>Currently I'm experimenting a little bit with recursive functions in Python. I've read some things on the internet about them and I also built some simple functioning recursive functions myself. Although, I'm still not sure how to use the base case.</p> <p>I know that a well-designed recursive function satisfies th...
2
2016-08-19T19:19:25Z
39,046,370
<p>Yes, of course it is: the only requirement on the base case is that it does not call the function recursively. Apart from that it can do anything it wants.</p>
2
2016-08-19T19:24:23Z
[ "python", "function", "recursion" ]
Python: base case of a recursive function
39,046,311
<p>Currently I'm experimenting a little bit with recursive functions in Python. I've read some things on the internet about them and I also built some simple functioning recursive functions myself. Although, I'm still not sure how to use the base case.</p> <p>I know that a well-designed recursive function satisfies th...
2
2016-08-19T19:19:25Z
39,046,388
<p>That is absolutely fine and valid function. Just remember that for any scenario that you can call a recursion function from, there should be a base case reachable by recursion flow. </p> <p>For example, take a look at the following (stupid) recursive function:</p> <pre><code>def f(n): if n == 0: return...
0
2016-08-19T19:25:38Z
[ "python", "function", "recursion" ]
Python: base case of a recursive function
39,046,311
<p>Currently I'm experimenting a little bit with recursive functions in Python. I've read some things on the internet about them and I also built some simple functioning recursive functions myself. Although, I'm still not sure how to use the base case.</p> <p>I know that a well-designed recursive function satisfies th...
2
2016-08-19T19:19:25Z
39,046,978
<p>In simple terms Yes, as long as it does not require the need to call the function recursively to arrive at the base case. Everything else is allowed.</p>
1
2016-08-19T20:09:42Z
[ "python", "function", "recursion" ]
How to convert sql table into a pyspark/python data structure and return back to sql in databricks notebook
39,046,319
<p>I am running a sql notebook on databricks. I would like to analyze a table with half a billion records in it. I can run simple sql queries on the data. However, I need to change the date column type from str to date.</p> <p>Unfortunately, update/alter statements do not seem to be supported by sparkSQL so it seems I...
0
2016-08-19T19:19:57Z
39,046,382
<pre><code>dataFrame = sqlContext.sql('select * from myTable') </code></pre>
3
2016-08-19T19:25:11Z
[ "python", "sql", "apache-spark", "databricks" ]
python 2.7 and subprocess() not passing args correctly
39,046,519
<p>This works from /bin/bash command line …</p> <pre><code>$ /usr/bin/kafka-console-producer --topic AsIs-CalculatedMeasure --broker-list wrlmr4:9092 &lt; /tmp/dataFile </code></pre> <p>'[' 0 -eq 0 ']'</p> <p>When I invoke python's subprocess, it chokes on my arguments, I've changed the arg order, it always causes...
0
2016-08-19T19:37:10Z
39,046,566
<p>Either you pass one big string with all arguments, protecting spaces by quotes, like this:</p> <pre><code>subprocess.Popen('/usr/bin/kafka-console-producer --broker-list wrlmr4:9092 --topic AsIs-CalculatedMeasure', stdin=subprocess.PIPE) </code></pre> <p>or you split the command line properly. You passed two param...
2
2016-08-19T19:39:46Z
[ "python", "bash", "python-2.7", "subprocess" ]
root.after unable to find function_name
39,046,539
<p>I am trying to put together a GUI that would read from a continuously updated TXT file and updated every once in a while. So far I succeeded with the first part and I am failing to use 'root.after()' to loop the whole thing but it results in NameError:</p> <pre><code>import tkinter as tk root = tk.Tk() class App: ...
0
2016-08-19T19:38:16Z
39,046,653
<p>Because <code>get_text</code> is a method of <code>App</code> class you should call it as <code>self.get_text</code>.</p> <p>After is a tkinter method. In that case you should call it as <code>root.after</code>. And self refers to the class you are in. So because get_text is a method of current class you should cal...
2
2016-08-19T19:46:11Z
[ "python", "tkinter" ]
root.after unable to find function_name
39,046,539
<p>I am trying to put together a GUI that would read from a continuously updated TXT file and updated every once in a while. So far I succeeded with the first part and I am failing to use 'root.after()' to loop the whole thing but it results in NameError:</p> <pre><code>import tkinter as tk root = tk.Tk() class App: ...
0
2016-08-19T19:38:16Z
39,046,689
<p>Firstly, like James commented, you should fix your indentation so that the functions are a part of the class.</p> <p>Then, change this line </p> <pre><code>root.after(1000,root,get_text(self)) </code></pre> <p>to this</p> <pre><code>root.after(1000, self.get_text) </code></pre> <p>Check out the answer to the fo...
0
2016-08-19T19:48:08Z
[ "python", "tkinter" ]
Remove html tag and string in between in Python
39,046,564
<p>I'm pretty new with regular expression. Basically, I would like to use regular expression to remove <code>&lt;sup&gt; ... &lt;/sup&gt;</code> from the string using regular expression.</p> <p>Input:</p> <pre><code>&lt;b&gt;something here&lt;/b&gt;&lt;sup&gt;1&lt;/sup&gt;&lt;sup&gt;,3&lt;/sup&gt;, another here&lt;su...
0
2016-08-19T19:39:44Z
39,046,697
<p>You could do something like this:</p> <pre><code>import re s = "&lt;b&gt;something here&lt;/b&gt;&lt;sup&gt;1&lt;/sup&gt;&lt;sup&gt;,3&lt;/sup&gt;, another here&lt;sup&gt;1&lt;/sup&gt;" s2 = re.sub(r'&lt;sup&gt;(.*?)&lt;/sup&gt;',"", s) print s2 # Prints: &lt;b&gt;something here&lt;/b&gt;, another here </code></p...
1
2016-08-19T19:48:43Z
[ "python", "regex" ]
Remove html tag and string in between in Python
39,046,564
<p>I'm pretty new with regular expression. Basically, I would like to use regular expression to remove <code>&lt;sup&gt; ... &lt;/sup&gt;</code> from the string using regular expression.</p> <p>Input:</p> <pre><code>&lt;b&gt;something here&lt;/b&gt;&lt;sup&gt;1&lt;/sup&gt;&lt;sup&gt;,3&lt;/sup&gt;, another here&lt;su...
0
2016-08-19T19:39:44Z
39,046,757
<p>The hard part is knowing how to do a minimal rather than maximal match of the stuff between the tags. This works.</p> <pre><code>import re s0 = "&lt;b&gt;something here&lt;/b&gt;&lt;sup&gt;1&lt;/sup&gt;&lt;sup&gt;,3&lt;/sup&gt;, another here&lt;sup&gt;1&lt;/sup&gt;" prog = re.compile('&lt;sup&gt;.*?&lt;/sup&gt;') ...
1
2016-08-19T19:52:47Z
[ "python", "regex" ]
How to compare requirement file and actually installed Python modules?
39,046,603
<p>Given <code>requirements.txt</code> and a virtualenv environment, what is the best way to check <strong>from a script</strong> whether requirements are met and possibly provide details in case of mismatch?</p> <p>Pip changes it's internal API with major releases, so I seen advices not to use it's <code>parse_requir...
0
2016-08-19T19:42:39Z
39,047,472
<p>You can save your virtualenv's current installed packages with <code>pip freeze</code> to a file, say current.txt</p> <pre><code>pip freeze &gt; current.txt </code></pre> <p>Then you can compare this to requirements.txt with difflib using a script like <a href="http://stackoverflow.com/a/15864963/5434629">this</a>...
0
2016-08-19T20:51:26Z
[ "python", "python-2.7", "pip", "requirements" ]
receiving PNG file in django
39,046,624
<p>I have a falcon server that I am trying to port to django. One of the falcon endpoints processes a request that contains a PNG file sent with <code>content_type = 'application/octet-stream'</code>. It writes the data to a file maintaining the correct PNG structure. </p> <p>The falcon code does this:</p> <pre><code...
0
2016-08-19T19:44:15Z
39,084,828
<p>I solved this by changing the client to set the file and filename fields each part of the multipart and then I was able it iterate through request.FILES and successfully write the files as PNG. </p>
0
2016-08-22T16:51:21Z
[ "python", "django", "png", "wsgi", "falconframework" ]
iterate over a list of lists with another list in python
39,046,676
<p>I am wondering if I can iterate over a list of lists with another list in python:</p> <p>let's say </p> <pre><code>lst_a = [x,y,z] lst_b = [[a,b,c,d],[e,f,g,h],[i,j,k,l]] </code></pre> <p>where len(lst_a) = len(lst_b) </p> <p>I am wondering how to get a new list like below: </p> <pre><code>lst_c = [[x/a, ...
2
2016-08-19T19:47:35Z
39,046,730
<p>You can use a nested list comprehension</p> <pre><code>&gt;&gt;&gt; lst_a = [1,2,3] &gt;&gt;&gt; lst_b = [[1,2,3,4],[2,3,4,5],[3,4,5,6]] &gt;&gt;&gt; lst_c = [[i/b for b in j] for i,j in zip(lst_a, lst_b)] &gt;&gt;&gt; lst_c [[1.0, 0.5, 0.3333333333333333, 0.25], [1.0, 0.6666666666666666, 0.5, 0.4], [1.0, 0.75, 0.6...
6
2016-08-19T19:51:14Z
[ "python", "list" ]
iterate over a list of lists with another list in python
39,046,676
<p>I am wondering if I can iterate over a list of lists with another list in python:</p> <p>let's say </p> <pre><code>lst_a = [x,y,z] lst_b = [[a,b,c,d],[e,f,g,h],[i,j,k,l]] </code></pre> <p>where len(lst_a) = len(lst_b) </p> <p>I am wondering how to get a new list like below: </p> <pre><code>lst_c = [[x/a, ...
2
2016-08-19T19:47:35Z
39,048,467
<pre><code>lst_a = [x,y,z] lst_b = [[a,b,c,d],[e,f,g,h],[i,j,k,l]] lst_c = [] for i in range(len(lst_a)): lst_c.append([lst_a[i]/lst_b[i][0]]) for j in range(1, len(lst_b[i])): lst_c[i].append(lst_a[i]/lst_b[i][j]) </code></pre>
0
2016-08-19T22:25:09Z
[ "python", "list" ]
iterate over a list of lists with another list in python
39,046,676
<p>I am wondering if I can iterate over a list of lists with another list in python:</p> <p>let's say </p> <pre><code>lst_a = [x,y,z] lst_b = [[a,b,c,d],[e,f,g,h],[i,j,k,l]] </code></pre> <p>where len(lst_a) = len(lst_b) </p> <p>I am wondering how to get a new list like below: </p> <pre><code>lst_c = [[x/a, ...
2
2016-08-19T19:47:35Z
39,050,094
<p>You can do this using numpy.</p> <pre><code>import numpy lst_a = [x,y,z] lst_b = [[a,b,c,d],[e,f,g,h],[i,j,k,l]] new_list = [] for i, item in enumerate(lst_a): new_list_i = float(lst_a[i])/numpy.array(lst_b[i]) new_list.append(new_list_i.tolist()) print new_list </code></pre>
0
2016-08-20T03:13:25Z
[ "python", "list" ]
How can I make the docstring in PyCharm as helpful as the one in the Jupyter Notebook?
39,046,688
<p><strong>Jupyter Notebook</strong> Documentation upon typing the command and "()" and pressing Shift+Tab in the Jupyter Notebook (a nice docstring with all parameters explained and examples shows up): <a href="http://i.stack.imgur.com/obrIU.png" rel="nofollow"><img src="http://i.stack.imgur.com/obrIU.png" alt="enter ...
2
2016-08-19T19:48:05Z
39,047,154
<p>Do you mean "How to write the docstring of my own code.."?</p> <p>Because, if you use <a href="http://www.sphinx-doc.org/en/stable/rest.html" rel="nofollow">Sphinx/reStructuredText</a> syntax, you can have beautiful documentation.</p> <p>Here is a basic example:</p> <pre><code>def axhline_demo(y=0, xmin=0, xmax=1...
1
2016-08-19T20:25:45Z
[ "python", "pycharm", "jupyter-notebook" ]
Pass array of function pointers via SWIG
39,046,704
<p>With the help of <a href="http://stackoverflow.com/a/22965961/353337">http://stackoverflow.com/a/22965961/353337</a>, I was able to create a simple example of how to pass one function pointer into a function via Python. Specifically, with</p> <pre><code>double f(double x) { return x*x; } double myfun(double (*...
4
2016-08-19T19:49:10Z
39,057,342
<p>I made the following test case to illustrate what you're trying to do. It has a real implementation of <code>myfun(const std::vector&lt;double(*)(double)&gt;&amp;)</code> to make life a little more interesting:</p> <pre class="lang-cpp prettyprint-override"><code>#include &lt;vector&gt; double g(double x) { retu...
1
2016-08-20T18:17:54Z
[ "python", "c++", "swig" ]
Column order in pandas.concat
39,046,931
<p>I do as below:</p> <pre><code>data1 = pd.DataFrame({ 'b' : [1, 1, 1], 'a' : [2, 2, 2]}) data2 = pd.DataFrame({ 'b' : [1, 1, 1], 'a' : [2, 2, 2]}) frames = [data1, data2] data = pd.concat(frames) data a b 0 2 1 1 2 1 2 2 1 0 2 1 1 2 1 2 2 1 </code></pre> <p>The data column order is i...
3
2016-08-19T20:06:44Z
39,047,071
<p>You are creating DataFrames out of dictionaries. Dictionaries are a unordered which means the keys do not have a specific order. So</p> <pre><code>d1 = {'key_a': 'val_a', 'key_b': 'val_b'} </code></pre> <p>and </p> <pre><code>d2 = {'key_b': 'val_b', 'key_a': 'val_a'} </code></pre> <p>are the same.</p> <p>In add...
5
2016-08-19T20:18:50Z
[ "python", "pandas", "concat" ]
Column order in pandas.concat
39,046,931
<p>I do as below:</p> <pre><code>data1 = pd.DataFrame({ 'b' : [1, 1, 1], 'a' : [2, 2, 2]}) data2 = pd.DataFrame({ 'b' : [1, 1, 1], 'a' : [2, 2, 2]}) frames = [data1, data2] data = pd.concat(frames) data a b 0 2 1 1 2 1 2 2 1 0 2 1 1 2 1 2 2 1 </code></pre> <p>The data column order is i...
3
2016-08-19T20:06:44Z
39,047,188
<p>You can create the original DataFrames with OrderedDicts</p> <pre><code>from collections import OrderedDict odict = OrderedDict() odict['b'] = [1, 1, 1] odict['a'] = [2, 2, 2] data1 = pd.DataFrame(odict) data2 = pd.DataFrame(odict) frames = [data1, data2] data = pd.concat(frames) data b a 0 1 2 1 1...
1
2016-08-19T20:28:50Z
[ "python", "pandas", "concat" ]
Synchronizing socket programming python
39,047,029
<p>I have a client-server application consisted of three rounds. At each round the client sends a file to the server, the server computes sth and send it back to the client. The client based on the received message prepares the message for the next round etc. </p> <p>The application sometimes works smoothly, sometimes...
-2
2016-08-19T20:14:11Z
39,047,207
<p>Have a look at <a href="http://zeromq.org/" rel="nofollow">ZeroMQ</a> and its Python client <a href="https://pyzmq.readthedocs.io/en/latest/" rel="nofollow">pyzmq</a>. It provides a bit easier way to write client/server or distributed applications.</p>
0
2016-08-19T20:30:17Z
[ "python", "python-sockets" ]
Python AttributeError: 'str' object has no attribute 'get_price'
39,047,058
<p>I am trying to take user input from main.py and then tailor the output to said user input. Not only am I getting this error but it seems the my runAnalytics is running when I start main.py, not when I hit my button command to do so.</p> <p>main.py</p> <pre><code>import runAnalytics import tkinter import os import ...
0
2016-08-19T20:17:18Z
39,047,247
<p>Your assumption that <code>runAnalytics</code> is running is correct since the function is executed when binding it to the button the way you did.</p> <p>According to the <a href="http://effbot.org/zone/tkinter-callbacks.htm" rel="nofollow">effbot docs</a> you need to use a <code>lambda</code> function in order to ...
2
2016-08-19T20:33:42Z
[ "python", "string", "tkinter", "python-3.5", "attributeerror" ]
Reorder Python argparse argument groups
39,047,075
<p>I'm using <code>argparse</code> and I have a custom argument group <code>required arguments</code>. Is there any way to change the order of the argument groups in the help message? I think it is more logical to have the required arguments before optional arguments, but haven't found any documentation or questions to...
2
2016-08-19T20:19:00Z
39,047,348
<p>You might consider adding an explicit optional arguments group:</p> <pre><code>import argparse parser = argparse.ArgumentParser(description='Foo', add_help=False) required = parser.add_argument_group('required arguments') required.add_argument('-i', '--input', help='Input file name', required=True) optional = pa...
3
2016-08-19T20:39:55Z
[ "python", "argparse" ]
Reorder Python argparse argument groups
39,047,075
<p>I'm using <code>argparse</code> and I have a custom argument group <code>required arguments</code>. Is there any way to change the order of the argument groups in the help message? I think it is more logical to have the required arguments before optional arguments, but haven't found any documentation or questions to...
2
2016-08-19T20:19:00Z
39,048,205
<p>The parser starts out with 2 argument groups, the usual <code>positional</code> and <code>optionals</code>. The <code>-h</code> help is added to <code>optionals</code>. When you do <code>add_argument_group</code>, a group is created (and returned to you). It is also appended to the <code>parser._action_groups</co...
1
2016-08-19T21:56:39Z
[ "python", "argparse" ]
Reorder Python argparse argument groups
39,047,075
<p>I'm using <code>argparse</code> and I have a custom argument group <code>required arguments</code>. Is there any way to change the order of the argument groups in the help message? I think it is more logical to have the required arguments before optional arguments, but haven't found any documentation or questions to...
2
2016-08-19T20:19:00Z
39,867,709
<p>This is admittedly a hack, and is reliant on the changeable internal implementation, but after adding the arguments, you can simply do:</p> <pre><code>parser._action_groups.reverse() </code></pre> <p>This will effectively make the required arguments group display above the optional arguments group. Note that this ...
0
2016-10-05T07:19:38Z
[ "python", "argparse" ]