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
graphlab create sframe combine two column
39,091,454
<p>I have two columns with strings. let's say col1 and col2 now how can we combine the content of col1 and col2 into col3 with graphlab SFrame? </p> <pre><code>col1 col2 23 33 42 11 ........ </code></pre> <p>into </p> <pre><code>col3 23,33 42,11 .... </code></pre> <p>unstack will only give sarray or dict, i ...
0
2016-08-23T02:35:49Z
39,091,575
<p>Using pandas:</p> <pre><code>In [271]: df Out[271]: col1 col2 0 23 33 1 42 11 In [272]: df['col3'] = (df['col1'].map(str) + ',' + df['col2'].map(str)) In [273]: df Out[273]: col1 col2 col3 0 23 33 23,33 1 42 11 42,11 </code></pre> <p>Using graphlab:</p> <pre><code>In [17]: ...
1
2016-08-23T02:51:20Z
[ "python", "pandas", "graphlab" ]
parsing output from command call
39,091,469
<p>So I'm trying to execute a shell command from python and then either store it in an array or directly parse the piped shell command.</p> <p>I am piping the shell data via the subprocess command and verified the output using print statement and it worked just fine.</p> <pre><code>a = subprocess.Popen('filepath/comm...
2
2016-08-23T02:37:38Z
39,104,350
<p>Quoting <a href="http://stackoverflow.com/users/2603/aaron-maenpaa">Aaron Maenpaa</a>'s <a href="http://stackoverflow.com/a/606199/4396006">answer</a>:</p> <blockquote> <p>You need to decode the bytes object to produce a string:</p> <pre><code>&gt;&gt;&gt; b"abcde" b'abcde' # utf-8 is used here because it is a ...
1
2016-08-23T14:46:55Z
[ "python", "string", "subprocess", "stdout", "popen" ]
matplotlib does not show legend in scatter plot
39,091,515
<p>I am trying to work on a clustering problem for which I need to plot a scatter plot for my clusters.</p> <pre><code>%matplotlib inline import matplotlib.pyplot as plt df = pd.merge(dataframe,actual_cluster) plt.scatter(df['x'], df['y'], c=df['cluster']) plt.legend() plt.show() </code></pre> <blockquote> <p>df['c...
0
2016-08-23T02:43:43Z
39,091,893
<p><strong>EDIT:</strong></p> <p>Generating some random data:</p> <pre><code>from scipy.cluster.vq import kmeans2 n_clusters = 10 df = pd.DataFrame({'x':np.random.randn(1000), 'y':np.random.randn(1000)}) _, df['cluster'] = kmeans2(df, n_clusters) </code></pre> <p>Plotting:</p> <pre><code>fig, ax = plt.subplots() cm...
0
2016-08-23T03:32:17Z
[ "python", "matplotlib", "plot", "cluster-analysis" ]
Python Flask + AngularJS + DevExtreme
39,091,519
<p>First, I am fairly new to javascript but I know my way around python. I am trying to learn javascript and I may be out of my league with trying this, but that is how you learn right.</p> <p>Secondly, Flask and AngularJS play well together with a little help. Special thanks goes to shea256 (<a href="https://github.c...
1
2016-08-23T02:44:06Z
39,095,838
<p><a href="http://js.devexpress.com/Documentation/Guide/Common/3rd-Party_Libraries_and_Frameworks_Integration/?version=16_1#Data_Binding_and_SPA_Frameworks" rel="nofollow">DevExtreme supports</a> AngularJS 1.2 - 1.4. Your try to use too old version of AngularJS. Scripts in this <a href="https://github.com/shea256/angu...
1
2016-08-23T08:15:46Z
[ "python", "angularjs", "flask", "devexpress" ]
ImportError: No module named pandas. Pandas installed
39,091,520
<p>I am pretty new to programming and am having issues importing pandas to my program. Hoping someone could point me in the right direction to fix this. I am running OSX</p> <p><strong>regresson.py</strong></p> <pre><code>import pandas as pd import Quandl df = Quandl.get('WIKI/GOOGL') print df.head </code></pre> <p...
-2
2016-08-23T02:44:36Z
39,091,612
<p>make sure to activate your conda environment </p> <p>in your terminal-</p> <pre><code>conda create -n environment_name quandl pandas cd path_to_env activate environment_name (environment_name)conda list (make sure u have the right packages) (environment_name) your_program.py </code></pre>
0
2016-08-23T02:56:21Z
[ "python", "osx", "pandas", "anaconda" ]
Can't use column name list to create SQLite View in Python
39,091,581
<p>I've created a database and am able to create a simple view using the following command:</p> <pre><code>CREATE VIEW IF NOT EXISTS monthly_terminals (year, month) AS SELECT reportYear, reportMonth FROM osMonthlyTerminals </code></pre> <p>This command works just fine if I paste into the SQLite Manager plugin on Fi...
0
2016-08-23T02:52:20Z
39,094,726
<p>Python has its own copy of the SQLite library (see <code>sqlite3.sqlite_version</code>).</p> <p>If the latest Python version does not have a recent enough version of SQLite, the only way to update it would be to recompile Python, or use some other DB driver like <a href="https://rogerbinns.github.io/apsw/" rel="nof...
1
2016-08-23T07:19:19Z
[ "python", "sqlite3", "anaconda" ]
Spotify - Audio Feature exception
39,091,665
<p>I've been successufully retrieving <code>audio_features</code> from <code>Spotify</code>'s <code>recommendations</code> <code>endpoint</code>, like so. </p> <pre><code>features = sp.audio_features(tracks_ids) </code></pre> <p>However, if I provide a list of <code>id</code>'s retrieved using <code>search</code> <co...
0
2016-08-23T03:02:02Z
39,096,859
<p>You are getting a <a href="https://www.w3.org/Protocols/rfc2616/rfc2616-sec10.html#sec10.4.15" rel="nofollow">414 status code</a>, which indicates that the requested URI is too long.</p> <p>If you are providing 100 or less ids, then this is a bug on Spotify's end. In this case I would recommend you to file a ticket...
0
2016-08-23T09:05:03Z
[ "python", "spotify", "spotipy" ]
Python Blackjack Count
39,091,677
<p>Not so much a problem or question, just wanted to know how other people would approach this. I'm working in python to make a blackjack game through python's class structure and I've made the deck an array with the cards as strings. This helps with the fact that 4 cards are worth 10 in blackjack and an Ace can be wor...
1
2016-08-23T03:03:06Z
39,091,815
<p>Do yourself a favor, get an explicit map of card values:</p> <pre><code>CARD_VALUE = { '2': 2, '3': 3, # etc 'A': 1, 'J': 12, 'Q': 13, 'K': 14, } # Calculate the value of a hand; # a hand is a list of cards. hand_value = sum(CARD_VALUE[card] for card in hand) </code></pre> <p>For different games, yo...
1
2016-08-23T03:22:06Z
[ "python", "list", "dictionary", "blackjack" ]
Python Blackjack Count
39,091,677
<p>Not so much a problem or question, just wanted to know how other people would approach this. I'm working in python to make a blackjack game through python's class structure and I've made the deck an array with the cards as strings. This helps with the fact that 4 cards are worth 10 in blackjack and an Ace can be wor...
1
2016-08-23T03:03:06Z
39,091,825
<p><a href="http://codereview.stackexchange.com/questions/57849/blackjack-game-with-classes-instead-of-functions">SOURCE</a></p> <p>So here is what you can do :</p> <p>Make your deck a string</p> <pre><code>import random cards = 'A'*4 + '2'*4 + ... + 'K'*4 self.deck = ''.join(random.sample(cards,len(cards))) value...
0
2016-08-23T03:23:47Z
[ "python", "list", "dictionary", "blackjack" ]
regarding using dtype.newbyteorder
39,091,765
<p>I once read the following function in a given program, but I am not very clear about what is this function used for? According <code>SciPy.org</code>, </p> <blockquote> <p>dtype.newbyteorder(new_order='S') Return a new dtype with a different byte order.</p> </blockquote> <p>I do not quite understand what does ...
1
2016-08-23T03:16:25Z
39,093,664
<p>Here's a simple example:</p> <pre><code>&gt;&gt;&gt; dt = np.dtype(np.uint32) &gt;&gt;&gt; val = np.frombuffer(b'\x01\x02\x03\x04', dtype=dt) &gt;&gt;&gt; hex(val) '0x4030201' &gt;&gt;&gt; val2 = np.frombuffer(b'\x01\x02\x03\x04', dtype=dt.newbyteorder('&gt;')) &gt;&gt;&gt; hex(val2) '0x1020304' </code></pre> <p>B...
0
2016-08-23T06:17:36Z
[ "python", "numpy", "scipy" ]
Reviving pandas KeyErrors seemingly at random, without changing my code. Possible memory errors?
39,091,791
<p>I'm working through a sklearn tutorial book, that had this section:</p> <pre><code>Next, we create a TfidfVectorizer. Recall from Chapter 3, Feature Extraction and Preprocessing, that TfidfVectorizer combines CountVectorizer and TfidfTransformer. We fit it with the training messages, and transform both the training...
1
2016-08-23T03:19:15Z
39,114,121
<p>UPDATE</p> <p>I found a solution from here: <a href="https://stackoverflow.com/questions/29305131/problems-with-pandas?answertab=votes#tab-top">Problems with Pandas</a></p> <p>I changed:</p> <pre><code>print 'Prediction: %s. Message: %s' % (pdn, X_test_raw[i]) </code></pre> <p>to</p> <pre><code>print 'Predictio...
0
2016-08-24T03:50:34Z
[ "python", "csv", "pandas", "memory", "keyerror" ]
Python: OpenGL Error 1280 Invalid Enumerant with glEnd()
39,091,819
<p>I am working on creating a flashlight app in Python using Numba for my kernel and OpenGL (code below) . It is very close to finished but when I run it I run into an error with glEnd error 1280. The terminal output for when the code is run is also below. I can't figure out what exactly is causing the issue and helpin...
0
2016-08-23T03:22:45Z
39,095,592
<p>The problem might come from this line:</p> <pre><code>glBegin(GL_TEXTURE_2D) </code></pre> <p>glBegin does not allow for this parameter. It only accepts primitive types (which TEXTURE_2D is not). Have a look at the <a href="https://www.opengl.org/sdk/docs/man2/xhtml/glBegin.xml" rel="nofollow">documentation</a> ab...
1
2016-08-23T08:03:56Z
[ "python", "opengl", "cuda", "numba" ]
Python getting element value for specific element
39,091,827
<p>I am attempting to parse the below XML file but having difficulty getting a specific element value. I am trying to specify element 'Item_No_2' to get the related value <code>&lt;v&gt;2222222222&lt;/v&gt;</code> but am unable to do it using get.element('Item_No_2'). Am I using the get.element value incorrectly?</p> ...
1
2016-08-23T03:24:02Z
39,091,977
<p>There is no <code>Item_No_1</code> at the elements that are found by <code>doc.findall('md/mi/ovalue/')</code>. </p> <p>I think what you may try to do is get both lists</p> <pre><code>items = [e.text for e in doc.findall('md/mi/it')] values = [e.text for e in doc.findall('md/mi/ovalue/v')] </code></pre> <p>Then f...
1
2016-08-23T03:43:01Z
[ "python", "xml", "elementtree" ]
odoo get the value of maximum array index
39,091,852
<p>I got a function to append data into array :</p> <pre><code>def _get_state(self, cr, uid, context=None): idemployee = _default_employee(self, cr, uid, context=None) sql = " SELECT C.id AS id, C.sequence, C.name \ FROM wf_group_member A \ LEFT JOIN wf_group B ON B.id = A.group_i...
0
2016-08-23T03:26:33Z
39,091,882
<p><code>states</code> is an index to the last element of <code>arr_state</code>. However you do not index <code>arr_state</code> with <code>states</code>, you index it with <code>0</code> and then index the result with <code>states</code>. It seems like you probably want to just index the other way around, i.e. <code>...
1
2016-08-23T03:30:40Z
[ "python", "openerp" ]
Edited aug 24 9pm - number game isn't working as I would like
39,091,899
<p>I have a number guessing game working but I would like it to count without pick numbers without having them have any with a single increment. What I am trying to say is 2 4 17 27 not 2 3 4 17 27 I would like it to go through all the possibilities from low to high like it is, just not with any in a single increment I...
-1
2016-08-23T03:32:50Z
39,092,156
<p>I'm not clear on what exactly you are answering, and we need a better explanation of "it will not work". However, it looks like you generate far too many options in <code>generate_possible_sequences()</code> which probably results in either memory filling up or far too long an execution time. A better approach is to...
1
2016-08-23T04:03:58Z
[ "python" ]
Changing values of tuple elements
39,091,908
<p>I entered the following at the command line:</p> <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt;a = 25 &gt;&gt;&gt;b = 50 &gt;&gt;&gt;t = (a, b) &gt;&gt;&gt;t (25, 50) &gt;&gt;&gt;a = 50 &gt;&gt;&gt;t (25, 50) &gt;&gt;&gt;t = (a, b) &gt;&gt;&gt;t (50, 50) </code></pre> <p>Why do I have to reassign the...
-1
2016-08-23T03:34:02Z
39,092,001
<p>This has less to do with tuples and more to do with how assignment works in Python which copies vs references.</p> <p>This works for other container types (lists) and plain variables.</p> <pre><code>&gt;&gt;&gt; a = 2 &gt;&gt;&gt; b = [1, a] &gt;&gt;&gt; a = 7 &gt;&gt;&gt; b [1, 2] &gt;&gt;&gt; c = 1 &gt;&gt;&gt; ...
1
2016-08-23T03:45:26Z
[ "python", "tuples" ]
Changing values of tuple elements
39,091,908
<p>I entered the following at the command line:</p> <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt;a = 25 &gt;&gt;&gt;b = 50 &gt;&gt;&gt;t = (a, b) &gt;&gt;&gt;t (25, 50) &gt;&gt;&gt;a = 50 &gt;&gt;&gt;t (25, 50) &gt;&gt;&gt;t = (a, b) &gt;&gt;&gt;t (50, 50) </code></pre> <p>Why do I have to reassign the...
-1
2016-08-23T03:34:02Z
39,092,015
<p>You can understand it in this way:- </p> <pre><code>&gt;&gt;&gt; a =25 &gt;&gt;&gt; b = 50 &gt;&gt;&gt; id(a) 6070712 &gt;&gt;&gt; t = (a, b) &gt;&gt;&gt; id(t[0]) 6070712 &gt;&gt;&gt; a = 50 &gt;&gt;&gt; id(a) 6070412 # When you assigned a = 50, it created new object, #id(t[0]) and a is not same now, so t is still...
1
2016-08-23T03:46:24Z
[ "python", "tuples" ]
Changing values of tuple elements
39,091,908
<p>I entered the following at the command line:</p> <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt;a = 25 &gt;&gt;&gt;b = 50 &gt;&gt;&gt;t = (a, b) &gt;&gt;&gt;t (25, 50) &gt;&gt;&gt;a = 50 &gt;&gt;&gt;t (25, 50) &gt;&gt;&gt;t = (a, b) &gt;&gt;&gt;t (50, 50) </code></pre> <p>Why do I have to reassign the...
-1
2016-08-23T03:34:02Z
39,092,040
<p>At first, the value in tuple in python can not be changed. You can only declare a new tuple.</p> <p><code>a = 25</code> means <code>a</code> is a variable. However, the <code>a</code> in <code>t</code> belong to the tuple t. It does not have any relationship with variable <code>a</code>. </p> <p>The second <code>t...
1
2016-08-23T03:49:47Z
[ "python", "tuples" ]
Changing values of tuple elements
39,091,908
<p>I entered the following at the command line:</p> <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt;a = 25 &gt;&gt;&gt;b = 50 &gt;&gt;&gt;t = (a, b) &gt;&gt;&gt;t (25, 50) &gt;&gt;&gt;a = 50 &gt;&gt;&gt;t (25, 50) &gt;&gt;&gt;t = (a, b) &gt;&gt;&gt;t (50, 50) </code></pre> <p>Why do I have to reassign the...
-1
2016-08-23T03:34:02Z
39,092,100
<p>If we do an assign action like a = b and b is immutable(number, string, tuple etc),assign will make a copy rather than make reference. As a result, modify to the b do not effect a.</p> <p>For mutable situation:</p> <pre><code>&gt;&gt;&gt; a = [] &gt;&gt;&gt; b = 3 &gt;&gt;&gt; c = (a, b) &gt;&gt;&gt; c ([], 3) &...
0
2016-08-23T03:57:05Z
[ "python", "tuples" ]
Changing values of tuple elements
39,091,908
<p>I entered the following at the command line:</p> <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt;a = 25 &gt;&gt;&gt;b = 50 &gt;&gt;&gt;t = (a, b) &gt;&gt;&gt;t (25, 50) &gt;&gt;&gt;a = 50 &gt;&gt;&gt;t (25, 50) &gt;&gt;&gt;t = (a, b) &gt;&gt;&gt;t (50, 50) </code></pre> <p>Why do I have to reassign the...
-1
2016-08-23T03:34:02Z
39,092,492
<p>It is simple. In Python, the names, such as <code>a</code> and <code>b</code> and <code>t</code> are not <em>objects</em>, they just point to objects. When you enter</p> <pre><code>&gt;&gt;&gt; a = 25 &gt;&gt;&gt; b = 50 </code></pre> <p>Python sets the name <code>a</code> to point to an <code>int</code> object wi...
0
2016-08-23T04:42:16Z
[ "python", "tuples" ]
How to put JSON file on a local server?
39,091,910
<p>I've driven myself insane for the last two hours attempting to find an answer for the issue that I'm encountering. I was trying to access a local JSON file called, data.json, which I placed inside my project directory. My console returned this error: </p> <p>Cross origin requests are only supported for protocol sch...
-1
2016-08-23T03:34:15Z
39,092,132
<blockquote> <p>How does someone setup a local server with this file?</p> </blockquote> <p>A very simple web server in Python can be launched with a single command. This would allow you to fetch the contents over HTTP.</p> <p>From the directory where your <code>data.json</code> file resides, you can run one of the...
1
2016-08-23T04:00:18Z
[ "python", "json", "ajax", "node.js", "localserver" ]
Search Functionality on a Django Site
39,091,914
<p>I'm trying to add a search function to my website but I'm having some issues. It's currently telling me that "Search" is not defined, but I have the class in my views file. This is what I have thus far:</p> <p>urls.py</p> <pre><code>from django.conf.urls import url from . import views urlpatterns = [ url(r'^$...
0
2016-08-23T03:34:55Z
39,092,585
<p>The problem is in the urls.py</p> <p>Give url(r'^search/$', views.Search.as_view(), name='search'),</p> <p>instead of just Search. </p>
3
2016-08-23T04:51:58Z
[ "python", "django" ]
Use a json file stored on fs/disk as output for an Ansible module
39,091,956
<p>I am struggling with an <code>ansible</code> module I needed to create. Everything is done, the module gets a <code>json</code> file delivered from a third party onto the <code>fs</code>. This <code>json</code> file is expected to be the (only) output to be able to access to register the <code>json</code> file and a...
-1
2016-08-23T03:39:32Z
39,104,544
<p>Interesting. My tests using <code>os.stdout.write</code> somehow failed, but using <code>print json.dumps(data)</code> works. </p> <p>This is solved.</p>
0
2016-08-23T14:56:05Z
[ "python", "json", "ansible" ]
Parsing human readable relative times
39,091,969
<p>I would like to parse human terms like <code>3 days ago</code> in <code>python 2.7</code> to get a timedelta equivalent.</p> <p>For example:</p> <pre><code>&gt;&gt;&gt; relativetimeparer.parser('3 days ago') datetime.timedelta(3) </code></pre> <p>I have tried the <code>dateparser</code> module.</p> <pre><code>&g...
1
2016-08-23T03:42:01Z
39,092,154
<p>You could specify the <code>RELATIVE_BASE</code> setting:</p> <pre><code>&gt;&gt;&gt; now = datetime.datetime.now() &gt;&gt;&gt; res = dateparser.parse('3 days ago', settings={'RELATIVE_BASE': now}) &gt;&gt;&gt; now - res datetime.timedelta(3) </code></pre>
1
2016-08-23T04:03:09Z
[ "python", "time" ]
Jupyter Notebook only has Python [conda root] and Python [default] kernels
39,092,008
<p>So I've been struggling with this and I'm new to programming so please be gentle. I followed all the steps outlined in the other Python [root] posts, but still cannot get the python2 and python3 kernels to show up. See photo below. I have Anaconda3 installed (the 3.5 version). Any help would be greatly appreciated. ...
2
2016-08-23T03:45:56Z
40,051,941
<p>I had a similar issue but i had python 2.7.12 installed from anaconda and the default one came with Mac is 2.7.10.</p> <p>When i open jupiter notebook, i used to get Python[conda root] and Python[default], after lot of struggling i did the following</p> <p><strong>conda update conda</strong> </p> <p><strong>conda...
0
2016-10-14T21:02:58Z
[ "python", "kernel", "jupyter", "conda" ]
Save and Restore dockwidgets position and size
39,092,010
<p>I can't quite figure out how the save and restore are suppose to work, so that I may save the dockwidgets geometrics, when the application is closed and opened again. I have 5 dockwidgets, which I'd like to have this feature.</p> <p>I assume I have to use both <code>restoreState</code> and <code>saveState</code> re...
0
2016-08-23T03:46:08Z
39,092,887
<p>This works here:</p> <pre><code>def __init__(self): self.readSettings() def closeEvent(self, event): print('closing') settings = QSettings() settings.setValue('geometry',self.saveGeometry()) settings.setValue('windowState',self.saveState()) super(Window, self).closeEvent(event) def readSet...
2
2016-08-23T05:16:02Z
[ "python", "pyqt" ]
Time complexity calculation for my algorithm
39,092,049
<p>Given a string, find the first non-repeating character in it and return its index. If it doesn't exist, return -1. You may assume the string contain only lowercase letters.</p> <p>I'm going to define a hash that tracks the occurrence of characters. Traverse the string from left to right, check if the current charac...
5
2016-08-23T03:50:33Z
39,092,153
<p>Your algorithm is O(n<sup>2</sup>), because you have a "hidden" iteration over a slice of <code>s</code> inside the loop over <code>s</code>.</p> <p>A faster algorithm would be:</p> <pre><code>def first_unique_character(s): good = {} # char:idx bad = set() # char for index, ch in enumerate(s): ...
4
2016-08-23T04:03:08Z
[ "python", "algorithm" ]
Time complexity calculation for my algorithm
39,092,049
<p>Given a string, find the first non-repeating character in it and return its index. If it doesn't exist, return -1. You may assume the string contain only lowercase letters.</p> <p>I'm going to define a hash that tracks the occurrence of characters. Traverse the string from left to right, check if the current charac...
5
2016-08-23T03:50:33Z
39,092,576
<p><s>As others have noted, your algorithm is <code>O(n²)</code> due to nested linear search.</s> As discovered by @Antti, the OP's algorithm is linear and bound by <code>O(kn)</code> for <code>k</code> as the number of all possible lowercase letters.</p> <p>My proposition for an <code>O(n)</code> solution:</p> <pre...
6
2016-08-23T04:50:58Z
[ "python", "algorithm" ]
Time complexity calculation for my algorithm
39,092,049
<p>Given a string, find the first non-repeating character in it and return its index. If it doesn't exist, return -1. You may assume the string contain only lowercase letters.</p> <p>I'm going to define a hash that tracks the occurrence of characters. Traverse the string from left to right, check if the current charac...
5
2016-08-23T03:50:33Z
39,092,904
<p>Your algorithm has time complexity of <code>O(kn)</code> where <code>k</code> is the number of unique characters in the string. If <code>k</code> is a constant then it is <code>O(n)</code>. As the problem description clearly bounds the number of alternatives for elements ("assume lower-case (ASCII) letters"), thus <...
9
2016-08-23T05:18:34Z
[ "python", "algorithm" ]
confused by numpy meshgrid output
39,092,106
<p>Using Python 2.7 with miniconda interpreter. I am confused by what means N-D coordinate in the following statements, and could anyone tell how in the below sample <code>xv</code> and <code>yv</code> are calculated, it will be great.</p> <p>"Make N-D coordinate arrays for vectorized evaluations of N-D scalar/vector ...
-1
2016-08-23T03:57:43Z
39,092,261
<p><code>xv,yv</code> are simply defined as:</p> <pre><code>xv = np.array([x for _ in y]) yv = np.array([y for _ in x]).T </code></pre> <p>so that for every index pair <code>(i,j)</code>, you have</p> <pre><code>xv[i,j] = x[i] yv[i,j] = y[j] </code></pre> <p>which is useful especially for plotting 2D maps.</p>
1
2016-08-23T04:15:18Z
[ "python", "python-2.7", "numpy" ]
argparse: How to make mutually exclusive arguments optional?
39,092,149
<p>I want to use my script like this:</p> <pre><code>python test.py run python test.py stop </code></pre> <p>and my code is like this:</p> <pre><code>parser = argparse.ArgumentParser() command_group = parser.add_mutually_exclusive_group(required=True) command_group.add_argument('run', help='run it', action='store_tr...
2
2016-08-23T04:02:33Z
39,092,229
<p>A better way to do this is to add a single positional argument that can have two choices. Since you want it to be optional, use <code>nargs='?'</code>, which means zero or one times:</p> <pre><code>parser = argparse.ArgumentParser() parser.add_argument('run', help='run or stop', nargs='?', choices=('run', 'stop'))...
2
2016-08-23T04:11:37Z
[ "python", "python-2.7" ]
Subtracting the values of two dictionaries
39,092,224
<p>I am trying to subtract dict1 - dict2. It does not matter if the result is a negative number for the dogs, I am just interested in learning the concept :) </p> <pre><code>owner = ['Bob', 'Sarah', 'Ann'] dict1 = {'Bob': {'shepherd': [4,6,3],'collie': [23, 3, 45], 'poodle':[2,0,6]}, {'Sarah': {'shepherd': [1,2,3],...
3
2016-08-23T04:11:23Z
39,092,283
<p>You can use a nested dictionary comprehension. I tweaked your dictionary a bit because it wasn't correct syntax (there were a few extra curly braces). There is no need for an owners array because we can just use the keys in the dictionaries.</p> <pre><code>dict1 = { 'Bob': { 'shepherd': [4, 6, 3], ...
5
2016-08-23T04:18:02Z
[ "python", "python-2.7", "dictionary" ]
Residual white pixels in transparent background from PIL
39,092,325
<p>I used this following code from another stackoverflow post</p> <pre><code>from PIL import Image as image img = image.open('output.png') img = img.convert("RGBA") datas = img.getdata() newData = [] for item in datas: if item[0] == 255 and item[1] == 255 and item[2] == 255: newData.append((255, 255, 255...
1
2016-08-23T04:24:21Z
39,111,459
<p>Those pixels are <em>not</em> exactly "white". The color you are testing against and removing from the image <em>is</em>, with its value of <code>#FFFFFF</code>. But those slanted lines are heavily antialiased, "fading" from the pure white of the background to the pure color of the center of the lines.</p> <p>This ...
2
2016-08-23T22:10:23Z
[ "python", "png", "python-imaging-library" ]
Sklearn Pipeline - How to inherit get_params in custom Transformer (not Estimator)
39,092,383
<p>I have a pipeline in scikit-learn that uses a custom transformer I define like below:</p> <pre><code>class MyPipelineTransformer(TransformerMixin): </code></pre> <p>which defines functions </p> <pre><code>__init__, fit() and transform() </code></pre> <p>However, when I use the pipeline inside RandomizedSearchCV,...
1
2016-08-23T04:30:57Z
39,093,021
<p>Yes it looks like this is the standard way of achieving this. For example in the source for <code>sklearn.preprocessing</code> we have</p> <pre><code>class FunctionTransformer(BaseEstimator, TransformerMixin) </code></pre>
1
2016-08-23T05:30:23Z
[ "python", "inheritance", "scikit-learn", "pipeline" ]
Drop Multi-index and auto rename columns
39,092,466
<p>I'd like to transform the below output into: </p> <ul> <li><p>remove the multiindex(it should just be one row of index) </p></li> <li><p>numbered accordingly Job 1, Job Effective Date 1, Job 2, Job Effective Date 2, etc.</p></li> <li><p>I'd like this to be scalable if I choose to add or remove additional variables,...
1
2016-08-23T04:39:52Z
39,092,607
<p>Try:</p> <pre><code>df3.columns = ['{} {}'.format(col[1], col[0]) for col in df3.columns] </code></pre> <p>if you are OK with 0-based indexing. Otherwise change to <code>col[0] + 1</code></p>
5
2016-08-23T04:53:45Z
[ "python", "pandas", "dataframe", "group-by", "multi-index" ]
Drop Multi-index and auto rename columns
39,092,466
<p>I'd like to transform the below output into: </p> <ul> <li><p>remove the multiindex(it should just be one row of index) </p></li> <li><p>numbered accordingly Job 1, Job Effective Date 1, Job 2, Job Effective Date 2, etc.</p></li> <li><p>I'd like this to be scalable if I choose to add or remove additional variables,...
1
2016-08-23T04:39:52Z
39,092,851
<p>Another solution with <code>join</code>:</p> <pre><code>df.columns = [' '.join((col[1], str(col[0] + 1))) for col in df.columns] print (df) Job 1 Job Eff Date 1 Job 2 Job Eff Date 2 Job 3 Job Eff Date 3 Name Jane Analyst ...
4
2016-08-23T05:12:45Z
[ "python", "pandas", "dataframe", "group-by", "multi-index" ]
Implementing functions with dataframes in python
39,092,584
<p><a href="http://i.stack.imgur.com/we38M.png" rel="nofollow"><img src="http://i.stack.imgur.com/we38M.png" alt="enter image description here"></a>I have this problem where I am stuck for quite a number of days.</p> <p>I have this function :</p> <pre><code>def cal_score(research, citations, teaching, international, ...
1
2016-08-23T04:51:56Z
39,092,697
<p>I think you can use:</p> <pre><code>df['Total Score'] = .3 **df.research + .3 **df.citations + .3 **df.teaching + .075 **df.international + .025 **df.income </code></pre> <p>If need <a href="http://pandas.pydata.org/pandas-docs/sta...
3
2016-08-23T05:00:55Z
[ "python", "pandas", "dataframe", "dataset", "data-science" ]
Implementing functions with dataframes in python
39,092,584
<p><a href="http://i.stack.imgur.com/we38M.png" rel="nofollow"><img src="http://i.stack.imgur.com/we38M.png" alt="enter image description here"></a>I have this problem where I am stuck for quite a number of days.</p> <p>I have this function :</p> <pre><code>def cal_score(research, citations, teaching, international, ...
1
2016-08-23T04:51:56Z
39,092,731
<p>Here is the most straightforward way:</p> <pre><code>df.assign(TotalScore=.3 **df.research + .3 **df.citations + .3 **df.teaching +.075 **df.international + .025 **df.income) </code></pre>
1
2016-08-23T05:03:35Z
[ "python", "pandas", "dataframe", "dataset", "data-science" ]
How to print amount_to_text in Indian Rupees format in Odoo reports.?
39,092,619
<p>I was trying to print the invoice amount in words in Odoo, </p> <p>Following is the code in .py</p> <pre><code>@api.multi def amount_to_text(self, amount_total, currency='INR'): return amount_to_text(amount_total, currency) </code></pre> <p>and following was the code in qweb report,</p> <pre><code>&l...
1
2016-08-23T04:54:40Z
39,110,206
<p>First of all go to Settings -> Reports -> Reports and search for <code>invoices</code> in order to find the Invoice report that interests you. Open it, and uncheck <code>Reload from attachment</code>.</p> <p>If <code>Reload from attachment</code> is checked only the first time the report will be generated for a rec...
1
2016-08-23T20:34:10Z
[ "python", "openerp", "odoo-8" ]
Numpy 2D- Array from Buffer?
39,092,664
<p>I have an memory map, which contains a 2D array and I would like to make a numpy array from it. Ideally, i would like to avoid copying, since the involved array can be big.</p> <p>My code looks like this:</p> <pre><code>n_bytes = 10000 tagname = "Some Tag from external System" map = mmap.mmap(-1, n_bytes, tagname)...
0
2016-08-23T04:57:40Z
39,093,256
<p>I haven't used <code>frombuffer</code> much, but I think the <code>np.array</code> works with those arrays as it does with conventionally constructed ones.</p> <p>Each <code>column_data</code> array will have its own data buffer - the mmap you assigned it. But <code>np.array(columns)</code> reads the values from e...
1
2016-08-23T05:48:19Z
[ "python", "numpy" ]
How to delete a dictionary in a list, if the same dictionary is in another list (Python 2.7)
39,092,701
<p>I have two lists that include same dictionaries in the format of:</p> <p>List 1:</p> <pre><code>[{'url': u'http://www.bloomberg.com/news/articles/2016-08-17/you-can-get-a-50-phone-from-amazon-if-you-don-t-mind-the-ads','title': u'You Can Get a $50 Phone From Amazon, If You Don\u2019t Mind the Ads'}, {'url': u'http...
0
2016-08-23T05:01:15Z
39,092,839
<p>Just do a simple comparison:</p> <pre><code>&gt;&gt;&gt; final = [i for i in one if i not in two] &gt;&gt;&gt; final [{'url': u'http://www.bloomberg.com/news/features/2016-08-18/uber-s-first-self-driving-fleet-arrives-in-pittsburgh-this-month-is06r7on', 'title': u'Uber\u2019s First Self-Driving Fleet Arrives in Pit...
5
2016-08-23T05:11:23Z
[ "python", "python-2.7", "dictionary", "list-comprehension" ]
How to delete a dictionary in a list, if the same dictionary is in another list (Python 2.7)
39,092,701
<p>I have two lists that include same dictionaries in the format of:</p> <p>List 1:</p> <pre><code>[{'url': u'http://www.bloomberg.com/news/articles/2016-08-17/you-can-get-a-50-phone-from-amazon-if-you-don-t-mind-the-ads','title': u'You Can Get a $50 Phone From Amazon, If You Don\u2019t Mind the Ads'}, {'url': u'http...
0
2016-08-23T05:01:15Z
39,092,841
<p>If I understand correctly, you want <code>list1</code> to consist only of the entries whose title does not exist in <code>list2</code>. This is probably best done with a two step process, to avoid repeated linear scans of <code>list2</code> for each element in <code>list1</code>:</p> <pre><code># Make a set of all ...
1
2016-08-23T05:11:48Z
[ "python", "python-2.7", "dictionary", "list-comprehension" ]
How to delete a dictionary in a list, if the same dictionary is in another list (Python 2.7)
39,092,701
<p>I have two lists that include same dictionaries in the format of:</p> <p>List 1:</p> <pre><code>[{'url': u'http://www.bloomberg.com/news/articles/2016-08-17/you-can-get-a-50-phone-from-amazon-if-you-don-t-mind-the-ads','title': u'You Can Get a $50 Phone From Amazon, If You Don\u2019t Mind the Ads'}, {'url': u'http...
0
2016-08-23T05:01:15Z
39,093,523
<p>Burhan Khalid's answer is perfect. In case, you want a solution matching to your line of previous thoughts, here it is : <br/> <code>list1 = [d for d in list1 if d.get('title') not in [f.get('title') for f in list2]]</code></p>
0
2016-08-23T06:07:31Z
[ "python", "python-2.7", "dictionary", "list-comprehension" ]
Tkinter pack Entry Widgets Based On OptionMenu Value, pack_forget Otherwise
39,092,707
<p>When <code>tk.OptionMenu</code> is equivalent to <code>CUSTOM</code>, the code below displays two <code>tk.Entry</code> fields. How does one hide the <code>tk.Entry</code> fields from view after a <code>tk.OptionMenu</code> is selected that's not <code>CUSTOM</code>?</p> <p>For example, the code below displays two...
1
2016-08-23T05:01:49Z
39,104,384
<p>I got it to work by putting <code>field1</code> and <code>field2</code> in a <code>new_frame</code> (<code>tk.Frame</code>) <strong>outside of the function</strong>. Then I let an if statement determine whether to <code>pack</code> or <code>pack_forget</code> <code>new_frame</code> based on the value from the <code>...
1
2016-08-23T14:48:35Z
[ "python", "tkinter", "trace", "entry", "optionmenu" ]
allen brain institute - brain observatory example
39,092,740
<p>I'm trying to follow the example of <a href="https://alleninstitute.github.io/AllenSDK/_static/examples/nb/brain_observatory.html" rel="nofollow">brain observatory ipython notebook</a>.</p> <p>However, I became stuck loading the <code>nwb</code> file like below.</p> <pre><code>from allensdk.core.brain_observatory_...
1
2016-08-23T05:04:23Z
39,358,028
<p>Summarizing the thread from github: </p> <p><a href="https://github.com/AllenInstitute/AllenSDK/issues/22" rel="nofollow">https://github.com/AllenInstitute/AllenSDK/issues/22</a></p> <p>The files were partially downloaded or corrupted somehow. No exceptions were reported during the download, so urllib must not ha...
0
2016-09-06T21:20:50Z
[ "python", "validation", "neuroscience", "neuron-simulator" ]
automatically change object colors in pymol from python
39,092,780
<p>I am trying to change the color of many objects in pymol from python. I made this for loop </p> <pre><code>obs = ['R8', 'R1X', 'R2X', 'R11'] for i in obs: print "color gray, %s" % i </code></pre> <p>from pymol I run </p> <pre><code>run myscript.py </code></pre> <p>but the pymol interface simply prints the th...
0
2016-08-23T05:07:33Z
39,190,186
<p>In order to execute Pymol commands from python you need to use <a href="http://pymol.org/pymol-command-ref.html" rel="nofollow"><code>cmd</code></a>. In your case this would be:</p> <pre><code>cmd.color('gray', i) </code></pre>
1
2016-08-28T10:10:09Z
[ "python", "colors", "pymol" ]
python unicode to original text character when being used as string not when printing
39,092,924
<p>I want an unicoded string I am getting from a method, I want to look like original text character rather than an unicode.</p> <pre><code>a=u'\u2018\u0997\u09c7\u09ae\u09bf\u0982 \u09aa\u09cd\u09b2\u09be\u099f\u09ab\u09b0\u09cd\u09ae\u2019 \u09a4\u09c8\u09b0\u09bf \u0995\u09b0\u09ac\u09c7 \u09ab\u09c7\u09b8\u09ac\u0...
1
2016-08-23T05:20:23Z
39,093,193
<p>You're misunderstanding the <code>repr</code> of a Python object. Those escapes in your literal string are actually being converted internally to the "real" characters that Python is displaying when you <code>print</code> (that is, internally, it's storing a single Unicode ordinal for each of the escapes, not the es...
3
2016-08-23T05:44:25Z
[ "python", "html", "string", "unicode", "utf-8" ]
Install Openalpr in Windows python
39,092,992
<p>I am using <strong>Windows 10</strong> and I want to install <strong>openalpr</strong> and import the library to <strong>python</strong>. </p> <p>However, after downloaded the <strong>Pre-compiled Windows binaries</strong>, I dont know how ti import alpr in python</p> <p>I follow the instruction in <a href="https:...
4
2016-08-23T05:27:51Z
39,215,441
<p>When you've downloaded the binary distribution, navigate to <code>python</code> subdirectory and run <code>python setup.py</code>. This would install OpenALPR as package, so then you would be able to import it from anywhere, not just from ALPR's directory.</p> <p><strong>Explaination</strong>: To be importable, it ...
2
2016-08-29T21:22:57Z
[ "python", "python-2.7", "python-3.x", "open-source", "openalpr" ]
Install Openalpr in Windows python
39,092,992
<p>I am using <strong>Windows 10</strong> and I want to install <strong>openalpr</strong> and import the library to <strong>python</strong>. </p> <p>However, after downloaded the <strong>Pre-compiled Windows binaries</strong>, I dont know how ti import alpr in python</p> <p>I follow the instruction in <a href="https:...
4
2016-08-23T05:27:51Z
39,245,480
<p>I setted up the same environment as you:</p> <ul> <li>Anaconda 4.0 installed into <code>C:\Users\user\Anaconda</code></li> <li>OpenAlpr installed into <code>C:\Users\user\Downloads\openalpr-2.3.0-win-64bit</code></li> </ul> <p>So I can call <code>python</code> from the console (<code>cmd</code>) and get:</p> <pre...
-1
2016-08-31T09:15:31Z
[ "python", "python-2.7", "python-3.x", "open-source", "openalpr" ]
Extracting date and time from a list in python
39,093,089
<p>I have a very simple list like this :</p> <pre><code>['Monday,30 December,2013', 'Delivered_it', '19:23', '1'] </code></pre> <p>Please guide me how to extract from this list the date , status and time </p> <p><strong>NOTE</strong> : I don't simply want to extract it like a string but as a <strong>date.time</stron...
-2
2016-08-23T05:35:04Z
39,119,010
<pre><code>import datetime data = ['Monday,30 December,2013', 'Delivered_it', '19:23', '1'] data = '{} {}'.format(data[0], data[2]) timestamp = datetime.datetime.strptime(data, '%A,%d %B,%Y %H:%M') print timestamp # 2013-12-30 19:23:00 </code></pre>
1
2016-08-24T09:08:50Z
[ "python", "list", "python-2.7", "date", "time" ]
Python module already installed but getting import error
39,093,092
<p>I have started getting this error for a few modules in python after I 'brew installed python' on my OS X El Capitan. I know that Mac comes with python 2.7 but due to some issues I had to install python explicitly using brew. Now I get this error. </p> <pre><code>~/Desktop ⌚ 10:57:29 $ python f.py Traceback (most...
0
2016-08-23T05:35:23Z
39,094,939
<p>This error may come from :</p> <ol> <li><p>The python you run by default isn’t the same that you call by your script : To check this, Please check this command (<code>$ which python</code>) Is this what you put on the top of your script?</p></li> <li><p>Brew doesn’t make symbol link, it’s common issue : Pleas...
1
2016-08-23T07:29:42Z
[ "python", "module", "pip", "youtube-dl" ]
How can I write a MapReduce code in Python to implement a matrix transpose.
39,093,171
<p>Assume the input file is a .txt and I am trying to run it on a cluster(like EMR on AWS) to test.</p>
0
2016-08-23T05:42:41Z
39,094,305
<p>The problem with what you want is that you demand that the order of the lines will be kept, meaning</p> <p>if you have:<br> a,b,c<br> d,e,f<br> g,h,i </p> <p>you want the output to be<br> a,d,g<br> b,e,h<br> c,f,i </p> <p>But the MapReduce does not work like this. The MR will get the file and split the file...
0
2016-08-23T06:57:17Z
[ "python", "mapreduce", "elastic-map-reduce" ]
Scrapy - offsite request to be processed based on a regex
39,093,211
<p>I have to crawl 5-6 domains. I wanted to write a the crawler as such that the offsite requests if contains a some substrings example set as [ aaa,bbb,ccc] if the offsite url contain a substring from the above set then it should be processed and not filter out. Should i write a custom middleware or can i just use re...
-1
2016-08-23T05:46:14Z
39,098,601
<p>Offsite middleware already uses regex by default, however it's no exposed. It compiles the domains you provide into regex, but the domains are escaped so providing regex code in <code>allowed_domains</code> would not work.</p> <p>What you can do though is extend that middleware and override <code>get_host_regex()</...
1
2016-08-23T10:26:05Z
[ "python", "regex", "scrapy" ]
PyQt5 QListView sluggish first drag/drop on windows - python 3.5/3.4 32bit, pyqt5 from sourceforge
39,093,226
<p>I have installed 32bit Python 3.4 and 3.5 and PyQt5 on our windows 7 work machine via the executable available from <a href="https://sourceforge.net/projects/pyqt/" rel="nofollow">https://sourceforge.net/projects/pyqt/</a>, however I now find that when I run my simple drag and drop test code it is very sluggish movi...
0
2016-08-23T05:46:38Z
39,325,880
<p>Ran same code on another windows 7 computer with same packages installed. The issue is not seen there, so is obviously a problem with something specific to this machine rather than the code I've written/versions of python I'm using/version of pyqt.</p>
0
2016-09-05T07:43:10Z
[ "python", "windows", "drag-and-drop", "pyqt5" ]
List index out of range error in web scraping
39,093,330
<p>I am now building a web-scraping program with Python 3.5 and bs4. In the code below I tried to retrieve the data from two tables in the url. I succeed in the first table, but error pops out for the second one. The error is "IndexError: list index out of range" for "D.append(cells[0].find(text=True))". I have checked...
1
2016-08-23T05:53:50Z
39,093,512
<p>It looks like you're expecting this code to choose between 'th' and 'td', but it will not. It will always choose 'th' and will return an empty list when there is no 'th' in that row.</p> <pre><code> try: cells = row.findAll('th') except: cells = row.findAll('td') </code></pre> <p>Instead, I ...
1
2016-08-23T06:06:52Z
[ "python", "web-scraping" ]
Error while connecting remote sql express database which is on windows -- connction using pyodbc
39,093,348
<p>I am using Ubuntu system and I want to connect to remote database SQL Express. </p> <p>I have tried the same using <strong>pyodbc</strong> using following steps.</p> <ol> <li><code>sudo apt-get install python-pyodbc</code></li> <li>Python code as follows :</li> </ol> <p></p> <pre><code> import pyodbc cnxn...
0
2016-08-23T05:54:55Z
39,093,565
<p>Have you checked the name of the driver in your ~/.odbc.ini file? This person had the same error as you and fixing that solved their problem:</p> <p><a href="http://stackoverflow.com/questions/16280304/pyodbc-data-source-name-not-found-and-no-default-driver-specified">Pyodbc - &quot;Data source name not found, and ...
0
2016-08-23T06:09:55Z
[ "python", "sql-server", "ubuntu-14.04", "pyodbc" ]
numpy.ndarray syntax understanding for confirmation
39,093,472
<p>I am referring the code example here (<a href="http://scikit-learn.org/stable/auto_examples/linear_model/plot_iris_logistic.html" rel="nofollow">http://scikit-learn.org/stable/auto_examples/linear_model/plot_iris_logistic.html</a>), and specifically confused by this line <code>iris.data[:, :2]</code>, since iris.dat...
0
2016-08-23T06:04:27Z
39,093,793
<p>You are right. The first syntax selects the first 2 columns/features. Another way to query dimensions is to look at <code>iris.data.shape</code>. This will return a n-dimensional tuple with the length. You can find some documentation here: <a href="http://docs.scipy.org/doc/numpy/reference/arrays.indexing.html" rel=...
1
2016-08-23T06:26:06Z
[ "python", "python-2.7", "numpy", "machine-learning", "logistic-regression" ]
how to join incorporate splitted lines with replacing data from a file into the same string
39,093,525
<p>So as most of us are thinking it's a duplicate which is not, so what I'm trying to achieve is let's say there is a Master string like the below and couple of files mentioned in it then we need to open the files and check if there are any other files included in it, if so we need to copy that into the line where we f...
1
2016-08-23T06:07:41Z
39,093,753
<p>You can try:</p> <pre><code>s = """Welcome How are you here is file.txt everything alright here is signature.txt Thanks""" data = s.split("\n") match = ['.txt'] all_matches = [s for s in data if any(xs in s for xs in match)] for index, item in enumerate(data): if item in all_matches: data[index] ="XYZ...
1
2016-08-23T06:23:00Z
[ "python", "python-2.7", "python-3.x" ]
how to join incorporate splitted lines with replacing data from a file into the same string
39,093,525
<p>So as most of us are thinking it's a duplicate which is not, so what I'm trying to achieve is let's say there is a Master string like the below and couple of files mentioned in it then we need to open the files and check if there are any other files included in it, if so we need to copy that into the line where we f...
1
2016-08-23T06:07:41Z
39,097,002
<p>We can create temporary file object and keep the replaced line in that temporary file object and once everything line is processed then we can replace with the new content to original file. This temporary file will be deleted automatically once its come out from the 'with' statement. </p> <pre><code>import tempfile...
0
2016-08-23T09:11:29Z
[ "python", "python-2.7", "python-3.x" ]
how to join incorporate splitted lines with replacing data from a file into the same string
39,093,525
<p>So as most of us are thinking it's a duplicate which is not, so what I'm trying to achieve is let's say there is a Master string like the below and couple of files mentioned in it then we need to open the files and check if there are any other files included in it, if so we need to copy that into the line where we f...
1
2016-08-23T06:07:41Z
39,105,614
<p>A recursive approach that works with any level of file name nesting:</p> <pre><code>from os import linesep def get_text_from_file(file_path): with open(file_path) as f: text = f.read() return SAK_replace(text) def SAK_replace(s): lines = s.splitlines() for index, l in enumerate(lines):...
1
2016-08-23T15:47:19Z
[ "python", "python-2.7", "python-3.x" ]
Python with MySql unicode problems
39,093,532
<p>I need to call MySQL stored procedure from my python script. As one of parameters I'm passing a unicode string (Russian language), but I get an error;</p> <blockquote> <p>UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-1: ordinal not in range(256)</p> </blockquote> <p>My script:</p> <p...
9
2016-08-23T06:07:55Z
39,107,719
<p>More things to check on: <a href="http://mysql.rjweb.org/doc.php/charcoll#python">http://mysql.rjweb.org/doc.php/charcoll#python</a></p> <p>Likely items:</p> <ul> <li>Start code file with <code># -*- coding: utf-8 -*-</code> -- (for literals in code) </li> <li>Literals should be u'...' </li> </ul> <p>Can you extr...
5
2016-08-23T17:47:47Z
[ "python", "mysql", "unicode", "utf-8", "character-encoding" ]
Python with MySql unicode problems
39,093,532
<p>I need to call MySQL stored procedure from my python script. As one of parameters I'm passing a unicode string (Russian language), but I get an error;</p> <blockquote> <p>UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-1: ordinal not in range(256)</p> </blockquote> <p>My script:</p> <p...
9
2016-08-23T06:07:55Z
39,142,011
<p>The MySQLdb module is not compatible with python 3. That might be why you are getting problems. I would advise to use a different connector, like <a href="https://github.com/PyMySQL/PyMySQL%20%22PyMySQL" rel="nofollow">PyMySQL</a> or <a href="https://pypi.python.org/pypi/mysqlclient" rel="nofollow">mysqlclient</a>.<...
2
2016-08-25T09:52:14Z
[ "python", "mysql", "unicode", "utf-8", "character-encoding" ]
Python with MySql unicode problems
39,093,532
<p>I need to call MySQL stored procedure from my python script. As one of parameters I'm passing a unicode string (Russian language), but I get an error;</p> <blockquote> <p>UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-1: ordinal not in range(256)</p> </blockquote> <p>My script:</p> <p...
9
2016-08-23T06:07:55Z
39,148,601
<p>Here are some thoughts. Maybe not a response. I've been playing with python/mysql/utf-8/unicode in the past and this is the things i remember:</p> <p>Looking at Saltstack mysql module's comment :</p> <p><a href="https://github.com/saltstack/salt/blob/develop/salt/modules/mysql.py#L314-L322" rel="nofollow">https://...
3
2016-08-25T14:57:26Z
[ "python", "mysql", "unicode", "utf-8", "character-encoding" ]
Python with MySql unicode problems
39,093,532
<p>I need to call MySQL stored procedure from my python script. As one of parameters I'm passing a unicode string (Russian language), but I get an error;</p> <blockquote> <p>UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-1: ordinal not in range(256)</p> </blockquote> <p>My script:</p> <p...
9
2016-08-23T06:07:55Z
39,217,383
<p>What's your database's charset? <br>use :</p> <pre><code>show variables like "characetr%"; </code></pre> <p>or see your database's charset</p>
1
2016-08-30T01:09:40Z
[ "python", "mysql", "unicode", "utf-8", "character-encoding" ]
Python with MySql unicode problems
39,093,532
<p>I need to call MySQL stored procedure from my python script. As one of parameters I'm passing a unicode string (Russian language), but I get an error;</p> <blockquote> <p>UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-1: ordinal not in range(256)</p> </blockquote> <p>My script:</p> <p...
9
2016-08-23T06:07:55Z
39,228,907
<p>Maybe you can reload your <code>sys</code> in <code>utf-8</code> and try to decode the string into <code>utf-8</code> as following :</p> <pre><code>import sys reload(sys) sys.setdefaultencoding("utf-8") ... stringUtf8 = u''.join(string_original).decode('utf-8') </code></pre>
2
2016-08-30T13:30:38Z
[ "python", "mysql", "unicode", "utf-8", "character-encoding" ]
Python with MySql unicode problems
39,093,532
<p>I need to call MySQL stored procedure from my python script. As one of parameters I'm passing a unicode string (Russian language), but I get an error;</p> <blockquote> <p>UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-1: ordinal not in range(256)</p> </blockquote> <p>My script:</p> <p...
9
2016-08-23T06:07:55Z
39,229,820
<p>I see here two problems.</p> <ol> <li><p>You have unicode but you try to define it as utf-8 by setting parameter "charset". You should first encode your unicode to utf-8 or another encoding system.</p></li> <li><p>If it however doesn't work, try to do so with <strong>init_command='SET NAMES UTF8'</strong> parameter...
1
2016-08-30T14:10:01Z
[ "python", "mysql", "unicode", "utf-8", "character-encoding" ]
Python with MySql unicode problems
39,093,532
<p>I need to call MySQL stored procedure from my python script. As one of parameters I'm passing a unicode string (Russian language), but I get an error;</p> <blockquote> <p>UnicodeEncodeError: 'latin-1' codec can't encode characters in position 0-1: ordinal not in range(256)</p> </blockquote> <p>My script:</p> <p...
9
2016-08-23T06:07:55Z
39,230,058
<p>I had a similar problem very recently but with PostgreSQL. After trying tons of suggestions from SO/ internet, I realized the issue was with my database. I had to drop my database and reinstall Postgres, because for some reason it was not allowing me to change the database's default collation. I was in a hurry so co...
2
2016-08-30T14:19:27Z
[ "python", "mysql", "unicode", "utf-8", "character-encoding" ]
python sort tuple by different criteria
39,093,546
<p>I have a list <code>a = [(1,'a'), (1,'b'), (2,'c')]</code>, and I want to get this list: <code>[(2,'c'), (1,'a'), (1,'b')]</code></p> <p>If I do this:</p> <pre><code>sorted(a, reverse=True) </code></pre> <p>I can only get:</p> <pre><code>[(2,'c'), (1,'b'), (1,'a')] </code></pre> <p>How can I get the list I want...
-1
2016-08-23T06:08:40Z
39,093,757
<p>Try this,</p> <pre><code>from operator import itemgetter sorted(a, key=itemgetter(0),reverse=True) </code></pre> <p><strong>Result</strong></p> <pre><code>[(2, 'c'), (1, 'a'), (1, 'b')] </code></pre>
0
2016-08-23T06:23:06Z
[ "python", "list", "sorting", "tuples" ]
python sort tuple by different criteria
39,093,546
<p>I have a list <code>a = [(1,'a'), (1,'b'), (2,'c')]</code>, and I want to get this list: <code>[(2,'c'), (1,'a'), (1,'b')]</code></p> <p>If I do this:</p> <pre><code>sorted(a, reverse=True) </code></pre> <p>I can only get:</p> <pre><code>[(2,'c'), (1,'b'), (1,'a')] </code></pre> <p>How can I get the list I want...
-1
2016-08-23T06:08:40Z
39,093,760
<p>If you want to preserve the sort order in the original list, but sort only by the first element, you can do</p> <pre><code>&gt;&gt;&gt; from operator import itemgetter &gt;&gt;&gt; a = [(1,'a'), (1, 'x'), (1,'b'), (2,'c')] &gt;&gt;&gt; sorted(a, key=itemgetter(0), reverse=True) [(2, 'c'), (1, 'a'), (1, 'x'), (1, 'b...
1
2016-08-23T06:23:20Z
[ "python", "list", "sorting", "tuples" ]
python sort tuple by different criteria
39,093,546
<p>I have a list <code>a = [(1,'a'), (1,'b'), (2,'c')]</code>, and I want to get this list: <code>[(2,'c'), (1,'a'), (1,'b')]</code></p> <p>If I do this:</p> <pre><code>sorted(a, reverse=True) </code></pre> <p>I can only get:</p> <pre><code>[(2,'c'), (1,'b'), (1,'a')] </code></pre> <p>How can I get the list I want...
-1
2016-08-23T06:08:40Z
39,094,013
<p>You may achieve this by using <code>lambda</code> function with <code>sorted</code>:</p> <pre><code>&gt;&gt;&gt; sorted(a, key=lambda x: (-x[0], x[1])) [(2, 'c'), (1, 'a'), (1, 'b')] </code></pre> <p>This will sort the list in descending order of the value at index 0, and then ascending order of value at index 1</...
1
2016-08-23T06:39:42Z
[ "python", "list", "sorting", "tuples" ]
Tensorflow RNN cells weight sharing
39,093,627
<p>I am wondering if in the following code the weights of the two stacked cells are shared: </p> <pre><code>cell = rnn_cell.GRUCell(hidden_dim) stacked_cell = tf.nn.rnn_cell.MultiRNNCell([cell] * 2) </code></pre> <p>If they are not shared, how to force sharing in any RNNs? </p> <p>Note: I might more probably want t...
0
2016-08-23T06:14:48Z
39,134,388
<p>You can see that the weights are not shared by executing the following script:</p> <pre class="lang-py prettyprint-override"><code>import tensorflow as tf with tf.variable_scope("scope1") as vs: cell = tf.nn.rnn_cell.GRUCell(10) stacked_cell = tf.nn.rnn_cell.MultiRNNCell([cell] * 2) stacked_cell(tf.Variable(...
1
2016-08-24T23:14:35Z
[ "python", "machine-learning", "tensorflow", "deep-learning", "recurrent-neural-network" ]
matplotlib - faster frame rate?
39,093,656
<p>I have written a simple script based on the code from <a href="https://jakevdp.github.io/blog/2013/02/16/animating-the-lorentz-system-in-3d/" rel="nofollow">here</a></p> <p>I just need to display dots, no lines needed.</p> <p>The script below displays the dots correctly but I would like to see the dots move much f...
1
2016-08-23T06:17:02Z
39,093,939
<ol> <li><p>From <a href="http://matplotlib.org/api/animation_api.html#matplotlib.animation.FuncAnimation" rel="nofollow">the documentation</a>:</p> <blockquote> <p>kwargs include <code>repeat</code>, <code>repeat_delay</code>, and <code>interval</code>: <code>interval</code> draws a new frame <strong>every <code>in...
0
2016-08-23T06:35:25Z
[ "python", "animation", "matplotlib" ]
Python sys.argv utf-8 to unicode not working
39,093,768
<p>I have the following code which is acting very weirdly.</p> <p>When I do the following, the utf-8 got converted into unicode nicely.</p> <pre><code>print u'\xE1\x80\x96\xE1\x80\xBB\xE1\x80\xB1\xE1\x80\xAC\xE1\x80\xBA\xE1\x80\x9B\xE1\x80\x8A\xE1\x80\xBA'.encode('raw_unicode_escape') </code></pre> <p>This works fin...
-1
2016-08-23T06:24:02Z
39,094,099
<p>Actual Python level string literals (for <code>str</code> and <code>unicode</code>) are the only place character escapes are parsed by Python automatically. If you want to convert outside strings that use literal escapes like this, you'd do something like this to <a href="https://docs.python.org/2/library/codecs.htm...
1
2016-08-23T06:45:08Z
[ "python", "unicode", "encoding", "utf-8" ]
How to do some operations like groupby() and value_counts() in pandas?
39,093,811
<p>Here is a pandas Dataframe defined as follow:</p> <pre><code>df = pd.DataFrame({'A' : ['foo', 'bar', 'foo', 'bar', 'foo', 'bar', 'foo', 'foo', 'foo'], 'B' : ['one', 'one', 'two', 'three', 'two', 'two', 'one', 'three', 'two'], 'C' : [0, 1, 0, 1, 1, 2, 0, 2, 1]}) &gt;&gt;&gt; df ...
1
2016-08-23T06:27:37Z
39,093,870
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.groupby.html" rel="nofollow"><code>groupby</code></a> with aggregating <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.size.html" rel="nofollow"><code>size</code></a>, then replace <...
1
2016-08-23T06:31:37Z
[ "python", "pandas", "dataframe", "group-by", "crosstab" ]
Counter not working
39,093,920
<p>I am trying to do some grouping with the usage of counters, such that it will increment accordingly.. I apologize if my title gives the wrong impression but...</p> <p>Anyway, when I have 2 or more selections and as I execute my code, instead of seeing groups with naming such as - TEST_1_GRP, TEST_2_GRP, TEST_3_GRP ...
0
2016-08-23T06:34:18Z
39,094,539
<p>Move your counter as follows, you aren't using the counter in your last loop so remove it from that. Check this does what you want?</p> <pre><code>def fix_shapes(): all_geos = cmds.ls(sl = True) counter = 0 for geo in all_geos: shapes = cmds.listRelatives(geo, fullPath=True, shapes=True) ...
0
2016-08-23T07:10:11Z
[ "python", "maya" ]
Counter not working
39,093,920
<p>I am trying to do some grouping with the usage of counters, such that it will increment accordingly.. I apologize if my title gives the wrong impression but...</p> <p>Anyway, when I have 2 or more selections and as I execute my code, instead of seeing groups with naming such as - TEST_1_GRP, TEST_2_GRP, TEST_3_GRP ...
0
2016-08-23T06:34:18Z
39,296,911
<p>I believe this may solve your problem. Keep in mind that the first time you execute your code, it will work as expected and produce groups named <code>TEST_1_GRP TEST_2_GRP</code> etc. However, the second time it will be named <code>TEST_1_GRP1 TEST_2_GRP1</code> etc. because you're not saving or checking if the nam...
0
2016-09-02T16:22:10Z
[ "python", "maya" ]
Counter not working
39,093,920
<p>I am trying to do some grouping with the usage of counters, such that it will increment accordingly.. I apologize if my title gives the wrong impression but...</p> <p>Anyway, when I have 2 or more selections and as I execute my code, instead of seeing groups with naming such as - TEST_1_GRP, TEST_2_GRP, TEST_3_GRP ...
0
2016-08-23T06:34:18Z
39,327,738
<pre><code>def fix_shapes(): all_geos = cmds.ls(sl = True) counter = 0 for geo in all_geos: shapes = cmds.listRelatives(geo, fullPath=True, shapes=True) if len(shapes) == 1: continue new_listing = [] new_listing.append(shapes[:1]) # pop out the first shape, ...
0
2016-09-05T09:37:52Z
[ "python", "maya" ]
Access .rds file from Python
39,093,931
<p>I am working on a project where I have got an .rds file which consist of trained model as per my requirement generated by R code.</p> <p>Now I need to load the trained model in python and use it in processing the records. </p> <p>Is there any way to do so? If not what are the alternatives.</p> <p>Thanks</p>
0
2016-08-23T06:34:44Z
39,094,052
<p>We can use feather: </p> <pre><code>import feather path = 'my_data.feather' feather.write_dataframe(df, path) df = feather.read_dataframe(path) </code></pre>
1
2016-08-23T06:41:51Z
[ "python" ]
Access .rds file from Python
39,093,931
<p>I am working on a project where I have got an .rds file which consist of trained model as per my requirement generated by R code.</p> <p>Now I need to load the trained model in python and use it in processing the records. </p> <p>Is there any way to do so? If not what are the alternatives.</p> <p>Thanks</p>
0
2016-08-23T06:34:44Z
39,094,076
<p>Look at this website, maybe this can help too.</p> <p><a href="http://mgimond.github.io/ES218/Week02b.html" rel="nofollow">http://mgimond.github.io/ES218/Week02b.html</a></p>
0
2016-08-23T06:43:39Z
[ "python" ]
Python - can I add UTF8 BOM to a file without opening it?
39,094,125
<p>How to add an utf8-bom to a text file without open() it?</p> <p>Theoretically, we just need to add utf8-bom to the beginning of the file, we don't need to read-in 'all' the content? </p>
1
2016-08-23T06:46:28Z
39,094,533
<p>You need to read in the data because you need to move all the data to make room for the BOM. Files can't just prepend arbitrary data. Doing it in place is harder than just writing a new file with the BOM followed by the original data, then replacing the original file, so the easiest solution is usually something lik...
3
2016-08-23T07:09:38Z
[ "python", "unicode", "utf-8", "byte-order-mark" ]
Python - can I add UTF8 BOM to a file without opening it?
39,094,125
<p>How to add an utf8-bom to a text file without open() it?</p> <p>Theoretically, we just need to add utf8-bom to the beginning of the file, we don't need to read-in 'all' the content? </p>
1
2016-08-23T06:46:28Z
39,095,381
<p>If you need in-place update, something like</p> <pre><code>def add_bom(fname, bom=None, buf_size=None): bom = bom or BOM buf_size = buf_size or max(resource.getpagesize(), len(bom)) buf = bytearray(buf_size) with open(fname, 'rb', 0) as in_fd, open(fname, 'rb+', 0) as out_fd: # we cannot jus...
1
2016-08-23T07:52:32Z
[ "python", "unicode", "utf-8", "byte-order-mark" ]
learning Python the hard way argv and file
39,094,156
<p>I am learning python from past weeks </p> <pre><code>from sys import argv script,filename = argv print "We're delete the file %r" %filename print "If you want to stop ctrl+c (^c)" print "Please hit enter to continue" raw_input("&gt;_") print "Opening file..." filen = open(filename,'w') print "Truncating your file....
-3
2016-08-23T06:48:49Z
39,094,243
<p>you can read data using <code>filen.read()</code> or <code>filen.readline()</code> or <code>filen.readlines()</code></p> <p>1) read</p> <pre><code>fo = open(filename,read) fo.seek(0, 0) #seek is used to change the file position.This requires only for read method fo.read(10) #This reads 1st 10 characters fo.close()...
0
2016-08-23T06:54:24Z
[ "python", "file", "argv", "filehandle" ]
learning Python the hard way argv and file
39,094,156
<p>I am learning python from past weeks </p> <pre><code>from sys import argv script,filename = argv print "We're delete the file %r" %filename print "If you want to stop ctrl+c (^c)" print "Please hit enter to continue" raw_input("&gt;_") print "Opening file..." filen = open(filename,'w') print "Truncating your file....
-3
2016-08-23T06:48:49Z
39,094,916
<p>If you want to print the content of the file you opened, just use: <code>print filen.read()</code>.</p>
0
2016-08-23T07:28:38Z
[ "python", "file", "argv", "filehandle" ]
learning Python the hard way argv and file
39,094,156
<p>I am learning python from past weeks </p> <pre><code>from sys import argv script,filename = argv print "We're delete the file %r" %filename print "If you want to stop ctrl+c (^c)" print "Please hit enter to continue" raw_input("&gt;_") print "Opening file..." filen = open(filename,'w') print "Truncating your file....
-3
2016-08-23T06:48:49Z
39,098,172
<p>At its simplest:</p> <pre><code>from sys import argv script,filename = argv with open(filename) as f: print f.readlines() </code></pre> <p>which dumps the files contents or:</p> <pre><code>from sys import argv script,filename = argv with open(filename) as f: lines=f.readlines() for line in lines: pr...
0
2016-08-23T10:06:31Z
[ "python", "file", "argv", "filehandle" ]
How to resize and crop in a video player using GStreamer in python TKinter?
39,094,171
<p>I wrote a small media player in python using TKinter and GStreamer which is embedded in my application. The player is based on the code below which is a small modification to <a href="http://stackoverflow.com/questions/7227162">Way to play video files in Tkinter?</a> which works.</p> <pre><code>import os, sys impo...
0
2016-08-23T06:49:19Z
39,102,389
<p>I figured it out, and it can be done by adding a video-filter element. the code to add is the following:</p> <pre><code>VideoCrop = Gst.ElementFactory.make('videocrop', 'VideoCrop') VideoCrop.set_property('top', 100) VideoCrop.set_property('bottom', 100) VideoCrop.set_property('left', 50) VideoCrop.set_property('ri...
0
2016-08-23T13:18:31Z
[ "python", "tkinter", "resize", "gstreamer", "crop" ]
xml to CSV - AttributeError: 'NoneType' object has no attribute 'text'
39,094,234
<pre><code> for tm in teamtree.iter('team_members'): </code></pre> <p>I'm trying to output these fields into a CSV using the above function. The xml data is stored in a variable called (projectDetJoined)</p> <p>I'm getting this error.</p> <pre><code>Traceback (most recent call last): File "10Other.py", line 48...
-2
2016-08-23T06:53:52Z
39,096,766
<p><strong>Ilja Everilä's</strong> comment solved my problem.</p> <blockquote> <p>In your XML the team_members element does not have subelements like cid etc. It has item subelements. Perhaps you meant for tm in teamtree.iterfind('team_members/item'). If your CSV headers didn't have different case for some it...
0
2016-08-23T09:00:56Z
[ "python", "xml", "csv" ]
scikit learn decision tree model evaluation
39,094,267
<p>Here are the related code and document, wondering for the default <code>cross_val_score</code> without explicitly specify <code>score</code>, the output array means precision, AUC or some other metrics? </p> <p>Using Python 2.7 with miniconda interpreter.</p> <p><a href="http://scikit-learn.org/stable/modules/gene...
0
2016-08-23T06:55:38Z
39,094,466
<p>If a scoring argument isn't given, <code>cross_val_score</code> will default to using the <code>.score</code> method of the estimator you're using. For <code>DecisionTreeClassifier</code>, it's mean accuracy (as shown in the docstring below): </p> <pre><code>In [11]: DecisionTreeClassifier.score? Signature: Decisio...
1
2016-08-23T07:05:28Z
[ "python", "python-2.7", "machine-learning", "scikit-learn", "decision-tree" ]
scikit learn decision tree model evaluation
39,094,267
<p>Here are the related code and document, wondering for the default <code>cross_val_score</code> without explicitly specify <code>score</code>, the output array means precision, AUC or some other metrics? </p> <p>Using Python 2.7 with miniconda interpreter.</p> <p><a href="http://scikit-learn.org/stable/modules/gene...
0
2016-08-23T06:55:38Z
39,094,469
<p>From the <a href="http://scikit-learn.org/stable/modules/cross_validation.html#cross-validation" rel="nofollow">user guide</a>:</p> <blockquote> <p>By default, the score computed at each CV iteration is the score method of the estimator. It is possible to change this by using the scoring parameter:</p> </bloc...
1
2016-08-23T07:05:46Z
[ "python", "python-2.7", "machine-learning", "scikit-learn", "decision-tree" ]
How to query max to min in Django?
39,094,365
<p>I want to query from max entry to min entry in a topic. Such that:</p> <p><strong>models.py</strong></p> <pre><code>class Topic(models.Model): title = models.CharField(max_length=140, unique=True, verbose_name=_("Title")) created_at = models.DateTimeField(auto_now=True, verbose_name=_("Created at")) </cod...
2
2016-08-23T06:59:54Z
39,094,487
<p>For min and max dates</p> <pre><code>### please use range for selecting between dates def get_topic_today(self): return self.filter(created_at__range=[min_date, max_date]).order_by('title') ### (or) use greater than or lesser than def get_topic_today(self): return self.filter(created_at__gte=min_date, cr...
0
2016-08-23T07:06:37Z
[ "python", "django" ]
How to query max to min in Django?
39,094,365
<p>I want to query from max entry to min entry in a topic. Such that:</p> <p><strong>models.py</strong></p> <pre><code>class Topic(models.Model): title = models.CharField(max_length=140, unique=True, verbose_name=_("Title")) created_at = models.DateTimeField(auto_now=True, verbose_name=_("Created at")) </cod...
2
2016-08-23T06:59:54Z
39,094,526
<p>If you want to filter a DateTimeField to a specific day, you can use the <a href="https://docs.djangoproject.com/en/1.10/ref/models/querysets/#day" rel="nofollow"><code>__day</code> lookup</a>.</p> <pre><code>def get_topic_today(self): return self.filter(created_at__day=datetime.date.today()).order_by('title') ...
2
2016-08-23T07:09:09Z
[ "python", "django" ]
How to query max to min in Django?
39,094,365
<p>I want to query from max entry to min entry in a topic. Such that:</p> <p><strong>models.py</strong></p> <pre><code>class Topic(models.Model): title = models.CharField(max_length=140, unique=True, verbose_name=_("Title")) created_at = models.DateTimeField(auto_now=True, verbose_name=_("Created at")) </cod...
2
2016-08-23T06:59:54Z
39,094,644
<p>If you want to order popular topic from max entry to min:</p> <pre><code>def get_topic_today(self): return self.filter(created_at__date=datetime.date.today()).annotate(entry_count=models.Count('entry_set')).order_by('-entry_count') </code></pre>
1
2016-08-23T07:14:54Z
[ "python", "django" ]
find all elements and indices larger than threshold in list of lists
39,094,459
<p>I have a list of lists like:</p> <pre><code> j=[[1,2,3],[4,5,6],[7,8,9,10],[11,12,13,14,15]] </code></pre> <p>and I want to get a list of all elements from the list of lists larger than a certain threshold. I know when having a list there is the Syntax:</p> <pre><code>k=[1,2,3,4,5,6,7] k2=[i for i in k if i&gt;5...
0
2016-08-23T07:05:16Z
39,094,500
<p>Is this what you mean?</p> <pre><code>In [3]: l1 = [[1,2,3],[4,5,6],[7,8,9,10],[11,12,13,14,15]] In [4]: [e for l2 in l1 for e in l2 if e&gt;5] Out[4]: [6, 7, 8, 9, 10, 11, 12, 13, 14, 15] </code></pre> <p>To get the index (of the inner lists), you can use <code>enumerate</code>:</p> <pre><code>In [5]: [(i2, e) f...
6
2016-08-23T07:07:28Z
[ "python", "list" ]
Odoo: _get_state() takes at least 4 arguments (4 given) in xml view
39,094,524
<p>Here is mycode. I want to get id_employee of current record before define its model class:</p> <pre><code>def _get_state(self, cr, uid, context=None): idemployee = "" for adv in self.browse(cr, uid, ids, context): id_employee = adv.id_employee if id_employee is None: idemployee =...
1
2016-08-23T07:08:54Z
39,138,502
<p><code>_get_state</code> has to be part of the class for you to use it not outside the class, the self you're passing in there is not seen as the python <code>self</code> i.e the current instance, it's seen as a normal argument of the function.</p> <p>Python isn't passing in self for you, let me deviate a little and...
1
2016-08-25T06:50:33Z
[ "python", "openerp" ]
Odoo: _get_state() takes at least 4 arguments (4 given) in xml view
39,094,524
<p>Here is mycode. I want to get id_employee of current record before define its model class:</p> <pre><code>def _get_state(self, cr, uid, context=None): idemployee = "" for adv in self.browse(cr, uid, ids, context): id_employee = adv.id_employee if id_employee is None: idemployee =...
1
2016-08-23T07:08:54Z
39,141,934
<p>In this case, you want this :</p> <pre><code>def _get_state(self, cr, uid, ids, context=None): current_record=self.browse(cr, uid, ids) idemployee = current_record[0].id_employee sql = " SELECT C.id AS id, C.sequence, C.name \ FROM wf_group_member A \ LEFT JOIN wf_...
0
2016-08-25T09:48:59Z
[ "python", "openerp" ]
Pandas slicing and indexing use with fillna
39,094,651
<p>I have a pandas dataframe <strong>tdf</strong> I am extracting a slice based on boolean labels</p> <pre><code>idx = tdf['MYcol1'] == 1 myslice = tdf.loc[idx] //I want myslice to be a view not a copy </code></pre> <p>Now i want to fill the missing values in a column of <strong>myslice</strong> and i want this to be...
0
2016-08-23T07:15:35Z
39,095,026
<p>When you assign it to a new variable, it creates a copy. The things you do after that are irrelevant. Consider this:</p> <pre><code>tdf Out: A B C 0 NaN 0.195070 -1.781563 1 -0.729045 0.196557 0.354758 2 0.616887 0.008628 NaN 3 NaN NaN 0.037006 4 0.767902 ...
2
2016-08-23T07:33:47Z
[ "python", "pandas" ]
how to pass null values as arguments from java to python
39,094,662
<p>I have a java method that passes some arguments to a python file. I am passing the the arguments this way :</p> <pre><code>String name=null; //can be null or some value in some cases. .... String[] cmd = { "python", "C:/Python34/myscript.py", name, ...
2
2016-08-23T07:16:04Z
39,094,760
<p>Instead of passing them as null, do a NullPointer check and pass in empty strings.</p> <pre><code>name = name == null ? "" : name; </code></pre> <p>That way your python script will just need to check for empty strings instead of nulls. And you can check for both by a simple if check. Something like below will work...
0
2016-08-23T07:21:01Z
[ "java", "python" ]
how to pass null values as arguments from java to python
39,094,662
<p>I have a java method that passes some arguments to a python file. I am passing the the arguments this way :</p> <pre><code>String name=null; //can be null or some value in some cases. .... String[] cmd = { "python", "C:/Python34/myscript.py", name, ...
2
2016-08-23T07:16:04Z
39,094,762
<p>Since python and java are different processes you are communicating between using system calls, you cannot convert Java <code>null</code> to the command line.</p> <p>(What you call <code>null</code> in Python is actually <code>None</code>)</p> <p>What you can do is: pass empty string (<code>""</code> not <code>nul...
0
2016-08-23T07:21:08Z
[ "java", "python" ]
Memory not released when a pyqtgraph Plot is closed
39,094,764
<p>My Python QApplication has a button (on the main window) which, when clicked, launches a pyqtgraph Plot. The code below shows how the plot is generated within a class.</p> <pre><code>self.win = pg.GraphicsWindow() self.win.setWindowTitle(self.title) self.p = self.win.addPlot() self.curve = self.p.plot(self.Data1) <...
0
2016-08-23T07:21:20Z
39,094,887
<p>A couple of things.</p> <ol> <li>Just closing the window doesn't explicitly deallocate anything. Yes, internally, Window structures aren't used any more, but that doesn't mean it would be wise for the GUI toolkit to throw away everything it has calculated – maybe parts of that would be relevant for the next windo...
0
2016-08-23T07:26:47Z
[ "python", "pyqtgraph" ]
Django deserialization of JSON stored in a model field
39,094,946
<p>I'm new to Django/Python and currently working on a project with a friend. His android app sends data to me in JSON format that looks like this: </p> <pre><code>"datum_isteka": "2", "e_mail": "null", "adress": "null", "goods": "[ {\"price\":\"2\", \"good\":\"dobro1\", \"tax_value\...
1
2016-08-23T07:29:58Z
39,097,195
<p>I'd use a <a href="https://pypi.python.org/pypi/django-jsonfield" rel="nofollow">JSONField</a> on the model</p> <pre><code>class Obraz(models.Model): ... goods = jsonfield.JSONField() </code></pre> <p>and a <a href="http://www.django-rest-framework.org/api-guide/fields/#jsonfield" rel="nofollow">JSONField<...
0
2016-08-23T09:19:14Z
[ "python", "json", "django", "serialization", "django-rest-framework" ]
Theanos Installation error linux compilation error
39,094,982
<p>So I was trying to setup theano on my Linux14.04 machine . Steps done so far : </p> <ul> <li>Installed miniconda</li> <li>installed dependencies - <code>conda install numpy scipy mkl &lt;nose&gt; &lt;sphinx&gt; &lt;pydot-ng&gt;</code></li> <li>Did not install the GPU drivers .... do not need the higher computation...
0
2016-08-23T07:31:42Z
39,096,469
<p>Package error : Solved by installing : </p> <pre><code>sudo apt-get install python-dev </code></pre> <p>Gave error for installing dependencies Theano[test, doc] : Clean install with only : </p> <pre><code>sudo pip install Theano </code></pre>
0
2016-08-23T08:47:17Z
[ "python", "linux", "theano" ]