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
comparing two pandas dataframes with list in column
39,148,941
<p>I have two data frames df1 and df2:</p> <pre><code>df1 : Name A_list abcd (apple,orange,banana) bcde (orange,mango) cdef (apple,pineapple) df2 : City B_list C1 (apple,mango,banana) C2 (mango) C3 (pineapple,banana) </code></pre> <p>I want to make a new dataframe df3</p> <pre><code>Name A_list City abcd (ap...
0
2016-08-25T15:14:14Z
39,150,169
<h3>Setup</h3> <pre><code>df1 = pd.DataFrame([ ['abcd', ('apple', 'orange', 'banana')], ['bcde', ('orange', 'mango')], ['cdef', ('apple', 'pineapple')] ], columns=['Name', 'A_list']) df2 = pd.DataFrame([ ['C1', ('apple', 'mango', 'banana')], ['C2', ('mango')], ['C3',...
2
2016-08-25T16:15:30Z
[ "python", "pandas" ]
Delete file start with
39,148,963
<p>I want this function to delete files. It does this correctly, but it <em>also</em> deletes folders, which I do not want.</p> <p>I also get an error during execution:</p> <pre><code>Access is denied: 'C:/temp3\\IDB_KKK </code></pre> <p>In folder temp3 i have:</p> <pre><code>IDB_OPP.txt IDB_KKK - folder </code></...
0
2016-08-25T15:15:45Z
39,149,112
<p>Use the following, to check if it is a directory: <br></p> <pre><code>os.path.isdir(fname) //if is a directory </code></pre>
1
2016-08-25T15:23:17Z
[ "python" ]
Delete file start with
39,148,963
<p>I want this function to delete files. It does this correctly, but it <em>also</em> deletes folders, which I do not want.</p> <p>I also get an error during execution:</p> <pre><code>Access is denied: 'C:/temp3\\IDB_KKK </code></pre> <p>In folder temp3 i have:</p> <pre><code>IDB_OPP.txt IDB_KKK - folder </code></...
0
2016-08-25T15:15:45Z
39,152,326
<p>Do you want to delete files recursively (i.e. including files that live in <em>subdirectories</em> of <code>Path</code>) without deleting those subdirectories themselves?</p> <pre><code>import os def delete_Files_StartWith(Path, Start_With_Key): for dirPath, subDirs, fileNames in os.walk(Path): for file...
0
2016-08-25T18:24:42Z
[ "python" ]
Delete file start with
39,148,963
<p>I want this function to delete files. It does this correctly, but it <em>also</em> deletes folders, which I do not want.</p> <p>I also get an error during execution:</p> <pre><code>Access is denied: 'C:/temp3\\IDB_KKK </code></pre> <p>In folder temp3 i have:</p> <pre><code>IDB_OPP.txt IDB_KKK - folder </code></...
0
2016-08-25T15:15:45Z
39,152,456
<p>To remove a directory and all its contents, <a href="https://docs.python.org/3/library/shutil.html" rel="nofollow">use <code>shutil</code></a>.</p> <blockquote> <p>The shutil module offers a number of high-level operations on files and collections of files.</p> </blockquote> <p>Refer to the question <a href="htt...
0
2016-08-25T18:32:45Z
[ "python" ]
Delete file start with
39,148,963
<p>I want this function to delete files. It does this correctly, but it <em>also</em> deletes folders, which I do not want.</p> <p>I also get an error during execution:</p> <pre><code>Access is denied: 'C:/temp3\\IDB_KKK </code></pre> <p>In folder temp3 i have:</p> <pre><code>IDB_OPP.txt IDB_KKK - folder </code></...
0
2016-08-25T15:15:45Z
39,153,632
<p>I fixed it by the following:</p> <pre><code>def delete_Files_StartWith(Path,Start_With_Key): os.chdir(Path) for fname in os.listdir("."): if os.path.isfile(fname) and fname.startswith(Start_With_Key): os.remove(fname) </code></pre> <p>thanks you all.</p>
0
2016-08-25T19:49:38Z
[ "python" ]
Python - Object call uses wrong list
39,149,021
<p>I'm new to python and have the following problem:</p> <p>Every Class 'Neuron' has two lists (map_dendrites, map_axons) in which I want to store IDs from other Neurons.</p> <p>My Problem is that if 'map_synapses' calls 'add_axon' it writes the given ID in the list 'map_dendrites' from the calling Neuron-Object and ...
0
2016-08-25T15:18:27Z
39,149,299
<p>It think the issue might be the scope of your variables. You are assigning them like this at the beginning of the class</p> <pre><code>class Neuron(object): c_dendrites = 1 # Inputs c_axons = 1 # Outputs c_unmap_dendrites = c_dendrites # Unmapped entspricht am Anfang der Gesamtanzahl der vorhandenen D...
2
2016-08-25T15:32:49Z
[ "python" ]
Converting a string to a list of lists
39,149,117
<p>Using Python 2.7, I want to convert a string in the following format to a list of lists:</p> <pre><code>&gt;&gt;&gt; value = "[[1 0 0 0] [0 1 0 0] [0 0 1 0] [0 0 0 1]]" &gt;&gt;&gt; ... &gt;&gt;&gt; result = [[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]] </code></pre> <p>I...
3
2016-08-25T15:23:22Z
39,149,180
<p>You can use <code>replace</code> + <code>eval</code>:</p> <pre><code>value = "[[1 0 0 0] [0 1 0 0] [0 0 1 0] [0 0 0 1]]" result = eval(value.replace(" ", ",")) result #output: [[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]] </code></pre> <p>And to convert the integers to floats:</p> <pre><code>[list(map(...
4
2016-08-25T15:26:15Z
[ "python", "python-2.7" ]
Converting a string to a list of lists
39,149,117
<p>Using Python 2.7, I want to convert a string in the following format to a list of lists:</p> <pre><code>&gt;&gt;&gt; value = "[[1 0 0 0] [0 1 0 0] [0 0 1 0] [0 0 0 1]]" &gt;&gt;&gt; ... &gt;&gt;&gt; result = [[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]] </code></pre> <p>I...
3
2016-08-25T15:23:22Z
39,149,462
<pre><code>value = "[[1 0 0 0] [0 1 0 0] [0 0 1 0] [0 0 0 1]]" eval(value.replace(" ", ",")) </code></pre> <p>Output :</p> <pre><code>[[1, 0, 0, 0], [0, 1, 0, 0], [0, 0, 1, 0], [0, 0, 0, 1]] </code></pre> <p>for return float values </p> <pre><code>import numpy as np l=np.array(eval(value.replace(" ", ",")))+0. l.to...
0
2016-08-25T15:39:41Z
[ "python", "python-2.7" ]
Converting a string to a list of lists
39,149,117
<p>Using Python 2.7, I want to convert a string in the following format to a list of lists:</p> <pre><code>&gt;&gt;&gt; value = "[[1 0 0 0] [0 1 0 0] [0 0 1 0] [0 0 0 1]]" &gt;&gt;&gt; ... &gt;&gt;&gt; result = [[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]] </code></pre> <p>I...
3
2016-08-25T15:23:22Z
39,149,504
<p>Use <a href="https://docs.python.org/3.4/library/json.html#json.loads" rel="nofollow">json.loads</a> from the standard library, with a little bit of preparation (replace spaces with commas) and asking it to convert all found integers as floats:</p> <pre><code>&gt;&gt;&gt; import json &gt;&gt;&gt; value = "[[1 0 0 0...
6
2016-08-25T15:41:44Z
[ "python", "python-2.7" ]
Converting a string to a list of lists
39,149,117
<p>Using Python 2.7, I want to convert a string in the following format to a list of lists:</p> <pre><code>&gt;&gt;&gt; value = "[[1 0 0 0] [0 1 0 0] [0 0 1 0] [0 0 0 1]]" &gt;&gt;&gt; ... &gt;&gt;&gt; result = [[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]] </code></pre> <p>I...
3
2016-08-25T15:23:22Z
39,150,745
<p>Well the most flexible and extensible way would be to implement an <a href="https://en.wikipedia.org/wiki/LL_parser" rel="nofollow">LL(1) parser</a>. It requires a bit of work though. Here is a rough implementation in Python 2.7:</p> <pre><code>value = "[[1 0 0 0] [0 1 0 0] [0 0 1 0] [0 0 0 1]]" class ParseError(V...
1
2016-08-25T16:49:19Z
[ "python", "python-2.7" ]
Converting a string to a list of lists
39,149,117
<p>Using Python 2.7, I want to convert a string in the following format to a list of lists:</p> <pre><code>&gt;&gt;&gt; value = "[[1 0 0 0] [0 1 0 0] [0 0 1 0] [0 0 0 1]]" &gt;&gt;&gt; ... &gt;&gt;&gt; result = [[1.0, 0.0, 0.0, 0.0], [0.0, 1.0, 0.0, 0.0], [0.0, 0.0, 1.0, 0.0], [0.0, 0.0, 0.0, 1.0]] </code></pre> <p>I...
3
2016-08-25T15:23:22Z
39,154,550
<p>Similar to the Johan Dahlin's answer:</p> <p>Instead of using <em>json</em> parser, you can user the integrated Python <a href="https://docs.python.org/2/library/ast.html" rel="nofollow">Abstract Syntax Trees</a> parser:</p> <p>Like this:</p> <pre><code>value = "[[1 0 0 0] [0 1 0 0] [0 0 1 0] [0 0 0 1]]" import ...
1
2016-08-25T20:52:38Z
[ "python", "python-2.7" ]
How to set inset_axes position in matplotlib
39,149,188
<p>I would like to place colorbar inside axes, because room is scarce in scientific publication. inset_axes seems like a good choice to creat sub axes, but I cannot find an easy way to place with other coordinate than 'loc = 0,1,2,3,4' : Results, the colormap label lay outside of the figures. I would like to use simila...
0
2016-08-25T15:26:40Z
39,150,161
<p>One possible solution which does not use <code>inset_axes</code> is to simply use matplotlib's <code>colorbar</code> but allow it to appear inside the figure. </p> <pre><code>x = np.linspace(-0.7,0.7,num = 50) y = np.linspace(0,1,num = 100) ext = (x[0],x[-1],y[-1],y[0]) xx,yy = np.meshgrid(x,y,indexing = 'ij') U = ...
0
2016-08-25T16:15:11Z
[ "python", "python-2.7", "matplotlib" ]
Python: Printing value after .upper
39,149,218
<p>I am trying to print a string in all uppercase letters. When I run the print command it prints the type of x and the location. </p> <p>Why does it print the operation instead of the result?</p> <pre><code>x = 'bacon' x = x.upper print x &gt;&gt;&gt; &lt;built-in method upper of str object at 0x02A95F60&gt; </cod...
2
2016-08-25T15:28:39Z
39,149,238
<p><code>upper</code> (and all other methods) is something like "function ready to use", that way you can do:</p> <pre><code>x = 'bacon' x = x.upper print x() </code></pre> <p>But the most common to see, and the way I think you want is:</p> <pre><code>x = 'bacon' x = x.upper() print x </code></pre> <p>"Ridiculous" ...
4
2016-08-25T15:29:45Z
[ "python", "python-2.7" ]
Python: Printing value after .upper
39,149,218
<p>I am trying to print a string in all uppercase letters. When I run the print command it prints the type of x and the location. </p> <p>Why does it print the operation instead of the result?</p> <pre><code>x = 'bacon' x = x.upper print x &gt;&gt;&gt; &lt;built-in method upper of str object at 0x02A95F60&gt; </cod...
2
2016-08-25T15:28:39Z
39,149,302
<p>Everything in Python is an object, including functions and methods. <code>x.upper</code> is the <code>upper</code> attribute of <code>x</code>, which happens to be a function object. <code>x.upper()</code> is the result of trying to call that attribute as a function, so you are trying to do</p> <pre><code>print x.u...
3
2016-08-25T15:32:50Z
[ "python", "python-2.7" ]
How do I connect to a SQL server database with python?
39,149,243
<p>Im trying to conennect to an sql database that its already created an that its located on a server. How can I connect to this database using python. Ive tried using java but I cant seem to get working either.</p>
0
2016-08-25T15:29:54Z
39,149,561
<p>Well depending on what sql database you are using you can pip install pymssql for microsoft sql (mssql), psycopg2 for postgres (psql) or mysqldb for mysql databases Here are a few examples of using it</p> <p>Microsoft sql</p> <pre><code>import pymssql conn = pymssql.connect(server=server, user=user, password=pass...
0
2016-08-25T15:44:27Z
[ "python", "sql-server", "database", "database-connection" ]
Travis CI encodes ü as ü
39,149,245
<p>I'm writing some Unicode strings to HTML in Python. The way I do it is to use Unicode internally and only encode when output. So something like:</p> <pre><code>with open(filename, 'w') as f: f.write(s.encode("utf-8")) </code></pre> <p>This works just as expect on my local machine. But when it's put on to Travi...
1
2016-08-25T15:29:58Z
39,162,171
<p>This seems to be because your browser is likely wrongly reading the file. Easiest fix to this is to encode it as UTF-8 BOM by adding the BOM marker to the start of the file.</p> <p>Here's the fixed code for writing to the file:</p> <pre><code>with open('output/test.html', 'w') as f: f.write(u'\ufeff'.encode('u...
-1
2016-08-26T08:49:28Z
[ "python", "unicode", "travis-ci", "python-unicode" ]
How to reshape a 1-d array into a an array of shape (1,4,5)?
39,149,251
<p>I have these vectors :</p> <pre><code>a = [1,2,3,4] b = [1,2,3,5] </code></pre> <p>and I could like to have this at the end :</p> <pre><code>A = [ [1,0,0,0,0] [0,1,0,0,0] [0,0,1,0,0] [0,0,0,1,0] ] B = [ [1,0,0,0,0] [0,1,0,0,0] [0,0,1,0,0] [0,0,0,0,1] ] </code></pre> <p>I have...
0
2016-08-25T15:30:31Z
39,149,448
<p>What you're trying to do is not actually a reshape, as you alter the structure of the data. Make a new array with the shape you want:</p> <pre><code>A = np.zeros(myshape) B = np.zeros(myshape) </code></pre> <p>and then index those arrays</p> <pre><code>n = 0 for i_a, i_b in zip(a, b): A[n, i_a - 1] = 1 B[...
1
2016-08-25T15:39:09Z
[ "python", "numpy", "reshape", "encoder" ]
How to reshape a 1-d array into a an array of shape (1,4,5)?
39,149,251
<p>I have these vectors :</p> <pre><code>a = [1,2,3,4] b = [1,2,3,5] </code></pre> <p>and I could like to have this at the end :</p> <pre><code>A = [ [1,0,0,0,0] [0,1,0,0,0] [0,0,1,0,0] [0,0,0,1,0] ] B = [ [1,0,0,0,0] [0,1,0,0,0] [0,0,1,0,0] [0,0,0,0,1] ] </code></pre> <p>I have...
0
2016-08-25T15:30:31Z
39,150,279
<p>Alternatively, numpy can assign value to multiple indexes on rows/columns in one go, example:</p> <pre><code>In [1]: import numpy as np In [2]: b = [1,2,3,5] ...: ...: In [3]: zero = np.zeros([4,5]) In [4]: brow, bcol = range(len(b)), np.array(b) -1 # logical transform In [5]: zero[brow, bcol] = 1 In ...
3
2016-08-25T16:21:30Z
[ "python", "numpy", "reshape", "encoder" ]
Need to cut out all characters in between 2 brackets in a string
39,149,286
<p>I have a string in python 2.7:</p> <pre><code>a = 'This is some text ( - 1) - And some more text (0:0) - Some more Text' </code></pre> <p>I would like to use a regex to get the ' - 1' out of this string. </p> <p>I've tried but can't find it, thanks for your help, I've tried: </p> <pre><code>re.search(r'.*?\((.*)...
0
2016-08-25T15:32:01Z
39,149,369
<p>regexes are greedy by default. Your expression gets the first <code>(</code> to the last <code>)</code></p> <p>you did that:</p> <pre><code>re.search(r'.*?\((.*)\).*', a) </code></pre> <p>instead, use</p> <pre><code>re.search(r'.*?\((.*?)\).*', a) </code></pre> <p>note the non-greedy version of the match <code>...
1
2016-08-25T15:35:55Z
[ "python", "regex" ]
Need to cut out all characters in between 2 brackets in a string
39,149,286
<p>I have a string in python 2.7:</p> <pre><code>a = 'This is some text ( - 1) - And some more text (0:0) - Some more Text' </code></pre> <p>I would like to use a regex to get the ' - 1' out of this string. </p> <p>I've tried but can't find it, thanks for your help, I've tried: </p> <pre><code>re.search(r'.*?\((.*)...
0
2016-08-25T15:32:01Z
39,149,383
<p>This would do it:</p> <pre><code>out = re.match('.*?\((.*?)\)', a).groups()[0] </code></pre> <p>if you wanted to remove from the original string,</p> <pre><code>a.replace(out, '') </code></pre>
0
2016-08-25T15:36:31Z
[ "python", "regex" ]
Need to cut out all characters in between 2 brackets in a string
39,149,286
<p>I have a string in python 2.7:</p> <pre><code>a = 'This is some text ( - 1) - And some more text (0:0) - Some more Text' </code></pre> <p>I would like to use a regex to get the ' - 1' out of this string. </p> <p>I've tried but can't find it, thanks for your help, I've tried: </p> <pre><code>re.search(r'.*?\((.*)...
0
2016-08-25T15:32:01Z
39,149,397
<p>Below code will return all the match in string:</p> <pre><code>&gt;&gt;&gt; import re &gt;&gt;&gt; mystring = 'This is some text ( - 1) - And some more text (0:0) - Some more Text' &gt;&gt;&gt; regex = re.compile(".*?\((.*?)\)") &gt;&gt;&gt; result = re.findall(regex, mystring) &gt;&gt;&gt; result [' - 1', '0:0'] <...
0
2016-08-25T15:37:04Z
[ "python", "regex" ]
Need to cut out all characters in between 2 brackets in a string
39,149,286
<p>I have a string in python 2.7:</p> <pre><code>a = 'This is some text ( - 1) - And some more text (0:0) - Some more Text' </code></pre> <p>I would like to use a regex to get the ' - 1' out of this string. </p> <p>I've tried but can't find it, thanks for your help, I've tried: </p> <pre><code>re.search(r'.*?\((.*)...
0
2016-08-25T15:32:01Z
39,149,762
<p>You can use <a href="https://docs.python.org/2/library/re.html#re.sub" rel="nofollow"><code>re.sub</code></a> to replace the first match found in the string, by using the optional <code>count</code> argument.</p> <pre><code>&gt;&gt;&gt;a = 'This is some text ( - 1) - And some more text (0:0) - Some more Text' &gt;&...
0
2016-08-25T15:54:03Z
[ "python", "regex" ]
Need to cut out all characters in between 2 brackets in a string
39,149,286
<p>I have a string in python 2.7:</p> <pre><code>a = 'This is some text ( - 1) - And some more text (0:0) - Some more Text' </code></pre> <p>I would like to use a regex to get the ' - 1' out of this string. </p> <p>I've tried but can't find it, thanks for your help, I've tried: </p> <pre><code>re.search(r'.*?\((.*)...
0
2016-08-25T15:32:01Z
39,152,447
<p>What about:</p> <pre><code>tmp_1 = str.split('(', mystring ) tmp_2 = str.split(')', tmp[1]) result = tmp[0] </code></pre> <p>This process is simpler, and can be generalized if the brackets are nested.</p>
-1
2016-08-25T18:31:48Z
[ "python", "regex" ]
Tkinter Attribute Error when configuring tk Buttons
39,149,303
<p>I'm building an SMTP mail sender and when I started building the login window, I stumbled uppon an <strong>Attribute Error</strong> when trying to set a button state to '<em>disabled</em>'.</p> <p>The first function in this example is the root and the second one is the one causing problems.</p> <pre><code>class sm...
0
2016-08-25T15:32:58Z
39,149,653
<p>The trace fires when the value changes. The value changes when you do <code>self.address.insert(0, "your address")</code> because that widget is tied to the variable. All of this happens before you define <code>self.login_btn</code>.</p> <p>You need to define the button before you enable the trace, or before you ch...
2
2016-08-25T15:49:27Z
[ "python", "class", "tkinter", "attributeerror" ]
How can I use an existing git repository in heroku
39,149,413
<p>I'm using heroku for creating a web application in python-django. I need to use an existing git repository in heroku. The name of my repository is <code>first-blog</code>. When I'm using </p> <pre><code>git clone https://github.com/heroku/first-blog.git </code></pre> <p>I got </p> <pre><code>Cloning into 'first-b...
1
2016-08-25T15:37:34Z
39,149,527
<p>The repository you are trying to clone does not exist, you'd get the same result trying to clone it on your local machine.</p> <p>You probably meant to clone <code>https://github.com/AparnaBalagopal/first-blo‌​g.git</code></p>
1
2016-08-25T15:42:43Z
[ "python", "django", "heroku", "github" ]
How can I use an existing git repository in heroku
39,149,413
<p>I'm using heroku for creating a web application in python-django. I need to use an existing git repository in heroku. The name of my repository is <code>first-blog</code>. When I'm using </p> <pre><code>git clone https://github.com/heroku/first-blog.git </code></pre> <p>I got </p> <pre><code>Cloning into 'first-b...
1
2016-08-25T15:37:34Z
39,150,010
<p>It looks like you're trying to clone a non-existent Git repository, which is why you're seeing that error. As some other users have mentioned already, you need to make sure you've got the right Github URL first of all, then you will be able to clone the repository no problem.</p> <p>Once you've cloned the repositor...
0
2016-08-25T16:07:29Z
[ "python", "django", "heroku", "github" ]
Scapy BGP Flags Attribute
39,149,455
<p><strong>Is there any other way I could use Scapy to configure a packet with multiple flag attributes?</strong></p> <p>I am trying to set up a BGP Layer with both optional and transitive attributes. I am using this github file: <a href="https://github.com/levigross/Scapy/blob/master/scapy/contrib/bgp.py" rel="nofoll...
0
2016-08-25T15:39:23Z
39,150,893
<p>It is possible to configure multiple flag attributes by enumerating them in a single string, delimited with the <code>'+'</code> sign:</p> <pre class="lang-py prettyprint-override"><code>In [1]: from scapy.all import * WARNING: No route found for IPv6 destination :: (no default route?) In [2]: from scapy.contrib.b...
1
2016-08-25T16:58:10Z
[ "python", "networking", "scapy", "bgp" ]
Maya Python: name not defined with floatSliderGrp
39,149,465
<p>I'm trying to get a scale slider steup, and whenever I change the slider value, I'd like for the new value to be printed out:</p> <pre><code> scaleSlider = cmds.floatSliderGrp(label='Curve Scale', field=True, minValue=0.0, ...
0
2016-08-25T15:39:49Z
39,162,776
<p>work with dict and lambda, </p> <pre><code>def get_ui_value(ui_id, ui_type): mcds = globals()["cmds"] method = getattr(mcds, ui_type) print method(ui_id, q=True, v=True) ui_dict = {} ui_dict["flt_slider_xy"] = cmds.floatSliderGrp(label='Curve Scale', field=True, ...
2
2016-08-26T09:20:10Z
[ "python", "user-interface", "maya" ]
Maya Python: name not defined with floatSliderGrp
39,149,465
<p>I'm trying to get a scale slider steup, and whenever I change the slider value, I'd like for the new value to be printed out:</p> <pre><code> scaleSlider = cmds.floatSliderGrp(label='Curve Scale', field=True, minValue=0.0, ...
0
2016-08-25T15:39:49Z
39,379,495
<p>Your problem is in the <code>cc</code> argument. First, you've passed a <em>statement</em> not a function: you'd need to wrap the whole thing in a def or a lambda to work correctly. Second, you're passing it a string reference to <code>scaleSlider</code>, but at the time the callback is defined that variable does...
1
2016-09-07T21:46:11Z
[ "python", "user-interface", "maya" ]
get best line when coordinates overlap
39,149,479
<p>I have a dataset like this:</p> <pre><code> FBti0018875 2031 2045 - TTCCAGAAACTGTTG hsf 62 0.9763443383736672 FBti0018875 2038 2052 + TTCTGGAATGGCAAC hsf 61 0.96581136371138 FBti0018925 2628 2642 - GACTGGAACTTTTCA hsf 60 0.9532992561656318 FBti0018925 2828 2842 + AG...
0
2016-08-25T15:40:32Z
39,162,210
<p>Finally I solved. There was a silly mistake with 'False' instead of False.</p> <p>Here is the solution:</p> <pre><code>def test(lista, listb): a = 0 b = 0 found = False while a&lt;len(lista) and b&lt;len(listb): result = check( lista[a] , listb[b] ) if result &lt; 0: a +...
0
2016-08-26T08:51:50Z
[ "python", "coordinates" ]
brew python versus non-brew ipython
39,149,554
<p>I installed python via brew, and made it my default python. If I run <code>which python</code>, I obtain <code>/usr/local/bin/python</code>. Also pip is installed via brew, <code>which pip</code> returns <code>/usr/local/bin/pip</code>.</p> <p>I do not remember how I installed ipython, but I didn't do it via brew, ...
0
2016-08-25T15:44:13Z
39,149,676
<p>To transfer all your packages you can use pip to freeze all of your packages installed in ipython and then install them all easily from the file that you put them in.</p> <p><code>pip freeze &gt; requirements.txt</code></p> <p>then to install them from the file <code>pip install -r requirements.txt</code></p> <p>...
0
2016-08-25T15:50:33Z
[ "python", "osx", "ipython", "homebrew" ]
brew python versus non-brew ipython
39,149,554
<p>I installed python via brew, and made it my default python. If I run <code>which python</code>, I obtain <code>/usr/local/bin/python</code>. Also pip is installed via brew, <code>which pip</code> returns <code>/usr/local/bin/pip</code>.</p> <p>I do not remember how I installed ipython, but I didn't do it via brew, ...
0
2016-08-25T15:44:13Z
39,149,915
<blockquote> <p>I installed <code>python</code> via <code>brew</code>, and made it my default python. If I run <code>which python</code>, I obtain <code>/usr/local/bin/python</code>. </p> </blockquote> <p>Okay, good so far. </p> <blockquote> <p>Also <code>pip</code> is installed via <code>brew</code>, which pip r...
0
2016-08-25T16:01:20Z
[ "python", "osx", "ipython", "homebrew" ]
brew python versus non-brew ipython
39,149,554
<p>I installed python via brew, and made it my default python. If I run <code>which python</code>, I obtain <code>/usr/local/bin/python</code>. Also pip is installed via brew, <code>which pip</code> returns <code>/usr/local/bin/pip</code>.</p> <p>I do not remember how I installed ipython, but I didn't do it via brew, ...
0
2016-08-25T15:44:13Z
39,151,146
<p>OK, so I solved by uninstalling macport (and so the ipython I was using, which was under /opt/local/bin) and installing ipython via pip. Then I re-install what I needed (e.g. jupyter) via pip.</p>
0
2016-08-25T17:14:31Z
[ "python", "osx", "ipython", "homebrew" ]
python package error when running from sublime
39,149,570
<p>I installed the python package <code>isochrones</code> using <code>pip install isochrones</code>.</p> <p>When I type <code>from isochrones.dartmouth import Dartmouth_Isochrone</code> in the <code>Sublime text editor</code> I get the following error:</p> <pre><code>from isochrones.dartmouth import Dartmouth_Isochro...
0
2016-08-25T15:45:00Z
39,151,493
<p>You need to create a new <a href="http://docs.sublimetext.info/en/latest/file_processing/build_systems.html" rel="nofollow">build system</a> for Anaconda. Select <strong><code>Tools → Build System → New Build System...</code></strong> and replace the contents of the file that opens with the following:</p> <pre ...
0
2016-08-25T17:35:17Z
[ "python", "python-2.7", "sublimetext2", "anaconda" ]
read an excel file and create a final text file from it including polish characters
39,149,572
<p>I need to be able to read in an excel file that has lots of polish characters. Then I need to be able to write this file to a text file keeping the polish characters. So far I can only open the file an write it but every time it wants to write the unicode values. As you can see from my code I strip out the u' befor...
0
2016-08-25T15:45:05Z
39,149,876
<p>Replace the last part of your code with this:</p> <pre><code>with open(xl_workbook+'.csv.txt', "wb") as f: sep=u"\t" #tab character for rownum in xrange(sh.nrows): stri_line=sep.join(unicode(val) for val in sh.row_values(rownum)) stri=stri_line.encode("utf8") # or any encoding you want that ...
1
2016-08-25T15:59:31Z
[ "python", "excel", "text", "unicode" ]
read an excel file and create a final text file from it including polish characters
39,149,572
<p>I need to be able to read in an excel file that has lots of polish characters. Then I need to be able to write this file to a text file keeping the polish characters. So far I can only open the file an write it but every time it wants to write the unicode values. As you can see from my code I strip out the u' befor...
0
2016-08-25T15:45:05Z
39,149,893
<p>The string.replace() function is purposely stripping out the unicode chars that would let python know how to to encode those chars. Define the encoding for the file handle, and python will take care of it for you.</p> <pre><code>with open('xl_workbook.txt', "w", encode="utf-8") as f: for rownum in xrange(sh.nro...
0
2016-08-25T16:00:24Z
[ "python", "excel", "text", "unicode" ]
Delete data in csv file using python?
39,149,585
<p>I have two csv files with a single column of data. How can I remove data in the second csv file in-place by comparing it with the data in the first csv file? For example: </p> <pre><code> import csv reader1 = csv.reader(open("file1.csv", "rb")) reader = csv.reader(open("file2.csv", "rb"))f for line in reader: ...
0
2016-08-25T15:46:02Z
39,149,801
<p>if both files are just single columns, then you could use <code>set</code> to remove the differences. However, this presumes that the entries in each file do not need to be duplicated and their order doesn't really matter. </p> <pre><code>#since each file is a column, unroll each file into a single list: dat1 = [x[...
0
2016-08-25T15:55:42Z
[ "python", "csv" ]
How to track class version numbers
39,149,658
<p>I have a file (call it munging.py) containing multiple functions and classes that all apply to munging data into a standardized format. I generally do not make substantial changes to this file, or the classes, but now and then a major change is needed. Suppose the file has the following contents: </p> <pre><code>...
0
2016-08-25T15:49:35Z
39,149,758
<p>For versioning the code, you do not need to make any change in code. Use any version control tool like <code>git</code> or <code>mercurial</code>. These are open-source and you can use it for free.</p> <p>Use below links to download any of them:</p> <ul> <li><a href="https://git-scm.com/downloads" rel="nofollow">G...
0
2016-08-25T15:53:41Z
[ "python", "version" ]
How to display mb/s instead of b/s in progressbar and Python?
39,149,701
<p>I am trying to change the way progressbar (version 2) displays the transferred/total file size in Python 3. Here's the code: </p> <pre><code>import progressbar import requests url = 'http://download.openbricks.org/sample/H264/big_buck_bunny_1080p_H264_AAC_25fps_7200K_short.MP4' request = requests.get(url, str...
0
2016-08-25T15:51:08Z
39,150,055
<p>From <code>progressbar</code> documentation :</p> <pre><code>class progressbar.widgets.SimpleProgress(format=’%(value)d of %(max_value)d’, max_width=None, **kwargs) Bases: progressbar.widgets.FormatWidgetMixin, progressbar.widgets.WidgetBase Returns progress as a count of the total (e.g.: “5 of 47”) </cod...
0
2016-08-25T16:09:51Z
[ "python", "python-3.x", "format", "progress-bar", "transfer" ]
How to display mb/s instead of b/s in progressbar and Python?
39,149,701
<p>I am trying to change the way progressbar (version 2) displays the transferred/total file size in Python 3. Here's the code: </p> <pre><code>import progressbar import requests url = 'http://download.openbricks.org/sample/H264/big_buck_bunny_1080p_H264_AAC_25fps_7200K_short.MP4' request = requests.get(url, str...
0
2016-08-25T15:51:08Z
39,160,964
<p>you can obtain this kind of display relatively easily with <a href="http://progressbar-2.readthedocs.io/en/latest/progressbar.widgets.html#progressbar.widgets.DataSize" rel="nofollow">DataSize</a> widget:</p> <pre><code>[###### ] 17% | 256.0 KiB/s | 631.0 KiB / 3.5 MiB | ETA: 0:00:...
0
2016-08-26T07:42:18Z
[ "python", "python-3.x", "format", "progress-bar", "transfer" ]
Put labels in the center of each bar
39,149,829
<p>I've created a bar plot with <code>matplotlib</code> pyplot library, using the following code: </p> <pre><code>fig = plt.figure(figsize=(15, 15), facecolor='white') ax_left = fig.add_subplot(221) ax_left.grid() ax_left.bar( [ix for ix in range(len(resp_tx.keys()))], resp_tx.values, ...
0
2016-08-25T15:57:05Z
39,152,931
<p>I resolved the issue with the following modifications: </p> <pre><code> resp_tx = self.tx_per_account[account].resp_tx.value_counts() ax_left = fig.add_subplot(221) ax_left.grid() ax_left.bar( ...
0
2016-08-25T19:03:31Z
[ "python", "python-2.7", "matplotlib" ]
JSON serialization error in Django Rest Framework when using pagination
39,149,941
<p>I just tried to add pagination using <code>pagination_class = TenItemsSetPagination</code> to my class-based-view. As a result, I get an error trying to access my endpoint: <code>&lt;Response status_code=200, "text/html; charset=utf-8"&gt; is not JSON serializable</code></p> <p>views.py:</p> <pre><code>class AllCa...
0
2016-08-25T16:02:58Z
39,150,229
<p>Just noticed that using <code>(ListModelMixin, generics.GenericAPIView)</code> instead of <code>(ListAPIView)</code> is responsible for the error.</p>
0
2016-08-25T16:19:05Z
[ "python", "django", "django-rest-framework" ]
Connect mongodb from Python in authorized mode
39,149,973
<p>I've created a user for my database in mongodb. I've tested with mongo shell to make sure that the user has proper privileges to access the database. Now I want to use my Python program to access the database, and I use <a href="http://api.mongodb.com/python/current/tutorial.html" rel="nofollow">PyMongo</a>. If I ru...
2
2016-08-25T16:05:05Z
39,150,113
<pre><code>client = MongoClient("mongodb://username:password@server/dbname") </code></pre> <p>This is the normal format for telling the client where and how to connect. The way you are using (with no parameters at all) defaults to a local mongo install, on the default port, with no authentication. </p>
2
2016-08-25T16:12:58Z
[ "python", "mongodb" ]
Connect mongodb from Python in authorized mode
39,149,973
<p>I've created a user for my database in mongodb. I've tested with mongo shell to make sure that the user has proper privileges to access the database. Now I want to use my Python program to access the database, and I use <a href="http://api.mongodb.com/python/current/tutorial.html" rel="nofollow">PyMongo</a>. If I ru...
2
2016-08-25T16:05:05Z
39,238,224
<p>Besides <a href="http://stackoverflow.com/a/39150113/4385621">Danielle's answer</a> you can also use <a href="http://api.mongodb.com/python/current/examples/authentication.html#scram-sha-1-rfc-5802" rel="nofollow">authenticate</a> method for that. Your code would look like this:</p> <pre><code>from pymongo import ...
1
2016-08-30T22:46:27Z
[ "python", "mongodb" ]
Login to Twitter using requests
39,150,015
<p>I am trying to login to Twitter with <code>requests</code> module in Python (2.7), and after I am logged in, I want to visit another directory on Twitter.</p> <p>So:</p> <ol> <li>Visit: <a href="https://twitter.com/login" rel="nofollow">https://twitter.com/login</a></li> <li>Locate username/pass elements</li> <li>...
0
2016-08-25T16:07:39Z
39,150,142
<p>You are using <code>r.json()</code> though response is HTML, try <code>r.text</code> instead.</p> <p>Also if you want to know you are successfully logged in, you'd rather check for your profile picture or something alike.</p> <p>Then, you should use <code>requests.Session()</code>, more info there : <a href="http:...
0
2016-08-25T16:14:40Z
[ "python", "twitter", "python-requests" ]
Pandas select columns and data dependant on header
39,150,020
<p>I have a large .csv file. I want to select only the column with he time/date and 20 other columns which I know by header. </p> <p>As a test I try to take only the column with the header 'TIMESTAMP' I know this is 4207823 rows long in the .csv and it only contains dates and times. The code below selects the TIMESTA...
0
2016-08-25T16:08:11Z
39,252,835
<p>The problem was due to an error in the input file so simple use of <code>usecols</code> in <code>pandas.read_csv</code> worked.</p> <p>code below demonstrates the selection of a few columns of data</p> <pre><code>import csv import pandas low_memory=False #read only the selected columns df = pandas.read...
0
2016-08-31T14:50:20Z
[ "python", "python-2.7", "csv", "pandas", "columnheader" ]
Python input() unresponsive after plink
39,150,054
<p>On Windows, I'm running the following Python 3.5 script from <code>cmd.exe</code>:</p> <pre><code>subprocess.run(['C:\\Program Files (x86)\\Putty\\plink.exe', 'root@server', '-P', '54022', '-i', 'key.ppk', 'exit']) input('Press Enter...') </code></pre> <p>But when it's time to press Enter, th...
1
2016-08-25T16:09:47Z
39,161,970
<p>A process might modify the console state and then for some reason fail to restore the original state when it exits. If this is a problem, the easiest solution is to spawn the child process with its own console by adding the parameter <code>creationflags=subprocess.CREATE_NEW_CONSOLE</code>. </p> <p>If that's not an...
1
2016-08-26T08:38:37Z
[ "python", "windows", "putty", "windows-console", "plink" ]
Python - file lines - pallindrome
39,150,139
<p>I have been doing python tasks for learning and I came across this task where I have to read a file that includes few words and if a line is palindrome (same when written backwards: lol > lol) so I tried with this code but It doesn't print anything on the terminal:</p> <pre><code>with open("words.txt") as f: fo...
1
2016-08-25T16:14:31Z
39,150,224
<p>The last character of each <code>line</code> is a newline character ("\n"). You need to strip trailing newlines (<code>"foo\n".strip()</code>) before checking whether the line is a palindrome.</p>
1
2016-08-25T16:18:40Z
[ "python", "python-2.7", "palindrome" ]
Python - file lines - pallindrome
39,150,139
<p>I have been doing python tasks for learning and I came across this task where I have to read a file that includes few words and if a line is palindrome (same when written backwards: lol > lol) so I tried with this code but It doesn't print anything on the terminal:</p> <pre><code>with open("words.txt") as f: fo...
1
2016-08-25T16:14:31Z
39,150,228
<p>This is because those lines contain <code>"\n"</code> on the end. <code>"\n"</code> means new line. Therefore none of those are palindromes according to python.</p> <p>You can strip off the <code>"\n"</code> first by doing:</p> <pre><code>with open("words.txt") as f: for line in f: if line.strip() == l...
1
2016-08-25T16:18:57Z
[ "python", "python-2.7", "palindrome" ]
Python - file lines - pallindrome
39,150,139
<p>I have been doing python tasks for learning and I came across this task where I have to read a file that includes few words and if a line is palindrome (same when written backwards: lol > lol) so I tried with this code but It doesn't print anything on the terminal:</p> <pre><code>with open("words.txt") as f: fo...
1
2016-08-25T16:14:31Z
39,150,258
<p>When you read a line from a file like this, you also get the newline character. So, e.g., you're seeing <code>'sefes\n'</code>, which when reversed is <code>'\nsefes'</code>. These two lines are of course not equal. One way to solve this is to use <code>rstrip</code> to remove these newlines:</p> <pre><code>with op...
1
2016-08-25T16:20:25Z
[ "python", "python-2.7", "palindrome" ]
django.core.exceptions.ImproperlyConfigured: Requested setting DEFAULT_INDEX_TABLESPACE, but settings are not configured
39,150,159
<p>I’m using Django 1.10 with Python 2.7. I have a problem running a Python script that uses Django models.</p> <pre><code> $ python contentui_app/content-util.py --sig Traceback (most recent call last): File "contentui_app/content-util.py", line 9, in &lt;module&gt; from models import * Fil...
0
2016-08-25T16:15:10Z
39,150,385
<p>This is caused when you don’t initialize Django. Try running this:</p> <pre><code>from django.conf import settings from contentui import settings settings.configure(settings) </code></pre> <p>before the rest of your code.</p>
0
2016-08-25T16:28:03Z
[ "python", "django" ]
Matplotlib subplots where one graph has multiple lines with and one doesn't
39,150,193
<p>currently trying this:</p> <pre><code>fig, ax1, ax3 = plt.subplots(1, 2, figsize=(10,5)) # share rate line and ax ax1.plot(temp_df.index, temp_df['share_rate'], 'b-') ax1.set_ylim([0,.03]) # % of total video views line and ax ax2 = ax1.twinx() ax2.plot(temp_df.index, temp_df['percent_of_total_views'], 'r-') # th...
0
2016-08-25T16:16:36Z
39,150,494
<p>You are using matplotlibs <a href="http://matplotlib.org/api/pyplot_api.html#matplotlib.pyplot.subplots" rel="nofollow">subplots-function</a> in a wrong way.</p> <p>The statement of yours</p> <pre><code>fig, ax1, ax3 = plt.subplots(1, 2, figsize=(10,5)) # WRONG 3 vars on left, 2 are returned </code></pre> <p>exp...
1
2016-08-25T16:33:44Z
[ "python", "matplotlib" ]
Load all modules (files) in directory without prefixes
39,150,206
<p>I am using python 2.7. I have a folder with a number of .py files in it that define functions, load objects, etc. that I would like to use in my main script. I want to accomplish the following two objectives:</p> <ol> <li>Load all objects from all .py files in this directory, without knowing the file names in adva...
0
2016-08-25T16:17:19Z
39,151,529
<p>Ok, here is the solution that I came up with based on the suggestion from @meetaig. I'd be delighted though to accept and upvote any other ideas or suggested implementations for this situation:</p> <pre><code>import os def Load_from_Script_Dir(DirPath): os.chdir(os.path.dirname(os.path.dirname(DirPath))) ## s...
0
2016-08-25T17:37:03Z
[ "python", "python-2.7", "module" ]
Load all modules (files) in directory without prefixes
39,150,206
<p>I am using python 2.7. I have a folder with a number of .py files in it that define functions, load objects, etc. that I would like to use in my main script. I want to accomplish the following two objectives:</p> <ol> <li>Load all objects from all .py files in this directory, without knowing the file names in adva...
0
2016-08-25T16:17:19Z
39,157,365
<p>Here is another solution, based on the same general principle as in my other implementation (which is inspired by the suggestion from @meetaig in comments). This one bypasses attempts to use the python module framework, however, and instead develops a workaround to be able to use <code>execfile()</code>. It seems ...
0
2016-08-26T02:14:03Z
[ "python", "python-2.7", "module" ]
Is it possible to return the IDs of a multi row insert in SQL?
39,150,265
<p>With the statement below I can insert multiple rows into a table. If the tag exists already then nothing happens, and if it doesn't exist it creates the row.</p> <pre><code>INSERT INTO tags (name) VALUES ('this'),('is'),('my'),('interest'),('list'),('running'),('pokemongo'),('fighting'),('eating') ON CONFLICT DO NO...
0
2016-08-25T16:20:46Z
39,150,433
<pre><code>INSERT INTO tags (name) VALUES ('this'),('is'),('my'),('interest'),('list'),('running'),('pokemongo'),('fighting'),('eating') ON CONFLICT DO NOTHING RETURNING ID; # &lt;== this is what you need. </code></pre> <p><strong>Edit:</strong> Right, with this solution you'll only get the ids of inserte...
0
2016-08-25T16:29:59Z
[ "python", "sql", "postgresql", "psycopg2", "postgresql-9.5" ]
Is it possible to return the IDs of a multi row insert in SQL?
39,150,265
<p>With the statement below I can insert multiple rows into a table. If the tag exists already then nothing happens, and if it doesn't exist it creates the row.</p> <pre><code>INSERT INTO tags (name) VALUES ('this'),('is'),('my'),('interest'),('list'),('running'),('pokemongo'),('fighting'),('eating') ON CONFLICT DO NO...
0
2016-08-25T16:20:46Z
39,151,054
<p>This can be accomplished in one query using a WITH block (see PostgreSQL docs on <a href="https://www.postgresql.org/docs/current/static/queries-with.html" rel="nofollow">WITH</a> and <a href="https://www.postgresql.org/docs/current/static/sql-select.html" rel="nofollow">SELECT</a>). For example:</p> <pre><code>WIT...
2
2016-08-25T17:07:50Z
[ "python", "sql", "postgresql", "psycopg2", "postgresql-9.5" ]
How to see every packet that comes to our computer?
39,150,274
<p>i wrote a very very easy script that monitors the Downloads folder for .part files, if there isn't any then it shuts down the computer and sends an email or text message. But i want to develop it by analyzing the packets to do that i need every packet that comes to our computer. How can i do that? or is there an eas...
0
2016-08-25T16:21:11Z
39,150,769
<p>There actually is an easier way.</p> <p>The cleanest I can think off would be monitoring the file system.</p> <p>On linux you could use <code>pyinotify</code> : <a href="https://pypi.python.org/pypi/pyinotify/" rel="nofollow">https://pypi.python.org/pypi/pyinotify/</a> <a href="https://github.com/seb-m/pyinotify/b...
2
2016-08-25T16:50:24Z
[ "python", "network-programming" ]
why don't I get index returns from list comprehension checking truth values?
39,150,369
<p>So I have a numpy array with numeric values, floats to be exact and NaNs:</p> <pre><code>In [1]: type(myarray) Out[1]: numpy.ndarray </code></pre> <p>now I want to check where there are NaNs in this array so I try:</p> <pre><code>nan_idx = [idx for idx, tf in enumerate(myarray) if not bool(tf)] </code></pre> <p>...
1
2016-08-25T16:26:51Z
39,150,393
<p>The reason your first snippet doesn't work is that <code>bool(float)</code> does not check for NaNs:</p> <pre><code>&gt;&gt;&gt; float('NaN') nan &gt;&gt;&gt; bool(float('NaN')) True &gt;&gt;&gt; not bool(float('NaN')) False </code></pre> <p>To check for NaNs, you could use <code>numpy.isnan</code> or the fact tha...
3
2016-08-25T16:28:30Z
[ "python", "numpy" ]
Why reddit cloudsearch returns wrong results with timestamp search?
39,150,406
<p>I have problem with this search:</p> <pre><code>list(r.search('timestamp:{}..{}'.format(ts1,ts2), sort='new', subreddit=subreddit, syntax='cloudsearch',limit=None)) </code></pre> <p>It gets ~1000 newest submissions from timestamp <code>ts1</code> (in my case subreddit creation time) to <code>ts2</code></p> <p>Wha...
0
2016-08-25T16:28:58Z
39,224,861
<p>For cloudsearch as far as I can gather you shouldn't use <code>created_utc</code>.</p> <p>If you change <code>submission.created_utc</code> to just <code>submission.created</code> you will get exactly the behaviour you need.</p> <p>This is due to cloudsearch using epochtime directly. There is no need to convert it...
1
2016-08-30T10:21:50Z
[ "python", "reddit", "praw" ]
Minimize the space widgets fill in a QGridLayout
39,150,459
<p>Below is a picture of my <code>QDockWidget</code>, which has a <code>QFrame</code>, and this <code>QFrame</code> has a <code>QGridLayout</code>. The single row I have in this layout places itself in the middle, but I'd like it to just sit neatly at the top instead. </p> <p>Does <code>QGridLayout</code> have any met...
0
2016-08-25T16:31:50Z
39,152,250
<p>Add a vertically expanding <a href="http://doc.qt.io/qt-4.8/qspaceritem.html" rel="nofollow">spacer-item</a> to the bottom of the grid-layout, so that it pushes the widgets above it to the top.</p>
0
2016-08-25T18:19:25Z
[ "python", "pyqt", "qgridlayout" ]
Python Multiprocessing: Child processes working at different speed
39,150,539
<p>I'm new to <code>python multiprocessing</code>. I'm trying to use a <code>third-party web-API</code> to fetch data for multiple symbols of interest. Here is my python code:</p> <pre><code>&lt;!-- language:lang-py--&gt; def my_worker(symbol, table_name): while True: # Real-time data for the symbol, thir...
0
2016-08-25T16:36:20Z
39,154,797
<p>An effective way to approach such things is to start with something vastly simpler, then <em>add</em> stuff to it until "a problem" shows up. Otherwise it's just blind guesswork.</p> <p>For example, here's something much simpler, which I'm running under Windows (like you - I'm using a current Win10 Pro) and Python...
0
2016-08-25T21:11:46Z
[ "python", "python-multiprocessing" ]
Django1.7: ModelForm has no model class specified
39,150,568
<p>I'm getting "ModelForm has no model class specified." error in Django. I've spent hours to get this fixed, but can't see what the problem is.</p> <p>Thank you very much in advance! </p> <p><strong>Traceback:</strong><br /> File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/django/c...
0
2016-08-25T16:37:49Z
39,150,986
<p>Change </p> <pre><code>class Mata: </code></pre> <p>to </p> <pre><code>class Meta: </code></pre> <p>Also, I have never seen a print statement in a modelform. Take that out just in case too. </p>
1
2016-08-25T17:03:32Z
[ "python", "django-1.7" ]
literal_eval of tuple with a single element
39,150,590
<p>I am using <code>ast.literal_eval(str)</code> to evaluate a string containing a tuple such as <code>('a', 'b', 'c')</code>. However, if for some reason this tuple only contains a single element, the expression ignores the parenthesis and returns only the element:</p> <pre><code>&gt;&gt;&gt; string = "('a')" &gt;&gt...
0
2016-08-25T16:39:13Z
39,150,625
<p>That is because <code>('a')</code> is not a tuple but a string treated as <code>a</code>. Tuple with only one object is defined as <code>('a',)</code> (note the <code>,</code>)</p> <pre><code>&gt;&gt;&gt; type('a') &lt;type 'str'&gt; &lt;-- String &gt;&gt;&gt; type(('a')) &lt;type 'str'&gt; &lt;-- String &gt;...
0
2016-08-25T16:41:01Z
[ "python", "abstract-syntax-tree" ]
representing a tree as a list in python
39,150,713
<p>I'm learning python and I'm curious about how people choose to store (binary) trees in python. </p> <p>Is there something wrong in storing the nodes of the tree as a list in python? something like:</p> <pre><code>[0,1,2,3,4,5,6,7,8] </code></pre> <p>where the 0'th position is 0 by default, 1 is the root, and for ...
0
2016-08-25T16:47:25Z
39,150,892
<p>There's nothing wrong with storing a binary tree as a list the way you're doing - it's the same idea as storing it as a flat array in a language like C or Java. Accessing the parent of a given node is very fast, and finding the children is also pretty efficient.</p> <p>I suppose a lot of examples and tutorials will...
0
2016-08-25T16:58:10Z
[ "python", "binary-tree" ]
representing a tree as a list in python
39,150,713
<p>I'm learning python and I'm curious about how people choose to store (binary) trees in python. </p> <p>Is there something wrong in storing the nodes of the tree as a list in python? something like:</p> <pre><code>[0,1,2,3,4,5,6,7,8] </code></pre> <p>where the 0'th position is 0 by default, 1 is the root, and for ...
0
2016-08-25T16:47:25Z
39,150,906
<p>You certainly COULD do this. I'd define it as a class deriving from list with a <code>get_children</code> method. However this is fairly ugly since either A) you'd have to preprocess the whole list in O(n) time to pair up indices with values or B) you'd have to call <code>list.index</code> in O(n log n) time to trav...
0
2016-08-25T16:59:02Z
[ "python", "binary-tree" ]
representing a tree as a list in python
39,150,713
<p>I'm learning python and I'm curious about how people choose to store (binary) trees in python. </p> <p>Is there something wrong in storing the nodes of the tree as a list in python? something like:</p> <pre><code>[0,1,2,3,4,5,6,7,8] </code></pre> <p>where the 0'th position is 0 by default, 1 is the root, and for ...
0
2016-08-25T16:47:25Z
39,150,912
<p>I've seen representations like this (your flat list/array) used in C code, and representations like this could be acceptable in Python too, but it depends on the nature of the data you're handling. In C code, a balanced tree in this list representation can be very fast to access (much quicker than navigating a serie...
0
2016-08-25T16:59:26Z
[ "python", "binary-tree" ]
How to look for a value in a Python DataFrame column?
39,150,783
<p>This is my first question on this forum, sorry if my English is not so good!</p> <p>I want to add a row to a DataFrame only if a specific column doesn't already contain a specific value. Let say I write this :</p> <pre><code>df = pd.DataFrame([['Mark', 9], ['Laura', 22]], columns=['Name', 'Age']) new_friend = pd.D...
2
2016-08-25T16:51:18Z
39,150,899
<pre><code>if 'Mark' in list(df['Name']): print('Mark already in DF') else: print('Mark not in DF') </code></pre>
0
2016-08-25T16:58:45Z
[ "python", "pandas", "dataframe" ]
defaultdict not available, implementation using an empty dictionary
39,150,818
<p>I have a code that looks like this:</p> <pre><code>abcd a1 abcd a2 abcd a3 abcd b1 abcd b2 q a1 q a2 </code></pre> <p>I have a defaultdict implementation that places them in dictionary. However, how would I do this without defaultdict(older python). My goal is to have a dictionary that looks something like this:<...
-1
2016-08-25T16:53:44Z
39,150,860
<p>Instead of <code>defaultdict</code> use <code>setdefault()</code>:</p> <pre><code>x = {} x.setdefault('abcd', []).append('a1') x.setdefault('abcd', []).append('a2') </code></pre> <p>This will result in:</p> <pre><code>abcd: ['a1', 'a2'] </code></pre> <p>and works by trying to lookup <code>'abcd'</code> as key fo...
2
2016-08-25T16:56:28Z
[ "python", "python-2.7" ]
defaultdict not available, implementation using an empty dictionary
39,150,818
<p>I have a code that looks like this:</p> <pre><code>abcd a1 abcd a2 abcd a3 abcd b1 abcd b2 q a1 q a2 </code></pre> <p>I have a defaultdict implementation that places them in dictionary. However, how would I do this without defaultdict(older python). My goal is to have a dictionary that looks something like this:<...
-1
2016-08-25T16:53:44Z
39,150,956
<p>You can implement <code>__missing__</code> on a subclass of <code>dict</code> and create an additional <code>count</code> method to count the number of occurences of a key:</p> <pre><code>class DefaultDict(dict): def __missing__(self, key): self[key] = [] return self[key] def count(self, ke...
2
2016-08-25T17:01:51Z
[ "python", "python-2.7" ]
Python Tornado: how do I set WebSocket headers?
39,150,911
<p>I'm new to web development so let me explain:<br> I want my Python Tornado server to communicate with a web page. My web page uses WebSockets and the <code>onmessage</code> function to print what it should receive from the Tornado server. Basically, here is the HTML JavaScript part:</p> <pre class="lang-js prettypr...
0
2016-08-25T16:59:19Z
39,159,316
<p>Your javascript is using EventSource but your server is serving WebSockets. These are two completely different things. You need to change one of those to match the other. </p>
2
2016-08-26T06:03:58Z
[ "javascript", "python", "websocket", "cors", "tornado" ]
Program only runs when not run from a script or batch file, but works perfectly when typed in by hand in CMD
39,150,947
<p>I am trying to run the windows helpfile compiler (<code>hhc.exe</code>) from a script, but it shows very unexpected behaviour.</p> <p>When I run it from cmd.exe with <code>hhc pathtohelpproject.hpp</code>, the helpfile is compiled as expected. However, invoking the exact same command from python with the same worki...
0
2016-08-25T17:01:19Z
39,182,138
<p>It's totally down to hhc.exe, nothing else. The trick is to look at the %ERRORLEVEL% after it runs. It returns "1" despite success. This could be used in a custom command to warn the user it's spurious, if the hhc.exe run is isolated from other stuff. HHC.exe is using HHA.dll. About HHA.dll info has not been publis...
0
2016-08-27T14:19:00Z
[ "python", "windows", "batch-file", "cmd", "chm" ]
Dynamic attributes or custom dictionary for fixed read-only fields
39,151,007
<p>I am creating a class for retrieving details about a computer such as host_name, kernel_version, bios_version, and so on. Some details are more expensive to collect than others so I have a get_* function to retrieve them, but keep the results cached in the object if they are needed again. I am considering implementi...
0
2016-08-25T17:04:45Z
39,171,820
<p>I think sticking with the read-only dictionary subclass approach you're using is fine. However your implementation could be improved somewhat by creating a generic read-only dictionary superclass from which to derive your specific subclass, and using a metaclass to create the value returned by the <code>keys()</code...
0
2016-08-26T17:32:55Z
[ "python", "python-2.7", "python-2.6" ]
Connect an existing github repository to heroku app
39,151,053
<pre><code>https://github.com/AparnaBalagopal/first-blog . </code></pre> <p>This is my existing github repository. I need to use this repository on a new heroku python app. I'm new to heroku. I referred <code>https://devcenter.heroku.com/</code>. There is no description about using an existing repository on heroku in...
0
2016-08-25T17:07:48Z
39,151,149
<p>You need to add your Heroku remote to your git repository.</p> <pre><code>git remote add heroku &lt;your-heroku-git-url&gt; </code></pre> <p>You can find that URL in your Herkou app's settings. You can then deploy to Heroku as per normal (<code>git push heroku master</code>).</p>
1
2016-08-25T17:14:39Z
[ "python", "heroku", "github" ]
Search for a partial string in an array of strings
39,151,056
<p>What is the Pythonic/quick way to search for a partial string in an array and then remove that string from the array?<br> (I can do it with a simple loop and IF IN and rebuild two array in the loop, Asking if there is a Pythonic way/function to do this)</p> <p>Example: </p> <pre><code>array = ['rule1','rule2','ex...
2
2016-08-25T17:07:52Z
39,151,109
<pre><code>&gt;&gt;&gt; [x for x in array if 'exception' not in x] ['rule1', 'rule2', 'rule3'] &gt;&gt;&gt; [x for x in array if 'exception' in x] ['exception[type_a]', 'exception[type_b]'] </code></pre> <p>See also: <a href="http://stackoverflow.com/questions/949098/python-split-a-list-based-on-a-condition">Python: s...
2
2016-08-25T17:11:49Z
[ "python", "arrays", "python-3.x" ]
Search for a partial string in an array of strings
39,151,056
<p>What is the Pythonic/quick way to search for a partial string in an array and then remove that string from the array?<br> (I can do it with a simple loop and IF IN and rebuild two array in the loop, Asking if there is a Pythonic way/function to do this)</p> <p>Example: </p> <pre><code>array = ['rule1','rule2','ex...
2
2016-08-25T17:07:52Z
39,151,121
<p>You may use in-built <code>filter</code> with <code>lambda</code> function to achieve this as:</p> <pre><code>&gt;&gt;&gt; my_array = array = ['rule1','rule2','exception[type_a]','rule3','exception[type_b]'] &gt;&gt;&gt; my_string = 'exception' &gt;&gt;&gt; filter(lambda x: my_string not in x, my_array) ['rule1', '...
0
2016-08-25T17:12:36Z
[ "python", "arrays", "python-3.x" ]
Search for a partial string in an array of strings
39,151,056
<p>What is the Pythonic/quick way to search for a partial string in an array and then remove that string from the array?<br> (I can do it with a simple loop and IF IN and rebuild two array in the loop, Asking if there is a Pythonic way/function to do this)</p> <p>Example: </p> <pre><code>array = ['rule1','rule2','ex...
2
2016-08-25T17:07:52Z
39,151,147
<p>If you want to separate your items you can do it with one loop and by preserving the items in a dictionary:</p> <pre><code>&gt;&gt;&gt; d = {} &gt;&gt;&gt; for i in array: ... if 'exception' in i: ... d.setdefault('exception', []).append(i) ... else: ... d.setdefault('other', []).append(i) ....
1
2016-08-25T17:14:32Z
[ "python", "arrays", "python-3.x" ]
Search for a partial string in an array of strings
39,151,056
<p>What is the Pythonic/quick way to search for a partial string in an array and then remove that string from the array?<br> (I can do it with a simple loop and IF IN and rebuild two array in the loop, Asking if there is a Pythonic way/function to do this)</p> <p>Example: </p> <pre><code>array = ['rule1','rule2','ex...
2
2016-08-25T17:07:52Z
39,151,218
<p>For list-of-strings <code>array</code> and thing-to-exclude <code>target</code>:</p> <p>List comprehensions work:</p> <pre><code>result = [s for s in array if target not in s] </code></pre> <p>Or a generator comprehension for the same:</p> <pre><code>result = (s for s in array if target not in s) </code></pre> ...
0
2016-08-25T17:19:21Z
[ "python", "arrays", "python-3.x" ]
Search for a partial string in an array of strings
39,151,056
<p>What is the Pythonic/quick way to search for a partial string in an array and then remove that string from the array?<br> (I can do it with a simple loop and IF IN and rebuild two array in the loop, Asking if there is a Pythonic way/function to do this)</p> <p>Example: </p> <pre><code>array = ['rule1','rule2','ex...
2
2016-08-25T17:07:52Z
39,151,684
<p>Seriously, just use a <code>for</code> loop, you're trying to create <em>two</em> lists so a single comprehension won't do (i.e the top solution so far iterates <em>twice</em> over the same list).</p> <p>Create two lists and append to them conditionally:</p> <pre><code>l1 = list() l2 = list() for i in array: l...
1
2016-08-25T17:45:32Z
[ "python", "arrays", "python-3.x" ]
Single Array & Data Plotting with it
39,151,141
<p>The data I have is printed in a .txt file format and has breaks in between readings, its just one really long line. Each data point is a 16 second average of the z-component of the magnetic field of an incoming particle field. This is currently the code I have typed to ascribe the variable name to the file</p> <pre...
0
2016-08-25T17:14:17Z
39,151,300
<p>numpy is loading your data as bytes, and marking them as such, with the b character. I tried the following:</p> <pre><code>data = np.loadtxt("ACE_MAG_Data.txt", dtype=bytes).astype(float) </code></pre> <p>And it converts everything to floats instead:</p> <pre><code>&gt;&gt;&gt; data array([[-13.695 , -13.481 ],...
0
2016-08-25T17:24:52Z
[ "python", "matplotlib", "plot" ]
How to split a list by a changing step size?
39,151,201
<p>I have a list that I want to split up in to variable steps sizes. For example, if I have a list from 1 to 100, at the end of each iteration, I would want the output to be:</p> <pre><code>[1, 2, 3] [4, 5, 6, 7, 8] [9, 10, 11, 12, ..., 15] [16, 17, ..., 25] </code></pre> <p>The length of the first list is 3, then 5...
1
2016-08-25T17:18:18Z
39,151,259
<p>Since the step size varies, you need a while loop:</p> <pre><code>lst = list(range(1,101)) step = 3 idx = 0 while idx&lt;len(lst): print(lst[idx:idx+step]) idx += step step += 2 </code></pre>
2
2016-08-25T17:21:54Z
[ "python", "list", "for-loop" ]
How to split a list by a changing step size?
39,151,201
<p>I have a list that I want to split up in to variable steps sizes. For example, if I have a list from 1 to 100, at the end of each iteration, I would want the output to be:</p> <pre><code>[1, 2, 3] [4, 5, 6, 7, 8] [9, 10, 11, 12, ..., 15] [16, 17, ..., 25] </code></pre> <p>The length of the first list is 3, then 5...
1
2016-08-25T17:18:18Z
39,151,336
<p>Note that the indices to begin a slice at are given by the closed form:</p> <pre><code>n**2 - 1 </code></pre> <p>Therefore:</p> <pre><code>&gt;&gt;&gt; [lst[n**2-1:(n+1)**2-1] for n in range(1, 10)] [[1, 2, 3], [4, 5, 6, 7, 8], [9, 10, 11, 12, 13, 14, 15], [16, 17, 18, 19, 20, 21, 22, 23, 24], [25, 26, 27, 2...
4
2016-08-25T17:26:58Z
[ "python", "list", "for-loop" ]
How to split a list by a changing step size?
39,151,201
<p>I have a list that I want to split up in to variable steps sizes. For example, if I have a list from 1 to 100, at the end of each iteration, I would want the output to be:</p> <pre><code>[1, 2, 3] [4, 5, 6, 7, 8] [9, 10, 11, 12, ..., 15] [16, 17, ..., 25] </code></pre> <p>The length of the first list is 3, then 5...
1
2016-08-25T17:18:18Z
39,151,384
<p>Daniel's answer is the most concise one, but I'd like to point out that sometimes, you have a more complex situation and want to have the same slices from different iterables. Then you can also go along and store the actual <code>slice(start,stop[,step])</code> objects that python generates when you write <code>[sta...
0
2016-08-25T17:29:26Z
[ "python", "list", "for-loop" ]
Broadcasting mathematical operations with PYMC3/Theano
39,151,247
<p>I think this issue boils down to my lack of understanding with <code>Theano</code> works. I'm in a situation where I want to create a variable that is the result of a subtraction between a distribution and a numpy array. This works fine when I specify the shape parameter as <code>1</code></p> <pre><code>import pymc...
0
2016-08-25T17:21:21Z
39,159,210
<p>You can do</p> <pre><code>X = np.random.randint(low = -10, high = 10, size = 100) X = x[:,None] # or x.reshape(-1, 1) </code></pre> <p>and then</p> <pre><code>with pm.Model() as model: nl = pm.Normal('nl', shape = 2) det = pm.Deterministic('det', nl - X) </code></pre> <p>In this case the shapes of nl and...
1
2016-08-26T05:57:08Z
[ "python", "theano", "bayesian", "pymc3" ]
Subsetting column from pandas dataframe with indexing
39,151,266
<p>I have a large data set in a pandas dataframe I would like to subset in order to further manipulate. </p> <p>For example, I have a df that looks like this:</p> <pre><code>Sample Group AMP ADP ATP 1 A 0.3840396 0.55635504 0.5844648 2 A 0.3971521 0.57851902 -0.2460320...
2
2016-08-25T17:22:31Z
39,151,359
<pre><code>df2 = df.loc[df['Group'] == 'B', ['Sample', 'Group', 'ATP']] </code></pre>
2
2016-08-25T17:28:21Z
[ "python", "pandas", "subset" ]
How to ignore NULL byte when reading a csv file
39,151,276
<p>I'm reading a csv file generated from an equipment and I got this error message:</p> <pre><code>Error: line contains NULL byte </code></pre> <p>I opened the csv file in text editor and I do see there're some NUL bytes in the header section, which I don't really care about. How can I make the csv reader function to...
-1
2016-08-25T17:23:00Z
39,151,484
<p>This will replace your NULL bytes</p> <pre><code>csvreader = csv.reader(x.replace('\0', '') for x in csvfile) </code></pre>
0
2016-08-25T17:34:42Z
[ "python", "csv" ]
Data Entry error
39,151,295
<p>l would like to create a control system for administrator on Tkinter and some functions (add, delete, update and load) are main part of control system but when l run the code , these functions do not work and there is no error message. But ,l could not figure out where the problem is. My code is still not complet...
0
2016-08-25T17:24:34Z
39,151,617
<p>It is bad practice to define your functions in a function and makes debugging pretty difficult. I would start by using an object to create this GUI. Object variables: </p> <ul> <li>passwordVar and nameVar, </li> <li>select</li> <li>userlist</li> <li>win</li> </ul>
0
2016-08-25T17:42:18Z
[ "python", "tkinter" ]
Data Entry error
39,151,295
<p>l would like to create a control system for administrator on Tkinter and some functions (add, delete, update and load) are main part of control system but when l run the code , these functions do not work and there is no error message. But ,l could not figure out where the problem is. My code is still not complet...
0
2016-08-25T17:24:34Z
39,151,693
<p>There's a lot going wrong for your code.</p> <p>For instance, you don't need to import <code>tkinter</code> twice. Your casing of the variable names doesn't follow <a href="https://www.python.org/dev/peps/pep-0008/" rel="nofollow">PEP8</a>. You could benefit from an <a href="https://en.wikipedia.org/wiki/Object-ori...
0
2016-08-25T17:46:13Z
[ "python", "tkinter" ]
sum columns in dataframe with pandas
39,151,443
<p>I have a dataframe df_F1</p> <p>df_F1.info()</p> <pre><code> &lt;class 'pandas.core.frame.DataFrame'&gt; Int64Index: 2 entries, 0 to 1 Data columns (total 7 columns): class_energy 2 non-null object ACT_TIME_AERATEUR_1_F1 2 non-null float64 ACT_TIME_AERATEUR_1_F3 2 non-null ...
0
2016-08-25T17:31:55Z
39,151,574
<p>you can do this:</p> <pre><code>In [20]: df.set_index('class_energy').apply(lambda x: x/x.sum()).reset_index() Out[20]: class_energy ACT_TIME_AERATEUR_1_F1 ACT_TIME_AERATEUR_1_F3 0 low 0.006812 0.334887 1 medium 0.993188 0.665113 </code>...
1
2016-08-25T17:39:40Z
[ "python", "pandas", "dataframe", "sum" ]
How to execute some code and have data global available to modules on import
39,151,468
<p>I'm trying to build a package and what I would like is that on import some code would parse some data from a set of files and then have some dictionaries available to my modules. I was wondering what the best way to do something like this would be. Thanks for the help.</p> <p>So if my package is:</p> <pre><code>Pa...
0
2016-08-25T17:33:42Z
39,151,938
<pre><code># run.py File where you are trying to display variable from other "global" module import imp def load_module(myglobals, path): with open(path, 'rb') as f: return imp.load_source(myglobals, path, f) filename_path = '/home/turkus/myglobals.py' module = load_module('myglobals', filename_path) pr...
1
2016-08-25T18:00:01Z
[ "python" ]
Calling jsonify on a variable for use in an html file renders incorrectly
39,151,472
<p>Is there any way to store "jsonify" in a variable? I dislike the pure json format of doing "return jsonify(data)" but I like the indentation so I'm trying to pretty it up using a rendered HTML template. Here is my python code:</p> <pre><code>from flask import Flask, jsonify, render_template app = Flask(__name__) @...
1
2016-08-25T17:34:03Z
39,151,552
<p><code>jsonify()</code> produces a <em>response object</em>, one that <em>contains</em> the JSON data. From the <a href="http://flask.pocoo.org/docs/0.11/api/#flask.json.jsonify" rel="nofollow"><code>flask.json.jsonify()</code> documentation</a>:</p> <blockquote> <p>This function wraps <code>dumps()</code> to add ...
3
2016-08-25T17:38:29Z
[ "python", "html", "json", "flask" ]
matplotlib not saving pdf w/ latex
39,151,477
<p>I am having an issue simular to <a href="http://stackoverflow.com/questions/37533912/error-saving-matplotlib-figures-to-pdf-str-object-has-no-attribute-decode">Error saving matplotlib figures to pdf: &#39;str&#39; object has no attribute &#39;decode&#39;</a>, but without the cyrillic letters. My code is below:</p> ...
1
2016-08-25T17:34:20Z
39,154,293
<p>It seems that I had the same issue caused by the lack of some necessary fonts in my MikTex installation. For me the solution was to reinstall it with all packages to make sure that all fonts are generated. I know that is an ugly workaround, but it solved my problem completely. I've tried your script (only without s...
1
2016-08-25T20:33:17Z
[ "python", "pdf", "matplotlib", "latex" ]
Finding daily patterns in timestamps data with python
39,151,482
<p>So i want to analyze database data of smart house. This is how data i have look like: </p> <pre><code>ID NAME STATUS TIME 1 light 1 2016-06-25 08:00:00 2 light 1 2016-06-25 08:01:05 3 light 1 2016-06-25 08:00:21 4 light 1 2016-06-25 08:00:30 ... </code></pre> <p>Basically...
0
2016-08-25T17:34:36Z
39,151,711
<p>This script takes lowest and maximum time from database and calculate time between these times.</p> <pre><code># db.txt 1 light 1 2016-06-25 08:00:00 1 light 1 2016-06-25 08:01:05 1 light 1 2016-06-25 08:00:21 1 light 1 2016-06-25 08:00:30 # python script import datetime def d...
1
2016-08-25T17:47:13Z
[ "python", "machine-learning", "statistics", "artificial-intelligence" ]
Initialize nested classes from JSON in Python?
39,151,488
<p>When writing APIs I often need to initialize classes from nested JSONs like this</p> <pre><code># When my API receives such a ... n_json = {"nested1": {"nested2" : { "nested3" : "..." }}} # .. I need to instantiate a proper object out of it ... nested1 = Nested1.from_json(json.loads(n_json)) # ... so I can later ...
1
2016-08-25T17:34:52Z
39,152,685
<p>This is how you can create a nested object from JSON (similarly to how PHP does that). To create object tree from JSON (rather, parsed JSON, which is just a Python structure), write the following class:</p> <pre><code>class Nested: def __new__(cls, structure): self = super(Nested, cls).__new__(cls) ...
0
2016-08-25T18:47:56Z
[ "python", "json", "api", "web-applications" ]
Finding a sum of series in Python 2.7.x
39,151,536
<p>Here's the equation </p> <pre><code>x + x^2/2 + x^3/3 +.... x^n/n </code></pre> <p>How will I find the sum of this series? x is a constant term to be entered by user and n which is power is also based on user! </p> <p>I made this program but it's not working properly.. Have a look - </p> <pre><code>n=input("Ente...
1
2016-08-25T17:37:37Z
39,151,609
<p>Something like this for your loop? Tried to keep it simple.</p> <pre><code>n = input("Enter power ") x = float(input("Enter value of x")) ans = 0 for i in range(1, n+1): ans += x**i/i print(ans) </code></pre> <p>See zev's answer regarding floats</p>
2
2016-08-25T17:42:02Z
[ "python" ]
Finding a sum of series in Python 2.7.x
39,151,536
<p>Here's the equation </p> <pre><code>x + x^2/2 + x^3/3 +.... x^n/n </code></pre> <p>How will I find the sum of this series? x is a constant term to be entered by user and n which is power is also based on user! </p> <p>I made this program but it's not working properly.. Have a look - </p> <pre><code>n=input("Ente...
1
2016-08-25T17:37:37Z
39,151,666
<p>You're not adding the terms together. </p> <p><strong><em>Also</em></strong>, you need to be careful that you use float division when <code>x</code> is an integer. <a href="http://stackoverflow.com/q/1267869/1090302">See this thread</a>.</p> <p>Here's a working implementation:</p> <pre><code>n = input("Enter powe...
2
2016-08-25T17:44:52Z
[ "python" ]
Finding a sum of series in Python 2.7.x
39,151,536
<p>Here's the equation </p> <pre><code>x + x^2/2 + x^3/3 +.... x^n/n </code></pre> <p>How will I find the sum of this series? x is a constant term to be entered by user and n which is power is also based on user! </p> <p>I made this program but it's not working properly.. Have a look - </p> <pre><code>n=input("Ente...
1
2016-08-25T17:37:37Z
39,151,921
<p>Issue with your program is that your are not adding the sum. See: <code>res=(x**(n-c))/(n-(c))</code>. Instead do:</p> <pre><code>res += (x**(n-c))/(n-(c)) </code></pre> <p>You may also achieve it by using in-built <code>sum</code>, <code>map</code> and <code>lambda</code> functions as:</p> <pre><code>y = 5 # or...
0
2016-08-25T17:59:17Z
[ "python" ]
Convert sparse pandas dataframe with `NaN` into integer values
39,151,545
<p>I have a binary pandas dataframe with values <code>0.0</code>, <code>1.0</code>, and <code>NaN</code>. </p> <pre><code>import pandas as pd df = pd.read_csv("file.csv") </code></pre> <p>I would like to turn the floats <code>1.0</code> and <code>0.0</code> into integers <code>1</code> and <code>0</code>. Unfortunate...
1
2016-08-25T17:38:00Z
39,152,098
<p><strong>UPDATE:</strong></p> <p>if you need nice looking <strong>string</strong> values you can do it:</p> <pre><code>In [84]: df.astype(object) Out[84]: a b c 0 0 1 0 1 0 0 1 2 1 1 1 3 0 1 1 4 1 1 NaN </code></pre> <p>but all values - are strings (<code>object</code> in pandas terms...
1
2016-08-25T18:10:58Z
[ "python", "pandas", "binary", "int" ]
Where to put .theanorc file for Anaconda installation? (Windows)
39,151,628
<p>I recently installed Python 2.7 using Anaconda on my Windows 10 (x64)</p> <p>I am trying to install Theano, I am however not sure where I should put the '.theanorc' file (for setting Theano parameters). I have verified that theano works (trained small neural network).</p> <p>I have tried to put it in <code>C:\Anac...
1
2016-08-25T17:42:48Z
39,152,622
<p>dotfiles are typically stored in the <code>%HOME%</code> directory, which on windows is <code>%USERPROFILE%</code>. This translates to <code>C:\Users\username</code></p>
3
2016-08-25T18:44:14Z
[ "python", "windows", "python-2.7", "anaconda", "theano" ]
Eloqua delete canvas dependencies using REST API
39,151,732
<p>I need to delete a big number of canvases and they have filters and segments as dependencies. </p> <p>I've done an application in Python which sends API calls to get the segments and filters by using a search key but I can't delete them because they are dependencies in canvases.</p> <p>Is there a way to delete the...
0
2016-08-25T17:48:50Z
39,824,955
<p>If the Campaign Canvas has dependencies, that means the Campaign Canvas is explicitly referenced. In example, the dependent Segment or Filter includes a "Clicked Emails from Campaigns" filer criteria that references the Campaign Canvas.</p> <p>In this example, in order to remove dependencies, you must edit the crit...
0
2016-10-03T05:16:41Z
[ "python", "rest", "api", "eloqua" ]
parsing a dictionary from file in python using argparse?
39,151,817
<p>I have been using a file containing variables as input for a program, which is then imported into the main program at runtime. I am moving this system to using argparse reading the input values from a file. One of the current input variables is a list of dictionaries, with each dictionary providing settings for a g...
0
2016-08-25T17:53:33Z
39,152,178
<p>That is not what argparse is for. It is for parsing command line arguments, not config files.</p> <p>It looks like your config is in JSON and unless you do something extremely weird and heavily abuse the library, argparse does not know how to parse JSON. So to understand the parameters you'd need to <code>import js...
1
2016-08-25T18:15:19Z
[ "python", "argparse" ]