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 solve "table "auth_permission" already exists" error when the database is shared among two Django projects
39,890,835
<p>in <a href="http://stackoverflow.com/questions/39774580/how-to-make-two-django-projects-share-the-same-database/39781404?noredirect=1#comment66877315_39781404">this</a> question I learned how to make two Django projects use the same database. I have:</p> <pre><code>projects project_1 settings.py ... p...
0
2016-10-06T08:11:24Z
39,890,888
<p>You can open the <code>migrations</code> file and comment out the SQL that tries to create the table. Then run migrations again.</p> <p>(another possibility would be to delete the table in the database, but you'd lose the data in the table.)</p>
2
2016-10-06T08:14:47Z
[ "python", "django" ]
How to solve "table "auth_permission" already exists" error when the database is shared among two Django projects
39,890,835
<p>in <a href="http://stackoverflow.com/questions/39774580/how-to-make-two-django-projects-share-the-same-database/39781404?noredirect=1#comment66877315_39781404">this</a> question I learned how to make two Django projects use the same database. I have:</p> <pre><code>projects project_1 settings.py ... p...
0
2016-10-06T08:11:24Z
39,891,803
<p>If you use django version >1.7 you should use migrations (<a href="https://docs.djangoproject.com/en/1.8/topics/migrations/" rel="nofollow">Django Migrations</a> - make sure to check version matches yours) Then you can make migrations more consistently (no conflicts). Even if they happen (but under very specific con...
1
2016-10-06T09:00:02Z
[ "python", "django" ]
How to solve "table "auth_permission" already exists" error when the database is shared among two Django projects
39,890,835
<p>in <a href="http://stackoverflow.com/questions/39774580/how-to-make-two-django-projects-share-the-same-database/39781404?noredirect=1#comment66877315_39781404">this</a> question I learned how to make two Django projects use the same database. I have:</p> <pre><code>projects project_1 settings.py ... p...
0
2016-10-06T08:11:24Z
39,893,524
<blockquote> <p>Django 1.8.15 for project_2/. I've just checked project_1/ django version and it is 1.6. I was convinced that both projects where using the same django version.. Is this the main problem?</p> </blockquote> <p>Yes. Because django 1.6 and django 1.8 use different <code>syncdb</code> commands. <code>syn...
1
2016-10-06T10:25:06Z
[ "python", "django" ]
How to add and reverse a new column according to an id column
39,890,857
<p>This is my first question at stackoverflow and I'm pretty new in the area of programming with python.</p> <p><a href="http://i.stack.imgur.com/1bKY7.jpg" rel="nofollow">image of what I'm trying to do</a></p> <p>As you can see in the picture column "id" and "period" are given. It's a csv dataset and I want to add a...
-2
2016-10-06T08:12:39Z
39,890,911
<p>You need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.sort_values.html" rel="nofollow"><code>sort_values</code></a>:</p> <pre><code>print (df) id period 0 1 1 1 1 2 2 1 3 3 2 1 4 2 2 5 2 3 6 3 1 7 3 2 8 3 ...
1
2016-10-06T08:16:04Z
[ "python", "pandas", "numpy", "order", "reverse" ]
How to add and reverse a new column according to an id column
39,890,857
<p>This is my first question at stackoverflow and I'm pretty new in the area of programming with python.</p> <p><a href="http://i.stack.imgur.com/1bKY7.jpg" rel="nofollow">image of what I'm trying to do</a></p> <p>As you can see in the picture column "id" and "period" are given. It's a csv dataset and I want to add a...
-2
2016-10-06T08:12:39Z
39,891,189
<p>somthing like this:</p> <pre><code>def f(x, y): if x[0] &lt; y[0] or x[0] == y[0] and x[1] &gt; y[1]: return -1 return 1 d = [1, 2, 3, 4, 1, 2, 3, 4, 5, 6, 7, 1, 2, 3, 4] o = [1, 1, 1, 1, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3] new = zip(o, d) new.sort(f) print new # [(1, 4), (1, 3), (1, 2), (1, 1), (2, ...
1
2016-10-06T08:28:54Z
[ "python", "pandas", "numpy", "order", "reverse" ]
Skip a list of migrations in Django
39,890,923
<p>I have migrations <code>0001_something</code>, <code>0002_something</code>, <code>0003_something</code> in a third-party app and all of them are applied to the database by my own app. I simply want to skip these three migrations. One option is to run the following command</p> <p><code>python manage.py migrate &lt;t...
2
2016-10-06T08:16:40Z
39,891,657
<p>If you really want to do that.Try</p> <ul> <li><p>Add entries in <code>django_migrations</code> table like</p> <pre><code>app name applied &lt;thirdpartyname&gt; 003_something #without .py 2014-04-16 14:12:30.839899+08 #some date before now </code></pre></li> </ul>
1
2016-10-06T08:53:24Z
[ "python", "django", "django-models", "django-migrations" ]
Skip a list of migrations in Django
39,890,923
<p>I have migrations <code>0001_something</code>, <code>0002_something</code>, <code>0003_something</code> in a third-party app and all of them are applied to the database by my own app. I simply want to skip these three migrations. One option is to run the following command</p> <p><code>python manage.py migrate &lt;t...
2
2016-10-06T08:16:40Z
39,891,704
<p>The django knows about applied migrations is only through migration history table. So if there is no record about applied migration it will think that this migration is not applied. Django does not check real db state against migration files.</p>
1
2016-10-06T08:55:33Z
[ "python", "django", "django-models", "django-migrations" ]
Skip a list of migrations in Django
39,890,923
<p>I have migrations <code>0001_something</code>, <code>0002_something</code>, <code>0003_something</code> in a third-party app and all of them are applied to the database by my own app. I simply want to skip these three migrations. One option is to run the following command</p> <p><code>python manage.py migrate &lt;t...
2
2016-10-06T08:16:40Z
39,893,239
<p>The <a href="https://docs.djangoproject.com/en/1.10/ref/settings/#migration-modules" rel="nofollow"><code>MIGRATION_MODULES</code></a> setting lets you specify an alternative module for an app's migrations. You could set this for your app, then leave out the migrations you wish to skip, or replace them with empty mi...
1
2016-10-06T10:11:12Z
[ "python", "django", "django-models", "django-migrations" ]
Replace special characters with words in python
39,890,943
<p>For the following string:</p> <p><code>s = The \r\n sun shines, that's fine [latex]not\r\nt for \r\n everyone[/latex] and if it rains, \r\nit Will Be better.</code>.</p> <p>If I want to replace <code>\n\r</code> by <code>' '</code> between <code>[latex]</code> and <code>[/latex]</code>, I can use:</p> <pre><code>...
2
2016-10-06T08:17:26Z
39,891,068
<p>The problem is due to presence of <code>]</code> before <code>[/latex]</code> in second input. Also better to use raw strings for your input and regex.</p> <p>You can use this regex for search:</p> <pre><code>\[latex\].*?\[/latex\] </code></pre> <p><a href="https://regex101.com/r/DXv0ep/2" rel="nofollow">RegEx De...
1
2016-10-06T08:23:17Z
[ "python", "regex" ]
NameError: name 'self' is not defined" when using inside with statement
39,890,999
<p>Can someone help me about using 'self' inside 'with'. Code below throws "NameError: name 'self' is not defined".</p> <pre><code>class Versions: def __init__(self): self.module_a = '1.0.0' self.module_b = '1.0.0' if os.path.exists('config.json'): with open('config.json') as...
1
2016-10-06T08:20:07Z
39,891,331
<p>please check Your indentation - if You mix spaces and tabs, this can happen; use $python -tt to verify. Your code snippet works fine for me.</p>
2
2016-10-06T08:36:51Z
[ "python", "class", "nameerror", "contextmanager" ]
Python directory conflicts with python executable location
39,891,023
<p>I have a python executable I wish to run from PowerShell using the command <code>python [executable].py</code>.</p> <p>First I changed the directory in PowerShell to the location of the executable using <code>cd path\to\my\directory</code> which worked fine. However whenever I tried to use python to execute my code...
-1
2016-10-06T08:21:20Z
39,893,553
<p>If you want to run <code>python.exe</code> from a location other than the installation directory you'd call it with its full path:</p> <pre><code>&amp; 'C:\path\to\python.exe' 'your.py' </code></pre> <p>If you want to run it from the current directory, prepend the filename with the relative path <code>.\</code>:</...
0
2016-10-06T10:26:16Z
[ "python", "python-3.x", "powershell", "directory" ]
Loading data from text file from only a part of the file name
39,891,035
<p>I have a lot of data in different text files. Each file name contains a word that is chosen by me, but they also include a lot of "gibberish". So for example I have a text file called <code>datapoints-(my chosen name)-12iu8w9e8v09wr-140-ad92-dw9</code></p> <p>So the <code>datapoints</code> string is in all text fil...
-1
2016-10-06T08:21:57Z
39,891,316
<p>this returns a list of all your files using the <a href="https://docs.python.org/2/library/glob.html" rel="nofollow">glob module</a></p> <pre><code>import glob your_words = ['word1', 'word2'] files = [] # find files matching 'datapoint-your words-*.txt' for word in your_words: # The * is a wildcard, your words ...
2
2016-10-06T08:35:46Z
[ "python" ]
Django 1.10 shows a square bracket in display of the form
39,891,074
<p>I'm quite new to django and i'm now creating my forms for uploading data in the database. I'm using django 1.10 and python 2.7</p> <p>I have a upload.html in my templates. And then i </p> <pre><code>&lt;div class="form"&gt;] &lt;form method="post" action="{% url 'upload' %}" enctype=multipart/form-data &gt; ...
0
2016-10-06T08:23:34Z
39,891,119
<p>Its not your form, its your html. Theres a square bracket lurking somewhere in there:</p> <pre><code>&lt;div class="form"&gt;] # ^ </code></pre>
1
2016-10-06T08:25:16Z
[ "python", "django", "django-forms" ]
Split string > list of sublists of words and characters
39,891,137
<p>No imports allowed (it's a school assignment).</p> <p>Wish to split a random string into a list of sublists. Words in a sublist, all other characters (including whitespace) would be in a sublist containing only one item. Anyone have some advice on how to do this;</p> <pre><code>part = "Hi! Goodmorning, I'm fine." ...
-4
2016-10-06T08:26:14Z
39,891,364
<p>Use this :</p> <pre><code>list1 = [] part = "Hi! Goodmorning, I'm fine." part = part.split() num=part.count(" ") for i in range(num+1): for item in part: list2 = [] for i in item: list2.append(i) list1.append(list2) list1.append(['_']) print list1 </code></pre>
0
2016-10-06T08:38:25Z
[ "python", "python-2.7" ]
Split string > list of sublists of words and characters
39,891,137
<p>No imports allowed (it's a school assignment).</p> <p>Wish to split a random string into a list of sublists. Words in a sublist, all other characters (including whitespace) would be in a sublist containing only one item. Anyone have some advice on how to do this;</p> <pre><code>part = "Hi! Goodmorning, I'm fine." ...
-4
2016-10-06T08:26:14Z
39,891,600
<p>This does the trick:</p> <pre><code>globalList = [] letters = "abcdefghijklmnopqrstuvwxyz" message = "Hi! Goodmorning, I'm fine." sublist = [] for char in message: #if the character is in the list of letters, append it to the current substring if char.lower() in letters: sublist.append(char) els...
0
2016-10-06T08:50:26Z
[ "python", "python-2.7" ]
Split string > list of sublists of words and characters
39,891,137
<p>No imports allowed (it's a school assignment).</p> <p>Wish to split a random string into a list of sublists. Words in a sublist, all other characters (including whitespace) would be in a sublist containing only one item. Anyone have some advice on how to do this;</p> <pre><code>part = "Hi! Goodmorning, I'm fine." ...
-4
2016-10-06T08:26:14Z
39,892,424
<p>Try this out :</p> <pre><code>part = "Hi! Goodmorning, I'm fine." n = part.count(" ") part = part.split() k = 0 # Add spaces to the list for i in range(1,n+1): part.insert(i+k, "_") k += 1 new = [] # list to return for s in part: new.append([letter for letter in s]) </code></pre>
0
2016-10-06T09:31:37Z
[ "python", "python-2.7" ]
Split string > list of sublists of words and characters
39,891,137
<p>No imports allowed (it's a school assignment).</p> <p>Wish to split a random string into a list of sublists. Words in a sublist, all other characters (including whitespace) would be in a sublist containing only one item. Anyone have some advice on how to do this;</p> <pre><code>part = "Hi! Goodmorning, I'm fine." ...
-4
2016-10-06T08:26:14Z
39,893,456
<pre><code>part = "Hi! Goodmorning, I'm fine." a = [] b = [] c = 0 for i in part: if i.isalpha(): if c == 1: a.append(b) b=[] b.append(i) c = 0 else: b.append(i) else: a.append(b) b=[] b.append(i) c = 1 a...
0
2016-10-06T10:21:30Z
[ "python", "python-2.7" ]
Merge two dictionaries
39,891,195
<p>I have something like this: </p> <pre><code>Dict1 = {'a': "blabla", 'b': "gugu"} Dict2 = {'a': "tadaa", 'b': "duduu"} </code></pre> <p>what I want to have is:</p> <pre><code>Dict3 = {'tadaa': "blabla", 'duduu': "gugu"} </code></pre>
-3
2016-10-06T08:29:06Z
39,891,294
<p>Would something like this work?</p> <pre><code>Dict3 = dict(zip(Dict2.values(), Dict1.values())) </code></pre>
-2
2016-10-06T08:34:29Z
[ "python", "python-2.7", "python-3.x" ]
Merge two dictionaries
39,891,195
<p>I have something like this: </p> <pre><code>Dict1 = {'a': "blabla", 'b': "gugu"} Dict2 = {'a': "tadaa", 'b': "duduu"} </code></pre> <p>what I want to have is:</p> <pre><code>Dict3 = {'tadaa': "blabla", 'duduu': "gugu"} </code></pre>
-3
2016-10-06T08:29:06Z
39,891,336
<p>Iterate over one dictionary's keys and values, use the value as key in a new dictionary and use the key to pull the associated value out of the second dictionary. In <a href="https://docs.python.org/3.6/tutorial/datastructures.html#dictionaries" rel="nofollow">a single expression</a>:</p> <pre><code>&gt;&gt;&gt; Di...
3
2016-10-06T08:37:00Z
[ "python", "python-2.7", "python-3.x" ]
Merge two dictionaries
39,891,195
<p>I have something like this: </p> <pre><code>Dict1 = {'a': "blabla", 'b': "gugu"} Dict2 = {'a': "tadaa", 'b': "duduu"} </code></pre> <p>what I want to have is:</p> <pre><code>Dict3 = {'tadaa': "blabla", 'duduu': "gugu"} </code></pre>
-3
2016-10-06T08:29:06Z
39,891,476
<p>To some extent, this depends on what the edge cases are, and what you want to do about them (for example, what if the keys in <code>Dict1</code> and <code>Dict2</code> can be different?</p> <p>Here's a solution that discards keys which only occur in one of the two dicts:</p> <pre><code>&gt;&gt;&gt; Dict1 = {'a': "...
1
2016-10-06T08:43:54Z
[ "python", "python-2.7", "python-3.x" ]
How to send raw string to a dotmatrix printer using python in ubuntu?
39,891,202
<p>I have a dot-matrix printer LX-300 connected to my computer through the network. How do I send a raw string with ESCP characters directly to my printer in Python?</p> <p>The computer is connected to the printer through another computer. I need to send a raw string because LX-300 image printing result is blurry.</p>...
5
2016-10-06T08:29:28Z
40,046,832
<p>Ultimately, you will need and want to write your own wrapper/script to do this. And since you are using a distribution of Linux, this is relatively easy.</p> <p>On a Linux OS, the simplest way to issue a print job is to open a <a href="http://docs.python.org/3/library/subprocess.html" rel="nofollow" title="subproce...
2
2016-10-14T15:27:37Z
[ "python", "epson", "dot-matrix", "escpos" ]
How to send raw string to a dotmatrix printer using python in ubuntu?
39,891,202
<p>I have a dot-matrix printer LX-300 connected to my computer through the network. How do I send a raw string with ESCP characters directly to my printer in Python?</p> <p>The computer is connected to the printer through another computer. I need to send a raw string because LX-300 image printing result is blurry.</p>...
5
2016-10-06T08:29:28Z
40,047,237
<h2>The Problem</h2> <p>To send data down this route:</p> <p>Client computer ---> Server (Windows machine) ---> printer (dot-matrix)</p> <p>...and to <em>not</em> let Windows mess with the data; instead to send the raw data, including printer control codes, straight from the client computer.</p> <h2>My Solution</h2...
3
2016-10-14T15:47:44Z
[ "python", "epson", "dot-matrix", "escpos" ]
unable to fetch json attribute in POST request
39,891,234
<p>This Json is received as a POST request. Now I want to get value of <code>text</code> key of each entry in <code>actions</code> array</p> <p>I am using Python's Bottle to receive the request. to fetch the value of required attribute, I did this</p> <pre><code>word = request.forms.get('[attachments][actions][0][tex...
0
2016-10-06T08:31:01Z
39,891,319
<p>That's not how you access items in a dictionary at all.</p> <p>Firstly, the JSON data is available via <code>request.json</code>. Secondly, I'm not sure what you're doing with that string you're passing to get, but you need to use normal dictionary/array syntax. And thirdly, attachments is a list just like actions,...
3
2016-10-06T08:36:14Z
[ "python", "json", "post", "bottle" ]
Better way convert json to SQLAlchemy object
39,891,387
<p>These days I am learning SQLAlchemy. When I want to load an object from json and save it to MySQL, things get difficult because the fields in my model are more that 20 and I wonder whether there're better ways to do this.</p> <p>My original code follows as an example:</p> <pre><code>class User(Base): __tablena...
-1
2016-10-06T08:39:41Z
39,891,537
<p>If you have in your json file only fields that you can initialize your <code>User</code> from. Then you simply can do.</p> <pre><code>user = User(**obj) </code></pre> <p><code>**obj</code> will unpack your <code>dict</code> object, so if have <code>obj = {'id': 1, 'name': 'Awesome'}</code>, <code>User(**obj)</code...
-1
2016-10-06T08:47:21Z
[ "python", "json", "sqlalchemy" ]
How can I simplify my code in an efficient way?
39,891,501
<p>so currently im stuck on a question of my assignment, the assignment question is: Define the print_most_frequent() function which is passed two parameters, a dictionary containing words and their corresponding frequencies (how many times they occurred in a string of text), e.g.,</p> <pre><code>{"fish":9, "parrot":...
0
2016-10-06T08:45:29Z
39,891,801
<p>You can use:</p> <pre><code>def print_most_frequent(words_dict, word_len): max_freq = 0 words = list() for word, frequency in words_dict.items(): if len(word) == word_len: if frequency &gt; max_freq: max_freq = frequency words = [word] elif...
0
2016-10-06T08:59:55Z
[ "python", "list", "dictionary" ]
How can I simplify my code in an efficient way?
39,891,501
<p>so currently im stuck on a question of my assignment, the assignment question is: Define the print_most_frequent() function which is passed two parameters, a dictionary containing words and their corresponding frequencies (how many times they occurred in a string of text), e.g.,</p> <pre><code>{"fish":9, "parrot":...
0
2016-10-06T08:45:29Z
39,891,998
<p>One way you can do is to map the values as keys and vice-versa, this way you can easily get the most frequent words:</p> <pre><code>a = {"fish":9, "parrot":8, "frog":9, "cat":9, "stork":1, "dog":4, "bat":9, "rat":4} getfunc = lambda x, dct: [i for i in dct if dct[i] == x] new_dict = { k : getfunc(k, a) for k...
0
2016-10-06T09:10:17Z
[ "python", "list", "dictionary" ]
Python - How to move the file after complete writing
39,891,584
<p>How to set python to move the file after complete writing in the server ?</p> <p>Below is my same to lock the file after complete writing, but it does'nt work in Linux server.</p> <pre><code>try: fcntl.lockf(file2,fcntl.LOCK_EX|fcntl.LOCK_NB) print "Yes Locked" time.sleep(20) except: print "No Lock" ...
0
2016-10-06T08:49:40Z
39,909,206
<p>You could use the os.rename method:</p> <pre><code>import os os.rename('oldPath/Name', 'newPath/Name') </code></pre> <p>Check out this answer for additional info: <a href="http://stackoverflow.com/questions/8858008/how-to-move-a-file-in-python">How to move a file in Python</a></p>
0
2016-10-07T04:06:19Z
[ "python", "linux" ]
List comprehension including elements of different sizes
39,891,632
<p>I have the following <code>for/if-elif-else</code> loop which extracts department information from tuples <code>t</code> in a list, based on the size of <code>t[0]</code>:</p> <pre><code>for t in filt: if len(t[0]) == 1: pass elif len(t[0]) == 2: if 'organization' in t[0][0]['affiliation']: ...
0
2016-10-06T08:52:05Z
39,892,617
<p>Turns out the following line of code will work, checking the index against the size of the list in question and using if else in the list comprehension:</p> <pre><code>depB = [t[0][1]['affiliation']['organization'] if 2&lt;=len(t[0]) and 'organization' in t[0][1]['affiliation'] else 'Not Available' for t in filt] <...
0
2016-10-06T09:41:06Z
[ "python" ]
Python usage of regular expressions
39,891,640
<p>How can I extract <em>string1#string2</em> from the bellow line?</p> <pre><code>&lt;![CDATA[&lt;html&gt;&lt;body&gt;&lt;p style="margin:0;"&gt;string1#string2&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;]]&gt; </code></pre> <p>The # character and the structure of the line is always the same.</p>
-1
2016-10-06T08:52:22Z
39,891,685
<p>I would like to refer you to this <a href="http://stackoverflow.com/questions/1732348/regex-match-open-tags-except-xhtml-self-contained-tags">gem</a>:</p> <p>In synthesis a regex is not the appropriate tool for this job<br> Also have you tried an <a href="https://docs.python.org/3/library/xml.etree.elementtree.html...
1
2016-10-06T08:54:35Z
[ "python", "regex" ]
Python usage of regular expressions
39,891,640
<p>How can I extract <em>string1#string2</em> from the bellow line?</p> <pre><code>&lt;![CDATA[&lt;html&gt;&lt;body&gt;&lt;p style="margin:0;"&gt;string1#string2&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;]]&gt; </code></pre> <p>The # character and the structure of the line is always the same.</p>
-1
2016-10-06T08:52:22Z
39,891,707
<p>Simple, buggy, not reliable:</p> <pre><code>line.replace('&lt;![CDATA[&lt;html&gt;&lt;body&gt;&lt;p style="margin:0;"&gt;', "").replace('&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;]]&gt;', "").split("#") </code></pre>
1
2016-10-06T08:55:42Z
[ "python", "regex" ]
Python usage of regular expressions
39,891,640
<p>How can I extract <em>string1#string2</em> from the bellow line?</p> <pre><code>&lt;![CDATA[&lt;html&gt;&lt;body&gt;&lt;p style="margin:0;"&gt;string1#string2&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;]]&gt; </code></pre> <p>The # character and the structure of the line is always the same.</p>
-1
2016-10-06T08:52:22Z
39,891,807
<p>If you wish to use a regex:</p> <pre><code>&gt;&gt;&gt; re.search(r"&lt;p.*?&gt;(.+?)&lt;/p&gt;", txt).group(1) 'string1#string2' </code></pre>
0
2016-10-06T09:00:13Z
[ "python", "regex" ]
Python usage of regular expressions
39,891,640
<p>How can I extract <em>string1#string2</em> from the bellow line?</p> <pre><code>&lt;![CDATA[&lt;html&gt;&lt;body&gt;&lt;p style="margin:0;"&gt;string1#string2&lt;/p&gt;&lt;/body&gt;&lt;/html&gt;]]&gt; </code></pre> <p>The # character and the structure of the line is always the same.</p>
-1
2016-10-06T08:52:22Z
39,892,048
<pre><code>re.search(r'[^&gt;]+#[^&lt;]+',s).group() </code></pre>
1
2016-10-06T09:12:54Z
[ "python", "regex" ]
wxpython treectrl show bitmap picture on hover
39,891,681
<p>So i'm programming python program that uses wxPython for UI, with wx.TreeCtrl widget for selecting pictures(.png) on selected directory. I would like to add hover on treectrl item that works like tooltip, but instead of text it shows bitmap picture.</p> <p>Is there something that already allows this, or would i hav...
0
2016-10-06T08:54:28Z
39,901,257
<p>Take a look at the <code>wx.lib.agw.supertooltip</code> module. It should help you to create a tooltip-like window that displays custom rich content.</p> <p>As for triggering the display of the tooltip, you can catch mouse events for the tree widget (be sure to call <code>Skip</code> so the tree widget can see the ...
1
2016-10-06T16:31:04Z
[ "python", "bitmap", "wxpython" ]
How to add outer tag to BeautifulSoup object
39,891,983
<p>I am trying to replace the content of an iframe a BeautifulSoup object. Let say this</p> <pre><code> s=""" &lt;!DOCTYPE html&gt; &lt;html&gt; &lt;body&gt; &lt;iframe src="http://www.w3schools.com"&gt; &lt;p&gt;Your browser does not support iframes.&lt;/p&gt; &lt;/iframe&gt; &lt;/body&gt; &lt;/h...
2
2016-10-06T09:09:15Z
39,892,989
<p><a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/#extract" rel="nofollow"><em>extract</em></a> the content then <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/#insert" rel="nofollow">insert</a>:</p> <pre><code>from bs4 import BeautifulSoup dom = BeautifulSoup(s, 'html.parser') f = dom...
2
2016-10-06T09:59:14Z
[ "python", "html", "iframe", "beautifulsoup" ]
Append and delete elements from a list using property
39,891,988
<p>In my base class is <em>_mylist</em> defined as a <em>list</em></p> <pre><code>class Foo(object): def __init__(self): self._mylist = list() @property def mylist(self): return self._mylist @mylist.setter def mylist(self, value): self._mylist = value </code></pre> <p>In...
0
2016-10-06T09:09:33Z
39,892,120
<p>Try something like this:</p> <pre><code>@property def del_element(self, value): self._mylist.remove(value) @property def add_element(self,value): self._mylist.append(value) </code></pre>
-2
2016-10-06T09:16:10Z
[ "python", "python-3.x" ]
Append and delete elements from a list using property
39,891,988
<p>In my base class is <em>_mylist</em> defined as a <em>list</em></p> <pre><code>class Foo(object): def __init__(self): self._mylist = list() @property def mylist(self): return self._mylist @mylist.setter def mylist(self, value): self._mylist = value </code></pre> <p>In...
0
2016-10-06T09:09:33Z
39,892,355
<p>Why must change the semantics of setter?</p> <p>What if just manipulating the list using list's method.</p> <pre><code>class Foo(object): def __init__(self): self._mylist = list() @property def mylist(self): return self._mylist @mylist.setter def mylist(self, value): ...
1
2016-10-06T09:28:13Z
[ "python", "python-3.x" ]
Python3 - Download file from google docs private and public url
39,892,017
<p>I want to download files from google docs urls. I want it to know how to authenticate to google to download private files also. I found this <a href="https://github.com/uid/gdoc-downloader" rel="nofollow">github project</a> and it is very old, The authentication doesn't work, i can only download public files. Using ...
0
2016-10-06T09:11:41Z
39,912,030
<p>The user has to authenticate the app, which will most likely call a browser which will bring up the user consent screen. You can use the official <a href="https://developers.google.com/drive/v3/web/quickstart/python" rel="nofollow">Python Quickstart</a> to handle this.</p> <p>As for downloading the docs, the docume...
2
2016-10-07T07:43:41Z
[ "python", "python-3.x", "google-docs", "google-docs-api" ]
How to merge to two pandas data frames?
39,892,028
<p>I have two pandas data frames (see below).I want to merge them based on the id (Dataframe1) and localid(Dataframe2). This code is not working; it creates additional rows in dfmerged as Dataframe2 may contains multiple same localid(e.g., D3). How can I merge these two dataframes and set the value of the 'color' colum...
1
2016-10-06T09:12:19Z
39,892,174
<p>I think you need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html" rel="nofollow"><code>groupby</code></a> and <code>sum</code> values in <code>list</code> in <code>df2</code> and then use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.merge.html" re...
2
2016-10-06T09:19:09Z
[ "python", "pandas", "merge" ]
How to merge to two pandas data frames?
39,892,028
<p>I have two pandas data frames (see below).I want to merge them based on the id (Dataframe1) and localid(Dataframe2). This code is not working; it creates additional rows in dfmerged as Dataframe2 may contains multiple same localid(e.g., D3). How can I merge these two dataframes and set the value of the 'color' colum...
1
2016-10-06T09:12:19Z
39,892,509
<p>You should probably simplify <code>df2</code> to <strong>have no repeating keys</strong>, and then tell <code>pd.merge</code> to use <a href="http://pandas.pydata.org/pandas-docs/stable/merging.html#brief-primer-on-merge-methods-relational-algebra" rel="nofollow">union of keys from both frames</a> (with <code>how:'o...
0
2016-10-06T09:36:04Z
[ "python", "pandas", "merge" ]
Python 3.4 does not read more than one line from a text file
39,892,150
<p>I am writing a python(3.4) code which uses a basic authentication. I have stored the credentials i.e the username &amp; password in a text file(abc.txt).<br> Whenever I login, the code accepts only the first line of the text file &amp; ignores the rest of the credentials and gives incorrect credentials error.</p> <...
1
2016-10-06T09:17:50Z
39,892,390
<p>That is happening because you are only checking the first line. Currently the user can only enter credentials that match the first line in the text file, otherwise the program will exit. You should create a dictionary with the username and password and then check if a username is in that dictionary instead of iterat...
1
2016-10-06T09:29:53Z
[ "python", "python-3.4" ]
Regular expression to find string with iterating letters on the end
39,892,170
<p>Can someone help me with this kind of regular expression matching?</p> <p>For example, I'm searching through list containing different strings with a letter iterating at the end of the string:</p> <ul> <li>MonsterA</li> <li>MonsterB</li> <li>MonsterC</li> <li>HeroA</li> <li>HeroB</li> <li>HeroC</li> <li>...</li> <...
-1
2016-10-06T09:19:01Z
39,892,360
<p>If you absolutely need a regex:</p> <pre><code>re.match(r"(.*)[A-Z]", word).group(1) </code></pre> <p>But it is not the most efficient if you just want to remove the last character.</p>
0
2016-10-06T09:28:27Z
[ "python", "regex", "string", "loops", "iterator" ]
Regular expression to find string with iterating letters on the end
39,892,170
<p>Can someone help me with this kind of regular expression matching?</p> <p>For example, I'm searching through list containing different strings with a letter iterating at the end of the string:</p> <ul> <li>MonsterA</li> <li>MonsterB</li> <li>MonsterC</li> <li>HeroA</li> <li>HeroB</li> <li>HeroC</li> <li>...</li> <...
-1
2016-10-06T09:19:01Z
39,892,528
<p>You could use a <em>positive lookahead assertion</em> <code>(?=...)</code> to check the words ends in a single uppercase character and then use word boudaries <code>\b...\b</code> to ensure it does not match patterns that arent whole words:</p> <pre><code>&gt;&gt;&gt; text = "This re will match MonsterA and HeroB b...
0
2016-10-06T09:36:49Z
[ "python", "regex", "string", "loops", "iterator" ]
Python: How to make a string to a list using a substring?
39,892,262
<p>For example I have a string like this...</p> <pre><code>StringA = "a city a street a room a bed" </code></pre> <p>I want to cut this string using a substring <code>"a "</code> and make a <code>list</code> from it. So the result looks like...</p> <pre><code>ListA = ["city ", "street " ,"room " ,"bed"] </code></pre...
0
2016-10-06T09:24:22Z
39,892,302
<p>You can use <code>split</code>:</p> <pre><code>list_a = string_a.split('a ') </code></pre>
1
2016-10-06T09:25:55Z
[ "python" ]
Python: How to make a string to a list using a substring?
39,892,262
<p>For example I have a string like this...</p> <pre><code>StringA = "a city a street a room a bed" </code></pre> <p>I want to cut this string using a substring <code>"a "</code> and make a <code>list</code> from it. So the result looks like...</p> <pre><code>ListA = ["city ", "street " ,"room " ,"bed"] </code></pre...
0
2016-10-06T09:24:22Z
39,892,361
<p>You can do it in one line:</p> <pre><code>filter(len, "a city a street a room a bed".split("a ")) </code></pre>
1
2016-10-06T09:28:28Z
[ "python" ]
Python: How to make a string to a list using a substring?
39,892,262
<p>For example I have a string like this...</p> <pre><code>StringA = "a city a street a room a bed" </code></pre> <p>I want to cut this string using a substring <code>"a "</code> and make a <code>list</code> from it. So the result looks like...</p> <pre><code>ListA = ["city ", "street " ,"room " ,"bed"] </code></pre...
0
2016-10-06T09:24:22Z
39,892,440
<p>This should also work:</p> <pre><code>ListA = StringA.split("a ")[1:] </code></pre> <p>The [1:] after the split statement has been added because the part before the first 'a' (which is '') will be treated as the first element of ListA and you don't want that.</p> <p>Your output will look exactly like the one you...
1
2016-10-06T09:32:10Z
[ "python" ]
Python: How to make a string to a list using a substring?
39,892,262
<p>For example I have a string like this...</p> <pre><code>StringA = "a city a street a room a bed" </code></pre> <p>I want to cut this string using a substring <code>"a "</code> and make a <code>list</code> from it. So the result looks like...</p> <pre><code>ListA = ["city ", "street " ,"room " ,"bed"] </code></pre...
0
2016-10-06T09:24:22Z
39,892,819
<p>This will make list from string:</p> <pre><code>re.split(r'\s*\ba\b\s*', a) </code></pre> <p>Output should be something like this:</p> <pre><code>['', 'city', 'cola', 'room', 'bed'] </code></pre> <p>So, to remove empty strings from list You can use:</p> <pre><code>[item for item in re.split(r'\s*\ba\b\s*', a) i...
0
2016-10-06T09:51:18Z
[ "python" ]
Variable and parameter in a method
39,892,270
<p>I am new to Python and I have an issue with it when I am creating a function:</p> <p>I created a dictionary where the keys are parameters like <code>n_estimators</code>, <code>C</code>, <code>max_depths</code> for instance.</p> <p>I have a loop where I would like to set the parameters for a given estimator (which ...
0
2016-10-06T09:24:44Z
39,892,340
<p>Use a dict with the <code>**</code> operator:</p> <pre><code>key = 'n_estimators' estimator = estimator.set_params(**{key: 100}) </code></pre>
0
2016-10-06T09:27:37Z
[ "python", "machine-learning" ]
Variable and parameter in a method
39,892,270
<p>I am new to Python and I have an issue with it when I am creating a function:</p> <p>I created a dictionary where the keys are parameters like <code>n_estimators</code>, <code>C</code>, <code>max_depths</code> for instance.</p> <p>I have a loop where I would like to set the parameters for a given estimator (which ...
0
2016-10-06T09:24:44Z
39,892,384
<p>or you know, just </p> <pre><code>estimator.set_params(n_estimators=100) </code></pre>
0
2016-10-06T09:29:45Z
[ "python", "machine-learning" ]
Variable and parameter in a method
39,892,270
<p>I am new to Python and I have an issue with it when I am creating a function:</p> <p>I created a dictionary where the keys are parameters like <code>n_estimators</code>, <code>C</code>, <code>max_depths</code> for instance.</p> <p>I have a loop where I would like to set the parameters for a given estimator (which ...
0
2016-10-06T09:24:44Z
39,913,780
<p>You could consider using <code>GridSearchCV</code> to evaluate a model over multiple hyperparameter values, and for different hyperparameters.</p>
0
2016-10-07T09:21:27Z
[ "python", "machine-learning" ]
Twisted - Twistar calling lastval() causing psycopg2 error
39,892,296
<p>At the end of an insertion query, twistar calls lastval() and causes the postgres driver to fail.</p> <pre><code>2016-10-06 11:08:02+0200 [-] Log opened. 2016-10-06 11:08:02+0200 [-] MAIN: Starting the reactor 2016-10-06 11:08:02+0200 [-] TWISTAR query: SELECT * FROM my_user WHERE user_id = %s LIMIT 1 2016-10-06 11...
0
2016-10-06T09:25:41Z
39,897,567
<p>If somebody else has the same problem here's how the developer solved to me: </p> <blockquote> <p>I think the issue is that you're explicitly setting the id column. Twistar is designed to use autoincrementing id values at the DB level (in the case of Postgres, this would be a SERIAL PRIMARY KEY column type), whic...
0
2016-10-06T13:37:01Z
[ "python", "postgresql", "twisted.web" ]
Python pandas: Find a value in another dataframe and replace it
39,892,399
<p>I have two dataframes df_l (with 3000 rows) and df_s(with 100 rows) : df_l</p> <pre><code>version|update_date 2.3.4| date1 3.4.5|date2 </code></pre> <p>and df_s</p> <pre><code>version|release_date 2.3.4| date1 3.4.5|date2 3.3.3|date3 </code></pre> <p>I want to check if a version in df_l is in df_s, t...
2
2016-10-06T09:30:19Z
39,892,478
<p>IIUC you need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.merge.html" rel="nofollow"><code>merge</code></a> with inner join <code>how='inner'</code> which is by default. Also you can omit <code>on</code> if in both <code>DataFrames</code> are only 2 columns and one of them is same in both:<...
1
2016-10-06T09:34:14Z
[ "python", "string", "pandas", "matching" ]
Obtain the difference between two files
39,892,460
<p><em>First of all, i searched on the web and stackoverflow for around 3 days and haven't found anything i've been looking for.</em></p> <p>I am doing a weekly security audit where i get back a .csv file with the IPs and the open ports. They look like this:</p> <p><strong>20160929.csv</strong></p> <pre><code>10.4.0...
4
2016-10-06T09:33:21Z
39,893,259
<p>Using your code as a base, you could do the following:</p> <pre><code>old = set((line.strip() for line in open('1.txt'))) new = set((line.strip() for line in open('2.txt'))) with open('diff.txt', 'w') as diff: for line in new: if line not in old: diff.write('[-] {}\n'.format(line)) for...
1
2016-10-06T10:12:17Z
[ "python", "python-2.7", "csv", "difference", "differentiation" ]
Obtain the difference between two files
39,892,460
<p><em>First of all, i searched on the web and stackoverflow for around 3 days and haven't found anything i've been looking for.</em></p> <p>I am doing a weekly security audit where i get back a .csv file with the IPs and the open ports. They look like this:</p> <p><strong>20160929.csv</strong></p> <pre><code>10.4.0...
4
2016-10-06T09:33:21Z
39,893,267
<p>You can try this one:</p> <pre><code>old_f = open('1.txt') new_f = open('2.txt') diff = open('diff.txt', 'w') old = [line.strip() for line in old_f] new = [line.strip() for line in new_f] for line in old: if line not in new: print '[-] ' + str(line) diff.write('[-] ' + str(line) + '\n' for l...
0
2016-10-06T10:12:46Z
[ "python", "python-2.7", "csv", "difference", "differentiation" ]
Obtain the difference between two files
39,892,460
<p><em>First of all, i searched on the web and stackoverflow for around 3 days and haven't found anything i've been looking for.</em></p> <p>I am doing a weekly security audit where i get back a .csv file with the IPs and the open ports. They look like this:</p> <p><strong>20160929.csv</strong></p> <pre><code>10.4.0...
4
2016-10-06T09:33:21Z
39,893,322
<p>In the following solution I've used sets, so the order doesn't matter and we can do direct subtraction with the old and new to see what has changed.</p> <p>I've also used the <code>with</code> context manager pattern for opening files, which is a neat way of ensuring they are closed again.</p> <pre><code>def read_...
3
2016-10-06T10:14:50Z
[ "python", "python-2.7", "csv", "difference", "differentiation" ]
csv writer expected byte like and space between rows
39,892,463
<p>I'm trying to combine several CSV files into one. But I'm getting a space between each row.</p> <p>I read somewhere I had to change w to wb in <code>filewriter = csv.writer(open("output.csv", "w"))</code></p> <p>but this gives me the following error:</p> <pre class="lang-none prettyprint-override"><code>Traceback...
0
2016-10-06T09:33:44Z
39,892,543
<p>Your method works in Python 2.</p> <p>But in python 3 you cannot open a text file in binary mode or the write method will expect bytes.</p> <p>A correct way of doing it in python 3 (with, added the <code>with</code> statement that ensures that the file is closed when exiting the <code>with</code> block):</p> <pre...
2
2016-10-06T09:37:41Z
[ "python", "python-3.x", "csv" ]
Fail to transfer the list in data frame to numpy array with python-pandas
39,892,464
<p>For a data frame <code>df</code>:</p> <pre><code>name list1 list2 a [1, 3, 10, 12, 20..] [2, 6, 23, 29...] b [2, 10, 14, 3] [4, 7, 8, 13...] c [] [98, 101, 200] ... </code></pre> <p>I want to transfer the <code>list1</code> and...
1
2016-10-06T09:33:45Z
39,894,100
<p>Your apply function is <em>almost</em> correct. All you have to do - convert the output of the <code>np.hstack()</code> function back to a python list.</p> <pre><code>df.apply(lambda row: list(np.hstack((np.asarray(row.list1), np.asarray(row.list2)))), axis=1) </code></pre> <p>The code is shown below (including th...
1
2016-10-06T10:54:11Z
[ "python", "pandas", "numpy" ]
multiprocessing freeze computer
39,892,551
<p>I improved my execution time by using multiprocessing but I am not sure whether the behavior of the PC is correct, it freezes the system until all processes are done. I am using Windows 7 and Python 2.7.</p> <p>Perhaps I am doing a mistake, here is what I did:</p> <pre><code>def do_big_calculation(sub_list, b, c)...
2
2016-10-06T09:37:58Z
39,896,352
<p>Here, you are creating 1 <code>Process</code> per task. This is will run all your tasks in parallel but it imposes an heavy overhead on your computer as your scheduler will need to manage many processes. This can cause a system freeze as too many ressources are used for your program. </p> <p>A solution here could ...
2
2016-10-06T12:43:49Z
[ "python", "windows", "python-multiprocessing" ]
Feather install error with pip3
39,892,605
<p>Hey everyone while I am trying to <code>pip3 install feather</code> this error popup on the screen.</p> <pre><code>During handling of the above exception, another exception occurred: Traceback (most recent call last): File "&lt;string&gt;", line 1, in &lt;module&gt; File "/tmp/pip-build-mijuoz_z/fe...
0
2016-10-06T09:40:20Z
39,893,511
<p>There seem to be this big bad error shown underneath it.</p> <pre><code>TypeError: chown() missing 1 required positional argument: 'numeric_owner' </code></pre> <p>What are your arguments to <code>chown()</code> function? </p>
0
2016-10-06T10:24:34Z
[ "python", "numpy", "matplotlib", "scikit-learn", "feather" ]
Using pandas to scrape weather data from wundergound
39,892,710
<p>I came across a very useful set of scripts on the Shane Lynn for the <a href="http://www.shanelynn.ie/analysis-of-weather-data-using-pandas-python-and-seaborn/" rel="nofollow">Analysis of Weather data</a>. The first script, used to scrape data from Weather Underground, is as follows:</p> <pre><code>import requests ...
0
2016-10-06T09:46:06Z
39,893,297
<p>The output you are getting is because an exception is being raised. If you added a <code>print e</code> you would see that this is because <code>import io</code> was missing from the top of the script. Secondly, the station name you gave was out by one character. Try the following:</p> <pre><code>import io import r...
1
2016-10-06T10:14:07Z
[ "python", "pandas", "import", "weather-api" ]
Mocking submodules in python
39,892,746
<p>I am trying to generate autodocumentation of my project through sphinx. However, I will run the generation of the autodocs in an environment that won't have all the modules I am importing. Hence I would like to mock the import statements.</p> <p>On <a href="http://read-the-docs.readthedocs.io/en/latest/faq.html" re...
0
2016-10-06T09:47:57Z
39,892,851
<p>The import</p> <pre><code>from foo.bar import blah </code></pre> <p>will look for <code>sys.modules['foo.bar']</code>. Just insert that:</p> <pre><code>&gt;&gt;&gt; from foo.bar import blah Traceback (most recent call last): File "&lt;stdin&gt;", line 1, in &lt;module&gt; ModuleNotFoundError: No module named 'f...
1
2016-10-06T09:53:14Z
[ "python", "python-3.x", "mocking", "python-sphinx", "autodoc" ]
LSTM implementation in keras Using specific dataset
39,892,774
<p>I am trying to understand how LSTM RNNs work and how they can be implemented in Keras in order to be able to solve a binary classification problem. My code and the dataset i use are visible below. When i compilr the code i get an error <code>TypeError: __init__() got multiple values for keyword argument 'input_dim'<...
1
2016-10-06T09:49:32Z
39,893,254
<p>Looks like two separate questions here. </p> <p>Regarding how to use LSTMs / Keras, there are some good tutorials around. Try <a href="http://machinelearningmastery.com/binary-classification-tutorial-with-the-keras-deep-learning-library/" rel="nofollow">this one</a> which also describes a binary classification prob...
0
2016-10-06T10:12:04Z
[ "python", "neural-network", "theano", "keras" ]
LSTM implementation in keras Using specific dataset
39,892,774
<p>I am trying to understand how LSTM RNNs work and how they can be implemented in Keras in order to be able to solve a binary classification problem. My code and the dataset i use are visible below. When i compilr the code i get an error <code>TypeError: __init__() got multiple values for keyword argument 'input_dim'<...
1
2016-10-06T09:49:32Z
39,907,711
<p>This is in fact a case where the error message you are getting is perfectly to-the-point. (I wish this would always be the case with Python and Keras...)</p> <p>Keras' <strong>Embedding</strong> layer constructor has <a href="https://keras.io/layers/embeddings/" rel="nofollow">this signature</a>: <code> keras.layer...
0
2016-10-07T00:44:19Z
[ "python", "neural-network", "theano", "keras" ]
Embedded document filtration in mongodb
39,892,799
<p>{</p> <pre><code>"_id" : ObjectId("57f5ee94536d1a50ed3337c6"), "details" : [ { "status" : NumberLong(0), "batch_id" : null, "applied_date" : NumberLong(1470283450), "call_letter" : 72, "fid" : "3273681" }, { "status" : NumberLong(0), "batch_id" : n...
-1
2016-10-06T09:50:33Z
39,895,193
<p>Try using and aggregate query like below</p> <pre><code>db.jobs.aggregate([{"$match":{"job_id" : "92854"}}, {"$unwind":"$details"}, {"$match":{call_letter"" : "75"}}]) </code></pre> <p>Add '$project' and '$group' to the pipeline to format your output as required (use '$push' to make it ...
0
2016-10-06T11:48:01Z
[ "python" ]
How can I get around memory limitation in this script?
39,892,920
<p>I'm trying to normalize my dataset which is <code>1.7 Gigabyte</code>. I have <code>14Gig of RAM</code> and I hit my limit very quickly. </p> <p>This happens when computing the <code>mean/std</code> of the training data. The training data takes up the majority of the memory when loaded into <code>RAM(13.8Gig)</code...
3
2016-10-06T09:55:59Z
39,893,540
<p>Why not compute the statistics on a subset of the original data? For example, here we compute the mean and std for just 100 points:</p> <pre><code>sample_size = 100 data_train = np.random.rand(1000, 20, 10, 10) # Take subset of training data idxs = np.random.choice(data_train.shape[0], sample_size) data_train_subs...
0
2016-10-06T10:25:48Z
[ "python" ]
extract RGB values from linear colourmap made using LinearSegmentedColormap
39,893,017
<p>I would like to create a linear colourmap from a list of discrete colors, and extract the underlying RGB values. I've managed to do the first step using the example script in the matplotlib document.</p> <pre><code>from matplotlib import cm import numpy as np import matplotlib.pyplot as plt from matplotlib.colors i...
0
2016-10-06T10:00:50Z
39,895,534
<p>Don't know if it's available directly somewhere, or if one can ask the <code>colormap</code> to evaluate a given value (return the colour corresponding to a given number), but you can make the list yourself in this simple case:</p> <pre><code>def color_interpolation(c1, c2, fraction=0.5): return ((1.-fraction)*...
1
2016-10-06T12:05:33Z
[ "python", "matplotlib", "colormap" ]
time taken by code is an issue for python dataframe
39,893,142
<p>I need help related to dataframe related time taken by following code. it takes around 20 sec to complete dataset around 2000 records.</p> <pre><code>def findRe(leaddatadf, keyAttributes, datadf): for combs in itertools.combinations(atrList, len(atrList)-1): v_by =(set(atrList) - set(combs)) # ...
-2
2016-10-06T10:06:24Z
39,893,260
<p>please print after every line how many ms it takes</p> <p>use this <a href="http://stackoverflow.com/a/1557584/2655092">http://stackoverflow.com/a/1557584/2655092</a></p> <p>and return with the lines that takes the most time</p>
0
2016-10-06T10:12:17Z
[ "python", "python-3.x", "pandas", "dataframe" ]
time taken by code is an issue for python dataframe
39,893,142
<p>I need help related to dataframe related time taken by following code. it takes around 20 sec to complete dataset around 2000 records.</p> <pre><code>def findRe(leaddatadf, keyAttributes, datadf): for combs in itertools.combinations(atrList, len(atrList)-1): v_by =(set(atrList) - set(combs)) # ...
-2
2016-10-06T10:06:24Z
39,896,337
<p>You're using <code>astype(float)</code> very often. Every time you use it - a copy of the series is created. You could try to set <code>dtype=float</code> at the very beginning when you're trying to load the dataframe - that way you're only converting the series to float once - and not on every iteration :)</p> <p>...
0
2016-10-06T12:42:57Z
[ "python", "python-3.x", "pandas", "dataframe" ]
How to calculate count and percentage in groupby in Python
39,893,148
<p>I have following output after grouping by</p> <pre><code>Publisher.groupby('Category')['Title'].count() Category Coding 5 Hacking 7 Java 1 JavaScript 5 LEGO 43 Linux 7 Networking 5 Others 123 Python 8 R 2 Ruby 4 Scrip...
0
2016-10-06T10:06:37Z
39,893,317
<p>I think you can use:</p> <pre><code>P = Publisher.groupby('Category')['Title'].count().reset_index() P['Percentage'] = 100 * P['Title'] / P['Title'].sum() </code></pre> <p>Sample:</p> <pre><code>Publisher = pd.DataFrame({'Category':['a','a','s'], 'Title':[4,5,6]}) print (Publisher) Category...
1
2016-10-06T10:14:42Z
[ "python", "pandas", "group-by" ]
Why does TensorFlow only find one CPU device despite having multiple cores?
39,893,161
<p>as far as I understood TensorFlow creates one device per core. (source: <a href="https://github.com/samjabrahams/tensorflow-white-paper-notes" rel="nofollow">https://github.com/samjabrahams/tensorflow-white-paper-notes</a>: <em>NOTE: To reiterate- in this context, "single device" means using a single CPU core or sin...
0
2016-10-06T10:07:23Z
39,904,672
<p>By default <code>cpu:0</code> represents all cores available to the process. You can create devices <code>cpu:0</code>, <code>cpu:1</code> which represent 1 logical core each by doing something like this</p> <pre><code>config = tf.ConfigProto(device_count={"CPU": 2}, inter_op_parallelism_thr...
0
2016-10-06T19:58:59Z
[ "python", "tensorflow" ]
multiply even numbers, add odd numbers
39,893,178
<p>I'm trying to solve how to multiply all even numbers in a list with 2, and add all odd numbers with 7. And then present the list in an descending order. It has to be with a function that takes the list as argument.</p> <p>I found this here on stackoverflow, but it's not really what I'm after, since the example sums...
-3
2016-10-06T10:08:10Z
39,893,357
<p>You can create new list using:</p> <pre><code>new_list = [item * 2 if item % 2 == 0 else item + 7 for item in L] </code></pre> <p>and then sort it using:</p> <pre><code>new_list.sort(reverse=True) </code></pre> <p>Output should look like this:</p> <pre><code>[996, 156, 52, 44, 4] </code></pre>
0
2016-10-06T10:16:19Z
[ "python", "list", "function" ]
multiply even numbers, add odd numbers
39,893,178
<p>I'm trying to solve how to multiply all even numbers in a list with 2, and add all odd numbers with 7. And then present the list in an descending order. It has to be with a function that takes the list as argument.</p> <p>I found this here on stackoverflow, but it's not really what I'm after, since the example sums...
-3
2016-10-06T10:08:10Z
39,893,504
<p>You can go through the list and check whether the number is even or not. Then do your multiplication/addition depending on the result. An example is shown below:</p> <pre><code>original_list = [45, 22, 2, 498, 78] new_list = [] for number in original_list: if number % 2 == 0: #check to see if the number is eve...
0
2016-10-06T10:24:17Z
[ "python", "list", "function" ]
To read data from Putty and store it in another file by Python
39,893,274
<p>I need a script in Python that will collect the logs/information from PUTTY and then need to store this information in an another file saved in drive.</p>
-4
2016-10-06T10:12:59Z
39,893,343
<pre><code>import subprocess import sys HOST="127.0.0.1" # Ports are handled in ~/.ssh/config since we use OpenSSH COMMAND="uname -a" ssh = subprocess.Popen(["ssh", "%s" % HOST, COMMAND], shell=False, stdout=subprocess.PIPE, stderr=subprocess.PIPE) ...
0
2016-10-06T10:15:30Z
[ "python" ]
How to navigate a webpage with python
39,893,382
<p>I was made a python script for bruteforce (pen test) but before the bruteforce start, I need to go through some links clicking and login, so I want to do those stuff with python. Basically when I start that script it should login and click some links then start the bruteforce.</p> <p>so, is there any way I can make...
0
2016-10-06T10:17:39Z
39,895,021
<p>You might like to check these:</p> <ul> <li><a href="http://wwwsearch.sourceforge.net/mechanize/" rel="nofollow">mechanize</a></li> <li><a href="http://seleniumhq.org/" rel="nofollow">Selenium</a></li> <li><a href="http://code.google.com/p/python-spidermonkey/" rel="nofollow">Spidermonkey</a></li> <li><a href="http...
2
2016-10-06T11:39:39Z
[ "python", "website" ]
python - pandas - check if date exists in dataframe
39,893,420
<p>I have a dataframe like this:</p> <pre><code> category date number 0 Cat1 2010-03-01 1 1 Cat2 2010-09-01 1 2 Cat3 2010-10-01 1 3 Cat4 2010-12-01 1 4 Cat5 2012-04-01 1 5 Cat2 2013-02-01 1 6 Cat3 2013-07-01 ...
2
2016-10-06T10:19:34Z
39,893,467
<p>I think you need convert to datetime first by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_datetime.html" rel="nofollow"><code>to_datetime</code></a> and then if need select all rows use <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow"><c...
1
2016-10-06T10:22:39Z
[ "python", "datetime", "pandas", "dataframe" ]
Returning multiple lists from pool.map processes?
39,893,635
<p>Win 7, x64, Python 2.7.12</p> <p>In the following code I am setting off some pool processes to do a trivial multiplication via the <code>multiprocessing.Pool.map()</code> method. The output data is collected in <code>List_1</code>.</p> <p>NOTE: this is a stripped down simplification of my actual code. There are mu...
1
2016-10-06T10:30:05Z
39,893,715
<p>This question has nothing to do with multiprocessing or threadpooling. It is simply about how to unzip lists, which can be done with the standard <code>zip(*...)</code> idiom.</p> <pre><code>myList_1, myList_2 = zip(*pool.map(createLists, splitBranches)) </code></pre>
1
2016-10-06T10:33:46Z
[ "python", "threadpool", "python-multiprocessing" ]
How to make a moving circle delete on impact with another circle in Python
39,893,693
<pre><code>from tkinter import * import time root = Tk() canvas =Canvas(root, width=1000, height=1000, bg= '#2B2B2B') canvas.pack() #id1 white x = 400 y = 400 r = 50 #rc2 orange f = 100 d = 400 r2 =100 id1 = canvas.create_oval(x - r, y - r, x + r, y + r, outline='white') id2 = canvas.create_oval(f - r2, d - r2, ...
0
2016-10-06T10:32:33Z
39,899,324
<p>You just need find_overlapping method.</p> <p>Basic example :</p> <pre><code>id1 = canvas.create_oval(x - r, y - r, x + r, y + r, outline='white') id2 = canvas.create_oval(f - r2, d - r2, f + r2, d + r2, outline='#CC7832') id1_coords = canvas.coords(id1) def move_circle(x, y): canvas.move(id2, x, y) if i...
0
2016-10-06T14:57:09Z
[ "python", "tkinter" ]
How to close tkinter window without a button?
39,893,719
<p>I'm an A-level computing student and I am the only one in my class who can code using Python. Even my teachers have not learned the language. I'm attempting to code a login program that exits when the info is put in correctly and displays a welcome screen image (I haven't coded that part yet). It has to close and di...
-1
2016-10-06T10:34:14Z
39,894,033
<p>Consider for a moment the following two lines in your logging_in method:</p> <pre><code>if user_get == 'octo' and pass_get == 'burger': elif user_get != 'octo' or pass_get != 'burger': </code></pre> <p>so if the login credentials are correct, the code after the first test is executed. If they are incorrect, the co...
1
2016-10-06T10:50:37Z
[ "python", "python-3.x", "tkinter" ]
How can I add a new column, choose the x-lowest values from another column, and use 1 and 0 to differentiate? (Accoring to id number)
39,893,819
<p>I have a csv.data and want to add a new column ("new"). In this new column I like to have 1's for the two lowest values in "cycle". The rest should be 0's. This procedure should be done for each group of numbers in "id". The result should be like the following image.(This is just a example. In my case I have much mo...
2
2016-10-06T10:39:25Z
39,894,161
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.SeriesGroupBy.nsmallest.html" rel="nofollow"><code>SeriesGroupBy.nsmallest</code></a> with <a href="http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.where.html" rel="nofollow"><code>numpy.where</code></a>:<...
0
2016-10-06T10:57:01Z
[ "python", "pandas", "numpy" ]
How can I add a new column, choose the x-lowest values from another column, and use 1 and 0 to differentiate? (Accoring to id number)
39,893,819
<p>I have a csv.data and want to add a new column ("new"). In this new column I like to have 1's for the two lowest values in "cycle". The rest should be 0's. This procedure should be done for each group of numbers in "id". The result should be like the following image.(This is just a example. In my case I have much mo...
2
2016-10-06T10:39:25Z
39,894,389
<p>Here's an approach assuming <code>a</code> as the input array with those two columns -</p> <pre><code>sorted_idx = np.lexsort(a[:,::-1].T) idx = np.unique(a[sorted_idx,0],return_index=1)[1] bin_arr = np.convolve(np.in1d(np.arange(a.shape[0]),idx),[1,1],'same') out = bin_arr[sorted_idx.argsort()] </code></pre> <p>F...
0
2016-10-06T11:09:19Z
[ "python", "pandas", "numpy" ]
Python Threading, list of 10 links taken as 10 positional arguments
39,893,852
<p>got a spider that is trying to crawl and add to a database, and thought I would use threading to quicken things up a little bit </p> <p>here is the code:</p> <pre><code>def final_function(link_set): root = 'http://www.rightmove.co.uk' pages = [] for link in link_set: try: links =...
0
2016-10-06T10:41:03Z
39,894,065
<p><code>args</code> in <code>threading.Thread</code> is supposed be a tuple of arguments, which means that when you pass iterable (list) to it, it considers every list element as separate argument.</p> <p>It can be avoided by passing tuple, containing a list, to <code>args</code>, like</p> <pre><code>for i in result...
2
2016-10-06T10:52:05Z
[ "python", "multithreading" ]
"The view polls.views.index didn't return an HttpResponse object. It returned None instead." Error in Django
39,894,047
<p>I am following the tutorial in Django documentation. I did exactly as it has said in the <a href="https://docs.djangoproject.com/en/1.10/intro/tutorial01/" rel="nofollow">tutorial</a>.</p> <p>ValueError at /polls/</p> <p>When I load on browser "<a href="http://localhost:8000/polls/" rel="nofollow">http://localhost...
0
2016-10-06T10:51:26Z
39,894,163
<p><code>HttpResponse("Welcome to poll's index!")</code> .should be </p> <pre><code>return HttpResponse("Welcome to poll's index!") </code></pre> <p>You are not returning anything from your view.</p>
3
2016-10-06T10:57:02Z
[ "python", "django", "anaconda" ]
Read all the data from one row of matrix
39,894,069
<p>I am reading a .mat file using python </p> <pre><code>mat= sio.loadmat('C:/Users/machine-learning-ex3/ex3/ex3data1') print(mat['X']) print(mat['X'].shape) </code></pre> <p>The out put looks like </p> <pre><code>[[ 0. 0. 0. ..., 0. 0. 0.] [ 0. 0. 0. ..., 0. 0. 0.] [ 0. 0. 0. ..., 0. 0. 0.] .....
0
2016-10-06T10:52:16Z
39,894,229
<p>From <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.io.loadmat.html" rel="nofollow">reference</a>, loadmat returns dictionary with key as variable name and value as the loaded matrix. From your print statements, mat['X'] is a 2-d array.</p> <p>For showing ith row, simply write</p> <pre><code>ma...
1
2016-10-06T11:01:00Z
[ "python" ]
Project Euler - Largest Palindrome #4 Python
39,894,123
<p>I'm new to python and decided it would be a good idea to improve my coding (in general) by doing some of the challenges on project Euler. I'm currently stuck on problem 4 and i'm not sure what is going wrong (for those not in the know, problem 4 is as follows):</p> <blockquote> <p>A palindromic number reads the s...
0
2016-10-06T10:55:26Z
39,894,642
<p>Starting at <code>x = 999</code> and <code>y = 999</code> and then decrementing only <code>y</code> until you restart with a decremented <code>x</code> and a reset <code>y</code> does not guarantee you that you will hit the largest palindrome first.</p> <p>Just think of the following example: Let’s imagine a diff...
3
2016-10-06T11:21:07Z
[ "python" ]
Project Euler - Largest Palindrome #4 Python
39,894,123
<p>I'm new to python and decided it would be a good idea to improve my coding (in general) by doing some of the challenges on project Euler. I'm currently stuck on problem 4 and i'm not sure what is going wrong (for those not in the know, problem 4 is as follows):</p> <blockquote> <p>A palindromic number reads the s...
0
2016-10-06T10:55:26Z
39,895,037
<p>OK, just to find the solution, let's use brute force:</p> <pre><code>&gt;&gt;&gt; prod = itertools.product(range(999,99,-1),range(999,99,-1)) &gt;&gt;&gt; palindromes = [(x*y,x,y) for x,y in prod if str(x*y) == str(x*y)[::-1]] &gt;&gt;&gt; max(palindromes, key=lambda t: t[0]) (906609, 993, 913) </code></pre> <p>T...
0
2016-10-06T11:40:31Z
[ "python" ]
How to compute the median and 68% confidence interval around the median of non-Gaussian distribution in Python?
39,894,213
<p>I have a data set which is a numpy array say a=[a1,a2,.....] and also the weights of the data w=[w1,w2,w3...]. I have computed the histogram using numpy histogram package which gives me the hist array. Now I want to compute the median of this probability distribution function and also the 68% contour around the medi...
1
2016-10-06T11:00:02Z
40,051,761
<p>Here a solution using <a href="http://docs.scipy.org/doc/scipy/reference/generated/scipy.stats.rv_discrete.html" rel="nofollow">scipy.stats.rv_discrete</a>:</p> <pre><code>import numpy as np, scipy.stats as st # example data set a = np.arange(20) w = a + 1 # create custom discrete random variable from data set rv...
2
2016-10-14T20:48:23Z
[ "python", "numpy", "scipy", "statistics" ]
Python checking equality of tuples
39,894,363
<p>I have a numpy array of source and destination ip's</p> <pre><code>consarray array([['10.125.255.133', '104.244.42.130'], ['104.244.42.130', '10.125.255.133']], dtype=object) </code></pre> <p>The actual array is much larger than this.</p> <p>I want to create a set of unique connection pairs from the array:</p>...
3
2016-10-06T11:08:18Z
39,894,511
<p>You can sort them first:</p> <pre><code>conset = set(map(tuple, map(sorted, consarray))) print (conset) </code></pre> <p>gives:</p> <pre><code>{('10.125.255.133', '104.244.42.130')} </code></pre>
1
2016-10-06T11:14:51Z
[ "python", "tuples" ]
Python checking equality of tuples
39,894,363
<p>I have a numpy array of source and destination ip's</p> <pre><code>consarray array([['10.125.255.133', '104.244.42.130'], ['104.244.42.130', '10.125.255.133']], dtype=object) </code></pre> <p>The actual array is much larger than this.</p> <p>I want to create a set of unique connection pairs from the array:</p>...
3
2016-10-06T11:08:18Z
39,894,522
<p>You could either apply <em>sorting</em> before making the <em>tuples</em>:</p> <pre><code>conset = set(map(lambda x: tuple(sorted(x)), consarray)) </code></pre> <p>Or use <em>fronzensets</em> instead of <em>tuples</em>:</p> <pre><code>conset = set(map(frozenset, consarray)) </code></pre> <p>To guarantee that the...
3
2016-10-06T11:15:20Z
[ "python", "tuples" ]
Python checking equality of tuples
39,894,363
<p>I have a numpy array of source and destination ip's</p> <pre><code>consarray array([['10.125.255.133', '104.244.42.130'], ['104.244.42.130', '10.125.255.133']], dtype=object) </code></pre> <p>The actual array is much larger than this.</p> <p>I want to create a set of unique connection pairs from the array:</p>...
3
2016-10-06T11:08:18Z
39,894,721
<p>Since you're using <code>numpy</code>, you can use <code>numpy.unique</code>, eg:</p> <pre><code>a = np.array([('10.125.255.133', '104.244.42.130'), ('104.244.42.130', ' 10.125.255.133')]) </code></pre> <p>Then <code>np.unique(a)</code> gives you:</p> <pre><code>array(['10.125.255.133', '104.244.42.130'], dtype='...
1
2016-10-06T11:25:03Z
[ "python", "tuples" ]
error installing PyObjC osX
39,894,476
<p>I am new to Python and I am desperately trying to install PyObjC via spyder. The command</p> <pre><code>pip install PyObjC </code></pre> <p>returns an error: </p> <blockquote> <p>Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/0v/cg_rdz_x4d32jm6hz7n5txgh3djxb1/T/pip-build-U...
1
2016-10-06T11:13:10Z
39,894,901
<p>The actual error message which can help more is in the beginning of the traceback. In my case it is</p> <pre><code>xcode-select: error: tool 'xcodebuild' requires Xcode, but active developer directory '/Library/Developer/CommandLineTools' is a command line tools instance Traceback (most recent call last): File "&...
0
2016-10-06T11:33:43Z
[ "python", "osx", "python-2.7", "install", "pyobjc" ]
merge data based on some specific columns, pands
39,894,527
<p>Assume I'm having two data frame's, <code>t1h</code> and <code>t2h</code>, I want to merge that dataframe in such a way that for a specific list of columns if those rows seem to be similar I need to perform addition operation with contents of rest of the columns.</p> <p><strong>t1h</strong></p> <pre><code> ti...
1
2016-10-06T11:15:29Z
39,895,158
<h2>Great use case for the <code>groupby.agg()</code> function</h2> <p>Assuming that <code>t1h</code> and <code>t2h</code> already exist, and have the same column names</p> <pre><code>groupby_fields = ['timestamp', 'ip', 'domain', 'http_status', 'test'] df = t2h.append(t2h, ignore_index = True) agg_dict = {'b_count...
1
2016-10-06T11:46:26Z
[ "python", "pandas", "dataframe", "merge" ]
pytest collecting 0 items
39,894,566
<p>I have a socket program - 2 scripts, server and client. On server side I have many functions. I want to test these functions. I am new to python. Found something called pytest. So for all functions on my server side I did something like this. </p> <pre><code>def fun(a): // fn definition return b def test_fun(...
0
2016-10-06T11:17:39Z
39,895,065
<p>if you want to test your client functions you should actually mock server responses. If you want to run some integration tests for client. Then start your server with:</p> <pre><code>python test_server.py </code></pre> <p>and run your client tests as:</p> <pre><code>py.test test_client.py </code></pre> <p>py.tes...
0
2016-10-06T11:41:36Z
[ "python", "sockets", "py.test" ]
Path manipulation in python
39,894,698
<p>I have looked on Stack Overflow everywhere but I cant find a solution to this problem.</p> <p>Given that I have a folder/file as string: <code>"/path1/path2/path3/file"</code> how can I get the parent folder and its parent folder. In other words if I want to traverse up one level <code>"/path1/path2/path3"</code> o...
2
2016-10-06T11:23:50Z
39,894,737
<p><a href="https://docs.python.org/2/library/os.path.html#os.path.split" rel="nofollow"><code>os.path.split</code></a> will do it for you. There are many other interesting functions in there.</p>
1
2016-10-06T11:25:41Z
[ "python" ]
Path manipulation in python
39,894,698
<p>I have looked on Stack Overflow everywhere but I cant find a solution to this problem.</p> <p>Given that I have a folder/file as string: <code>"/path1/path2/path3/file"</code> how can I get the parent folder and its parent folder. In other words if I want to traverse up one level <code>"/path1/path2/path3"</code> o...
2
2016-10-06T11:23:50Z
39,894,743
<pre><code>'/'.join (originalPath.split ('/') [:-2]) </code></pre> <p>It will take you 2 levels up. </p>
0
2016-10-06T11:25:59Z
[ "python" ]
Path manipulation in python
39,894,698
<p>I have looked on Stack Overflow everywhere but I cant find a solution to this problem.</p> <p>Given that I have a folder/file as string: <code>"/path1/path2/path3/file"</code> how can I get the parent folder and its parent folder. In other words if I want to traverse up one level <code>"/path1/path2/path3"</code> o...
2
2016-10-06T11:23:50Z
39,894,751
<p><a href="https://docs.python.org/2/library/os.path.html#os.path.dirname" rel="nofollow">os.path.dirname</a> gives you the parent directory.</p>
0
2016-10-06T11:26:35Z
[ "python" ]
Path manipulation in python
39,894,698
<p>I have looked on Stack Overflow everywhere but I cant find a solution to this problem.</p> <p>Given that I have a folder/file as string: <code>"/path1/path2/path3/file"</code> how can I get the parent folder and its parent folder. In other words if I want to traverse up one level <code>"/path1/path2/path3"</code> o...
2
2016-10-06T11:23:50Z
39,894,831
<p><code>os.path.dirname()</code> (<a href="https://docs.python.org/2/library/os.path.html#os.path.dirname" rel="nofollow"><em>doc</em></a>) is the way to go. It returns the directory which contains the object pointed by the path:</p> <pre><code>&gt;&gt;&gt; import os.path &gt;&gt;&gt; os.path.dirname('/path1/path2/pa...
4
2016-10-06T11:30:04Z
[ "python" ]
Path manipulation in python
39,894,698
<p>I have looked on Stack Overflow everywhere but I cant find a solution to this problem.</p> <p>Given that I have a folder/file as string: <code>"/path1/path2/path3/file"</code> how can I get the parent folder and its parent folder. In other words if I want to traverse up one level <code>"/path1/path2/path3"</code> o...
2
2016-10-06T11:23:50Z
39,895,111
<p>additionally to all other answers, you can also use <a href="https://docs.python.org/2/library/os.path.html#os.path.join" rel="nofollow">os.path.join</a> function with the <code>os.path.pardir</code> variable which usually equals <code>..</code>.</p> <pre><code>&gt;&gt;&gt; path = "some/random/path/to/process" &gt;...
2
2016-10-06T11:43:49Z
[ "python" ]
Path manipulation in python
39,894,698
<p>I have looked on Stack Overflow everywhere but I cant find a solution to this problem.</p> <p>Given that I have a folder/file as string: <code>"/path1/path2/path3/file"</code> how can I get the parent folder and its parent folder. In other words if I want to traverse up one level <code>"/path1/path2/path3"</code> o...
2
2016-10-06T11:23:50Z
39,895,494
<p>You can use the <a href="https://docs.python.org/3.6/library/pathlib.html#module-pathlib" rel="nofollow"><code>pathlib</code></a> module:</p> <pre><code>&gt;&gt;&gt; path = pathlib.PurePath('/file1/file2/file3/file') &gt;&gt;&gt; path.parts ('/', 'file1', 'file2', 'file3', 'file') &gt;&gt;&gt; os.path.join(*path.pa...
2
2016-10-06T12:03:45Z
[ "python" ]
Combine two files with Pandas
39,894,821
<p>I am having trouble using pandas to combine two input files as shown in the data sample below. They start out as CSV files exported from WordPress. I load them into data frames. My idea was to create an empty output data frame and fill it by looping through each <code>id</code> in the first input file, but that seem...
1
2016-10-06T11:29:40Z
39,894,925
<p>you can use <code>pivot</code> in conjunction with <code>join</code>:</p> <pre><code>In [126]: df1.set_index('id').join(df2.pivot(index='id', columns='key', values='value')) Out[126]: postDate age city name id 23 2016-10-03 24 boston smith 24 2016-02-15 35 chicago jones 25 2016-07-22 ...
0
2016-10-06T11:34:40Z
[ "python", "pandas" ]
Set points outside plot to upper limit
39,894,896
<p>Maybe this question exists already, but I could not find it. </p> <p>I am making a scatter plot in Python. For illustrative purposes, I don't want to set my axes range such that all points are included - there may be some really high or really low values, and all I care about in those points is that they exist - th...
3
2016-10-06T11:33:06Z
39,896,204
<p>There is no equivalent syntactic sugar in matplotlib. You will have to preprocess your data, e.g.: </p> <pre><code>import numpy as np import matplotlib.pyplot as plt ymin, ymax = 0, 0.9 x, y = np.random.rand(2,1000) y[y&gt;ymax] = ymax fig, ax = plt.subplots(1,1) ax.plot(x, y, 'o', ms=10) ax.set_ylim(ymin, ymax) p...
2
2016-10-06T12:36:31Z
[ "python", "matplotlib", "plot", "limits" ]
Set points outside plot to upper limit
39,894,896
<p>Maybe this question exists already, but I could not find it. </p> <p>I am making a scatter plot in Python. For illustrative purposes, I don't want to set my axes range such that all points are included - there may be some really high or really low values, and all I care about in those points is that they exist - th...
3
2016-10-06T11:33:06Z
39,896,349
<p>you can just use <a href="http://docs.scipy.org/doc/numpy-1.10.1/reference/generated/numpy.minimum.html" rel="nofollow"><code>np.minimum</code></a> on the <code>y</code> data to set anything above your upper limit to that limit. <code>np.minimum</code> calculates the minima element-wise, so only those values greater...
1
2016-10-06T12:43:45Z
[ "python", "matplotlib", "plot", "limits" ]