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
What is efficient way of detecting if date range of object is occupied?
37,449,123
<p>I'm stuck and hope you can help me.</p> <p>I have app for renting bikes, where user through calendar pick a date range(from startUser to endUser).Every bike has several copies(Variation), if some of the copies is available on user range,he'll take that.</p> <p>i know formula: if not(endBike &lt; startCar or start...
0
2016-05-25T23:15:07Z
37,450,987
<p>If you are using django>=1.8, you may use <a href="https://docs.djangoproject.com/en/1.9/ref/models/fields/#durationfield" rel="nofollow">DurationField</a> for your model.</p> <p>With <code>DurationField</code>, you needn't set a start_time and end_time. And by setting DurationField unique=True, you can check if t...
0
2016-05-26T03:19:29Z
[ "python", "django", "django-models" ]
What is efficient way of detecting if date range of object is occupied?
37,449,123
<p>I'm stuck and hope you can help me.</p> <p>I have app for renting bikes, where user through calendar pick a date range(from startUser to endUser).Every bike has several copies(Variation), if some of the copies is available on user range,he'll take that.</p> <p>i know formula: if not(endBike &lt; startCar or start...
0
2016-05-25T23:15:07Z
37,451,211
<p>You may need something like this:</p> <pre><code>available_bikes = Variation.objects.filter(... ).exclude( Q(rentdate__startCar__range=(start_date, end_date)) | Q(rentdate__endCar__range=(start_date, end_date)) ) </code></pre> <p>This will check that the rental start date and end date are not rente...
0
2016-05-26T03:45:59Z
[ "python", "django", "django-models" ]
How to include supplemental packages in setup.py dependancy install
37,449,137
<p>I want to use https with SSL via requests as a dependency to a python package I am designing. In order to run requests with https via ssl, it is necessary to run </p> <pre><code>pip install requests[security] </code></pre> <p>How would I include an equivalent of this call in setup.py so that when the user installs...
1
2016-05-25T23:16:10Z
37,449,221
<p>Any dependent packages must be installed separately. You cannot have supplemental requests in your setup file, for security purposes the user must deliberately install each package.</p> <p>You can, though, list the dependencies so users can see what is required. The best way to do this would be in your setup file...
0
2016-05-25T23:26:20Z
[ "python", "python-requests", "setup.py" ]
Delete a tkinter widgets after checking the value of an entry (Beginner)
37,449,154
<p>I'm a beginner trying to code a program that will add or delete a widget (checkbutton) depending on the value of the entry. For example, if the entry is greater than 1, the checkbox will be added, otherwise, the program will delete the checkbox.</p> <p>My code will create the widget but won't delete it after changi...
1
2016-05-25T23:18:12Z
37,449,276
<p>One problem is that cb is "unresolved" under try:, once you declare it global, it will kind of "behave" as you want:</p> <pre><code>from Tkinter import * root = Tk() def update(*args): print EntryVar.get() global cb if EntryVar.get()&gt;'1': cb = Checkbutton(root,text="Show check box") ...
0
2016-05-25T23:33:13Z
[ "python", "python-2.7", "tkinter", "widget", "trace" ]
In Python, how to write a regular expression matching strings starting with string A but NOT ending with B
37,449,199
<p>I have some strings like:</p> <pre><code>tool_abc tool_abc_data tool_xyz tool_xyz_data file_abc file_xyz_data </code></pre> <p>My goal is to have an RegEx to match any strings starting with <code>tool_</code> and NOT ending with <code>_data</code>. How can I write one?</p>
1
2016-05-25T23:23:57Z
37,449,268
<p>maybe something like this?:</p> <pre><code>strStart = "tool_" strEnd = "_data" for s in Strings_list: if s.startswith(strStart) and not s.endswith(strEnd): doSomething() else: doSomethingElse() </code></pre>
1
2016-05-25T23:32:41Z
[ "python", "regex" ]
In Python, how to write a regular expression matching strings starting with string A but NOT ending with B
37,449,199
<p>I have some strings like:</p> <pre><code>tool_abc tool_abc_data tool_xyz tool_xyz_data file_abc file_xyz_data </code></pre> <p>My goal is to have an RegEx to match any strings starting with <code>tool_</code> and NOT ending with <code>_data</code>. How can I write one?</p>
1
2016-05-25T23:23:57Z
37,449,321
<p>From <a href="https://docs.python.org/2/library/re.html#regular-expression-syntax" rel="nofollow">https://docs.python.org/2/library/re.html#regular-expression-syntax</a>:</p> <pre><code>(?&lt;!...) Matches if the current position in the string is not preceded by a match for .... This is called a negative lookbehind...
2
2016-05-25T23:38:58Z
[ "python", "regex" ]
In Python, Need an Efficient way to map kdtree indexes to the values
37,449,202
<p>I am using kdtree from scikit-learn with a very large data set. </p> <p>I can get kdtree to do the query in a somewhat reasonable time (20 minutes on my machine) but I can't map the indexes to the values they represent in any time less than 1 hour (I stop waiting after 1 hour).</p> <p>I load up 2 csv files (train...
0
2016-05-25T23:24:05Z
37,449,437
<p>Maybe you can give it a try, since you don't want distance from <code>query</code>:</p> <pre><code>indexes = tree.query(test[['x','y']],k=30,return_distance=False,dualtree=True,sort_results=False) </code></pre> <p>This might reduce some computation time for the first part. For the second part , I am thinking about...
1
2016-05-25T23:56:18Z
[ "python", "python-2.7", "pandas", "scikit-learn", "kdtree" ]
Convert Human Readable Timestamp to Milliseconds from the Epoch in Python
37,449,303
<p>I have a timestamp like "2016-05-24 11:30 PST".</p> <p>How do I get the milliseconds since the epoch?</p>
0
2016-05-25T23:37:14Z
37,449,304
<pre><code>import datetime import pytz import dateutil t = "2016-05-24 11:30 PST" #Convert the timestamp to a datetime object with timezone information d = pytz.timezone("PST8PDT").localize(dateutil.parser.parse(t)) #In order to subtract a datetime object with timezone information is required. #Build the epoch datet...
0
2016-05-25T23:37:14Z
[ "python", "python-2.7" ]
Convert Human Readable Timestamp to Milliseconds from the Epoch in Python
37,449,303
<p>I have a timestamp like "2016-05-24 11:30 PST".</p> <p>How do I get the milliseconds since the epoch?</p>
0
2016-05-25T23:37:14Z
37,449,634
<p>Consider the following:</p> <pre><code>import datetime as DT import dateutil.parser as DP import pytz t = "2016-05-24 11:30 PST" date = DP.parse(t) DATE_FORMAT = '%Y-%m-%d %H:%M:%S %Z%z' wrong_tzone = pytz.timezone('PST8PDT') wrong_date = wrong_tzone.localize(date) print('{:16}: {}'.format(str(wrong_tzone), wrong...
2
2016-05-26T00:20:43Z
[ "python", "python-2.7" ]
Passing multiple variables from python script to shell script
37,449,327
<p>I am trying to run a shell script from python by exporting the python variable to the shell script instead of directly reading them from the user. A question regarding <a href="http://stackoverflow.com/questions/37446911/how-to-pass-an-array-from-python-to-shell-script-and-execute-it">passing array values as variabl...
0
2016-05-25T23:39:55Z
37,449,366
<p>Is it an option for you to pass the variables as parameters?</p> <pre><code>subprocess.call(['./testfile1 %s %s' % (FLUID, FLIBRARY)] + [str(n) for n in HSPACE]) </code></pre> <p>and in the bash script</p> <pre><code>#!/bin/bash FLUID=$1 FLIBRARY=$2 echo "$FLUID, $FLIBRARY" | ./vls.exe </code></pre>
0
2016-05-25T23:46:02Z
[ "python", "shell", "variables" ]
Passing multiple variables from python script to shell script
37,449,327
<p>I am trying to run a shell script from python by exporting the python variable to the shell script instead of directly reading them from the user. A question regarding <a href="http://stackoverflow.com/questions/37446911/how-to-pass-an-array-from-python-to-shell-script-and-execute-it">passing array values as variabl...
0
2016-05-25T23:39:55Z
37,449,409
<p>You could set them as environment variables within the Python script:</p> <pre><code>import os import subprocess os.environ['FLUID'] ="MDM" os.environ['TTYPE'] = str(0) os.environ['FLIBRARY'] = "RefProp" HSPACE=[0.01, 0.009, 0.008, 0.007] subprocess.call(['./testfile1'] + [str(n) for n in HSPACE]) </code></pre>
1
2016-05-25T23:52:14Z
[ "python", "shell", "variables" ]
Passing multiple variables from python script to shell script
37,449,327
<p>I am trying to run a shell script from python by exporting the python variable to the shell script instead of directly reading them from the user. A question regarding <a href="http://stackoverflow.com/questions/37446911/how-to-pass-an-array-from-python-to-shell-script-and-execute-it">passing array values as variabl...
0
2016-05-25T23:39:55Z
37,463,216
<h3>Through the environment</h3> <pre><code>#!/usr/bin/env python import subprocess FLUID="MDM" TTYPE=0 FLIBRARY="RefProp" HSPACE=[0.01, 0.009, 0.008, 0.007] subprocess.call(['./testfile1'] + [str(n) for n in HSPACE], env={'fluid': FLUID, 'ttype': str(TTYPE), 'flibrary': FLIBRARY}) </code></pre> <p>...thereafter, ...
0
2016-05-26T14:06:00Z
[ "python", "shell", "variables" ]
Module not found when drag and drop Python file
37,449,333
<p>I have a Python script which user's drag and drop KML files into for easy use. It takes the dropped file as sys.arg[1]. When entered into the command line as <code>myScript.py Location.kml</code> everything works fine. But when I drag and drop the file in an error is thrown saying <code>no module named xlsxwriter</c...
0
2016-05-25T23:41:03Z
37,449,798
<p>Thanks to erkysun this issue was solved! eryksun's solution worked perfectly and I found another reason it wasn't working. This was because when I dragged and dropped the file into the python script then ran <code>os.getcwd()</code> no matter where the file was it returned <code>C:\WINDOWS\system32</code>. To counte...
0
2016-05-26T00:42:02Z
[ "python", "windows", "drag-and-drop", "xlsxwriter" ]
Python - asterisk when zipping
37,449,448
<p>I'm a newbie with python and I don't understand why doesn't the following work:</p> <pre><code>ea = zip([[200, 1], [10, 1]]) </code></pre> <p>since I'm getting </p> <pre><code>[([200, 1],), ([10, 1],)] </code></pre> <p>while I should add an asterisk like</p> <pre><code>ea = zip(*[[200, 1], [10, 1]]) </code></pr...
1
2016-05-25T23:57:34Z
37,449,480
<p><code>zip</code> expects multiple arguments, like this:</p> <pre><code>&gt;&gt;&gt; zip([200, 1], [10, 1]) [(200, 10), (1, 1)] </code></pre> <p>If you want to use only one argument, then use the <code>*</code> because it has the effect of breaking it up into multiple arguments:</p> <pre><code>&gt;&gt;&gt; zip(*[[...
0
2016-05-26T00:00:43Z
[ "python" ]
Python - asterisk when zipping
37,449,448
<p>I'm a newbie with python and I don't understand why doesn't the following work:</p> <pre><code>ea = zip([[200, 1], [10, 1]]) </code></pre> <p>since I'm getting </p> <pre><code>[([200, 1],), ([10, 1],)] </code></pre> <p>while I should add an asterisk like</p> <pre><code>ea = zip(*[[200, 1], [10, 1]]) </code></pr...
1
2016-05-25T23:57:34Z
37,449,543
<p>If you have time you can read this <a href="http://stackoverflow.com/questions/9754453/in-python-what-type-of-object-does-ziplist1-list2-return">post</a>, it's good resource to understand how <code>*</code> works in Python.</p> <p>The asterisk in Python unpacks augment to function, please refer to <a href="https://...
0
2016-05-26T00:09:06Z
[ "python" ]
how to use named arguments in dask task graph
37,449,460
<p>How can I create a call with named arguments in creating a dask task graph? For instance:</p> <pre><code>def foo (x=1, y=2): ... graph = { 'z': foo, "y=100" } </code></pre> <p>This doesn't work.</p>
0
2016-05-25T23:58:55Z
37,449,991
<h3>Dask.delayed</h3> <p>You could use <a href="http://dask.pydata.org/en/latest/delayed-overview.html" rel="nofollow">dask.delayed</a> to generate a custom graph.</p> <pre><code>def foo(x=1, y=2): ... x = delayed(foo)(x=1, y=2) </code></pre> <p>This is usually the best way to go. It's fool-proof, simple, and ...
0
2016-05-26T01:10:50Z
[ "python", "dask" ]
How do I set up and use Praw for Reddit scraping?
37,449,475
<p>I've been trying to use Praw with Python 2.7, and I've been encountering problems. This is the error I've been getting:</p> <p><code>Traceback (most recent call last): File "redditscraper.py", line 18, in &lt;module&gt; subreddit = r.get_subreddit(args.subreddit) AttributeError: 'Reddit' object has no attribu...
0
2016-05-26T00:00:05Z
37,450,183
<p>I still have no idea what this issue is from. I downgraded from 4.0.2 to 3.5 and it works fine now.</p>
0
2016-05-26T01:35:29Z
[ "python", "screen-scraping", "reddit", "praw" ]
populating form from database : shorthand print/if AND concatenate
37,449,501
<p>so im writing a edit form , basically im showing the form and if user has already fill it i want to populate the from with database stored values </p> <p>my view : </p> <pre><code>def edit(request): try: account = Accounts.objects.get(user=request.user.id) except Accounts.DoesNotExist : acc...
0
2016-05-26T00:03:10Z
37,450,137
<p>you dont need any checks, just put this: </p> <pre><code>&lt;input type="text" name="name" value="{{ cuAcc.name }}"&gt; </code></pre> <p>if user has <code>name</code>, it fills it, otherwise it doesnot. </p> <p>or you may want <a href="https://docs.djangoproject.com/en/1.9/ref/templates/builtins/#default-if-none"...
1
2016-05-26T01:30:11Z
[ "python", "django", "templates" ]
populating form from database : shorthand print/if AND concatenate
37,449,501
<p>so im writing a edit form , basically im showing the form and if user has already fill it i want to populate the from with database stored values </p> <p>my view : </p> <pre><code>def edit(request): try: account = Accounts.objects.get(user=request.user.id) except Accounts.DoesNotExist : acc...
0
2016-05-26T00:03:10Z
37,452,170
<p>Try to create an empty Account in the except clause like this:</p> <pre><code>def edit(request): try: account = Accounts.objects.get(user=request.user.id) except Accounts.DoesNotExist : account = Accounts() return render(request , 'account/edit.html' , {'cuAcc':account}) </code></pre> <...
1
2016-05-26T05:19:38Z
[ "python", "django", "templates" ]
aggregate(Max('id')) returns exception 'str' object has no attribute 'email'
37,449,532
<p>I've been trying to get the user with the highest id but no success. :/ This is my user model:</p> <pre><code>class User(models.Model): email=models.EmailField(unique=True, null=False) name=models.TextField(null=True) </code></pre> <p>It's serializer:</p> <pre><code>class UserSerializer(serializers.ModelS...
1
2016-05-26T00:07:37Z
37,450,796
<p>the problem is at your view,</p> <p>when you are trying to get the queryset, you are using a <code>aggregate()</code> method.</p> <p>BUT <code>aggregate()</code> not return queryset, but a dictionary of name-value pairs. see <a href="https://docs.djangoproject.com/en/1.9/topics/db/aggregation" rel="nofollow">https...
1
2016-05-26T02:57:28Z
[ "python", "django", "django-models", "django-rest-framework" ]
aggregate(Max('id')) returns exception 'str' object has no attribute 'email'
37,449,532
<p>I've been trying to get the user with the highest id but no success. :/ This is my user model:</p> <pre><code>class User(models.Model): email=models.EmailField(unique=True, null=False) name=models.TextField(null=True) </code></pre> <p>It's serializer:</p> <pre><code>class UserSerializer(serializers.ModelS...
1
2016-05-26T00:07:37Z
37,473,527
<p>I'm expanding on what zhaochy wrote. Try changing your view's <code>get_queryset()</code> method to the below. Instead of returning the result of the aggregate (not a queryset because it's already been evaluated), we use that number to find the instance associated with the max id and return that (which is a querys...
1
2016-05-27T01:46:38Z
[ "python", "django", "django-models", "django-rest-framework" ]
aggregate(Max('id')) returns exception 'str' object has no attribute 'email'
37,449,532
<p>I've been trying to get the user with the highest id but no success. :/ This is my user model:</p> <pre><code>class User(models.Model): email=models.EmailField(unique=True, null=False) name=models.TextField(null=True) </code></pre> <p>It's serializer:</p> <pre><code>class UserSerializer(serializers.ModelS...
1
2016-05-26T00:07:37Z
37,517,048
<p>The problem is here</p> <pre><code>def get_queryset(self): return User.objects.aggregate(Max('id')) </code></pre> <p>The expected return value is a queryset. But aggregate does not return a queryset. Using User.objects.get() does not return a queryset either. The only way to return a queryset, is to use <code>...
1
2016-05-30T03:02:43Z
[ "python", "django", "django-models", "django-rest-framework" ]
Pandas/Python - Excel Data Manipulation
37,449,584
<p>So, relatively new to Python/Pandas but I do have a couple of years of programming under my belt but it's mainly with Java/C++ so nothing like a scripting language like Python. </p> <p>My new job has me doing some scripting stuff and it's been pretty basic so far so I decided to try and do more and hopefully show m...
0
2016-05-26T00:13:15Z
37,451,414
<p>You could try</p> <p><code>sheet1['GN'] = sheet1.Description.apply(lambda x: x.split('JIG')[1].split()[0]) </code></p> <p>which should insert a new column with the name <code>GN</code> into your DataFrame with the appropriate <code>GN=*</code> values.</p> <p>To sort the DataFrame from any particular column you ca...
0
2016-05-26T04:07:48Z
[ "python", "arrays", "string", "excel", "pandas" ]
How to map XGBoost predictions to the corresponding data rows?
37,449,620
<p>XGBoost generates a list of predictions for the test dataset. My question is how can I map the generated predictions to the actual test file rows ? Is it strictly safe to assume that the nth prediction corresponds to the nth data row ? XGBoost leverages multi-threading for its operations. So, in such a setting can i...
0
2016-05-26T00:18:46Z
37,451,160
<p>I'm not sure if its <em>strictly safe</em> but based on my experience, that assumption works. Also, for most of the code snippets using xgboost I have seen on Kaggle competitions <a href="https://www.kaggle.com/scirpus/santander-customer-satisfaction/python-xgb-lb-41047" rel="nofollow">like this one</a>, folks make ...
0
2016-05-26T03:41:04Z
[ "python", "machine-learning", "xgboost" ]
Determine if one range is within another
37,449,668
<p>If there is a file with ranges sorted by the first column (no overlap of ranges):</p> <pre><code>1 10 12 15 18 19 </code></pre> <p>And another, sorted by the first column (can have overlaps):</p> <pre><code>1 5 2 10 12 13 13 20 </code></pre> <p>I would like to determine for each line (range)in the second file, i...
2
2016-05-26T00:25:07Z
37,449,777
<p>If you just want to know if the range of <code>df2</code> overlaps with the range of <code>df1</code>:</p> <p><code>if df1.ix[:,0].min() &gt;= df2.ix[:,0].max() or df1.ix[:,0].max() &lt;= df2.ix[:,0].min(): print ("nope") else: print ("overlap")</code></p>
0
2016-05-26T00:37:56Z
[ "python", "pandas" ]
Determine if one range is within another
37,449,668
<p>If there is a file with ranges sorted by the first column (no overlap of ranges):</p> <pre><code>1 10 12 15 18 19 </code></pre> <p>And another, sorted by the first column (can have overlaps):</p> <pre><code>1 5 2 10 12 13 13 20 </code></pre> <p>I would like to determine for each line (range)in the second file, i...
2
2016-05-26T00:25:07Z
37,455,445
<p>@Olivier Pellier-Cuit has provided a <a href="https://en.wikipedia.org/wiki/Interval_tree#Overlap_test" rel="nofollow">link to fast overlap test</a>. If you need membership check instead of overlap test, use <a href="https://en.wikipedia.org/wiki/Interval_tree#Membership_queries" rel="nofollow">this algorithm</a>.</...
1
2016-05-26T08:27:10Z
[ "python", "pandas" ]
python asyncio explanations and signals handler
37,449,693
<p>I've this code to test how does asyncio works:</p> <pre class="lang-python prettyprint-override"><code>stop = False async def subcoro(): # same result even with a range of 30 for i in range(30000): pass async def first(): global stop while not stop: await subcoro() # witho...
1
2016-05-26T00:28:36Z
37,483,614
<p>I like this question, first thing I tried is to <code>strace</code> both:</p> <p>With the <code>sleep</code> I see a lot of <code>epoll</code> (to wait the signal, which is "forwarded" via a socket, typically to comply with the atomicity requiered by the treatment of a received signal).</p> <p>Without the <code>sl...
0
2016-05-27T12:28:14Z
[ "python", "python-3.x", "async-await", "python-asyncio" ]
Python 3 while True: loop
37,449,772
<p>I am struggling to implement a <code>while True:</code> loop in my code.</p> <p>At the point of <code>if file_removed in bs:</code> I need to ask the user for a new <code>int</code> from the list of links provided (go back to <code>which_link = input(lb + "\n|Which vodlocker link should we use?\n|\n| --&gt; ")</cod...
0
2016-05-26T00:37:24Z
37,449,826
<p>Put the part that needs to be repeated into a loop. When you reach a successful exit condition, <code>break</code> out of the loop:</p> <pre><code>... headers = {"User-Agent":"Mozilla/5.0 (iPhone; CPU iPhone OS 7_1_2 like Mac OS X) Safari/9537.53", "Accept":"text/q=0.9,image/webp,*/*;q=0.8", "Accept-Language":"en-U...
0
2016-05-26T00:46:06Z
[ "python", "loops", "while-loop", "python-3.4" ]
runspider: error: File not found: - Scrapy
37,449,895
<p><a href="http://i.stack.imgur.com/mDyJA.png" rel="nofollow"><img src="http://i.stack.imgur.com/mDyJA.png" alt="enter image description here"></a> </p> <p>After working through the official tut I decided to try to build my own spider in the same project. I created parker_spider.py in spiders which contains:</p> <pr...
1
2016-05-26T00:56:40Z
37,450,284
<p>The <a href="http://doc.scrapy.org/en/latest/topics/commands.html#runspider" rel="nofollow"><code>runspider</code> command</a> expects a <em>spider filename</em>, not the spider name:</p> <pre><code>$ scrapy runspider parker_spider.py </code></pre> <p>And, if you have created a Scrapy project and are running spide...
2
2016-05-26T01:50:16Z
[ "python", "scrapy" ]
Assign multiple functions to a single variable?
37,449,945
<p>In Python we can assign a function to a variable. For example, the math.sine function:</p> <pre><code>sin = math.sin rad = math.radians print sin(rad(my_number_in_degrees)) </code></pre> <p>Is there any easy way of assigning multiple functions (ie, a function of a function) to a variable? For example:</p> <pre><c...
2
2016-05-26T01:04:40Z
37,449,967
<p>Just create a wrapper function:</p> <pre><code>def sin_rad(degrees): return math.sin(math.radians(degrees)) </code></pre> <p>Call your wrapper function as normal:</p> <pre><code>print sin_rad(my_number_in_degrees) </code></pre>
4
2016-05-26T01:08:06Z
[ "python" ]
Assign multiple functions to a single variable?
37,449,945
<p>In Python we can assign a function to a variable. For example, the math.sine function:</p> <pre><code>sin = math.sin rad = math.radians print sin(rad(my_number_in_degrees)) </code></pre> <p>Is there any easy way of assigning multiple functions (ie, a function of a function) to a variable? For example:</p> <pre><c...
2
2016-05-26T01:04:40Z
37,450,089
<p>You could write a helper function perform the <a href="https://en.wikipedia.org/wiki/Function_composition_%28computer_science%29" rel="nofollow">function composition</a> for you and use it to create the kind of variable you want. Some nice features are that it can combine a variable number of functions together that...
0
2016-05-26T01:24:35Z
[ "python" ]
Assign multiple functions to a single variable?
37,449,945
<p>In Python we can assign a function to a variable. For example, the math.sine function:</p> <pre><code>sin = math.sin rad = math.radians print sin(rad(my_number_in_degrees)) </code></pre> <p>Is there any easy way of assigning multiple functions (ie, a function of a function) to a variable? For example:</p> <pre><c...
2
2016-05-26T01:04:40Z
37,450,259
<p>I think what the author wants is some form of functional chaining. In general, this is difficult, but may be possible for functions that </p> <ol> <li>take a single argument, </li> <li>return a single value, </li> <li>the return values for the previous function in the list is of the same type as that of the input t...
1
2016-05-26T01:46:42Z
[ "python" ]
python matplotlib gridspec, unwanted arbitrary axis labels
37,450,127
<p>I have some code to plot a grid, with the data in each cell being distinct and having a very specific position. The easiest way I found to do this was to create the grid with gridspec and use it to precisely position my subplots, however I'm having a problem where the overall grid is labelled from 0 to 1 along each ...
3
2016-05-26T01:29:03Z
37,450,274
<p>If you just want to draw a grid over the plot, use this code:</p> <pre><code>import numpy as np import matplotlib.pyplot as plt # mock-up of data being used x = 6 y = 7 table = np.zeros((x, y)) # plotting fig = plt.figure(1) plt.title('Example Plot') plt.gca().xaxis.grid(True, color='darkgrey', linestyle='-') pl...
1
2016-05-26T01:49:12Z
[ "python", "matplotlib" ]
Iterate over edges at a node
37,450,130
<p>I'm trying to clip edges that have irregular values in my graph, the actual values associated with these edges are stored outside <code>networkx</code>. I plan to iterate over all the nodes in my graph to do this kind of pruning (100,000 elements).</p> <pre><code>import networkx as nx G=nx.Graph() G.add_node(1) G.a...
-1
2016-05-26T01:29:31Z
37,522,048
<pre><code>import networkx as nx G=nx.Graph() G.add_node(1) G.add_node(2) G.add_node(3) G.add_edges_from([(1,2),(2,3)]) </code></pre> <p>You can iterate over all the nodes in the following manner:</p> <pre><code>for n in G.node.items(): print(n) (1, {}) (2, {}) (3, {}) </code></pre> <p>You can also add your val...
1
2016-05-30T09:22:30Z
[ "python", "graph", "networkx" ]
Python tkinter after
37,450,146
<p>I use <code>tinter.after()</code> for refreshing the display of an analog clock on a raspberry pi every <code>200ms</code>. At the beginning it's OK but gradually the time between each refresh reaches about 2-3 seconds. Is there any solution to keep the refresh interval to <code>200ms</code>?</p> <pre><code>#!/usr/...
3
2016-05-26T01:30:34Z
37,470,684
<p>No, there is not. Tkinter only guarantees that the event will be triggered sometime <em>after</em> the delay. Usually the difference is only a millisecond or two, but it can be longer. </p> <p>That being said, if you trigger the new event before doing any work, you'll likely witness less drift than if you do it aft...
1
2016-05-26T20:47:22Z
[ "python", "tkinter", "raspberry-pi2" ]
Remap kmeans labels_ based on sorted cluster_centers_
37,450,158
<p>I'm using KMeans to cluster records in a data set based off of one column, <code>cards</code>, which is an int. However, the cluster labels returned are in an non-intuitive order (which is expected since it's an unsupervised algorithm).</p> <p>To make the output more intelligible for my colleagues, I would like to ...
0
2016-05-26T01:32:05Z
37,471,733
<p>I needed to change the line </p> <p><code>_f = lambda x: cluster_df['set_size'][cluster_df.index == x].values</code> </p> <p>to </p> <p><code>_f = lambda x: cluster_df['set_size'][cluster_df['index'] == x].values[0]</code> </p> <p>as it was using the actual dataframe index which was identical to the cluster labe...
0
2016-05-26T22:00:25Z
[ "python", "python-3.x", "pandas", "scikit-learn", "k-means" ]
Alphabetical pseudocode for Python
37,450,182
<p>So I've written this code:</p> <pre><code>#input and output files infile = open("unsorted_fruits.txt", "r") outfile = open("sorted_fruits.txt","w") #reading infile Fruits = infile.read() #time to sort the fruit Fruits = Fruits.split() Fruits.sort() for fruit in Fruits: if fruit != "\n": outfile.write...
0
2016-05-26T01:35:26Z
37,450,985
<p>This process is entirely up to your wants and needs, unless you are doing a school project with specific guidelines. </p> <p>going off of what you already have:</p> <pre><code>BEGIN insert both file names READ unsorted_fruits.txt ASSIGN lines in unsorted_fruits to variable Fruits TURN Fruits into a list SORT l...
0
2016-05-26T03:19:23Z
[ "python", "pseudocode" ]
Python doesn't differentiate len() of list and string?
37,450,224
<p>For example I have this pandas simple data frame:</p> <pre><code>&gt;&gt; print(file) Name 0 ['junior','senior'] 1 freshgrad </code></pre> <p>when I tried using :</p> <pre><code>&gt;&gt; len(file[0]) 2 </code></pre> <p>but for the second one</p> <pre><code>&gt;&gt; len(file[1]) 9 </code></pre> ...
0
2016-05-26T01:41:03Z
37,450,282
<p>You could define your own length function, which uses the type to determine how to calculate the length:</p> <pre><code>def mylen(data): return len(data) if isinstance(data,list) else 1 </code></pre>
0
2016-05-26T01:50:06Z
[ "python", "list", "pandas", "string-length" ]
Python doesn't differentiate len() of list and string?
37,450,224
<p>For example I have this pandas simple data frame:</p> <pre><code>&gt;&gt; print(file) Name 0 ['junior','senior'] 1 freshgrad </code></pre> <p>when I tried using :</p> <pre><code>&gt;&gt; len(file[0]) 2 </code></pre> <p>but for the second one</p> <pre><code>&gt;&gt; len(file[1]) 9 </code></pre> ...
0
2016-05-26T01:41:03Z
37,450,309
<p>The best way to do what you want is to check the data type of the item in question. You can use:</p> <pre><code>if isinstance(item, list): ... </code></pre> <p>And:</p> <pre><code>if isinstance(item, str): ... </code></pre> <p>In the case of a string, you can then use 1 for the length if you wish. Note...
1
2016-05-26T01:54:36Z
[ "python", "list", "pandas", "string-length" ]
Python doesn't differentiate len() of list and string?
37,450,224
<p>For example I have this pandas simple data frame:</p> <pre><code>&gt;&gt; print(file) Name 0 ['junior','senior'] 1 freshgrad </code></pre> <p>when I tried using :</p> <pre><code>&gt;&gt; len(file[0]) 2 </code></pre> <p>but for the second one</p> <pre><code>&gt;&gt; len(file[1]) 9 </code></pre> ...
0
2016-05-26T01:41:03Z
37,450,315
<p>freshgrad is a string<br> so len(file[1]) means that you are calculate the length of this string.It is 9.<br> if file[1] is a list containing freshgrad like['freshgrad'],len(file[1]) will be 1.<br></p>
0
2016-05-26T01:55:09Z
[ "python", "list", "pandas", "string-length" ]
Python doesn't differentiate len() of list and string?
37,450,224
<p>For example I have this pandas simple data frame:</p> <pre><code>&gt;&gt; print(file) Name 0 ['junior','senior'] 1 freshgrad </code></pre> <p>when I tried using :</p> <pre><code>&gt;&gt; len(file[0]) 2 </code></pre> <p>but for the second one</p> <pre><code>&gt;&gt; len(file[1]) 9 </code></pre> ...
0
2016-05-26T01:41:03Z
37,450,421
<p>The Python Doc say about function len</p> <p>Return the length (the number of items) of an object. The argument may be a sequence <strong>(such as a string, bytes, tuple, list, or range) or a collection (such as a dictionary, set, or frozen set)</strong>.</p> <p>See <a href="https://docs.python.org/3/library/funct...
0
2016-05-26T02:09:51Z
[ "python", "list", "pandas", "string-length" ]
Python doesn't differentiate len() of list and string?
37,450,224
<p>For example I have this pandas simple data frame:</p> <pre><code>&gt;&gt; print(file) Name 0 ['junior','senior'] 1 freshgrad </code></pre> <p>when I tried using :</p> <pre><code>&gt;&gt; len(file[0]) 2 </code></pre> <p>but for the second one</p> <pre><code>&gt;&gt; len(file[1]) 9 </code></pre> ...
0
2016-05-26T01:41:03Z
37,450,425
<p>You could use <code>np.size</code>:</p> <pre><code>In [301]: file = pd.Series([['junior','senior'], 'freshgrad']) In [302]: file.apply(np.size) Out[302]: 0 2 1 1 dtype: int64 In [327]: np.size(file[0]) Out[327]: 2 In [328]: np.size(file[1]) Out[328]: 1 </code></pre> <p>But to some extent this might just ...
0
2016-05-26T02:10:01Z
[ "python", "list", "pandas", "string-length" ]
Send More Money Puzzle in Python
37,450,302
<p>A famous puzzle follows. SEND + MORE = MONEY</p> <p>Substitute each letter in the equation with a single integer 0-9 (no duplicates) such that the addition is correct. Write a program to solve this puzzle. Hint: Brute force works well {try all possibilities}.</p> <p>Here's my code so far:</p> <pre><code>def so...
0
2016-05-26T01:52:51Z
37,450,420
<p>Casting lists to sets will only change their length if they have non-unique elements. Check how sets work: <a href="https://docs.python.org/2/library/sets.html" rel="nofollow">https://docs.python.org/2/library/sets.html</a></p> <p>From <a href="http://stackoverflow.com/help/how-to-ask" title="How to ask a good ques...
0
2016-05-26T02:09:48Z
[ "python" ]
Send More Money Puzzle in Python
37,450,302
<p>A famous puzzle follows. SEND + MORE = MONEY</p> <p>Substitute each letter in the equation with a single integer 0-9 (no duplicates) such that the addition is correct. Write a program to solve this puzzle. Hint: Brute force works well {try all possibilities}.</p> <p>Here's my code so far:</p> <pre><code>def so...
0
2016-05-26T01:52:51Z
37,450,635
<p>with uniqueness requirement and search for all solutions:</p> <pre><code>def solutions(): # letters = ('s', 'e', 'n', 'd', 'm', 'o', 'r', 'y') all_solutions = list() for s in range(9, -1, -1): for e in range(9, -1, -1): for n in range(9, -1, -1): for d in range(9, -1,...
2
2016-05-26T02:36:22Z
[ "python" ]
Send More Money Puzzle in Python
37,450,302
<p>A famous puzzle follows. SEND + MORE = MONEY</p> <p>Substitute each letter in the equation with a single integer 0-9 (no duplicates) such that the addition is correct. Write a program to solve this puzzle. Hint: Brute force works well {try all possibilities}.</p> <p>Here's my code so far:</p> <pre><code>def so...
0
2016-05-26T01:52:51Z
37,451,079
<p>I could not resist to write a little more concise brute-force solution since I never heard of the puzzle bevor.</p> <pre><code>from itertools import combinations, permutations a, b, c = 'SEND', 'MORE', 'MONEY' for comb in combinations(range(10), 8): for perm in permutations(comb): d = dict(zip('SENDMO...
1
2016-05-26T03:31:28Z
[ "python" ]
Send More Money Puzzle in Python
37,450,302
<p>A famous puzzle follows. SEND + MORE = MONEY</p> <p>Substitute each letter in the equation with a single integer 0-9 (no duplicates) such that the addition is correct. Write a program to solve this puzzle. Hint: Brute force works well {try all possibilities}.</p> <p>Here's my code so far:</p> <pre><code>def so...
0
2016-05-26T01:52:51Z
37,464,122
<p>@ siwica: your 'fast' solution provides a list of multiple results, so I propose a change in your second last line:</p> <pre><code> if (f(a) + f(b) == f(c)) &amp; (len(a) == len(str(f(a)))) &amp; (len(b) == len(str(f(b)))): </code></pre> <p>so, I have no rights to comment, which is why I write this 'answer'</p>...
0
2016-05-26T14:43:48Z
[ "python" ]
TK Image Not Appearing
37,450,334
<p>I am trying to put an image on a TKinter canvas with other buttons under the image. For some reason I can not get this picture to appear. I have not yet implemented the buttons. Here is my code thus far.</p> <pre><code>class GUI_Control: def __init__(self, player): self.player = player self.map ...
2
2016-05-26T01:57:26Z
37,450,736
<p>You need to call the <code>pack()</code> (or <code>grid()</code>) method of widgets for them to be displayed:</p> <pre><code>class GUI_Control: def __init__(self, player): self.player = player self.map = Tk() self.MAP_WIDTH = 600 self.MAP_HEIGHT = 375 #define map gui here...
1
2016-05-26T02:50:17Z
[ "python", "user-interface", "tkinter", "tkinter-canvas" ]
TK Image Not Appearing
37,450,334
<p>I am trying to put an image on a TKinter canvas with other buttons under the image. For some reason I can not get this picture to appear. I have not yet implemented the buttons. Here is my code thus far.</p> <pre><code>class GUI_Control: def __init__(self, player): self.player = player self.map ...
2
2016-05-26T01:57:26Z
37,450,766
<p>You'll need to use one of Tk’s geometry-management mechanisms to tell it where to render the canvas within it's container.</p> <p>the simplest way would be to add <code>self.canvas.pack()</code> like so:</p> <pre><code> #define map gui here self.canvas = Canvas(self.map, width=self.MAP_WIDTH, height=self....
1
2016-05-26T02:54:01Z
[ "python", "user-interface", "tkinter", "tkinter-canvas" ]
How do I "pretend" to install a package using pip?
37,450,352
<p>This feels like such a simple question, but I can't find any reference in the <a href="https://pip.pypa.io/en/stable/" rel="nofollow">pip documentation</a> and <a href="http://stackoverflow.com/questions/11460681/listing-the-dependencies-of-a-package-using-pip">the only question that seemed relevant</a> mentions a f...
2
2016-05-26T01:59:25Z
37,450,408
<p>Per the pip documentation, the proper way to generate the requirements.txt file is via <code>pip freeze &gt; requirements.txt</code>. Hopefully this is what you wanted.</p>
0
2016-05-26T02:08:21Z
[ "python", "python-3.x", "pip" ]
How do I "pretend" to install a package using pip?
37,450,352
<p>This feels like such a simple question, but I can't find any reference in the <a href="https://pip.pypa.io/en/stable/" rel="nofollow">pip documentation</a> and <a href="http://stackoverflow.com/questions/11460681/listing-the-dependencies-of-a-package-using-pip">the only question that seemed relevant</a> mentions a f...
2
2016-05-26T01:59:25Z
37,450,440
<p>There is also the pretty useful <a href="https://github.com/nvie/pip-tools" rel="nofollow"><code>pip-tools</code> package</a> that provides a <code>pip-review</code> tool which you can execute in a "dry run" mode against your requirements file(s):</p> <pre><code>$ mkvirtualenv test_so New python executable in test_...
1
2016-05-26T02:12:05Z
[ "python", "python-3.x", "pip" ]
How to pass an object argument via signal
37,450,396
<p>Would it be possible to pass <code>point</code> object as an argument to <code>run</code> function? The code below results to <code>TypeError: signal() only accepts 0 arguments, 2 given!</code></p> <pre><code>import PySide.QtCore as QtCore def run(arg = None, *args, **kwargs): print 'run:', arg, args, kwargs ...
0
2016-05-26T02:06:12Z
37,450,521
<p>You have to specify the type of the object you want to send. For example, to pass an int with a signal.</p> <pre><code>def Emitter(QtCore.QObject): signal = QtCore.Signal(int) </code></pre> <p>I recommend reading more doc about this. For example, <a href="https://wiki.qt.io/Signals_and_Slots_in_PySide" rel="no...
0
2016-05-26T02:24:09Z
[ "python", "qt", "pyqt", "signals" ]
How to pass an object argument via signal
37,450,396
<p>Would it be possible to pass <code>point</code> object as an argument to <code>run</code> function? The code below results to <code>TypeError: signal() only accepts 0 arguments, 2 given!</code></p> <pre><code>import PySide.QtCore as QtCore def run(arg = None, *args, **kwargs): print 'run:', arg, args, kwargs ...
0
2016-05-26T02:06:12Z
37,450,545
<p>Approach 1.0: Specify <code>object</code> as a type while declaring <code>signal = QtCore.Signal(object)</code>:</p> <pre><code>import PySide.QtCore as QtCore def run(arg = None, *args, **kwargs): print 'run:', arg, args, kwargs class Emitter(QtCore.QObject): signal = QtCore.Signal(object) emitter = Emi...
0
2016-05-26T02:26:45Z
[ "python", "qt", "pyqt", "signals" ]
Passing variables in python to another web platform
37,450,499
<p>I have a code which requires to pass the latency, upspeed, dlspeed to another web site to display. Right now the code is as below</p> <pre><code>import datetime import os import sys import shutil import webbrowser import tempfile import subprocess import json import urllib.request import statistics import pymysql i...
-2
2016-05-26T02:20:19Z
37,460,559
<p>You have a method that returns this dictionary... </p> <pre><code>res = { 'ip': ip, 'latency': avg_latency, 'upspeed': u_bits_per_second, 'dlspeed': d_bits_per_second, 'upspeedtime': u_testtime, 'dlspeedtime': d_testtime, 'upspeeddate': u_testdate, 'dlspeeddate': d_testdate } </code>...
0
2016-05-26T12:14:09Z
[ "python", "rest" ]
How to optimize the code for this situation?
37,450,573
<p>I defined several Django models and need to process the field value like the following, the codes are so redundant </p> <pre><code>version = 'xxxx' version_objs = AP_Release_Version.objects.filter(ap_version__icontains=version) for version_obj in version_objs: version_value = version_obj.ap_version .........
0
2016-05-26T02:30:43Z
37,450,748
<p>have an idea, using kwargs: </p> <pre><code>map_info = { 'ap_version' : AP_Release_Version, 'cp_version' : CP_Release_Version, 'gps_version' : GPS_Release_Version, } for k, v in map_info.items(): version_objs = v.objects.filter(**{'%s_icontains' %k : version}) for version_obj in version_objs:...
1
2016-05-26T02:51:26Z
[ "python", "django", "django-models" ]
How to optimize the code for this situation?
37,450,573
<p>I defined several Django models and need to process the field value like the following, the codes are so redundant </p> <pre><code>version = 'xxxx' version_objs = AP_Release_Version.objects.filter(ap_version__icontains=version) for version_obj in version_objs: version_value = version_obj.ap_version .........
0
2016-05-26T02:30:43Z
37,450,879
<p>It seems like you have three variables: the object, the icontains, and the attribute. So create a list of tuples:</p> <pre><code>import collections VersionInfo = collections.namedtuple('VersionInfo', 'obj icontains attrname') Vinfos = [ VersionInfo(AP_Release_Version, 'ap_version__icontains', 'ap_version'), ...
1
2016-05-26T03:06:41Z
[ "python", "django", "django-models" ]
TensorFlow image classification
37,450,620
<p>I am very new to TensorFlow. I am now doing the <strong>image classification</strong> by using my own training database. </p> <p>However, after I trained my own dataset, I have no idea on how to classify the input image. </p> <p>Here is my code for <strong>preparing my own dataset</strong></p> <pre><code>filename...
3
2016-05-26T02:34:39Z
37,451,880
<p>maybe you could try this after you have install PIL python lib:</p> <pre><code>from __future__ import absolute_import from __future__ import division from __future__ import print_function import time import math import numpy import numpy as np import random from PIL import Image from six.moves import xrange # pyl...
1
2016-05-26T04:54:37Z
[ "python", "image-processing", "tensorflow", "tensorboard" ]
Python Regex expression for parsing HTML document
37,450,647
<p><a href="https://en.wikipedia.org/wiki/List_of_largest_companies_by_revenue" rel="nofollow">https://en.wikipedia.org/wiki/List_of_largest_companies_by_revenue</a></p> <p>I am trying to find the names of the companies in order of revenue. It's a bit challenging because the titles all have differently formatted tags....
1
2016-05-26T02:37:49Z
37,450,814
<p>I believe this will help.</p> <p><a href="http://stackoverflow.com/a/590789/6378535">http://stackoverflow.com/a/590789/6378535</a></p> <p>Hence, you should be using BeautifulSoup instead.</p>
-1
2016-05-26T02:59:07Z
[ "python", "html", "regex" ]
Python Regex expression for parsing HTML document
37,450,647
<p><a href="https://en.wikipedia.org/wiki/List_of_largest_companies_by_revenue" rel="nofollow">https://en.wikipedia.org/wiki/List_of_largest_companies_by_revenue</a></p> <p>I am trying to find the names of the companies in order of revenue. It's a bit challenging because the titles all have differently formatted tags....
1
2016-05-26T02:37:49Z
37,450,914
<p>Group the content of the <code>title</code> attribute in <code>a</code> tags. It checks if it's the first table cell after the ranking.</p> <pre><code>regex = /th&gt;\n&lt;td.*?&gt;&lt;a .* ?title="(.*?)".*&gt;/ </code></pre> <p>It's known to work <em>currently</em>. But it's a fairly brittle method. Check the <a ...
0
2016-05-26T03:10:57Z
[ "python", "html", "regex" ]
Python Regex expression for parsing HTML document
37,450,647
<p><a href="https://en.wikipedia.org/wiki/List_of_largest_companies_by_revenue" rel="nofollow">https://en.wikipedia.org/wiki/List_of_largest_companies_by_revenue</a></p> <p>I am trying to find the names of the companies in order of revenue. It's a bit challenging because the titles all have differently formatted tags....
1
2016-05-26T02:37:49Z
37,450,961
<p>This can be done easily with <code>beautifulsoup</code></p> <pre><code>from bs4 import BeautifulSoup as soup x = ['&lt;td&gt;&lt;a href="/wiki/Wal-Mart_Stores,_Inc." title="Wal-Mart Stores, Inc."class="mw-redirect"&gt;Wal-Mart Stores, Inc.&lt;/a&gt;&lt;/td&gt;', '&lt;td style="background: #ffffcc;"&gt;&lt;a href="...
0
2016-05-26T03:16:03Z
[ "python", "html", "regex" ]
Bracket Balance - checking if there are more right brackets or left brackets (Python)
37,450,705
<p>I have been lurking on Stack Overflow for a bit now, and could not find a question similar to this of mine. In regards to balance brackets, how is it determined that an equation has more right brackets than left brackets, or more left brackets than right?</p>
-2
2016-05-26T02:46:29Z
37,450,793
<p>Use a <code>collections.Counter</code> object to quickly establish counts of all the characters in the string. Check on the bracket types you're concerned about:</p> <pre><code>s = "([{&lt;&gt;}]" import collections c = collections.Counter(s) pairs = '()[]{}&lt;&gt;' for l,r in zip(pairs[0::2], pairs[1::2]): ...
0
2016-05-26T02:56:51Z
[ "python", "python-3.x" ]
packaging biom for FreeBSD
37,450,859
<p>I'm working on packaging <code>biom</code> (2.1.5) for FreeBSD.</p> <p>Based on the documentation, I initially had it depending on <code>pynumpy</code> and <code>h5py</code>, but digging I think it should also depend on:</p> <pre><code>py27-click-6.6 py27-future-0.14.3 py27-pyqi-0.2.0 py27-scipy-0.16.1. </code></p...
0
2016-05-26T03:03:57Z
37,452,557
<p>In future 0.14.3, there is no <code>string_types</code> in <code>future.utils</code>. (Although it is mentioned in the documentation). Look at the <code>0.14.x</code> branch of the <a href="https://github.com/PythonCharmers/python-future" rel="nofollow">github repo for future</a>.</p> <p>At the time of writing the ...
1
2016-05-26T05:48:37Z
[ "python", "biom" ]
Looking to loop this script? Python 3
37,450,921
<pre><code>import time morse = {'a': '.-', 'b': '-...', 'c': '-.-.', 'd': '-..', 'e': '.', 'f': '..-.', 'g': '--.', 'h': '....', 'i': '..', 'j': '.---', 'k': '-.-', 'l': '.-..', 'm': '--', 'n': '-.', 'o': '---', 'p': '.--.', 'q': '--.-', 'r': ...
-3
2016-05-26T03:11:23Z
37,451,024
<pre><code>while True: msg = input('''What would you like translated? please use lower-case letters.:''') print ("") for i in msg: print(morse[i]) </code></pre> <p>to give the user a chance to quit the program:</p> <pre><code>while True: msg = input('''What would you like translated?...
0
2016-05-26T03:23:48Z
[ "python", "morse-code" ]
spark Row creation in a map
37,450,952
<p>I saw a Dataframes tutorial at <a href="https://databricks.com/blog/2015/02/17/introducing-dataframes-in-spark-for-large-scale-data-science.html" rel="nofollow">https://databricks.com/blog/2015/02/17/introducing-dataframes-in-spark-for-large-scale-data-science.html</a> which is written in <code>Python</code>. I am t...
3
2016-05-26T03:14:53Z
37,451,306
<blockquote> <p>how to assign the field names to the rows</p> </blockquote> <p>Python <code>Row</code> is quite different type of object than its Scala counterpart. It is a tuple augmented with names which makes it more equivalent to product type than untyped collection (<code>o.a.s.sql.Row</code>).</p> <blockquote...
2
2016-05-26T03:55:23Z
[ "python", "scala", "apache-spark", "spark-dataframe" ]
Grabbing HTML source after delayed redirect
37,450,953
<p>I am trying to grab the HTML source of a website with Python. However, when you visit any page on the site there is a delayed redirect almost like a loading screen. Whenever I do a <code>requests.get(url)</code> I end up grabbing that loading screen and not what comes after it. I am using the Requests library. Is th...
0
2016-05-26T03:14:56Z
37,451,112
<p>you can turn off the default auto redirect characteristic, and get the object page by request the web page that indicated in r.history where store the redirect location</p>
-1
2016-05-26T03:35:21Z
[ "python", "python-3.x", "redirect", "python-requests" ]
Grabbing HTML source after delayed redirect
37,450,953
<p>I am trying to grab the HTML source of a website with Python. However, when you visit any page on the site there is a delayed redirect almost like a loading screen. Whenever I do a <code>requests.get(url)</code> I end up grabbing that loading screen and not what comes after it. I am using the Requests library. Is th...
0
2016-05-26T03:14:56Z
37,451,267
<p>The redirect is probably done by your browser, not by the server. There are 2 common ways: <a href="https://en.wikipedia.org/wiki/Meta_refresh" rel="nofollow">"meta refresh"</a> or Javascript.</p> <p>For the former you can parse the HTML response using something like <a href="https://www.crummy.com/software/Beautif...
1
2016-05-26T03:52:11Z
[ "python", "python-3.x", "redirect", "python-requests" ]
Make sober plots with matplotlib
37,450,990
<p>I'm plotting some transfer function with matplotlib and seaborn.</p> <p>This is the format I'm making the plots so far:</p> <p><a href="http://i.stack.imgur.com/9rKJh.png" rel="nofollow"><img src="http://i.stack.imgur.com/9rKJh.png" alt="enter image description here"></a></p> <p><a href="http://i.stack.imgur.com...
0
2016-05-26T03:20:13Z
37,454,889
<p>The following should work:</p> <pre><code>import matplotlib.pyplot as plt x = [0, 1, 2, 3] y = [0, 1, 2, 3] plt.plot(x, y) plt.ylabel('$\\frac{V_i}{V_o}$', rotation=0, size=25) plt.xlabel('$D$') ax = plt.gca() ax.set_yticks([max(y)]) ax.set_xticks([max(x)]) plt.hlines([max(y)], 0 ,max(x), linestyles='--') plt.vline...
3
2016-05-26T07:58:40Z
[ "python", "matplotlib" ]
python: pickle.load() raising EOFError
37,451,014
<p>I have a pickle file using .txt format. I want to load this pickle file with python 2.7. The size is 438.5 MB. This is how I load data :</p> <pre><code>def readpickle(path="C:/Python27/Lib/site-packages/xy/"): with open(path+"filenamereal2.txt","rb") as f: model = pickle.load(f) return model </code></pre> <p>...
0
2016-05-26T03:23:00Z
37,451,433
<p>To load data, wouldn't you want to be reading data ("rb") instead of writing data ("wb")?</p> <p>Loading data should look like this:</p> <pre><code> with open("C:/Users/Lab Komputasi/Documents/estu/filenamereal1.txt", "rb") as f: data = pickle.load(f) </code></pre> <p>Also, using f.close() is unnecessary bec...
0
2016-05-26T04:09:23Z
[ "python", "python-2.7", "pickle" ]
How to remove origin file after unziped in python
37,451,031
<p>I have a python code to unzip a file and then remove it (the origin file),but my code catch some exception:cannot remove the file,becasue it was in used. I think the problem is that when the code of remove action was run,the unzip action was not finished,so the exception was thrown,so,how can I check the run s...
0
2016-05-26T03:24:26Z
37,451,070
<p>Try closing the file before removing it.</p> <pre><code>file = zipfile.ZipFile(lfilename) for filename in file.namelist(): file.extract(filename,dir) file.close() remove(lfilename) </code></pre>
1
2016-05-26T03:29:56Z
[ "python" ]
How to remove origin file after unziped in python
37,451,031
<p>I have a python code to unzip a file and then remove it (the origin file),but my code catch some exception:cannot remove the file,becasue it was in used. I think the problem is that when the code of remove action was run,the unzip action was not finished,so the exception was thrown,so,how can I check the run s...
0
2016-05-26T03:24:26Z
37,451,093
<p>The documentation for ZipFile says:</p> <blockquote> <p>ZipFile is also a context manager and therefore supports the <a href="https://docs.python.org/2/reference/compound_stmts.html#with" rel="nofollow">with</a> statement.</p> </blockquote> <p>So, I'd recommend doing the following:</p> <pre><code>with zipfile.Z...
3
2016-05-26T03:33:33Z
[ "python" ]
How to remove origin file after unziped in python
37,451,031
<p>I have a python code to unzip a file and then remove it (the origin file),but my code catch some exception:cannot remove the file,becasue it was in used. I think the problem is that when the code of remove action was run,the unzip action was not finished,so the exception was thrown,so,how can I check the run s...
0
2016-05-26T03:24:26Z
37,451,129
<p>You must first close the file.</p> <pre><code> file.close() remove(lfilename) </code></pre> <p>Alternatively you could do the following:</p> <pre><code>with ZipFile('lfilename') as file: for filename in file.namelist(): file.extract(filename,dir) remove(lfilename) </code></pre>
1
2016-05-26T03:36:47Z
[ "python" ]
Wrong counting while using dictionary replacing multi-if statement
37,451,077
<p>My target is to count offers to specified companies in Excel. </p> <p>I used plenty of if statements to do counting work before. codes like below</p> <pre><code>ipl=gs=gt=0 for file in glob.glob('*.xlsm'): wb=load_workbook(file,data_only=True) ws=wb["Tim"] client=ws['B2'].value if client=='Injecti...
0
2016-05-26T03:31:19Z
37,451,118
<p>Are your indents correct? The block beginning with</p> <pre><code>if client in companypool: </code></pre> <p>doesn't look to be correctly indented. And the line</p> <pre><code>companypool = {'Injection Parts Ltd.':ipl, 'Gulf Sample Ltd':gs, 'Great test Ltd.':gt} </code></pre> <p>is going to reset your di...
0
2016-05-26T03:35:52Z
[ "python", "counting" ]
Adding a new string method in Python
37,451,089
<p>I am parsing a bunch of HTML and am encountering a lot of "\n" and "\t" inside the code. So I am using </p> <pre><code>"something\t\n here".replace("\t","").replace("\n","") </code></pre> <p>This works, but I'm using it often. Is there a way to define a string function, along the lines of replace itself (or find...
1
2016-05-26T03:32:52Z
37,451,144
<p>While you could do something along these lines (<a href="http://stackoverflow.com/a/4698550/1867876">http://stackoverflow.com/a/4698550/1867876</a>), the more Pythonic thing to do would be:</p> <p><code>myString = "something\t\n here" ' '.join(myString.split()) </code></p> <p>You can see this thread for more infor...
0
2016-05-26T03:38:37Z
[ "python", "string", "function", "class" ]
Adding a new string method in Python
37,451,089
<p>I am parsing a bunch of HTML and am encountering a lot of "\n" and "\t" inside the code. So I am using </p> <pre><code>"something\t\n here".replace("\t","").replace("\n","") </code></pre> <p>This works, but I'm using it often. Is there a way to define a string function, along the lines of replace itself (or find...
1
2016-05-26T03:32:52Z
37,451,155
<p>Make a subclass with a custom method like this:</p> <pre><code>class string(str): def customMethod(self): print "In customMethod" x = string("my string") x.customMethod() </code></pre> <p>Read more in this question: <a href="http://stackoverflow.com/questions/4698493/can-i-add-custom-methods-attributes...
0
2016-05-26T03:40:04Z
[ "python", "string", "function", "class" ]
Adding a new string method in Python
37,451,089
<p>I am parsing a bunch of HTML and am encountering a lot of "\n" and "\t" inside the code. So I am using </p> <pre><code>"something\t\n here".replace("\t","").replace("\n","") </code></pre> <p>This works, but I'm using it often. Is there a way to define a string function, along the lines of replace itself (or find...
1
2016-05-26T03:32:52Z
37,451,183
<p>you can try encoding='utf-8'. otherwise in my opinion there is no other way otherthan replacing it . python also replaces it spaces with '/xa0' so in anyway you have to replace it. our you can read it line by line via (readline()) instead of just read() it .</p>
0
2016-05-26T03:43:19Z
[ "python", "string", "function", "class" ]
Could not create collator Error in Eric6
37,451,156
<p>I'm totally a beginner in Python, and try to build my first pyQt project by Eric6. Then I got this problem. This warning comes whi <a href="http://i.stack.imgur.com/PDU3h.png" rel="nofollow">Picture here: Warning: Could not create collator: 4</a></p> <p>This problem does not affect the basic functionality, and I ca...
-1
2016-05-26T03:40:19Z
37,455,547
<p>I changed my Python to V3.4.4, and changed pyQt to 5.5.0, then everything is ok.</p>
0
2016-05-26T08:31:50Z
[ "python", "pyqt" ]
Could not create collator Error in Eric6
37,451,156
<p>I'm totally a beginner in Python, and try to build my first pyQt project by Eric6. Then I got this problem. This warning comes whi <a href="http://i.stack.imgur.com/PDU3h.png" rel="nofollow">Picture here: Warning: Could not create collator: 4</a></p> <p>This problem does not affect the basic functionality, and I ca...
-1
2016-05-26T03:40:19Z
37,853,351
<p>The developer of Eric6 explained like the following </p> <blockquote> <p>this is nothing caused by eric because there is no code creating q QCollator object. However, due to the Qt documentation QLocale is creating such an object. Therefore I assume an issue within Qt.</p> </blockquote>
0
2016-06-16T08:06:49Z
[ "python", "pyqt" ]
Pandas Create Data Frame Column from List
37,451,197
<p>Given the following list:</p> <pre><code>list=['a','b','c'] </code></pre> <p>I'd like to create a data frame where the list is the column of values. I'd like the header to be "header".</p> <p>Like this:</p> <pre><code>header a b c </code></pre> <p>Thanks in advance!</p>
1
2016-05-26T03:44:41Z
37,451,241
<p>Wouldn't that be:</p> <pre><code>list=['a','b','c'] df= pd.DataFrame({'header': list}) header 0 a 1 b 2 c </code></pre>
3
2016-05-26T03:49:19Z
[ "python", "python-3.x", "pandas", "dataframe" ]
PyCharm Cannot Run Program C:\\Anaconda\\python.exe
37,451,236
<p>When I go to run scripts in the terminal, I get an error in a red box that says "Pycharm cannot run program C:\Anaconda\python.exe (in directory E:\etc... CreateProcessError=2 The System cannot find the file specified."</p> <p>I have uninstalled Anaconda and reinstalled it. I have also reinstalled PyCharm. Thing is...
2
2016-05-26T03:49:08Z
37,486,303
<p>Most likely one of your installations was set for "All Users" and installed to the C:\ directory. The error is "The System cannot find the file specified." This is most likely because "C:\Anaconda\python.exe" does not exist and should be "C:\users\my_name\Anaconda2". Be sure you have set PyCharm to use the correct p...
1
2016-05-27T14:40:48Z
[ "python", "jar", "ide", "settings", "pycharm" ]
Where to handle Exceptions - in Library or User Code
37,451,238
<p>I'm working on a Library to handle interaction with an API. Later on I will use it to create some tools.</p> <p>Now I'm wondering where to 'really' handle the exceptions.</p> <ol> <li>Should the Library handle the exception and only return for example error codes like '{"error": "URL not found"}'</li> <li>Pass the...
0
2016-05-26T03:49:11Z
37,451,352
<p>i would keep it on your end and add a blanket exception that prints traceback:</p> <pre><code>import urllib2 class Request: def send(self, url): try: req = urllib2.Request(url) request = urllib2.urlopen(req) response = request.read() return response ...
0
2016-05-26T04:00:26Z
[ "python", "exception", "exception-handling" ]
Python selenium handle windows
37,451,338
<p>Trying to make a bot for a website too chat in with a lot of accounts.</p> <pre><code>for x in range(0,2): project_dir = os.path.dirname(__file__) chromedriver_path = os.path.join(project_dir, 'chromedriver.exe') driver = webdriver.Chrome(chromedriver_path) driver.get("https://*********/login") ...
0
2016-05-26T03:59:16Z
37,451,420
<p>where is window_handles and how big is it.</p> <p>I would debug your code by commenting out everything in the while True loop and printing the length of driver.window_handles</p> <pre><code>while True: #enter = raw_input("Chat: ") #for i in range(0, 2): #g= driver.window_handles[i] #x.send_...
0
2016-05-26T04:08:27Z
[ "python", "python-2.7", "python-3.x", "selenium" ]
Python selenium handle windows
37,451,338
<p>Trying to make a bot for a website too chat in with a lot of accounts.</p> <pre><code>for x in range(0,2): project_dir = os.path.dirname(__file__) chromedriver_path = os.path.join(project_dir, 'chromedriver.exe') driver = webdriver.Chrome(chromedriver_path) driver.get("https://*********/login") ...
0
2016-05-26T03:59:16Z
37,451,455
<p>Try this one, I have updated the for loop that you were using. Now the for loop will iterate based on your number of windows.</p> <pre><code>x = driver.find_element_by_class_name("js-chat_input") while True: enter = raw_input("Chat: ") for i in range(0, len(driver.window_handles)): g= driver.window_...
0
2016-05-26T04:12:09Z
[ "python", "python-2.7", "python-3.x", "selenium" ]
Two Windows Opening When Only One Should
37,451,397
<p>I am trying to make a game where a map Tk() window opens, the player chooses location, the map window closes, and the level window opens. When the player has a choice the leave the level and chooses 'yes', the level Tk() should close and the map should open back up so the player can click on a different location and...
1
2016-05-26T04:05:42Z
37,452,610
<p>In a <em>Tkinter/tkinte</em>r application, you must have only one <code>Tk()</code> instance running at the same time. So to resolve your problem, you can simply use <a href="http://effbot.org/tkinterbook/toplevel.htm" rel="nofollow"><code>Toplevel()</code></a>.</p>
1
2016-05-26T05:52:18Z
[ "python", "user-interface", "tkinter" ]
How to get and show counts of values each column
37,451,483
<p>I have a pandas dataframe.</p> <p>df:</p> <pre><code> col1 col2 col3 col4 col5 0 1.0 1.0 NaN NaN 1.0 1 NaN 1.0 1.0 2.0 1.0 2 2.0 NaN 1.0 NaN 1.0 </code></pre> <p>I want to get the count number of rows that have the same data each column like following.</p> <p>OutPut:</p> <pre><code> col1 ...
1
2016-05-26T04:14:34Z
37,452,071
<p><strong>Edit</strong>: <em>df.replace(np.NaN, 0) does not work reliably across versions, so updated to use df.fillna(0) instead.</em></p> <p>To count the occurrences of a value in each column use value_counts. Non-occurring values become NaN, so need to be replaced with 0:</p> <pre><code>&gt;&gt;&gt; df.apply(pd....
0
2016-05-26T05:11:21Z
[ "python", "pandas", "dataframe" ]
How to get and show counts of values each column
37,451,483
<p>I have a pandas dataframe.</p> <p>df:</p> <pre><code> col1 col2 col3 col4 col5 0 1.0 1.0 NaN NaN 1.0 1 NaN 1.0 1.0 2.0 1.0 2 2.0 NaN 1.0 NaN 1.0 </code></pre> <p>I want to get the count number of rows that have the same data each column like following.</p> <p>OutPut:</p> <pre><code> col1 ...
1
2016-05-26T04:14:34Z
37,452,437
<p>You could use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.value_counts.html" rel="nofollow"><code>value_counts</code></a> method of pandas Series and then <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.fillna.html" rel="nofollow"><code>fillna</code></...
0
2016-05-26T05:39:44Z
[ "python", "pandas", "dataframe" ]
Fastest way to grep list 1000 records in another million of records in a file in Linux
37,451,494
<p>What is the fastest way to grep a list of 1000 records in another million of records in a file in Linux. </p> <p>Let's say these are my sample records :</p> <pre><code>1,,EE1,1000,WAT,EEE,20160222T02:00:15+0400,20181231T23:59:59+0400,,vEEE,,47126469f184fee9a80664d952d7fea7,50278774602,95223904,140495221530736,2100...
-3
2016-05-26T04:15:35Z
37,451,808
<p>If you have tac and grep (GNU) you can use </p> <p><code>tac /test/done/TEST_RT* | grep -m 1 $i</code></p> <p>Inside your for loop. This is much faster than finding all matches and picking only the last one.</p>
0
2016-05-26T04:47:39Z
[ "python", "linux", "bash", "shell", "awk" ]
Fastest way to grep list 1000 records in another million of records in a file in Linux
37,451,494
<p>What is the fastest way to grep a list of 1000 records in another million of records in a file in Linux. </p> <p>Let's say these are my sample records :</p> <pre><code>1,,EE1,1000,WAT,EEE,20160222T02:00:15+0400,20181231T23:59:59+0400,,vEEE,,47126469f184fee9a80664d952d7fea7,50278774602,95223904,140495221530736,2100...
-3
2016-05-26T04:15:35Z
37,451,841
<p>Obviously performance issues come from the fact that for each line in the bigger file you grep over all your data again and again. Perhaps you should take a different approach. Without knowning the specific domain of the problem, I'd guess something like: </p> <ol> <li>first sort the data in <code>/test/done/TEST_R...
0
2016-05-26T04:51:04Z
[ "python", "linux", "bash", "shell", "awk" ]
Fastest way to grep list 1000 records in another million of records in a file in Linux
37,451,494
<p>What is the fastest way to grep a list of 1000 records in another million of records in a file in Linux. </p> <p>Let's say these are my sample records :</p> <pre><code>1,,EE1,1000,WAT,EEE,20160222T02:00:15+0400,20181231T23:59:59+0400,,vEEE,,47126469f184fee9a80664d952d7fea7,50278774602,95223904,140495221530736,2100...
-3
2016-05-26T04:15:35Z
37,453,364
<p>If I didn't misunderstand your problem, </p> <pre><code>grep -f PATTERNFILE HUGEFILE | tail -n 1 </code></pre> <p>will find the last line in HUGEFILE, which contains any pattern in PATTERNFILE.</p> <p>In case you are looking for the last of occurance of <em>every</em> pattern in PATTERNFILE, I wouldn't do this wi...
0
2016-05-26T06:41:49Z
[ "python", "linux", "bash", "shell", "awk" ]
Python 2.7 no console output in Windows 10
37,451,510
<p>Using python 2.7.11 on Windows 10 64-bit Home Premium upgraded in place from Windows 7</p> <p>In a standard console, the following code is saved as hello.py and prints: Hello World When invoked with <code>python hello.py</code></p> <pre><code>#! python print 'Hello World' </code></pre> <p>It produces no console ...
2
2016-05-26T04:18:01Z
37,452,745
<p>On a whim, I navigated to the registry key specified in my previous comment.<br> The instruction here: <a href="https://support.microsoft.com/en-us/kb/321788" rel="nofollow">https://support.microsoft.com/en-us/kb/321788</a><br> Say to add a REG_DWORD value "InheritConsoleHandles" to the key <br><strong>HKEY_LOCAL_MA...
1
2016-05-26T06:02:39Z
[ "python", "windows" ]
Sql Insert Statement not displaying anything
37,451,553
<p>Im trying to insert a value in a python script, and im not getting any errors but it isnt displaying in the SQL file and I cant find any documentation that helps me understand why it isnt displaying.</p> <p>Here is the code</p> <pre><code>#Connect the db to this python script top10_connection = connect(database = ...
0
2016-05-26T04:21:20Z
37,451,629
<p>If you arent getting any traceback errors you are msot likely forgetting to commit changes to the db.</p> <p>add <code>top10_connection.commit()</code> before you close the connection:</p> <pre><code>top10_connection = connect(database = 'top_ten.db') #Get a cursor for the database which allows you to make #and e...
1
2016-05-26T04:29:32Z
[ "python", "sql", "database", "insert", "value" ]
Python Selenium PhantomJS not clicking on same button that Firefox Webdriver is able to click
37,451,599
<p>I was implementing a bot to click on upvote button in reddit</p> <p>Here is the html code of the upvote button.</p> <p><div class="snippet" data-lang="js" data-hide="false" data-console="true"> <div class="snippet-code"> <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;div class="arrow up ...
0
2016-05-26T04:25:45Z
37,452,167
<p>Try performing click() operation via jQuery or JavaScript using execute_script method of selenium. Below is the sample code that will perform the click operation. </p> <pre><code>driver.execute_script("$('div.arrow.up').click()") </code></pre> <p>For the page which has multiple upvote fields then you can use an in...
1
2016-05-26T05:19:31Z
[ "python", "selenium" ]
ProgrammingError: column "column" of relation "schema" does not exist
37,451,660
<p>I'm following this tutorial about using Scrapy with Postgres <a href="http://newcoder.io/scrape" rel="nofollow">http://newcoder.io/scrape</a>. I'm new with postgres and very familiar with scrapy.</p> <p>Nowhere in the tutorial does it state anything about migrations so I think it intends to generate the tables usi...
0
2016-05-26T04:31:21Z
37,451,832
<p>In pipeline.py it looks like you need to import create_scores_table instead of create_matchups_table</p> <p>it reads:</p> <pre><code>from sqlalchemy.orm import sessionmaker from models import Scores, db_connect, create_matchups_table </code></pre> <p>should read:</p> <pre><code>from sqlalchemy.orm import session...
1
2016-05-26T04:50:16Z
[ "python", "sql", "postgresql", "sqlalchemy", "scrapy" ]
Properly Implement Method Inheritance During Class Construction
37,451,753
<p>How do I implement super-like behavior in methods that are called before a class has been completely constructed. Can I implement a series of interdependent methods like this?</p> <pre><code>from six import with_metaclass class Meta(type): """a metaclass""" def __init__(cls, name, bases, classdict): ...
1
2016-05-26T04:41:46Z
37,451,754
<p>I had this question for quite a while and couldn't really find a post that explained this aspect of metaclasses. In fact I had it for so long that I came up with this alternate, and ultimately unnecessary, <a href="https://gist.github.com/rmorshea/7a1b130f0792a5b1babffb37bfc30744" rel="nofollow">solution</a>. Techni...
1
2016-05-26T04:41:46Z
[ "python", "inheritance", "super", "metaclass" ]
How to make an HTTP proxy that points to a specific server
37,451,775
<p>I am trying to set up an HTTP proxy using Python. I found this library on GitHub: <a href="https://github.com/abhinavsingh/proxy.py" rel="nofollow">https://github.com/abhinavsingh/proxy.py</a>. However, I noticed that it is a generic proxy--it extracts the target server from the original HTTP request, and uses that ...
0
2016-05-26T04:44:04Z
37,451,821
<p>please use python twisted library </p> <pre><code>from twisted.internet import reactor from twisted.web import proxy, server site = server.Site(proxy.ReverseProxyResource('www.yahoo.com', 80, '')) reactor.listenTCP(8080, site) reactor.run() </code></pre>
0
2016-05-26T04:49:12Z
[ "python", "proxy" ]
The strange jump over when I use pandas to read specific columns in .csv
37,451,844
<h3>1. Background</h3> <p>The .csv file I upload <a href="https://drive.google.com/file/d/0B7FE0kxAL8kQUjZ3bzdYNXBpb0k/view?usp=sharing" rel="nofollow">here</a> is an example file for me to explain my problem. </p> <p>This file contain all the air quality information for all cities in China(represent in Code) in at ...
3
2016-05-26T04:51:22Z
37,451,957
<p>Your csv has two commas in that position:</p> <pre><code>...19,20,24,19,22,24,29,,42,39... </code></pre> <p>this gets read as NaN by pandas.</p> <p><em>It looks like in your version of LibreOffice it's skipped and uses the subsequent value (incorrectly).</em></p> <hr> <pre><code>In [11]: s = open("china_sites_2...
2
2016-05-26T05:00:58Z
[ "python", "excel", "python-2.7", "csv", "pandas" ]
QGIS - Select by expression - howto make multiple selections/querys
37,451,924
<p>I have an attribute table with ~ 100 fields and I want to select some fields. So far my workflow looks like this: </p> <pre><code>Select by expression "field1" Add to selection Select by expression "field2" Add to selection Select by expression "field3" Add to selection Select by expression "fiel...
0
2016-05-26T04:58:01Z
37,452,285
<p>Say your DB has two columns named <code>fruit</code> and <code>place</code> and you've to select rows where <code>fruit</code> is <code>apple</code> or <code>place</code> is <code>india</code>. </p> <p>Use the following </p> <pre><code>"fruit" = 'apple' OR "place" = 'india' </code></pre>
0
2016-05-26T05:27:15Z
[ "python", "sql", "gis", "qgis" ]
How to align a single cell in reportlab Table
37,451,977
<p>I am Creating a table with <a href="/questions/tagged/reportlab" class="post-tag" title="show questions tagged &#39;reportlab&#39;" rel="tag">reportlab</a>, I want to align a single cell (to the right) in the following table:</p> <p><a href="http://i.stack.imgur.com/KyOVa.png" rel="nofollow"><img src="http://i.stac...
0
2016-05-26T05:02:46Z
37,458,112
<p>In order to align a single cell in a Reportlab <code>Table</code> we need to change the <code>TableStyle</code> to the following:</p> <pre><code>TableStyle([ ('ALIGN', (0, 0), (0, -1), "LEFT"), ('FONTSIZE', (0,0), (-1, -1), 13), ('ALIGN', (0, 7), (0, 7), "RIGHT"), ]) </co...
1
2016-05-26T10:25:06Z
[ "python", "django", "pdf-generation", "reportlab" ]
Install thrift_sasl for Python in Windows
37,452,024
<p>I have been trying to install the <code>thrift_sasl</code> package through <code>pip</code> in Windows 10 x64. </p> <p>The <code>thrift_sasl</code> depends on the <code>sasl</code> package, but on running <code>pip install thrift_sasl</code> or <code>pip install sasl</code>, I run into the same error.</p> <pre><co...
2
2016-05-26T05:07:03Z
37,452,192
<p>if you dont have chocolatey installed, install it using these directions<a href="https://chocolatey.org/install" rel="nofollow">chocolatey install</a></p> <p>then try </p> <pre><code>choco install msinttypes </code></pre> <p>from command prompt. </p> <p>then try installing thrift_sasl again</p>
0
2016-05-26T05:21:31Z
[ "python", "visual-c++", "pip", "mingw", "sasl" ]
I am trying to get binary data from text and converting to numpy arrays
37,452,031
<p>I am trying to get binary data from text and convert to numpy arrays. I tried these codes:</p> <pre><code>import numpy as np import matplotlib.pylab as pl '''a=open ('rawdata.txt ','r',) print (a.read()) a.close()''' data=np.genfromtxt ('rawdata.txt', delimiter=',') print (data) time =data [1:,][:,0] print (time) v...
3
2016-05-26T05:07:52Z
37,452,221
<p>You have to specify a type for cols you want to read, f.e.:</p> <pre><code>data1 = np.loadtxt(flname, delimiter=',', unpack = True, skiprows=1, usecols=(0,1), dtype='float') data2 = np.loadtxt(flname, delimiter=',', unpack = True, skiprows=1, usecols=(2,), dtype='int') for i in xrange(data1.shape[1]): print da...
2
2016-05-26T05:22:54Z
[ "python", "numpy", "matplotlib" ]
I am trying to get binary data from text and converting to numpy arrays
37,452,031
<p>I am trying to get binary data from text and convert to numpy arrays. I tried these codes:</p> <pre><code>import numpy as np import matplotlib.pylab as pl '''a=open ('rawdata.txt ','r',) print (a.read()) a.close()''' data=np.genfromtxt ('rawdata.txt', delimiter=',') print (data) time =data [1:,][:,0] print (time) v...
3
2016-05-26T05:07:52Z
37,452,355
<p>Using the answer by Stanley R, just add a little bit of logic to convert the binary data to integers.</p> <pre><code>base10 = np.loadtxt(filename, delimiter=',', unpack = True, skiprows=1, usecols=(0,), dtype=float) base02 = np.loadtxt(filename, delimiter=',', unpack = True, skiprows=1, usecols=(1,2,), dtype=int) b...
2
2016-05-26T05:32:57Z
[ "python", "numpy", "matplotlib" ]
I am trying to get binary data from text and converting to numpy arrays
37,452,031
<p>I am trying to get binary data from text and convert to numpy arrays. I tried these codes:</p> <pre><code>import numpy as np import matplotlib.pylab as pl '''a=open ('rawdata.txt ','r',) print (a.read()) a.close()''' data=np.genfromtxt ('rawdata.txt', delimiter=',') print (data) time =data [1:,][:,0] print (time) v...
3
2016-05-26T05:07:52Z
37,452,484
<p>You can use pandas to read it:</p> <pre><code>import pandas as pd binary = lambda s: int(s, 2) df = pd.read_csv('rawdata.txt', converters={'voltage(V) ': binary, 'current(A)': binary}) print(df) </code></pre> <p>This allows you to specify separate converters for each column based on the name of the column. In thi...
4
2016-05-26T05:42:55Z
[ "python", "numpy", "matplotlib" ]