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 |
|---|---|---|---|---|---|---|---|---|---|
Multiprocessing: main programm stops until process is finished | 39,462,926 | <p>I know, a minimal working example is the gold standard and I am working on it. However, maybe there is an obvious error. The function <code>run_worker</code> is executed upon a button press event. It initiates a class instance and should start a method of that class. However the function run_worker waits until the c... | 0 | 2016-09-13T05:44:25Z | 39,467,181 | <p>I suggest you study daemon processes here:
<a href="https://pypi.python.org/pypi/python-daemon/" rel="nofollow">https://pypi.python.org/pypi/python-daemon/</a></p>
<p><a href="http://askubuntu.com/questions/192058/what-is-technical-difference-between-daemon-service-and-process">http://askubuntu.com/questions/192058... | 0 | 2016-09-13T09:57:51Z | [
"python",
"kivy",
"python-multiprocessing"
] |
Multiprocessing: main programm stops until process is finished | 39,462,926 | <p>I know, a minimal working example is the gold standard and I am working on it. However, maybe there is an obvious error. The function <code>run_worker</code> is executed upon a button press event. It initiates a class instance and should start a method of that class. However the function run_worker waits until the c... | 0 | 2016-09-13T05:44:25Z | 39,486,560 | <p>I found a solution. Not sure why it works:</p>
<pre><code> def worker(self):
"""
The pHBot application is started as a second process. Otherwise kivy would be blocked until the function stops
(which is controlled by the close button)
"""
# initiate the process
args... | 0 | 2016-09-14T09:08:21Z | [
"python",
"kivy",
"python-multiprocessing"
] |
pelican make serve error with broken pipe? | 39,462,958 | <p>I was trying to make a blog with pelican, and in the step of make serve I had below errors. By searching online it looks like a web issue ( I'm not familiar with these at all ) and I didn't see a clear solution. Could anyone shed some light on? I was running on Ubuntu with Python 2.7. Thanks!
Python info:</p>
<bloc... | 0 | 2016-09-13T05:48:03Z | 39,462,999 | <p>Well I installed pip on Ubuntu and then it all worked..</p>
<p>Not sure if it is a version thing..</p>
| 0 | 2016-09-13T05:51:53Z | [
"python",
"python-2.7",
"ubuntu",
"makefile",
"server"
] |
How to read strange csv files in Pandas? | 39,462,978 | <p>I would like to read sample csv file shown in below</p>
<pre><code>--------------
|A|B|C|
--------------
|1|2|3|
--------------
|4|5|6|
--------------
|7|8|9|
--------------
</code></pre>
<p>I tried </p>
<pre><code>pd.read_csv("sample.csv",sep="|")
</code></pre>
<p>But it didn't work well.</p>
<p>How ca... | 5 | 2016-09-13T05:49:58Z | 39,463,003 | <p>You can add parameter <code>comment</code> to <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.read_csv.html"><code>read_csv</code></a> and then remove columns with <code>NaN</code> by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.dropna.html"><code>dropna</code... | 10 | 2016-09-13T05:52:07Z | [
"python",
"csv",
"pandas"
] |
How to read strange csv files in Pandas? | 39,462,978 | <p>I would like to read sample csv file shown in below</p>
<pre><code>--------------
|A|B|C|
--------------
|1|2|3|
--------------
|4|5|6|
--------------
|7|8|9|
--------------
</code></pre>
<p>I tried </p>
<pre><code>pd.read_csv("sample.csv",sep="|")
</code></pre>
<p>But it didn't work well.</p>
<p>How ca... | 5 | 2016-09-13T05:49:58Z | 39,463,044 | <p>Try "import csv" rather than directly use pandas.</p>
<pre><code>import csv
easy_csv = []
with open('sample.csv', 'rb') as csvfile:
test = csv.reader(csvfile, delimiter=' ', quotechar='|')
for row in test:
row_preprocessed = """ handling rows at here; removing |, ignoring row that has ----"""
ea... | 1 | 2016-09-13T05:55:22Z | [
"python",
"csv",
"pandas"
] |
How to read strange csv files in Pandas? | 39,462,978 | <p>I would like to read sample csv file shown in below</p>
<pre><code>--------------
|A|B|C|
--------------
|1|2|3|
--------------
|4|5|6|
--------------
|7|8|9|
--------------
</code></pre>
<p>I tried </p>
<pre><code>pd.read_csv("sample.csv",sep="|")
</code></pre>
<p>But it didn't work well.</p>
<p>How ca... | 5 | 2016-09-13T05:49:58Z | 39,463,090 | <p>i try this code and its ok !:</p>
<pre><code>import pandas as pd
import numpy as np
a = pd.read_csv("a.csv",sep="|")
print(a)
for i in a:
print(i)
</code></pre>
<p><a href="http://i.stack.imgur.com/87JF9.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/87JF9.jpg" alt="enter image description here"></a></... | 1 | 2016-09-13T05:59:09Z | [
"python",
"csv",
"pandas"
] |
how to copy numpy array value into higher dimensions | 39,463,019 | <p>I have a (w,h) np array in 2d. I want to make a 3d dimension that has a value greater than 1 and copy its value over along the 3rd dimensions. I was hoping broadcast would do it but it can't. This is how i'm doing it</p>
<pre><code>arr = np.expand_dims(arr, axis=2)
arr = np.concatenate((arr,arr,arr), axis=2)
</code... | 2 | 2016-09-13T05:53:17Z | 39,463,055 | <p>You can <em>push</em> all dims forward, introducing a singleton dim/new axis as the last dim to create a <code>3D</code> array and then repeat three times along that one with <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.repeat.html" rel="nofollow"><code>np.repeat</code></a>, like so -</p>
<pre... | 2 | 2016-09-13T05:56:18Z | [
"python",
"numpy"
] |
how to copy numpy array value into higher dimensions | 39,463,019 | <p>I have a (w,h) np array in 2d. I want to make a 3d dimension that has a value greater than 1 and copy its value over along the 3rd dimensions. I was hoping broadcast would do it but it can't. This is how i'm doing it</p>
<pre><code>arr = np.expand_dims(arr, axis=2)
arr = np.concatenate((arr,arr,arr), axis=2)
</code... | 2 | 2016-09-13T05:53:17Z | 39,463,117 | <p>Not sure if I understood correctly, but broadcasting seems working to me in this case:</p>
<pre><code>>>> a = numpy.array([[1,2], [3,4]])
>>> c = numpy.zeros((4, 2, 2))
>>> c[0] = a
>>> c[1:] = a+1
>>> c
array([[[ 1., 2.],
[ 3., 4.]],
[[ 2., 3.],
... | 0 | 2016-09-13T06:01:12Z | [
"python",
"numpy"
] |
FormSet saves the data of only one form | 39,463,265 | <p>When I submitted forms (but on page I filled id more than 1 form) - my FormSet saves the data of only one form, the rest of the data just disappear...</p>
<p>My template:</p>
<pre><code> <div id="data">
<form method="post" action="/lookup/" id="test_data">{% csrf_token %}
{{ formset.management_... | 0 | 2016-09-13T06:11:49Z | 39,464,240 | <p>You cannot save a formset as it contains multiple forms. So I would suggest you change your code to:</p>
<pre><code> if formset.is_valid():
for form in formset:
form.save()
return HttpResponseRedirect('/')
</code></pre>
<p>See the <a href="https://docs.djangoproject.com/en/1.10/topics/f... | 0 | 2016-09-13T07:18:04Z | [
"python",
"django",
"django-forms"
] |
redis.exceptions.ConnectionError: Error 97 connecting to localhost:6379. Address family not supported by protocol | 39,463,403 | <p>when ever i try to run my program following error will will raise.</p>
<p>redis.exceptions.ConnectionError: Error 97 connecting to localhost:6379. Address family not supported by protocol.</p>
<p>Previously the program runs normally now this error will be raised.</p>
<pre><code>Traceback (most recent call last):
... | 0 | 2016-09-13T06:21:51Z | 39,464,427 | <p>Finally i got answer for above qustion.Step by step the following done</p>
<pre><code> Setup
Before you install redis, there are a couple of prerequisites that need to be downloaded to make the installation as easy as possible.
Start off by updating all of the apt-get packages:
**sudo apt-get update*... | 0 | 2016-09-13T07:28:53Z | [
"python",
"django",
"redis",
"socket.io"
] |
Converting a PNG image to 2D array | 39,463,455 | <p>I have a PNG file which when I convert the image to a numpy array, it is of the format that is 184 x 184 x 4. The image is 184 by 184 and each pixel is in RGBA format and hence the 3D array.</p>
<p>This a B&W image and the pixels are either [255, 255, 255, 255] or [0, 0, 0, 255].</p>
<p>I want to convert this ... | 0 | 2016-09-13T06:25:31Z | 39,463,609 | <p>There would be several ways to do the comparison to give us a <code>boolean array</code> and then, we just need to convert to <code>int array</code> with type conversion. So, for the comparison, one simple way would be to compare against <code>255</code> and check for <code>ALL</code> matches along the last axis. Th... | 0 | 2016-09-13T06:35:59Z | [
"python",
"arrays",
"numpy"
] |
Converting a PNG image to 2D array | 39,463,455 | <p>I have a PNG file which when I convert the image to a numpy array, it is of the format that is 184 x 184 x 4. The image is 184 by 184 and each pixel is in RGBA format and hence the 3D array.</p>
<p>This a B&W image and the pixels are either [255, 255, 255, 255] or [0, 0, 0, 255].</p>
<p>I want to convert this ... | 0 | 2016-09-13T06:25:31Z | 39,469,616 | <p>If there are really only two values in the array as you say, simply scale and return one of the dimensions:</p>
<pre><code>(arr[:,:,0] / 255).astype(int)
</code></pre>
| 1 | 2016-09-13T12:03:08Z | [
"python",
"arrays",
"numpy"
] |
Error iterating through a Pandas series | 39,463,692 | <p>When I get the first and second elements of this series, it works OK, but from element 3 onwards, giving an error when I try to fetch.</p>
<pre><code>type(X_test_raw)
Out[51]: pandas.core.series.Series
len(X_test_raw)
Out[52]: 1393
X_test_raw[0]
Out[45]: 'Go until jurong point, crazy.. Available only in bugis n g... | 3 | 2016-09-13T06:41:28Z | 39,463,734 | <p>There is no index with value <code>2</code>.</p>
<p>Sample:</p>
<pre><code>X_test_raw = pd.Series([4,8,9], index=[0,4,5])
print (X_test_raw)
0 4
4 8
5 9
dtype: int64
#print (X_test_raw[2])
#KeyError: 2
</code></pre>
<p>If need third value use <a href="http://pandas.pydata.org/pandas-docs/stable/generat... | 3 | 2016-09-13T06:43:51Z | [
"python",
"pandas",
"for-loop",
"indexing",
"keyerror"
] |
Error iterating through a Pandas series | 39,463,692 | <p>When I get the first and second elements of this series, it works OK, but from element 3 onwards, giving an error when I try to fetch.</p>
<pre><code>type(X_test_raw)
Out[51]: pandas.core.series.Series
len(X_test_raw)
Out[52]: 1393
X_test_raw[0]
Out[45]: 'Go until jurong point, crazy.. Available only in bugis n g... | 3 | 2016-09-13T06:41:28Z | 39,463,764 | <p>consider the series <code>X_test_raw</code></p>
<pre><code>X_test_raw = pd.Series(
['Go until jurong point, crazy.. Available only in bugis n great world la e buffet... Cine there got amore wat...',
'Ok lar... Joking wif u oni...',
'PLEASE DON\'T FAIL'
], [0, 1, 3])
</code></pre>
<p><code>X_test_... | 2 | 2016-09-13T06:45:50Z | [
"python",
"pandas",
"for-loop",
"indexing",
"keyerror"
] |
How to find duplicate names from table? | 39,463,906 | <p>I know we can use <code>GROUP BY</code> and <code>HAVING COUNT > 1</code>. But this works when you have duplicate data. I have a little bit different data.</p>
<pre><code>Id Names
1 Rahul S
2 Rohit S
3 Rishu
4 Sinu
5 Rahul S
6 Rohit S
</code></pre>
<p>In the above table id 1 and 5 are same and 2 and 6 a... | 0 | 2016-09-13T06:55:38Z | 39,464,008 | <p>Have you tried removing the spaces on selecting of the data?</p>
<p>Doing it this way ought to Cut the spaces in the string, and provide similar data. Take in mind that i mean removing double spaces and replacing it with 1 space, then doing a left and right trim on the data</p>
<p>Something like this : </p>
<pre>... | 0 | 2016-09-13T07:03:10Z | [
"python",
"psql",
"peewee"
] |
How to find duplicate names from table? | 39,463,906 | <p>I know we can use <code>GROUP BY</code> and <code>HAVING COUNT > 1</code>. But this works when you have duplicate data. I have a little bit different data.</p>
<pre><code>Id Names
1 Rahul S
2 Rohit S
3 Rishu
4 Sinu
5 Rahul S
6 Rohit S
</code></pre>
<p>In the above table id 1 and 5 are same and 2 and 6 a... | 0 | 2016-09-13T06:55:38Z | 39,464,031 | <p>You can use trim
SELECT trim(name),trim(count(name)) FROM <code>tablename</code> group by trim(name)</p>
| 0 | 2016-09-13T07:04:38Z | [
"python",
"psql",
"peewee"
] |
How to find duplicate names from table? | 39,463,906 | <p>I know we can use <code>GROUP BY</code> and <code>HAVING COUNT > 1</code>. But this works when you have duplicate data. I have a little bit different data.</p>
<pre><code>Id Names
1 Rahul S
2 Rohit S
3 Rishu
4 Sinu
5 Rahul S
6 Rohit S
</code></pre>
<p>In the above table id 1 and 5 are same and 2 and 6 a... | 0 | 2016-09-13T06:55:38Z | 39,464,097 | <p>You can use the REPLACE function to remove white spaces. </p>
<p>I would save the string without spaces into a new column and use the group by on that.
Like:</p>
<pre><code>Select <values you are looking for>, replace(Names, ' ', '') as d
from <Table name>
group by d
</code></pre>
| 1 | 2016-09-13T07:08:44Z | [
"python",
"psql",
"peewee"
] |
How to find duplicate names from table? | 39,463,906 | <p>I know we can use <code>GROUP BY</code> and <code>HAVING COUNT > 1</code>. But this works when you have duplicate data. I have a little bit different data.</p>
<pre><code>Id Names
1 Rahul S
2 Rohit S
3 Rishu
4 Sinu
5 Rahul S
6 Rohit S
</code></pre>
<p>In the above table id 1 and 5 are same and 2 and 6 a... | 0 | 2016-09-13T06:55:38Z | 39,464,207 | <p>I have created table and inserted your data.Try this: </p>
<pre><code>DROP TABLE IF EXISTS Emp;
CREATE TABLE Emp (Id INT, Name VARCHAR(50));
INSERT INTO Emp (Id, Name) VALUES
(1, 'Rahul S'), (2, 'Rohit S'), (3, 'Rishu'), (4, 'Sinu'), (5, ' Rahul S'),(5, 'Rohit S');
select * from Emp Group by Name Having Na... | 0 | 2016-09-13T07:16:12Z | [
"python",
"psql",
"peewee"
] |
Python: Accessing YAML values using "dot notation" | 39,463,936 | <p>I'm using a YAML configuration file. So this is the code to load my config in Python:</p>
<pre><code>import os
import yaml
with open('./config.yml') as file:
config = yaml.safe_load(file)
</code></pre>
<p>This code actually creates a dictionary. Now the problem is that in order to access the values I need to u... | 3 | 2016-09-13T06:57:11Z | 39,464,072 | <h1>The Simple</h1>
<p>You could use <a href="https://docs.python.org/3/library/functools.html#functools.reduce" rel="nofollow"><code>reduce</code></a> to extract the value from the config:</p>
<pre><code>In [41]: config = {'asdf': {'asdf': {'qwer': 1}}}
In [42]: from functools import reduce
...:
...: def g... | 7 | 2016-09-13T07:06:45Z | [
"python",
"python-3.x",
"yaml"
] |
Python: Accessing YAML values using "dot notation" | 39,463,936 | <p>I'm using a YAML configuration file. So this is the code to load my config in Python:</p>
<pre><code>import os
import yaml
with open('./config.yml') as file:
config = yaml.safe_load(file)
</code></pre>
<p>This code actually creates a dictionary. Now the problem is that in order to access the values I need to u... | 3 | 2016-09-13T06:57:11Z | 39,464,793 | <p>I had the same problem a while ago and built this getter:</p>
<pre><code> def get(self, key):
"""Tries to find the configuration value for a given key.
:param str key: Key in dot-notation (e.g. 'foo.lol').
:return: The configuration value. None if no value was found.
"""
try:
return self... | 1 | 2016-09-13T07:51:12Z | [
"python",
"python-3.x",
"yaml"
] |
Python: Accessing YAML values using "dot notation" | 39,463,936 | <p>I'm using a YAML configuration file. So this is the code to load my config in Python:</p>
<pre><code>import os
import yaml
with open('./config.yml') as file:
config = yaml.safe_load(file)
</code></pre>
<p>This code actually creates a dictionary. Now the problem is that in order to access the values I need to u... | 3 | 2016-09-13T06:57:11Z | 39,485,868 | <p>On the one hand your example takes the right approach by using <code>get_config_value('mysql.user.pass', config)</code> instead of solving the dotted access with attributes. I am not sure
if you realised that on purpose you were not trying to do the more intuitive:</p>
<p>print(config.mysql.user.pass)
which you can... | 1 | 2016-09-14T08:32:12Z | [
"python",
"python-3.x",
"yaml"
] |
How to print the recursive stack in Python | 39,464,057 | <p>How do I print or show the recursive stack in Python when I'm running a recursive function?</p>
| 0 | 2016-09-13T07:06:01Z | 39,464,491 | <p>It's not clear what you want but as far as I get your question, you can print the stack of function callers in a recursive manner like the following, using the python <a href="https://docs.python.org/2/library/inspect.html" rel="nofollow">inspect module</a>.</p>
<pre><code>import inspect, sys
max_recursion_depth =... | 2 | 2016-09-13T07:31:59Z | [
"python",
"recursion"
] |
How do I use Python Django variables in my JS code? | 39,464,103 | <p>I'm trying to make a vertical side navigation bar populated with categories (dynamic, fetched from django models) where each category has sub-categories (also dynamic and fetched from models). When I refer to classes in my JS code, the code works i.e., upon clicking of a category, the sub-menu consisting of its resp... | 0 | 2016-09-13T07:09:10Z | 39,466,469 | <p>I'm not sure to have understood perfectly as 3 things bother me in your code :</p>
<ol>
<li>In both your lists, you use a 'div' between a 'ul' and a 'li'. I'm not sure if it is correct / can cause issues. <a href="https://developer.mozilla.org/en-US/docs/Web/HTML/Element/ul" rel="nofollow">https://developer.mozilla... | 0 | 2016-09-13T09:22:49Z | [
"javascript",
"jquery",
"python",
"html",
"django"
] |
Make a 'ref' field to auto increment when I press CONFIRM SALE button | 39,464,458 | <p><a href="http://i.stack.imgur.com/pjKv4.jpg" rel="nofollow">confrm_sale</a></p>
<p>I have the problem how to make a 'ref' field to be auto increment every time I press the <em>Confirm Sale Button</em>.</p>
<p>In my first case I made this field to be auto increment every time I create a new customer with the follow... | 2 | 2016-09-13T07:30:39Z | 39,483,967 | <p>If I get your requirement right, I guess you should do something like inside your loop on orders:</p>
<pre><code>order.partner_id.ref = self.env['ir.sequence'].get('res.debt')
</code></pre>
| 1 | 2016-09-14T06:40:58Z | [
"python",
"auto-increment",
"confirm",
"odoo-9"
] |
Transform values of a dictionary to new dictionary | 39,464,626 | <p>I have a dictionary:</p>
<pre><code>{
'doc0': {
'individu': 1,
'manajemen': 1,
'tahu': 1,
'logistik': 1,
'transaksi': 1
},
'doc1': {
'manajemen': 1,
'transfer': 1,
'individu':1,
'tahu':1,
'transaksi': 1,
'logistik': ... | 0 | 2016-09-13T07:40:31Z | 39,465,312 | <p>You can take a look at the following code :</p>
<pre><code>>>> all = list(set([j for i in list(d.keys()) for j in list(d[i].keys())]))
>>> all
['transfer', 'tahu', 'transaksi', 'individu', 'manajemen', 'logistik']
>>> for k in all:
for j in list(d.keys()):
if not k in d[j]... | 0 | 2016-09-13T08:19:27Z | [
"python",
"dictionary"
] |
Transform values of a dictionary to new dictionary | 39,464,626 | <p>I have a dictionary:</p>
<pre><code>{
'doc0': {
'individu': 1,
'manajemen': 1,
'tahu': 1,
'logistik': 1,
'transaksi': 1
},
'doc1': {
'manajemen': 1,
'transfer': 1,
'individu':1,
'tahu':1,
'transaksi': 1,
'logistik': ... | 0 | 2016-09-13T07:40:31Z | 39,465,700 | <p>You will face the problem with the key ordering in a dictionary. The keys (or the key-value pairs) in the dictionary are sorted arbitrarily. The order is not fixed and can change in different steps.</p>
<p>To mitigate this problem you can use the <code>OrderedDict</code> from the module <code>collections</code>.</p... | 0 | 2016-09-13T08:42:28Z | [
"python",
"dictionary"
] |
Transform values of a dictionary to new dictionary | 39,464,626 | <p>I have a dictionary:</p>
<pre><code>{
'doc0': {
'individu': 1,
'manajemen': 1,
'tahu': 1,
'logistik': 1,
'transaksi': 1
},
'doc1': {
'manajemen': 1,
'transfer': 1,
'individu':1,
'tahu':1,
'transaksi': 1,
'logistik': ... | 0 | 2016-09-13T07:40:31Z | 39,465,716 | <p>I'm not entirely clear what you are trying to accomplish, but to cause all the key/value pairs in dict2 to be added to dict1 or updated in dict1, you do <code>dict1.update(dict2)</code>. Example:</p>
<pre><code>>>> dict1={"apples":14, "bananas":22}
>>> dict2={"apples":4, "pears":7}
>>> di... | 0 | 2016-09-13T08:43:23Z | [
"python",
"dictionary"
] |
How to find values from one dataframe in another using pandas? | 39,464,636 | <pre><code>I have two dataframes:
df1 = pd.DataFrame({'A': ['A0', 'A1', 'A2', 'A3'],'B': ['B7', 'B4', 'B0', 'B3'] })
df2 = pd.DataFrame({'A': ['A4', 'A3', 'A7', 'A8'],'B': ['B0', 'B1', 'B2', 'B3']})
</code></pre>
<p>and i need to get all the common values from the column <code>B</code>, so here it would be <... | 3 | 2016-09-13T07:40:55Z | 39,464,656 | <p>You need <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow"><code>boolean indexing</code></a>:</p>
<pre><code>print (df1[df1.B.isin(df2.B)])
A B
2 A2 B0
3 A3 B3
print (df1.ix[df1.B.isin(df2.B), 'B'])
2 B0
3 B3
Name: B, dtype: object
print (df1.ix[d... | 4 | 2016-09-13T07:42:12Z | [
"python",
"pandas",
"indexing",
"merge",
"condition"
] |
How to get Bundle ID of MAC application? | 39,464,668 | <p>I want to use Python and <code>atomac</code> module to trigger an application in MAC OS like following scripts:</p>
<pre><code>atomac.launchAppByBundleID()
app_win = atomac.getAppRefByBundleId(app_bundle_ID)
</code></pre>
<p>But I don't know how to get the Bundle ID (<code>app_bundle_ID</code>) of the application.... | 2 | 2016-09-13T07:42:44Z | 39,464,824 | <p>I use two methods to get the bundler ID:</p>
<pre><code>osascript -e 'id of app "SomeApp"'
</code></pre>
<p>and</p>
<pre><code>mdls -name kMDItemCFBundleIdentifier -r SomeApp.app
</code></pre>
| 0 | 2016-09-13T07:52:30Z | [
"python",
"osx",
"ui-automation"
] |
How to get Bundle ID of MAC application? | 39,464,668 | <p>I want to use Python and <code>atomac</code> module to trigger an application in MAC OS like following scripts:</p>
<pre><code>atomac.launchAppByBundleID()
app_win = atomac.getAppRefByBundleId(app_bundle_ID)
</code></pre>
<p>But I don't know how to get the Bundle ID (<code>app_bundle_ID</code>) of the application.... | 2 | 2016-09-13T07:42:44Z | 39,938,914 | <p>if you just need it to launch the app look in the app's info.plist file. the file is in the app bundle in the Contents directory. This works for a lot of apps.</p>
| 0 | 2016-10-09T00:57:15Z | [
"python",
"osx",
"ui-automation"
] |
Don't make stats public when uploading to YouTube via API | 39,464,705 | <p>I'm uploading to YouTube using Python via <a href="https://developers.google.com/youtube/v3/guides/uploading_a_video" rel="nofollow">an officially provided script</a>.</p>
<p>The default settings for my channel (defined on youtube.com/upload_defaults when logged in) have <strong>Make video statistics on the watch p... | 3 | 2016-09-13T07:44:57Z | 39,464,890 | <p>Just type:</p>
<pre><code> status=dict(
privacyStatus="private"
)
</code></pre>
| 0 | 2016-09-13T07:55:54Z | [
"python",
"youtube-api",
"youtube-api-v3"
] |
Don't make stats public when uploading to YouTube via API | 39,464,705 | <p>I'm uploading to YouTube using Python via <a href="https://developers.google.com/youtube/v3/guides/uploading_a_video" rel="nofollow">an officially provided script</a>.</p>
<p>The default settings for my channel (defined on youtube.com/upload_defaults when logged in) have <strong>Make video statistics on the watch p... | 3 | 2016-09-13T07:44:57Z | 39,484,635 | <p>The solution was to modify the body to include <code>status.publicStatsViewable</code>, set to <code>False</code>. Just add the following line to the <code>body</code> construction block:</p>
<pre><code> publicStatsViewable=False,
</code></pre>
<p>so that it looks like:</p>
<pre><code>body=dict(
snippet=... | 0 | 2016-09-14T07:20:11Z | [
"python",
"youtube-api",
"youtube-api-v3"
] |
Should a connection to Redis cluster be made on each Flask request? | 39,464,748 | <p>I have a Flask API, it connects to a Redis cluster for caching purposes. Should I be creating and tearing down a Redis connection on each flask api call? Or, should I try and maintain a connection across requests?</p>
<p>My argument against the second option is that I should really try and keep the api as stateless... | 0 | 2016-09-13T07:47:58Z | 39,465,104 | <p>This is about performance and scale. To get those 2 buzzwords buzzing you'll in fact need persistent connections.</p>
<p>Eventual race conditions will be no different than with a reconnect on every request so that shouldn't be a problem. Any RCs will depend on how you're using redis, but if it's just caching there'... | 2 | 2016-09-13T08:07:44Z | [
"python",
"flask",
"redis"
] |
Should a connection to Redis cluster be made on each Flask request? | 39,464,748 | <p>I have a Flask API, it connects to a Redis cluster for caching purposes. Should I be creating and tearing down a Redis connection on each flask api call? Or, should I try and maintain a connection across requests?</p>
<p>My argument against the second option is that I should really try and keep the api as stateless... | 0 | 2016-09-13T07:47:58Z | 39,465,980 | <p>It's good idea from the performance standpoint to keep connections to a database opened between requests. The reason for that is that opening and closing connections is not free and takes some time which may become problem when you have too many requests. Another issue that a database can only handle up to a certain... | 0 | 2016-09-13T08:57:02Z | [
"python",
"flask",
"redis"
] |
How to make my chatbot learn permanently? | 39,464,762 | <p>I am using <code>pyAIML v1.0</code> to create an offline chatbot in Python.</p>
<p>This type of response is pretty easy with AIML:</p>
<blockquote>
<p>Human: Hi <br>
Bot: Hi what is your name? <br>
Human: My name is Dev <br>
Bot: Nice to meet you Dev <br>
Human: What is my name? <br>
Bot: Your name is ... | -4 | 2016-09-13T07:49:01Z | 39,465,573 | <p>I think you should call <code>saveBrain</code> (<a href="https://github.com/creatorrr/pyAIML/blob/master/Kernel.py#L162" rel="nofollow">https://github.com/creatorrr/pyAIML/blob/master/Kernel.py#L162</a>) in a regular manner to store your progress. e.g.:</p>
<pre><code># Enter the main input/output loop.
print "\nUl... | 0 | 2016-09-13T08:35:34Z | [
"python",
"aiml"
] |
Permutations in python (Hour,Minutes,Seconds) | 39,464,959 | <p>Please, help.<br>
I need to get list of all permutations, when first number from 0 to 23, second number from 0 to 59 and third number from 0 to 59.<br><br>
For example:<br>
01,01,01<br>
...<br>
10,10,10<br>
...<br>
23,59,59<br>
...etc</p>
| -5 | 2016-09-13T08:00:40Z | 39,467,127 | <p>Something like this if I have understood your question:</p>
<pre><code>>>> [(h,m,s) for h in range(24) for m in range(60) for s in range(60)]
</code></pre>
| 0 | 2016-09-13T09:54:39Z | [
"python",
"permutation"
] |
How can I raise an error if input is NaN? | 39,465,094 | <p>I am trying to implement an algorithm that converts a decimal number to is binary equivalent.</p>
<p>This is what I have. </p>
<pre><code>def binary_converter(n):
if n < 0:raise ValueError, "Invalid input"
if n >255:raise ValueError, "Invalid input"
if n > 1:
binary_converter(n//2)
... | -1 | 2016-09-13T08:07:13Z | 39,465,628 | <p>A couple of methods. One of which is using the strings <code>.isdigit()</code>. The general problem with <code>.isdigit()</code> is that it doesn't work on negatives, however with your code, it really isn't a problem. Try replacing your input with the following custom function:</p>
<pre><code>def positive_int_input... | 0 | 2016-09-13T08:38:38Z | [
"python"
] |
MATLAB ind2sub and Numpy unravel_index inconsistency | 39,465,157 | <p>Based on the <a href="http://stackoverflow.com/a/33072609">following answer</a>:</p>
<p>Using Octave, I get:</p>
<pre><code>>> [x, y, z] = ind2sub([27, 5, 58], 3766)
x = 13
y = 5
z = 28
</code></pre>
<p>Using Numpy, I get:</p>
<pre><code>>>> import numpy as np
>>> np.unravel_index(3765... | 1 | 2016-09-13T08:10:52Z | 39,465,469 | <p>Well with MATLAB that follows column-major indexing, for <code>(x,y,z)</code> the elements are stored at <code>x</code>, then <code>y</code> and then <code>z</code>. With NumPy for <code>(x,y,z)</code> because of row-major indexing, it's the other way - <code>z</code>, <code>y</code> and then <code>x</code>. So, to ... | 1 | 2016-09-13T08:29:34Z | [
"python",
"matlab",
"numpy"
] |
AttributeError - module 'django.http.request' has no attribute 'META' | 39,465,214 | <p>I got this error, but I've done exactly the same:</p>
<blockquote>
<p>AttributeError at /courses/
module 'django.http.request' has no attribute 'META'</p>
</blockquote>
<p>The error is occuring in :</p>
<pre><code>from django.shortcuts import render
from django.http import request
from django.http import H... | 0 | 2016-09-13T08:13:49Z | 39,465,250 | <p>Your function parameter is called <code>response</code> but then you use <code>request</code> which is a module you import, change the field param to be called <code>request</code> or change its usage inside the function to be <code>response</code></p>
<pre><code>def course_list(request):
courses = Course.objec... | 2 | 2016-09-13T08:15:45Z | [
"python",
"django"
] |
Encoding with 'idna' codec failed in RethinkDB | 39,465,259 | <p>I have a <code>flask</code> app that runs and connects to a remote <code>rethinkdb</code> database on <a href="https://www.compose.io" rel="nofollow">compose.io</a>. The app is also deployed to <a href="https://www.pythonanywhere.com" rel="nofollow">pythonanywhere.com</a>, but this deployment keeps throwing the foll... | 1 | 2016-09-13T08:16:19Z | 39,469,868 | <p>The idna codec is attempting to convert your rethinkdb URL into an ascii-compatible equivalent string.</p>
<p>This worked for me:</p>
<pre><code>"rethinkdb://user:[email protected]:23232".encode("idna")
</code></pre>
<p>So my guess is that some character/sequence of characters in your us... | 2 | 2016-09-13T12:15:56Z | [
"python",
"flask",
"rethinkdb",
"pythonanywhere",
"compose"
] |
python - django - using a flag on each model field | 39,465,465 | <p>I want to build a simple moderation system for my application.I have a class in my application models like this:</p>
<pre><code>#models.py
class TableName(models.Model):
is_qualified = False
title = models.CharField(max_length=300, blank=False)
description = models.TextField(max_length=500, ... | 0 | 2016-09-13T08:29:14Z | 39,465,507 | <p>You need to make <code>is_qualified</code> an actual field - a BooleanField would be appropriate - and have it default to False.</p>
<pre><code>is_qualified = model.BooleanField(default=False)
</code></pre>
| 1 | 2016-09-13T08:31:54Z | [
"python",
"django"
] |
python - django - using a flag on each model field | 39,465,465 | <p>I want to build a simple moderation system for my application.I have a class in my application models like this:</p>
<pre><code>#models.py
class TableName(models.Model):
is_qualified = False
title = models.CharField(max_length=300, blank=False)
description = models.TextField(max_length=500, ... | 0 | 2016-09-13T08:29:14Z | 39,466,060 | <p>Hmm, adding is_qualified for each field would be a bit too much.</p>
<p>If your are using postgresql I would consider using <a href="https://github.com/djangonauts/django-hstore" rel="nofollow">django-hstore</a>, where you can dynamically add key-value fields. </p>
<p>Using this package, you can make something lik... | 1 | 2016-09-13T09:00:42Z | [
"python",
"django"
] |
Count the number of open browser tabs in Firefox and Chrome | 39,465,747 | <p>I want to make a function that counts the number of open tabs in the browser - Chrome or Firefox - using Java or Python. I know Firefox and Chrome tab counters exist, because there are <em>AddOns</em> and <em>Extensions</em> that achieve that, but I cannot export the value to another function like I want. </p>
<p>D... | -1 | 2016-09-13T08:44:46Z | 39,468,746 | <p>Unless Firefox exposes an API for other programs (not addons nor extensions) to control and query its internal state (a quick Google search suggests that it doesn't), I suspect you'll be out of luck. </p>
| 1 | 2016-09-13T11:19:47Z | [
"python",
"firefox"
] |
How to debug external .py functions run from Jupyter/IPython notebook | 39,465,752 | <p>My Jupyter/IPython notebook executes functions in an external .py.</p>
<p>I need to set breakpoints within these functions, inspect variables, single step, etc.</p>
<p>It just isn't practical to use a combination of <code>print</code> statements and throwing exceptions to early-exit a cell.</p>
<p>I need some kin... | 7 | 2016-09-13T08:44:55Z | 39,562,438 | <blockquote>
<p>Is it possible to hook up some third-party editor/IDE to view the .py
and somehow connect it to the Python runtime Jupyter/IPython is using?</p>
</blockquote>
<p>Yes, <strong>it's possible</strong>.</p>
<h2>Using <a href="https://www.gnu.org/software/emacs/" rel="nofollow">Emacs</a> as your third ... | 5 | 2016-09-18T20:35:39Z | [
"python",
"debugging",
"ipython",
"jupyter-notebook",
"spyder"
] |
How to debug external .py functions run from Jupyter/IPython notebook | 39,465,752 | <p>My Jupyter/IPython notebook executes functions in an external .py.</p>
<p>I need to set breakpoints within these functions, inspect variables, single step, etc.</p>
<p>It just isn't practical to use a combination of <code>print</code> statements and throwing exceptions to early-exit a cell.</p>
<p>I need some kin... | 7 | 2016-09-13T08:44:55Z | 39,594,357 | <p>In Jupyter, you can use python debugger by adding below two lines for a breakpoint. </p>
<pre><code>import pdb
pdb.set_trace()
</code></pre>
<p>Code execution will pause at this step and will provide you text box for debugging python code. I have attached screenshot for same.</p>
<p>You can refer to pdb <a href="... | 2 | 2016-09-20T12:39:21Z | [
"python",
"debugging",
"ipython",
"jupyter-notebook",
"spyder"
] |
Machine Learning Cocktail Party Audio Application | 39,465,776 | <p>What's going on people,</p>
<p>I have a question with regards to this post:</p>
<p><a href="http://stackoverflow.com/questions/20414667/cocktail-party-algorithm-svd-implementation-in-one-line-of-code">cocktail party algorithm SVD implementation ... in one line of code?</a></p>
<p>I realize there are similar quest... | 0 | 2016-09-13T08:45:57Z | 39,466,992 | <p>How about using numpy?
Using <a href="http://docs.scipy.org/doc/numpy-dev/user/numpy-for-matlab-users.html" rel="nofollow">this</a> guide I translated the statement to</p>
<pre><code>from numpy import *
U, S, Vh = linalg.svd(dot((tile(sum(x*x,0),(x.shape[0],1))*x),x.T))
</code></pre>
<p>It runs but I do not have a... | 1 | 2016-09-13T09:48:38Z | [
"python",
"octave"
] |
How to crop zero edges of a numpy array? | 39,465,812 | <p>I have this ugly, un-pythonic beast:</p>
<pre><code>def crop(dat, clp=True):
'''Crops zero-edges of an array and (optionally) clips it to [0,1].
Example:
>>> crop( np.array(
... [[0,0,0,0,0,0],
... [0,0,0,0,0,0],
... [0,1,0,2,9,0],
... [0,0,0,0,0,0]... | 3 | 2016-09-13T08:47:53Z | 39,466,129 | <p>Try incorporating something like this:</p>
<pre><code># argwhere will give you the coordinates of every non-zero point
true_points = np.argwhere(dat)
# take the smallest points and use them as the top left of your crop
top_left = true_points.min(axis=0)
# take the largest points and use them as the bottom right of ... | 3 | 2016-09-13T09:04:36Z | [
"python",
"numpy",
"crop"
] |
How to crop zero edges of a numpy array? | 39,465,812 | <p>I have this ugly, un-pythonic beast:</p>
<pre><code>def crop(dat, clp=True):
'''Crops zero-edges of an array and (optionally) clips it to [0,1].
Example:
>>> crop( np.array(
... [[0,0,0,0,0,0],
... [0,0,0,0,0,0],
... [0,1,0,2,9,0],
... [0,0,0,0,0,0]... | 3 | 2016-09-13T08:47:53Z | 39,467,080 | <p>This should work in any number of dimensions. I believe it is also quite efficient because swapping axes and slicing create only views on the array, not copies (which rules out functions such as <code>take()</code> or <code>compress()</code> which one might be tempted to use) or any temporaries. However it is not si... | 1 | 2016-09-13T09:52:38Z | [
"python",
"numpy",
"crop"
] |
How to crop zero edges of a numpy array? | 39,465,812 | <p>I have this ugly, un-pythonic beast:</p>
<pre><code>def crop(dat, clp=True):
'''Crops zero-edges of an array and (optionally) clips it to [0,1].
Example:
>>> crop( np.array(
... [[0,0,0,0,0,0],
... [0,0,0,0,0,0],
... [0,1,0,2,9,0],
... [0,0,0,0,0,0]... | 3 | 2016-09-13T08:47:53Z | 39,469,078 | <p>Definitely not the prettiest approach but wanted to try something else.</p>
<pre><code>def _fill_gap(a):
"""
a = 1D array of `True`s and `False`s.
Fill the gap between first and last `True` with `True`s.
Doesn't do a copy of `a` but in this case it isn't really needed.
"""
a[slice(*a.nonzer... | 1 | 2016-09-13T11:37:59Z | [
"python",
"numpy",
"crop"
] |
Convex Optimization in Python | 39,465,864 | <p>I recently got interested in soccer statistics. Right now I want to implement the famous Dixon-Coles Model in Python 3.5 (<a href="http://www.math.ku.dk/~rolf/teaching/thesis/DixonColes.pdf" rel="nofollow">paper-link</a>).</p>
<p>The basic problem is, that from the model described in the paper a Likelihood function... | 0 | 2016-09-13T08:50:39Z | 39,466,169 | <p>You can make use of Metaheuristic algorithms which work both on convex and non-convex spaces. Probably the most famous one of them is <a href="https://en.wikipedia.org/wiki/Genetic_algorithm" rel="nofollow">Genetic algorithm</a>. It is also easy to implement and the concept is straightforward. The beautiful thing ab... | 0 | 2016-09-13T09:07:18Z | [
"python",
"python-3.x",
"optimization",
"scipy",
"convex"
] |
How to specify a firefox identity when calling bokeh.show | 39,465,963 | <p>I'm using bokeh to do some interactive data analysis. I'm using a separate firefox profile for this work than I do for other browsing, and I would like to be able to have bokeh open a tab with this other identity when I run the script. The general form is </p>
<pre><code>from bokeh.client import push_session
from b... | 0 | 2016-09-13T08:55:57Z | 39,475,218 | <p>There is a bug fixed in Bokeh <strong>0.12.3</strong>. You can set the browser to use like:</p>
<pre><code>from bokeh.client import push_session
from bokeh.io import curdoc
from bokeh.plotting import figure, show
# prepare some data
x = [1, 2, 3, 4, 5]
y = [6, 7, 2, 4, 5]
# create a new plot with a title and axis... | 1 | 2016-09-13T16:50:21Z | [
"python",
"firefox",
"bokeh"
] |
What does x ^ 2 mean? in python | 39,466,009 | <p>i'm sure it's very basic and I should understand it, but I don't!</p>
<p>I'm given this to do:</p>
<pre><code>> a=int(input("Enter the value for the co-efficient of x^2. "))
> b=int(input("Enter the value for the co-efficient of x. "))
> c=int(input("Enter the value for the constant term. ")) s=b**2-4*a*c... | -6 | 2016-09-13T08:58:12Z | 39,466,030 | <p>It doesn't 'mean' anything, not to Python; it is just another character in a string literal:</p>
<pre><code>"Enter the value for the co-efficient of x^2. "
</code></pre>
<p>You could have written something else:</p>
<pre><code>"Enter the value for the co-efficient of x to the power 2. "
</code></pre>
<p>and noth... | 3 | 2016-09-13T08:59:24Z | [
"python",
"python-3.x"
] |
StanfordCoreNLP openIE issue | 39,466,086 | <p>I am facing the same issue as
<a href="http://stackoverflow.com/questions/37375137/stanford-corenlp-openie-annotator">Stanford CoreNLP OpenIE annotator</a>
I try output = nlp.annotate(s, properties={"annotators":"tokenize,ssplit,pos,depparse,natlog,openie", "outputFormat": "json","openie.triple.strict":"true", "ope... | -2 | 2016-09-13T09:02:02Z | 39,520,850 | <p>This is actually expected behavior. It was a design decision in the OpenIE system to produce all triples which are logically entailed by the original sentence, even if they are redundant. The idea being that these triples are usually used for something akin to IR-ish lookup, and in these cases it's convenient to not... | 0 | 2016-09-15T21:47:55Z | [
"python",
"stanford-nlp",
"stanford-nlp-server"
] |
Import Only Work Inside Python Function | 39,466,228 | <p><strong>Background Info:</strong> I'm developing a model with scikit-learn. I'm splitting the data into separate training and testing sets using the sklearn.cross_validation module, as shown below:</p>
<pre><code>def train_test_split(input_data):
from sklearn.cross_validation import train_test_split
... | 1 | 2016-09-13T09:10:28Z | 39,466,293 | <p>You are importing the function <code>train_test_split</code> from <code>sklear.cross_validation</code> and then overriding the name with your local function <code>train_test_split</code>.</p>
<p>Try:</p>
<pre><code>from sklearn.cross_validation import train_test_split as sk_train_test_split
def train_test_split(i... | 4 | 2016-09-13T09:13:01Z | [
"python",
"scikit-learn",
"python-import"
] |
How to make a file transfer program in python | 39,466,458 | <p>The title might not be relevant for my question becuase I don't actually want a wireless file transfering script, I need a file manager type.</p>
<p>I want something with which I can connect my phone with my pc (eg: hotspot and wifi) and then I would like to show text file browser (I have the code for that) by send... | 0 | 2016-09-13T09:22:06Z | 39,468,470 | <p>A very naive approach using Python is to go to the root of the directory you want to be served and use:</p>
<pre><code>python -m SimpleHTTPServer
</code></pre>
<p>The connect to it on port 8000.</p>
| 2 | 2016-09-13T11:04:32Z | [
"python"
] |
How to make a file transfer program in python | 39,466,458 | <p>The title might not be relevant for my question becuase I don't actually want a wireless file transfering script, I need a file manager type.</p>
<p>I want something with which I can connect my phone with my pc (eg: hotspot and wifi) and then I would like to show text file browser (I have the code for that) by send... | 0 | 2016-09-13T09:22:06Z | 39,468,592 | <p>you may need to <a href="https://docs.python.org/3/howto/sockets.html" rel="nofollow">socket programming</a>. creating a link (connection) between your PC and you smart phone and then try to transfer files</p>
| 1 | 2016-09-13T11:11:43Z | [
"python"
] |
Use of Scaler with LassoCV, RidgeCV | 39,466,671 | <p>I would like to use scikit-learn LassoCV/RidgeCV while applying a 'StandardScaler' on each fold training set. I do not want to apply the scaler before the cross-validation to avoid leakage but I cannot figure out how I am supposed to do that with LassoCV/RidgeCV. </p>
<p>Is there a way to do this ? Or should I crea... | 0 | 2016-09-13T09:34:31Z | 39,481,787 | <p>I got the answer through the scikit-learn mailing list so here it is: </p>
<p>'There is no way to use the "efficient" EstimatorCV objects with pipelines.
This is an API bug and there's an open issue and maybe even a PR for that.'</p>
<p>Many thanks to Andreas Mueller for the answer.</p>
| 0 | 2016-09-14T02:52:59Z | [
"python",
"machine-learning",
"scikit-learn"
] |
change datetime format in python | 39,466,677 | <p>I am getting this datetime in this format from my database.</p>
<pre><code>2016-09-13T08:46:59.953948+00:00
</code></pre>
<p>I want to change this date into format like </p>
<pre><code>13 sep 2016 08:46:59
</code></pre>
<p>I have used datetime module like</p>
<pre><code>import datetime
datetime.datetime.strptim... | -1 | 2016-09-13T09:35:08Z | 39,466,764 | <p>You can use</p>
<pre><code>import datetime
# n is your time as shown in example
your_time = n.strftime("%d/%m/%y %H:%M:%S")
</code></pre>
<p>When trying to make human readable format I recommend <a href="https://docs.djangoproject.com/en/1.10/ref/contrib/humanize/" rel="nofollow">django humanize</a></p>
| -1 | 2016-09-13T09:38:13Z | [
"python",
"django"
] |
change datetime format in python | 39,466,677 | <p>I am getting this datetime in this format from my database.</p>
<pre><code>2016-09-13T08:46:59.953948+00:00
</code></pre>
<p>I want to change this date into format like </p>
<pre><code>13 sep 2016 08:46:59
</code></pre>
<p>I have used datetime module like</p>
<pre><code>import datetime
datetime.datetime.strptim... | -1 | 2016-09-13T09:35:08Z | 39,467,293 | <p>If you don't care about the timezone and milliseconds you can try by the following function:</p>
<pre><code>from datetime import datetime
def parse_db_time_string(time_string):
date = datetime.strptime(time_string.split('.')[0], '%Y-%m-%dT%H:%M:%S')
return datetime.strftime(date, '%d %b %Y %H:%M:%S')
</cod... | 0 | 2016-09-13T10:03:28Z | [
"python",
"django"
] |
change datetime format in python | 39,466,677 | <p>I am getting this datetime in this format from my database.</p>
<pre><code>2016-09-13T08:46:59.953948+00:00
</code></pre>
<p>I want to change this date into format like </p>
<pre><code>13 sep 2016 08:46:59
</code></pre>
<p>I have used datetime module like</p>
<pre><code>import datetime
datetime.datetime.strptim... | -1 | 2016-09-13T09:35:08Z | 39,467,931 | <p>By importing Datetime and Arrow you can convert into your required format. Arrow is a python library to format date & time.</p>
<pre><code>import arrow
import datetime
today = arrow.utcnow().to('Asia/Calcutta').format('YYYY-MM-DD HH:mm:ss')
'2016-09-13 15:57:38'
current_date = datetime.datetime.strptime(today... | 0 | 2016-09-13T10:36:13Z | [
"python",
"django"
] |
How do I write lists into CSV in python? | 39,466,695 | <p>I have the following list in Python. </p>
<pre><code>[('a1',
[('b', 1),
('c', 2),
('d', 3),
('e', 4),
('f', 5),
('g', 6]),
('a2',
[('c', 7),
('f', 8),
('g', 9),
('b', 1),
('e', 2),
('d', 3)])]
</code></pre>
<p>I would like to save the list as the following format in csv: </p>
<pre><code>a1 a2
b 1... | -1 | 2016-09-13T09:35:41Z | 39,466,944 | <p>This should get you started:</p>
<pre><code>>>> a = [('b', 1), ('c', 2)]
>>> b = [('c', 7), ('f', 8)]
>>>
>>> for x,y in zip(a,b):
... k1, v1 = x
... k2, v2 = y
... print("{k1} {v1} {k2} {v2}".format(k1=k1, v1=v1, k2=k2, v2=v2))
...
b 1 c 7
c 2 f 8
</code></pre>
| -1 | 2016-09-13T09:46:42Z | [
"python",
"csv"
] |
How do I write lists into CSV in python? | 39,466,695 | <p>I have the following list in Python. </p>
<pre><code>[('a1',
[('b', 1),
('c', 2),
('d', 3),
('e', 4),
('f', 5),
('g', 6]),
('a2',
[('c', 7),
('f', 8),
('g', 9),
('b', 1),
('e', 2),
('d', 3)])]
</code></pre>
<p>I would like to save the list as the following format in csv: </p>
<pre><code>a1 a2
b 1... | -1 | 2016-09-13T09:35:41Z | 39,467,367 | <p>The csv format is quite simple.</p>
<p>To start to know how to that, just create a csv file with the output you want, and open it with any text editor, you will obtain:</p>
<pre><code>a1,,a2,
b,1,c,7
c,2,f,8
d,3,g,9
e,4,b,1
f,5,e,2
g,6,d,3
</code></pre>
<p>So here is the code you need, but should have at least to... | 0 | 2016-09-13T10:07:25Z | [
"python",
"csv"
] |
Unique permutations of fixed length integer partitions where each element has a maximum | 39,466,720 | <p>This question is similar to a question I had several months ago: <a href="http://stackoverflow.com/questions/36435754/generating-a-numpy-array-with-all-combinations-of-numbers-that-sum-to-less-than/36563744#36563744">Generating a numpy array with all combinations of numbers that sum to less than a given number</a>.
... | 1 | 2016-09-13T09:36:48Z | 39,488,039 | <p>I've had to think about this pretty long, but I've managed to modify the solution to <a href="http://stackoverflow.com/questions/36435754/generating-a-numpy-array-with-all-combinations-of-numbers-that-sum-to-less-than/36563744#36563744">Generating a numpy array with all combinations of numbers that sum to less than ... | 0 | 2016-09-14T10:22:07Z | [
"python",
"performance",
"numpy",
"permutation",
"integer-partition"
] |
Most frequently occuring n words in a string | 39,466,725 | <p>I have a problem with the following problem:</p>
<p><strong>Problem</strong>:</p>
<p>Implement a function count_words() in Python that takes as input a string s and a number n, and returns the n most frequently-occuring words in s. The return value should be a list of tuples - the top n words paired with their res... | 0 | 2016-09-13T09:36:53Z | 39,466,849 | <p>You can sort them using the <em>number of occurrence</em> (in reverse order) and then the <em>lexicographical order</em>:</p>
<pre><code>>>> lst = [('meat', 2), ('butter', 2), ('a', 1), ('betty', 1)]
>>>
>>> sorted(lst, key=lambda x: (-x[1], x[0]))
# ^ revers... | 3 | 2016-09-13T09:42:15Z | [
"python"
] |
Most frequently occuring n words in a string | 39,466,725 | <p>I have a problem with the following problem:</p>
<p><strong>Problem</strong>:</p>
<p>Implement a function count_words() in Python that takes as input a string s and a number n, and returns the n most frequently-occuring words in s. The return value should be a list of tuples - the top n words paired with their res... | 0 | 2016-09-13T09:36:53Z | 39,467,092 | <p>The python function <code>sorted</code> is <a href="http://stackoverflow.com/a/1915418/1112586">stable</a>, which means in case of a tie, the tied items will be in the same order. Because of this, you can sort first on the strings to get them in order:</p>
<pre><code>alphabetical_sort = sorted(words.items(), key=la... | 0 | 2016-09-13T09:53:01Z | [
"python"
] |
What does "local to a blueprint" mean? | 39,466,753 | <p>I'm having some trouble understanding the difference between <a href="http://flask.pocoo.org/docs/0.10/api/#flask.Blueprint.errorhandler" rel="nofollow">Blueprint.errorhandler</a> and <a href="http://flask.pocoo.org/docs/0.10/api/#flask.Blueprint.app_errorhandler" rel="nofollow">Blueprint.app_errorhandler</a>. Accor... | 0 | 2016-09-13T09:38:02Z | 39,466,847 | <p>'local' means that in relation to the routes a blueprint registers. Blueprint routes are always prefixed by the name you registered your blueprint with, so they are naturally grouped and in a URL path topology sense they have locality. 'nonlocal' then is any view not associated with the blueprint; they'll have a dif... | 1 | 2016-09-13T09:42:14Z | [
"python",
"flask",
"error-handling",
"decorator"
] |
Fill MISSING values only in a dataframe (pandas) | 39,466,757 | <p>What I have in a dataframe:</p>
<pre><code>email user_name sessions ymo
[email protected] JD 1 2015-03-01
[email protected] JD 2 2015-05-01
</code></pre>
<p>What I need:</p>
<pre><code>email user_name sessions ymo
[email protected] JD 0 2015-01-01
[email protected] JD 0 2015-02-01
[email protected] JD 1... | 1 | 2016-09-13T09:38:05Z | 39,467,108 | <ul>
<li>generate month beginning dates and <code>reindex</code> </li>
<li><code>ffill</code> and <code>bfill</code> columns <code>['email', 'user_name']</code></li>
<li><code>fillna(0)</code> for column <code>'sessions'</code></li>
</ul>
<hr>
<pre><code>mbeg = pd.date_range('2015-01-31', periods=12, freq='M') - pd.... | 2 | 2016-09-13T09:53:39Z | [
"python",
"pandas"
] |
Fill MISSING values only in a dataframe (pandas) | 39,466,757 | <p>What I have in a dataframe:</p>
<pre><code>email user_name sessions ymo
[email protected] JD 1 2015-03-01
[email protected] JD 2 2015-05-01
</code></pre>
<p>What I need:</p>
<pre><code>email user_name sessions ymo
[email protected] JD 0 2015-01-01
[email protected] JD 0 2015-02-01
[email protected] JD 1... | 1 | 2016-09-13T09:38:05Z | 39,467,725 | <p>I try create more general solution with <code>periods</code>:</p>
<pre><code>print (df)
email user_name sessions ymo
0 [email protected] JD 1 2015-03-01
1 [email protected] JD 2 2015-05-01
2 [email protected] AB 1 2015-03-01
3 [email protected] AB 2 2015-05-01
mbeg = pd.period... | 2 | 2016-09-13T10:25:06Z | [
"python",
"pandas"
] |
simple SNTP python script | 39,466,780 | <p>I need help to complete following script:</p>
<pre class="lang-py prettyprint-override"><code>import socket
import struct
import sys
import time
NTP_SERVER = '0.uk.pool.ntp.org'
TIME1970 = 2208988800L
def sntp_client():
client = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
data = str.encode('\xlb' + 4... | 2 | 2016-09-13T09:39:02Z | 40,121,066 | <p>There is nothing wrong with your script as written, you need to look for another reason why the server might not be responding to you, such as firewall settings.
My own python SNTP script is almost exactly the same:</p>
<pre><code>#!/bin/env python
import socket
import struct
import sys
import time
TIME1970 = 220... | 0 | 2016-10-19T02:26:22Z | [
"python"
] |
Maya python incomplete autocompletion | 39,466,822 | <p>I'm really new with python programming in Maya and I'm trying to find a confortable way to write code
I would like to have an IDE where if I write "cmds.ls" the autocompletion give me the list off all the arguments
What I have now is a completion with some pointers and a function with "pass" inside
I know that until... | 0 | 2016-09-13T09:41:03Z | 39,573,381 | <p>I never used auto-completion but here is an easy way to get it in Sublime Text, I was not able to get the arguments though, only the function names. You should be able to do the same thing for any other IDE in a similar way.</p>
<ul>
<li>Go into your Maya install <em>folder/MayaXXXX/devkit/other/pymel/extras/comple... | 1 | 2016-09-19T12:36:51Z | [
"python",
"maya",
"code-completion"
] |
how to print json data | 39,466,890 | <p>I have following json file and python code and i need output example...</p>
<p><strong>json file</strong></p>
<pre><code>{"b": [{"1": "add"},{"2": "act"}],
"p": [{"add": "added"},{"act": "acted"}],
"pp": [{"add": "added"},{"act": "acted"}],
"s": [{"add": "adds"},{"act": "acts"}],
"ing": [{"add": "adding"},{"act": ... | 0 | 2016-09-13T09:44:14Z | 39,466,925 | <p>This doesn't have anything to do with JSON. You have a dictionary, and you want to print the keys, which you can do with <code>data.keys()</code>.</p>
| 4 | 2016-09-13T09:45:48Z | [
"python",
"json",
"python-3.x"
] |
how to print json data | 39,466,890 | <p>I have following json file and python code and i need output example...</p>
<p><strong>json file</strong></p>
<pre><code>{"b": [{"1": "add"},{"2": "act"}],
"p": [{"add": "added"},{"act": "acted"}],
"pp": [{"add": "added"},{"act": "acted"}],
"s": [{"add": "adds"},{"act": "acts"}],
"ing": [{"add": "adding"},{"act": ... | 0 | 2016-09-13T09:44:14Z | 39,467,000 | <p>Simply unpack the <code>keys</code> with <code>*</code> in a print call, this provides the keys as positional arguments to <code>print</code>; use <code>sep = '\n'</code> if you want each key on a different line:</p>
<pre><code>print(*data.keys(), sep= '\n')
</code></pre>
<p>This will print out:</p>
<pre><code>b
... | 2 | 2016-09-13T09:48:59Z | [
"python",
"json",
"python-3.x"
] |
how to print json data | 39,466,890 | <p>I have following json file and python code and i need output example...</p>
<p><strong>json file</strong></p>
<pre><code>{"b": [{"1": "add"},{"2": "act"}],
"p": [{"add": "added"},{"act": "acted"}],
"pp": [{"add": "added"},{"act": "acted"}],
"s": [{"add": "adds"},{"act": "acts"}],
"ing": [{"add": "adding"},{"act": ... | 0 | 2016-09-13T09:44:14Z | 39,467,118 | <p>Here's a working example (it's emulating your file using <a href="https://docs.python.org/3/library/io.html#io.StringIO" rel="nofollow">io.StringIO</a>):</p>
<pre><code>import json
import io
jsonfile_json = io.StringIO("""
{
"b": [{"1": "add"}, {"2": "act"}],
"p": [{"add": "added"}, {"act": "acted"}],
... | 2 | 2016-09-13T09:54:14Z | [
"python",
"json",
"python-3.x"
] |
how to print json data | 39,466,890 | <p>I have following json file and python code and i need output example...</p>
<p><strong>json file</strong></p>
<pre><code>{"b": [{"1": "add"},{"2": "act"}],
"p": [{"add": "added"},{"act": "acted"}],
"pp": [{"add": "added"},{"act": "acted"}],
"s": [{"add": "adds"},{"act": "acts"}],
"ing": [{"add": "adding"},{"act": ... | 0 | 2016-09-13T09:44:14Z | 39,467,331 | <p>For the sake of completeness:</p>
<pre><code>d = {'p': 'pstuff', 'pp': 'ppstuff', 'b': 'bstuff', 's': 'sstuff'}
print('\n'.join(d))
</code></pre>
<p>Works in any version of Python. If you care about order:</p>
<pre><code>print('\n'.join(sorted(d)))
</code></pre>
<p>Though in all honesty, I'd probably do Jim's ap... | 2 | 2016-09-13T10:05:16Z | [
"python",
"json",
"python-3.x"
] |
Django: using context variable in a script | 39,467,023 | <p>I have a class view that inherits from <code>TemplateView</code> and sets a context variable to a serialized list of items:</p>
<pre><code>class MyView(TemplateView):
def get_context_data(self, **kwargs):
context = super(MyView, self).get_context_data(**kwargs)
context['items'] = serializers.serialize("js... | 0 | 2016-09-13T09:49:46Z | 39,467,144 | <p>You can't use spaces between a template variable, the filter character, and the filter itself. So it should be <code>{{ items|escapejs }}</code>.</p>
<p>Although as Sebastian points out, you probably want <code>{{ items|safe }}</code> instead.</p>
| 3 | 2016-09-13T09:55:53Z | [
"javascript",
"python",
"django"
] |
Django: using context variable in a script | 39,467,023 | <p>I have a class view that inherits from <code>TemplateView</code> and sets a context variable to a serialized list of items:</p>
<pre><code>class MyView(TemplateView):
def get_context_data(self, **kwargs):
context = super(MyView, self).get_context_data(**kwargs)
context['items'] = serializers.serialize("js... | 0 | 2016-09-13T09:49:46Z | 39,467,524 | <pre><code><script>
var items = "{{items}}";
</script>
</code></pre>
| 0 | 2016-09-13T10:15:23Z | [
"javascript",
"python",
"django"
] |
How to keep every nth item in a list and make the rest zeros | 39,467,082 | <p>I am trying to model and fit to noisy data over a long time series and I want to see what happens to my fit if I remove a substantial amount of my data.</p>
<p>I have a long time-series of data and I am only interested in every nth item. However I still want to plot this list over time but with every other unwanted... | 1 | 2016-09-13T09:52:41Z | 39,467,128 | <p>Use a <em>list comprehension</em> with a <a href="http://stackoverflow.com/questions/394809/does-python-have-a-ternary-conditional-operator"><em>ternary conditional</em></a> that takes the <code>mod</code> of each element on the number <code>n</code>:</p>
<pre><code>>>> a = [1,2,3,4,5,6,7,8,9,10]
>>&... | 5 | 2016-09-13T09:54:44Z | [
"python",
"list"
] |
How to keep every nth item in a list and make the rest zeros | 39,467,082 | <p>I am trying to model and fit to noisy data over a long time series and I want to see what happens to my fit if I remove a substantial amount of my data.</p>
<p>I have a long time-series of data and I am only interested in every nth item. However I still want to plot this list over time but with every other unwanted... | 1 | 2016-09-13T09:52:41Z | 39,467,239 | <pre><code>[0 if i%4 else num for i, num in enumerate(a)]
</code></pre>
| 0 | 2016-09-13T10:00:43Z | [
"python",
"list"
] |
How to keep every nth item in a list and make the rest zeros | 39,467,082 | <p>I am trying to model and fit to noisy data over a long time series and I want to see what happens to my fit if I remove a substantial amount of my data.</p>
<p>I have a long time-series of data and I am only interested in every nth item. However I still want to plot this list over time but with every other unwanted... | 1 | 2016-09-13T09:52:41Z | 39,467,273 | <p>Here's a working example to filter functions given a certain step K:</p>
<pre><code>def filter_f(data, K=4):
if K <= 0:
return data
N = len(data)
f_filter = [0 if i % K else 1 for i in range(N)]
return [a * b for a, b in zip(data, f_filter)]
f_input = range(10)
for K in range(10):
... | 0 | 2016-09-13T10:02:15Z | [
"python",
"list"
] |
Can't get this custom logging adapter example to work | 39,467,271 | <p>I have been looking at examples related to context logging here:
<a href="https://docs.python.org/2/howto/logging-cookbook.html#using-loggeradapters-to-impart-contextual-information" rel="nofollow" title="Logging Cookbook">Logging Cookbook</a></p>
<p>However, I cannot get the following example to work. The example ... | 0 | 2016-09-13T10:02:12Z | 39,467,475 | <p>You have to use the adapter for logging, not the logger. Try this:</p>
<pre><code>import logging
class CustomAdapter(logging.LoggerAdapter):
def process(self, msg, kwargs):
# use my_context from kwargs or the default given on instantiation
my_context = kwargs.pop('my_context', self.extra['my_co... | 1 | 2016-09-13T10:12:32Z | [
"python",
"logging"
] |
Install python package zipline on cloud 9 environment Support workspace python | 39,467,287 | <p>I am trying to install python on the cloud 9 environment.</p>
<p>I simply did below, from the <a href="http://www.zipline.io/install.html" rel="nofollow">installation tutorial</a>:</p>
<pre><code>pip install zipline
</code></pre>
<p>However, I get:</p>
<pre><code>Command python setup.py egg_info failed with erro... | 4 | 2016-09-13T10:03:10Z | 39,542,507 | <p>As recommended by <code>zipline</code>'s <a href="http://www.zipline.io/install.html#installing-with-pip" rel="nofollow">documentation</a>, this answer uses a virtualenv where we use <code>pip</code> to install and manage <code>zipline</code> and its dependencies.</p>
<p>First, go to the terminal in your Cloud9 IDE... | 2 | 2016-09-17T03:12:51Z | [
"python",
"ubuntu",
"c9.io"
] |
How to count concurrent events in a dataframe in one line? | 39,467,341 | <p>I have a dataset with phone calls. I want to count how many active calls there are for each record.
I found this <a href="https://stackoverflow.com/questions/24745882/pandas-cumulative-sum-using-current-row-as-condition">question</a> but I'd like to avoid loops and functions.</p>
<p>Each call has a <code>date</code... | 1 | 2016-09-13T10:05:48Z | 39,484,971 | <p>You can use:</p>
<pre><code>#convert time and date to datetime
df['date_start'] = pd.to_datetime(df.start + ' ' + df.date)
df['date_end'] = pd.to_datetime(df.end + ' ' + df.date)
#remove columns
df = df.drop(['start','end','date'], axis=1)
</code></pre>
<p>Solution with loop:</p>
<pre><code>active_events= []
for ... | 1 | 2016-09-14T07:39:48Z | [
"python",
"python-3.x",
"datetime",
"pandas",
"condition"
] |
Python Site Scrape Help Needed | 39,467,369 | <p>I'm new to python (and a lot of coding outside of SQL, SAS, and a little R) and I am trying to use it to build a dataset based on data from a number of different web pages. Thanks in advance for your help.</p>
<p>I am using Python 3.4.4 and have successfully pulled the code of the sites, but I'm having trouble with... | -3 | 2016-09-13T10:07:28Z | 39,467,677 | <p>I think you might want to look at lxml and xpath not to mention other scraping soft. Thousends of posts in aera. Check the link below:</p>
<p><a href="http://docs.python-guide.org/en/latest/scenarios/scrape/" rel="nofollow">http://docs.python-guide.org/en/latest/scenarios/scrape/</a></p>
<p>If you dont like to use... | 0 | 2016-09-13T10:23:06Z | [
"python",
"html",
"regex"
] |
error when using keras' sk-learn API | 39,467,496 | <p>  i'm learning keras these days, and i met an error when using scikit-learn API.Here are something maybe useful: </p>
<p><strong>ENVIRONMENT</strong>: </p>
<pre><code>python:3.5.2
keras:1.0.5
scikit-learn:0.17.1
</code></pre>
<p><strong>CODE</strong></p>
<pre><code>import pandas as pd
from keras.... | 2 | 2016-09-13T10:13:56Z | 39,877,785 | <p><a href="http://stackoverflow.com/users/6825808/xiao">xiao</a>, I ran into the same issue! Hopefully this helps:</p>
<h1>Background and The Issue</h1>
<p>The <a href="https://keras.io/scikit-learn-api/#wrappers-for-the-scikit-learn-api" rel="nofollow">documentation for Keras</a> states that, when implementing Wrap... | 0 | 2016-10-05T15:13:04Z | [
"python",
"machine-learning",
"scikit-learn",
"keras"
] |
save numpy arrays to txt | 39,467,517 | <p>I have to arrays (q, I) with different number of columns each and I want to save them in a txt file preserving the order of the columns, meaning in the txt file the arrays should be like:</p>
<pre><code>q, I0, I1, I2, ...
</code></pre>
<p>The shape of my arrays are:</p>
<pre><code>q.shape = (300, )
I.shape = (300... | 0 | 2016-09-13T10:15:08Z | 39,468,219 | <p>Try <code>save_arrays = np.hstack((q[:,np.newaxis],I))</code></p>
| 1 | 2016-09-13T10:50:07Z | [
"python",
"arrays",
"numpy"
] |
Python Newbie - Rock, Paper, Scissors | 39,467,619 | <p>I'm very new to Python and decided to set myself a challenge of programming a Rock, Paper, Scissors game without copying someone else's code. However, I need help from a Pythonista grown-up!</p>
<p>I've seen many other variations on Rock, Paper, Scissors, on here but nothing to explain why my version isn't working.... | 2 | 2016-09-13T10:20:16Z | 39,467,910 | <p>You have missed returning values in most of the case.</p>
<p>** Add '<strong>return playerInput</strong> ' in <strong>playerChoose()</strong> instead of only return.</p>
<p>** Add ' <strong>return computerPick</strong> ' in <strong>computerChoose()</strong> instead of return.</p>
<p>** Initialize <strong>winsTota... | 1 | 2016-09-13T10:35:32Z | [
"python"
] |
Python Newbie - Rock, Paper, Scissors | 39,467,619 | <p>I'm very new to Python and decided to set myself a challenge of programming a Rock, Paper, Scissors game without copying someone else's code. However, I need help from a Pythonista grown-up!</p>
<p>I've seen many other variations on Rock, Paper, Scissors, on here but nothing to explain why my version isn't working.... | 2 | 2016-09-13T10:20:16Z | 39,467,974 | <p>It is always a draw because you aren't returning the answers from your function, both playerAnswer and computerAnswer return None</p>
| 1 | 2016-09-13T10:37:55Z | [
"python"
] |
Python Newbie - Rock, Paper, Scissors | 39,467,619 | <p>I'm very new to Python and decided to set myself a challenge of programming a Rock, Paper, Scissors game without copying someone else's code. However, I need help from a Pythonista grown-up!</p>
<p>I've seen many other variations on Rock, Paper, Scissors, on here but nothing to explain why my version isn't working.... | 2 | 2016-09-13T10:20:16Z | 39,468,035 | <p>As some of people said playerChoose() and computerChoose() return with None</p>
<p>Modifidy these statement playerChoose() -> return playerInput
and computerChoose() -> return computerPick</p>
<p>AS well as you have to use global variable. Insert this row </p>
<pre><code>global winsTotal
</code></pre>
<p>in the ... | 0 | 2016-09-13T10:40:24Z | [
"python"
] |
Python Newbie - Rock, Paper, Scissors | 39,467,619 | <p>I'm very new to Python and decided to set myself a challenge of programming a Rock, Paper, Scissors game without copying someone else's code. However, I need help from a Pythonista grown-up!</p>
<p>I've seen many other variations on Rock, Paper, Scissors, on here but nothing to explain why my version isn't working.... | 2 | 2016-09-13T10:20:16Z | 39,468,088 | <p>add input and return in your functions</p>
<p><code>def computerChoose</code> And <code>def assessResult</code>return None</p>
<p>for Example by this code you can play this game :</p>
<pre><code>import random
playerAnswer = ''
computerAnswer = ''
winsTotal = 0
timesPlayed = 0
def playerChoose():
playerInpu... | 1 | 2016-09-13T10:43:03Z | [
"python"
] |
tkinter "Class" has no attribute "button" even though is set in an instance | 39,467,809 | <p>I'm trying run example from this <a href="http://zetcode.com/articles/tkinterlongruntask/" rel="nofollow">tutorial</a> and getting an error:</p>
<pre><code>self.startBtn.config(state=tk.DISABLED) AttributeError: 'Example' object has no attribute 'startBtn'
</code></pre>
<p>I rewrite my code for simplicity (and get... | 2 | 2016-09-13T10:29:23Z | 39,468,019 | <p>In the <em>function</em>, you use:</p>
<pre><code>def disableButton(self):
self.startBtn.config(state=tk.DISABLED)
</code></pre>
<p>but the <em>button is created</em> without <code>self</code>:</p>
<pre><code>startBtn = tk.Button(self, text="Start", command=self.disableButton)
startBtn.grid(row=0, column=0, p... | 2 | 2016-09-13T10:39:53Z | [
"python",
"class",
"tkinter"
] |
How to convert a list of strings into a list of integers | 39,467,821 | <p>In the below part of code <strong>v</strong> is a list of characters. </p>
<pre><code>import collections
import csv
import sys
with open("prom output.csv","r") as f:
cr = csv.reader(f,delimiter=",")
d=collections.defaultdict(lambda : list())
header=next(cr)
for r in cr:
d[r[0]].appe... | 0 | 2016-09-13T10:29:57Z | 39,467,911 | <p>You can use <a href="https://docs.python.org/3/library/functions.html#map" rel="nofollow"><code>map()</code></a> to apply an operation to each item in a list:</p>
<pre><code>a = ['a', 'b', 'c']
b = map(lambda c: ord(c), a)
print b
>>> [97, 98, 99]
</code></pre>
| 0 | 2016-09-13T10:35:33Z | [
"python",
"excel"
] |
How to convert a list of strings into a list of integers | 39,467,821 | <p>In the below part of code <strong>v</strong> is a list of characters. </p>
<pre><code>import collections
import csv
import sys
with open("prom output.csv","r") as f:
cr = csv.reader(f,delimiter=",")
d=collections.defaultdict(lambda : list())
header=next(cr)
for r in cr:
d[r[0]].appe... | 0 | 2016-09-13T10:29:57Z | 39,467,938 | <p>If you have a list of letters that you want converting into numbers try:</p>
<pre><code>>>> [ord(l) for l in letters]
[97, 98, 99, 100, 101, 102, 103]
</code></pre>
<p>or </p>
<pre><code>>>> list(map(ord, letters))
[97, 98, 99, 100, 101, 102, 103]
</code></pre>
<p>Or if you're dealing with capi... | 3 | 2016-09-13T10:36:32Z | [
"python",
"excel"
] |
How to change variable of main class from inherited class? | 39,467,861 | <p>I need to change object variable directly from inherited class.
Here is my code example: </p>
<pre><code>class A(object):
def __init__(self,initVal=0):
self.myVal = initVal
def worker(self):
self.incrementor = B()
self.incrementor.incMyVal(5)
class B(A):
def incMyVal(se... | 0 | 2016-09-13T10:32:21Z | 39,467,923 | <p><code>super()</code> can only search for <em>class attributes</em> in the class MRO, not instance attributes. <code>myVal</code> is set on an <em>instance</em> of the class, not on a class itself.</p>
<p>There is only ever one instance; it doesn't matter if code from class <code>A</code> or a derived class is alter... | 3 | 2016-09-13T10:35:58Z | [
"python",
"python-3.x"
] |
Passing Series with dtype= 'category' as categories for Pandas Categorical function | 39,467,885 | <p>when I run this code I get the following error :</p>
<pre><code>import pandas as pd
car_colors = pd.Series(['Blue', 'Red', 'Green'],
dtype='category')
car_data = pd.Categorical(['Yellow', 'Green', 'Red', 'Blue','Purple'],
categories= car_colors, ordered=False)
print car_co... | 1 | 2016-09-13T10:33:44Z | 39,467,943 | <p>It looks like need add <code>tolist</code> to <code>categories</code> in <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Categorical.html" rel="nofollow"><code>Categorical</code></a>:</p>
<pre><code>car_colors = pd.Series(['Blue', 'Red', 'Green'],
dtype='category')
car_data = pd.Ca... | 0 | 2016-09-13T10:36:48Z | [
"python",
"pandas",
"categorical-data"
] |
How can I redirect the output to be put into a file in python (version 3.3.3)? | 39,467,939 | <pre><code>sentence = "ASK NOT WHAT YOUR COUNTRY CAN DO FOR YOU ASK WHAT YOU CAN DO FOR YOUR COUNTRY"
s = sentence.split()
another = [0]
print(sentence)
for count, i in enumerate(s):
if s.count(i) < 2:
another.append(max(another) + 1)
else:
another.append(s.index(i) +1)
another.remove(0)
pr... | -4 | 2016-09-13T10:36:34Z | 39,468,049 | <p>I am guessing you want the sentence put into a text file? If so, here is the code:</p>
<pre><code>text_file = ("textfile.txt", "w")
text_file.write(sentence)
text_file.close()
</code></pre>
<p>Make sure textfile.txt is in the same folder as your program.</p>
| 0 | 2016-09-13T10:41:02Z | [
"python"
] |
Is it possible to use pango markup text on a Gtk+ 3 toolbutton label using Glade and PyDev? | 39,468,012 | <p>I have put together a Gtk+ interface in Glade and part of the UI is a tool palette with several toolbuttons using utf-8 characters as labels. They work fine in the default font, but I would like to change font details using pango markup. This is straightforward when dealing with a label as such, as one can apply</... | 1 | 2016-09-13T10:39:31Z | 39,477,395 | <p>To save any others from hours of fruitless head-scratching and searching, and to open the eyes of other newbies to the powers of Gtk+ 3 and Glade, I present the solution I found.</p>
<ol>
<li>Right click on your tool palette in the <em>outliner</em> and select edit</li>
<li>Choose the hierarchy tab in the editor</l... | 1 | 2016-09-13T19:13:10Z | [
"python",
"pygtk",
"gtk3",
"glade",
"pango"
] |
How to compare two different pandas dataframe whose lengths are not equal? | 39,468,033 | <p>I'm having two dataframes i.e. <strong>df1 and df2</strong> </p>
<pre><code>df1: df2:
Column1 Column2 ColumnA ColumnB
0 abc a 0 stu aaa
1 pqr b 1 mno bbb
2 stu c 2 pqr ccc
3 mno... | 0 | 2016-09-13T10:40:20Z | 39,468,152 | <p>I think you need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.merge.html" rel="nofollow"><code>merge</code></a>, but first rename column <code>ColumnA</code> and last <code>ColumnB</code>:</p>
<pre><code>print (pd.merge(df1,df2.rename(columns={'ColumnA':'Column1'}))
.rename(columns... | 1 | 2016-09-13T10:46:08Z | [
"python",
"pandas",
"dataframe",
"merge",
"comparison"
] |
Crop overlapping images with pillow | 39,468,216 | <p>I need help, please.
I'm trying to select and crop the overlapping area of two images with the Python Pillow library.</p>
<p>I have the upper-left pixel coordinate of the two pictures. With these, I can find out which one is located above the other.</p>
<p>I wrote a function, taking two images as arguments:</p>
<... | 0 | 2016-09-13T10:49:50Z | 39,469,880 | <p>First of all, I don't quite get what do you mean by one picture being "above" the other (shouldn't that be a z-position?), but take a look at this: <a href="http://stackoverflow.com/questions/20484942/how-to-make-rect-from-the-intersection-of-two">How to make rect from the intersection of two?</a> , the first answer... | 0 | 2016-09-13T12:16:30Z | [
"python",
"pillow"
] |
Spark performance issue (likely caused by "basic" mistakes) | 39,468,225 | <p>I'm relatively new to Apache Spark (version 1.6), and I feel I hit a wall: I looked through most of the Spark-related question on SE, but I found nothing that helped me so far. I believe I am doing something fundamentally wrong at the basic level, but I cannot point out what exactly it is, especially since other pie... | 0 | 2016-09-13T10:50:40Z | 39,470,910 | <blockquote>
<p>how much time has passed between two visits by the same person to the same shop. The output should be the list of shops which have had at least one customer visit them at least once every 5 seconds, alongside the number of customers that meet this requirement.</p>
</blockquote>
<p>How about simple <c... | 1 | 2016-09-13T13:07:01Z | [
"python",
"sql",
"apache-spark",
"pyspark",
"spark-dataframe"
] |
rolling mean with increasing window | 39,468,228 | <p>I have a range</p>
<pre><code>np.arange(1,11) # [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
</code></pre>
<p>and for each element, <em>i</em>, in my range I want to compute the average from element <em>i=0</em> to my current element. the result would be something like:</p>
<pre><code>array([ 1. , 1.5, 2. , 2.5, 3. , 3.5... | 2 | 2016-09-13T10:50:52Z | 39,468,295 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.expanding.html" rel="nofollow"><code>expanding()</code></a> (requires pandas 0.18.0):</p>
<pre><code>ser = pd.Series(np.arange(1, 11))
ser.expanding().mean()
Out:
0 1.0
1 1.5
2 2.0
3 2.5
4 3.0
5 3.5
6 4.0... | 4 | 2016-09-13T10:55:06Z | [
"python",
"pandas",
"numpy"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.