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
Integration openstack &opendaylight
38,241,463
<p><strong>strong text</strong>i need your help , i would like to do intergartion between openstack liberty(devstack) and opendaylight Beryllium. some one who know whow? i check lot of in internet but always the same documentation .</p>
0
2016-07-07T09:05:16Z
39,857,721
<p>you can go through the following links to get an idea about openstack - odl integration</p> <p><a href="http://www.flaviof.com/blog/work/how-to-odl-with-openstack-part1.html" rel="nofollow">OpenStack with Opendaylight Part 1: Intro to Pipeline</a></p> <p><a href="http://www.flaviof.com/blog/work/how-to-odl-with-op...
-1
2016-10-04T16:46:27Z
[ "python", "openstack", "openflow", "opendaylight" ]
Statistics based on number of matches in dataframe column
38,241,478
<p>I'm looking for a Pythonic approach to capture stats based on the amount of matches in a DF column. So working with this example:</p> <pre><code>rng = pd.DataFrame( {'initial_data': ['A', 'A','A', 'A', 'B','B', 'A' , 'A', 'A', 'A','B' , 'B', 'B', 'A',]}, index = pd.date_range('4/2/2014', periods=14, freq='BH')) t...
3
2016-07-07T09:06:23Z
38,242,534
<h3>Initial setup</h3> <pre><code>rng = pd.DataFrame({'initial_data': ['A', 'A', 'A', 'A', 'B', 'B', 'A', 'A', 'A', 'A', 'B', 'B', 'B', 'A',]}, index = pd.date_range('4/2/2014', periods=14, freq='BH')) </code></pre> <h3>Assign <code>bool</code> to columns <code>'test_for_B'</code></h3> <pre><code>...
4
2016-07-07T09:56:18Z
[ "python", "pandas" ]
Statistics based on number of matches in dataframe column
38,241,478
<p>I'm looking for a Pythonic approach to capture stats based on the amount of matches in a DF column. So working with this example:</p> <pre><code>rng = pd.DataFrame( {'initial_data': ['A', 'A','A', 'A', 'B','B', 'A' , 'A', 'A', 'A','B' , 'B', 'B', 'A',]}, index = pd.date_range('4/2/2014', periods=14, freq='BH')) t...
3
2016-07-07T09:06:23Z
38,242,765
<pre><code>df = pd.DataFrame({'ID': ['A', 'A','A', 'A', 'B','B', 'A' , 'A', 'A', 'A','B' , 'B', 'B', 'A',]}, index = pd.date_range('4/2/2014', periods=14, freq='BH')) df.head() Out: ID 2014-04-02 09:00:00 A 2014-04-02 10:00:00 A 2014-04-02 11:00:00 A 2014-04-02 12:00:00 A 2014-04-02 13:00:00 B </c...
3
2016-07-07T10:06:35Z
[ "python", "pandas" ]
Python trying to run behave get errors
38,241,517
<p>I'm trying to use behave to run selenium tests but I'm stuck at start of that idea. I've setup python, selenium and behave as it should be. I'm running python scripts with selenium without an problem. My problems starts when I try to run them with behave. My python is 3.5.2, selenium is 2.53.2 and behave is 1.2.5. W...
0
2016-07-07T09:08:09Z
38,241,624
<p>Your traceback returns: 'IndentationError: unindent does not match any outer indentation level'.</p> <p>This is usually an indicator that your tab/spaces of your indentation level is incorrect.<br /> Could you try to reformat the file tabbing to 4 spaces?</p> <blockquote> <p>As khelwood noted, the file you shoul...
3
2016-07-07T09:13:49Z
[ "python", "selenium", "python-behave" ]
Thread cannot get the item in queue
38,241,520
<p>There are two files related: backend_service.py and web_handler.py</p> <p>in backend_service.py</p> <pre><code>job_queue = Queue.Queue(5) def submit_job(job): job_queue.put(job) logger.info("Enqueue new Job: JobID:%d,queue size:%d" %(job.order_id,job_queue.qsize())) def handle_photos(): while True:...
0
2016-07-07T09:08:15Z
38,245,154
<p>I think your problem is that your script finishes before the thread has a chance to collect any items off the queue. </p> <p>In <code>backend_service.py</code>, your thread is started before anything is added to the queue, so you get <em>"The queue is empty..."</em>, the first time round.</p> <p>In <code>web-han...
0
2016-07-07T12:11:32Z
[ "python", "multithreading", "queue" ]
Thread cannot get the item in queue
38,241,520
<p>There are two files related: backend_service.py and web_handler.py</p> <p>in backend_service.py</p> <pre><code>job_queue = Queue.Queue(5) def submit_job(job): job_queue.put(job) logger.info("Enqueue new Job: JobID:%d,queue size:%d" %(job.order_id,job_queue.qsize())) def handle_photos(): while True:...
0
2016-07-07T09:08:15Z
38,413,157
<p>It is due to the new consumer thread is not in the same process with the producer one.</p> <p>I am not sure the root cause,maybe due uwsgi? </p>
0
2016-07-16T16:24:34Z
[ "python", "multithreading", "queue" ]
PIL load RGB matrix of a grayscale image
38,241,598
<p>How can I load the RGB matrix of an image. Basically, if I have a 224x224 image(grayscale), I need it's RGB matrix so I want a 224x224 matrix consisting of 3 element tuples. I have tried:</p> <pre><code>f="/path/to/grayscale/image" image = Image.open(f) new_width = 224 new_height = 224 im = image.resize((new_width...
0
2016-07-07T09:12:03Z
38,242,375
<p>I am not proficien in PIL, but it looks there is an <code>image.Convert("RGB")</code> method that may or may not work, so give it a try.</p> <p>However, if your intention is to continue using <code>np.array</code> then the following will work:</p> <pre><code>im=np.array(im) imRGB = np.repeat(im[:, :, np.newaxis], ...
1
2016-07-07T09:48:37Z
[ "python", "image-processing", "matrix", "python-imaging-library" ]
where should i put the partial js and css file in flask project
38,241,648
<p>i have a flask project and use jinja2 template engine, in template part: i make a base.html like this:</p> <pre><code> {%- block styles %} {% include 'static_partial/style.html' %} {%- endblock styles %} &lt;body{% block body_attribs %}{% endblock body_attribs %}&gt; {% block body -%} &lt;div cl...
0
2016-07-07T09:14:53Z
38,243,089
<p>Unless I am missing something, you can add another js file for your navbar's JavaScript under <code>assets/js</code> ie <code>navbar.js</code>.</p> <p>The add it as another script tag in <code>scripts.html</code>:</p> <pre><code>&lt;script src="{{ url_for('static', filename='assets/js/navbar.js')}}"&gt;&lt;/script...
0
2016-07-07T10:23:53Z
[ "javascript", "python", "html", "flask", "jinja2" ]
python storing a dataframe as value associated with key in dictionary
38,241,729
<p>I am trying to store a dataframe as a value associated with a key in dictionary. When i print dictionary for the key,i get only column names.</p> <pre><code>keys=['A','B','C'] temp_list= {} temp_list=temp_list.fromkeys(keys,list) for key in keys: temp_list[key]=[] for key in keys: A=pd.DataFrame(np.rando...
0
2016-07-07T09:18:37Z
38,242,260
<p>How about something like:</p> <pre><code>keys=['a','b','c','d','e'] A=pd.DataFrame(np.random.randn(10, 5),columns=['a', 'b', 'c', 'd', 'e']) DICT_MAP={} for key in keys: DICT_MAP[key]=pd.Series(A[key]) </code></pre> <p>You could now map keys to DataFrame: DICT_MAP['a']= ..SeriesDataFrame</p>
0
2016-07-07T09:42:16Z
[ "python", "dataframe" ]
prevent sorting of column names in pandas - python
38,241,835
<pre><code>df = pd.DataFrame(data={'i1':['x','x','x','x','y','y','y','y'], 'i2':['f','a','w','h','f','a','w','h'], 'c1':np.random.randn(8),'c2':np.random.randn(8)}) df.set_index(['i1','i2'],inplace=True) </code></pre> <p><code>df.unstack('i2')</code> sorts the column names in <code>i2</code> alphabetically. How can I ...
1
2016-07-07T09:23:20Z
38,241,962
<p>You can use <code>ordered Categorical</code>:</p> <pre><code>df['i2'] = pd.Categorical(df.i2, categories=['f', 'a', 'w', 'h'], ordered=True) df.set_index(['i1','i2'],inplace=True) print (df) print (df.unstack('i2')) c1 c2 \ i2 f a...
2
2016-07-07T09:28:27Z
[ "python", "pandas" ]
prevent sorting of column names in pandas - python
38,241,835
<pre><code>df = pd.DataFrame(data={'i1':['x','x','x','x','y','y','y','y'], 'i2':['f','a','w','h','f','a','w','h'], 'c1':np.random.randn(8),'c2':np.random.randn(8)}) df.set_index(['i1','i2'],inplace=True) </code></pre> <p><code>df.unstack('i2')</code> sorts the column names in <code>i2</code> alphabetically. How can I ...
1
2016-07-07T09:23:20Z
38,241,978
<p>Another method is to <code>set_levels</code> on the columns using the original <code>index</code> ordering:</p> <pre><code>In [261]: cols = df.columns df1 = df.unstack('i2') df1.columns = cols.set_levels(df.index.get_level_values(1), level=1) df1 Out[261]: c1 c2 ...
2
2016-07-07T09:29:23Z
[ "python", "pandas" ]
Parsing XML in Python using ElementTree
38,241,841
<p>The answers were given hundreds of times, but still I could not find a solution. I tried the official documentation and answers on stackoverflow.</p> <p>I have that XML structure:</p> <pre><code>&lt;?xml version="1.0" encoding="windows-1252"?&gt; &lt;OpenShipments xmlns="x-schema:OpenShipments.xdr"&gt; &lt;Ope...
2
2016-07-07T09:23:32Z
38,242,041
<p>You need a <a href="https://docs.python.org/3/library/xml.etree.elementtree.html#parsing-xml-with-namespaces" rel="nofollow">namespace</a> mapping:</p> <pre><code>from xml.etree import ElementTree as et xm = et.fromstring(x) ns = {"op": 'x-schema:OpenShipments.xdr'} print(xm.findall('.//op:TrackingNumber',ns)) </c...
2
2016-07-07T09:32:40Z
[ "python", "xml", "elementtree" ]
python / sqlite3 - Which is the process writing the file?
38,241,851
<p>If I build a database using sqlite3 from within python, what will be the process called that edits the database file?</p> <p>Will I be able to notice from shell that a database is not closed - even if no inserts are currently being committed?</p>
0
2016-07-07T09:24:00Z
38,322,642
<p>SQLite is an <em>embedded</em> database, so there is no separate process.</p> <p>You can check with <code>lsof</code> or similar tools whether the Python process has an open handle to the database file. However, such a handle corresponds to an open connection; it does not tell you whether there is an active transac...
1
2016-07-12T07:34:57Z
[ "python", "shell", "sqlite3", "insert", "edit" ]
Conditional import python in notebook
38,241,898
<p>I'm trying to modify the import names of a module depending on whether I'm in a notebook or not. I tried something like</p> <p><strong>api.py</strong></p> <pre><code>is_notebook = False if is_notebook: from tqdm import tnrange as trange from tqdm import tqdm_notebook as tqdm else: from tqdm import tran...
1
2016-07-07T09:25:58Z
38,242,249
<p>I think we can achieve the same by using an intermediate file abc.py like this:</p> <h1>contents of abc.py</h1> <pre><code>is_notebook = False if is_notebook: from tqdm import tnrange as trange from tqdm import tqdm_notebook as tqdm else: from tqdm import trange from tqdm import tqdm </code></pre> <p>...
0
2016-07-07T09:42:04Z
[ "python", "import", "module", "jupyter-notebook" ]
Conditional import python in notebook
38,241,898
<p>I'm trying to modify the import names of a module depending on whether I'm in a notebook or not. I tried something like</p> <p><strong>api.py</strong></p> <pre><code>is_notebook = False if is_notebook: from tqdm import tnrange as trange from tqdm import tqdm_notebook as tqdm else: from tqdm import tran...
1
2016-07-07T09:25:58Z
38,242,328
<p>api.py</p> <pre><code>def imports(is_notebook): if is_notebook: from tqdm import tnrange as trange from tqdm import tqdm_notebook as tqdm else: from tqdm import trange from tqdm import tqdm </code></pre> <p>after importing the api.py call this function:</p> <pre><code>api.i...
0
2016-07-07T09:46:11Z
[ "python", "import", "module", "jupyter-notebook" ]
Conditional import python in notebook
38,241,898
<p>I'm trying to modify the import names of a module depending on whether I'm in a notebook or not. I tried something like</p> <p><strong>api.py</strong></p> <pre><code>is_notebook = False if is_notebook: from tqdm import tnrange as trange from tqdm import tqdm_notebook as tqdm else: from tqdm import tran...
1
2016-07-07T09:25:58Z
38,242,379
<p>This is a bit of a hacky solution relying on the way python module import works, and it will probably break very easily. My appolgies.</p> <p>In your code, you are setting notebook to True only after the module api is imported, so it will have no effect. However, neither can you access the notebook variable before ...
0
2016-07-07T09:48:52Z
[ "python", "import", "module", "jupyter-notebook" ]
how to convert column names into column values in pandas - python
38,241,933
<pre><code>df=pd.DataFrame(index=['x','y'], data={'a':[1,2],'b':[3,4]}) </code></pre> <p>how can I convert column names into values of a column? This is my desired output</p> <pre><code> c1 c2 x 1 a x 3 b y 2 a y 4 b </code></pre>
3
2016-07-07T09:27:17Z
38,242,010
<p>You can use:</p> <pre><code>print (df.T.unstack().reset_index(level=1, name='c1') .rename(columns={'level_1':'c2'})[['c1','c2']]) c1 c2 x 1 a x 3 b y 2 a y 4 b </code></pre> <p>Or:</p> <pre><code>print (df.stack().reset_index(level=1, name='c1') .rename(columns...
2
2016-07-07T09:31:08Z
[ "python", "pandas" ]
how to convert column names into column values in pandas - python
38,241,933
<pre><code>df=pd.DataFrame(index=['x','y'], data={'a':[1,2],'b':[3,4]}) </code></pre> <p>how can I convert column names into values of a column? This is my desired output</p> <pre><code> c1 c2 x 1 a x 3 b y 2 a y 4 b </code></pre>
3
2016-07-07T09:27:17Z
38,242,025
<p>try this:</p> <pre><code>In [279]: df.stack().reset_index().set_index('level_0').rename(columns={'level_1':'c2',0:'c1'}) Out[279]: c2 c1 level_0 x a 1 x b 3 y a 2 y b 4 </code></pre>
3
2016-07-07T09:31:44Z
[ "python", "pandas" ]
how to convert column names into column values in pandas - python
38,241,933
<pre><code>df=pd.DataFrame(index=['x','y'], data={'a':[1,2],'b':[3,4]}) </code></pre> <p>how can I convert column names into values of a column? This is my desired output</p> <pre><code> c1 c2 x 1 a x 3 b y 2 a y 4 b </code></pre>
3
2016-07-07T09:27:17Z
38,242,029
<p>Try:</p> <pre><code>df1 = df.stack().reset_index(-1).iloc[:, ::-1] df1.columns = ['c1', 'c2'] df1 </code></pre> <p><a href="http://i.stack.imgur.com/asHzP.png" rel="nofollow"><img src="http://i.stack.imgur.com/asHzP.png" alt="enter image description here"></a></p>
2
2016-07-07T09:31:56Z
[ "python", "pandas" ]
how to convert column names into column values in pandas - python
38,241,933
<pre><code>df=pd.DataFrame(index=['x','y'], data={'a':[1,2],'b':[3,4]}) </code></pre> <p>how can I convert column names into values of a column? This is my desired output</p> <pre><code> c1 c2 x 1 a x 3 b y 2 a y 4 b </code></pre>
3
2016-07-07T09:27:17Z
38,242,228
<pre><code>In [62]: (pd.melt(df.reset_index(), var_name='c2', value_name='c1', id_vars='index') .set_index('index')) Out[62]: c2 c1 index x a 1 y a 2 x b 3 y b 4 </code></pre>
2
2016-07-07T09:41:26Z
[ "python", "pandas" ]
Django ManyToManyField as multiset
38,242,038
<p>Is there any way how to store the same object in m2m field multiple times?</p> <p>Let's say I have the following models</p> <pre><code>class Item(models.Model): name = models.CharField(max_length=64) class Inventory(models.Model): items = models.ManyToManyField('Items', blank=True) </code></pre> <p>And ...
0
2016-07-07T09:32:29Z
38,242,107
<p>Instead of storing <code>Item</code>'s in your inventory, you can store <code>InventoryItem</code>'s</p> <pre><code>class InventoryItem(models.Model): item = models.ForeignKey(Items) quantity = models.SmallIntegerField(default=1) inventory = models.ForeignKey(Inventory) </code></pre> <p>The idea is you...
1
2016-07-07T09:35:50Z
[ "python", "django", "django-models", "many-to-many", "multiset" ]
how to do recursion in python outside and inside loop
38,242,063
<p>Below is the python code to get the longest concat str with count I am not able to call the function again when in loop and out side loop I am not able to access <code>suffixString</code></p> <p>if i call outside the loop it's </p> <pre><code> t = {"asds":"asds","asas":"asas"} def checkIfitsLongest(str1): ...
0
2016-07-07T09:34:01Z
38,242,609
<p>Putting some well-positioned <code>print</code> debugging statements we can see that your problem is not with scoping of the <code>checkIfitsLongest</code> function or <code>suffixString</code> variable.</p> <pre><code>t = {"asds":"asds","asas":"asas"} def checkIfitsLongest(str1): print "checking", str1 fo...
0
2016-07-07T09:59:23Z
[ "python", "recursion" ]
Serving django from sub-folder in dev: static files not resolving
38,242,166
<p>So, I'm using nginx to serve my django app from <code>/my_app/</code>:</p> <p><code> location /my_app/ { proxy_pass http://127.0.0.1:8000/; } </code></p> <p>And I have <code>STATIC_URL = '/my_app/static</code></p> <p>Then, when using the django admin, the request to <code>/my_app/static/admin/css/bas...
2
2016-07-07T09:38:24Z
38,246,328
<p>It doesn't look like you're serving the static files through Nginx. The proxy pass is taking requests to the django domain and passing them to something else on the backend - What are you using to serve the base app? Assuming it's something other than runserver (don't do this!), gunicorn/uwsgi serve the django ap...
0
2016-07-07T13:07:17Z
[ "python", "django", "nginx" ]
Save Uploaded Image to exisitng Model in Django
38,242,196
<p>I am using a Form to Upload a picture via dropzone.js. The picture gets saved and uploaded fine. But it's creating a new model with empty fields.. I want to save the picture to that existing model I'm referencing to. But I can't seem to find a solution to reference it. Here's my code:</p> <p><strong>views.py</stron...
0
2016-07-07T09:39:42Z
38,242,944
<p>In my opinion, don't use </p> <pre><code>form.save() </code></pre> <p>Because it is creating a new instance in the model. Rather I would like to suggest something like-</p> <pre><code>def client_view(request, pk): client = get_object_or_404(Client, pk=pk) if request.method == 'POST': form = Uploa...
0
2016-07-07T10:16:10Z
[ "python", "django", "file", "web", "server" ]
Save Uploaded Image to exisitng Model in Django
38,242,196
<p>I am using a Form to Upload a picture via dropzone.js. The picture gets saved and uploaded fine. But it's creating a new model with empty fields.. I want to save the picture to that existing model I'm referencing to. But I can't seem to find a solution to reference it. Here's my code:</p> <p><strong>views.py</stron...
0
2016-07-07T09:39:42Z
38,243,914
<p>The <a href="https://docs.djangoproject.com/en/1.9/topics/forms/modelforms/#the-save-method" rel="nofollow">Django specified way</a> is to instantiate the <code>ModelForm</code> using an existing model:</p> <p>In your <strong>views.py</strong>:</p> <pre><code>client = get_object_or_404(Client, pk=pk) if request.m...
0
2016-07-07T11:06:45Z
[ "python", "django", "file", "web", "server" ]
plot a decision tree with python
38,242,237
<p>Hi I've found this code and I'm trying to plot a decision tree, but at the very end this "visualize_tree(test,columns)" give me an error: this is the code </p> <pre><code>from __future__ import print_function import os import subprocess import pandas as pd import numpy as np from sklearn.tree import DecisionTre...
0
2016-07-07T09:41:41Z
38,242,981
<p>The docstring of <code>visualize_tree</code> states that the first argument should be an instance of <code>DecisionTreeClassifier</code>. So the correct way to call it is</p> <pre><code>visualize_tree(dt, columns) </code></pre> <p>and not</p> <pre><code>visualize_tree(test, columns) </code></pre> <p>because <cod...
0
2016-07-07T10:17:51Z
[ "python", "plot", "scikit-learn", "decision-tree" ]
Drawing on Tkinter grid
38,242,247
<p>I couldn't find a way how to Draw line using grid. I want to have a line going from North to South seperating left and right frames.</p> <pre><code> self.left= Frame(self.tk, bg="black") self.left.grid(column=0, row = 0, pady=5 ,padx=10, sticky=N) self.center = Frame (self.tk ,bg= "black") self.cent...
0
2016-07-07T09:42:01Z
38,242,567
<p>I don't know what you want exactly, but you can create a line like this.</p> <pre><code>from Tkinter import * master = Tk() w = Canvas(master, width=200, height=100) w.pack() w.create_line(100, 0, 100, 100) #first 2 args are starting point of line and next 2 are ending point of line. mainloop() </code></pre> <...
0
2016-07-07T09:57:16Z
[ "python", "tkinter", "grid" ]
Drawing on Tkinter grid
38,242,247
<p>I couldn't find a way how to Draw line using grid. I want to have a line going from North to South seperating left and right frames.</p> <pre><code> self.left= Frame(self.tk, bg="black") self.left.grid(column=0, row = 0, pady=5 ,padx=10, sticky=N) self.center = Frame (self.tk ,bg= "black") self.cent...
0
2016-07-07T09:42:01Z
38,243,965
<p>If you want to separate the left frame from the right one, you can use a separator from ttk module (<a href="http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/ttk-Separator.html" rel="nofollow">http://infohost.nmt.edu/tcc/help/pubs/tkinter/web/ttk-Separator.html</a>)</p> <p>Here is an example:</p> <pre><code># pyt...
1
2016-07-07T11:09:49Z
[ "python", "tkinter", "grid" ]
Get range from sparse datetimeindex
38,242,363
<p>I have this kind of pandas DataFrame for each user in a large database.</p> <p><a href="http://i.stack.imgur.com/FUrHp.png" rel="nofollow"><img src="http://i.stack.imgur.com/FUrHp.png" alt="enter image description here"></a></p> <p>each row is a period of length [start_date, end_date], but sometimes 2 consecutive ...
3
2016-07-07T09:47:52Z
38,338,058
<p>I found a much more efficient way to do this by using <code>apply</code>:</p> <pre><code> def get_range(row): '''returns a DataFrame containing the day-range from a "start_date" and a "end_date"''' start_date = row["start_date"] end_date = row["end_date"] period = pd.date_range(start_date, end_date, freq=...
0
2016-07-12T20:10:58Z
[ "python", "datetime", "pandas", "dataframe", "date-range" ]
"Anti-merge" in pandas (Python)
38,242,368
<p>How can I pick out the difference between to columns of the same name in two dataframes? I mean I have dataframe A with a column named X and dataframe B with column named X, if i do <code>pd.merge(A, B, on=['X'])</code>, i'll get the common X values of A and B, but how can i get the "non-common" ones?</p>
1
2016-07-07T09:48:05Z
38,242,463
<p>If you change the merge type to <code>how='outer'</code> and <code>indicator=True</code> this will add a column to tell you whether the values are left/both/right only:</p> <pre><code>In [2]: A = pd.DataFrame({'x':np.arange(5)}) B = pd.DataFrame({'x':np.arange(3,8)}) print(A) print(B) x 0 0 1 1 2 2 3 3 4 4 ...
2
2016-07-07T09:52:58Z
[ "python", "pandas", "merge" ]
pandas dataframe: error joining
38,242,559
<p>I've got these two dataframes:</p> <pre><code>1) df STATCODE OCCDATE COWNNUM AGNTNUM IF 20130725 50033901 61002624 IF 20130725 50033901 61002624 IF 20130725 50033901 61002624 IF 20130725 50033901 61002624 2) dfCus CLNTNUM CLTTYPE CLTSEX...
1
2016-07-07T09:57:10Z
38,242,606
<p>I think you need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.merge.html" rel="nofollow"><code>merge</code></a>, parameter <code>how='inner'</code> is by default, so can be omited:</p> <pre><code>data = df.merge(dfCus, left_index=True, right_index=True) </code></pre> <p>and this ...
1
2016-07-07T09:59:15Z
[ "python", "pandas", "join", "dataframe" ]
pandas dataframe: error joining
38,242,559
<p>I've got these two dataframes:</p> <pre><code>1) df STATCODE OCCDATE COWNNUM AGNTNUM IF 20130725 50033901 61002624 IF 20130725 50033901 61002624 IF 20130725 50033901 61002624 IF 20130725 50033901 61002624 2) dfCus CLNTNUM CLTTYPE CLTSEX...
1
2016-07-07T09:57:10Z
38,243,412
<p>Found the solution, i.e. using <code>lsuffix</code>:</p> <pre><code>data = df.join(dfCus, how='inner', on='CLNTNUM',lsuffix='_l') </code></pre>
1
2016-07-07T10:42:03Z
[ "python", "pandas", "join", "dataframe" ]
how to update data of one column for all row in SqlAlchemy?
38,242,654
<p>for single record update i have tried below code and its working</p> <pre><code>uid=1 info = Info.query.filter_by(id=uid).first() info.sold_status ='1' db.session.add(info) db.session.commit() </code></pre> <p>now i want to update one column multiple row i have tried </p> <pre><code>for row in db.session.query(...
1
2016-07-07T10:01:30Z
38,243,715
<pre><code>for row in Uninstall.query.all(): print row.status row.status = &lt;new status&gt; db.session.add(row) db.session.commit() </code></pre>
-1
2016-07-07T10:56:20Z
[ "python", "mysql", "flask", "flask-sqlalchemy" ]
how to update data of one column for all row in SqlAlchemy?
38,242,654
<p>for single record update i have tried below code and its working</p> <pre><code>uid=1 info = Info.query.filter_by(id=uid).first() info.sold_status ='1' db.session.add(info) db.session.commit() </code></pre> <p>now i want to update one column multiple row i have tried </p> <pre><code>for row in db.session.query(...
1
2016-07-07T10:01:30Z
38,294,885
<p>The suggested is not optimized. You can use the options to update: 1. </p> <pre><code>for row in Uninstall.query: # all() is extra row.status = new_status Session.commit() </code></pre> <p>If there is a lot of rows it can be more fastier. But it will invoke UPDATE for every row. Not good, doesn't it? </p> <...
1
2016-07-10T17:57:26Z
[ "python", "mysql", "flask", "flask-sqlalchemy" ]
Python Function puzzle (heads,legs)
38,242,672
<p>I got one puzzle and I want to solve it using Python.</p> <p>Function that accepts two positive integers as parameters. The first integer is the number of heads and the second integer is the number of legs of all the creatures in a farm which consists of chickens and dogs. Your function should calculate and return ...
0
2016-07-07T10:02:29Z
38,242,876
<p>I believe it's finding the number of dogs there could be, try solving it with an example number of heads and legs, e.g. 10 heads and 40 legs:</p> <pre><code>dogs = (legs - heads * 2) / 2 dogs = (40 - 10 * 2) / 2 dogs = (40 - 20) / 2 dogs = 20 / 2 dogs = 10 </code></pre>
0
2016-07-07T10:12:24Z
[ "python", "function", "puzzle" ]
Pandas: increment datetime
38,242,692
<p>I need to do some actions with <code>date</code> in df column</p> <pre><code>buys['date_min'] = (buys['date'] - MonthDelta(1)) buys['date_min'] = (buys['date'] + timedelta(days=5)) </code></pre> <p>But it return </p> <blockquote> <p>TypeError: incompatible type [object] for a datetime/timedelta operation</p> </...
1
2016-07-07T10:03:11Z
38,242,712
<p>I think you need first convert column <code>date</code> <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.to_datetime.html" rel="nofollow"><code>to_datetime</code></a>, because <code>type</code> od values in column <code>date</code> is <code>string</code>:</p> <pre><code>buys['date_min'] = (pd.t...
1
2016-07-07T10:04:12Z
[ "python", "datetime", "pandas", "dataframe", "timedelta" ]
Replace a column in a csv file using python?
38,242,806
<p>How to replace a column in <code>csv</code> file with a condition in <code>python</code>?</p> <p>My <code>csv</code> file contains:</p> <pre><code> 34,2016-06-14 13:37:10,,1,,,t 34,2016-06-15 13:48:20,,1,,,f 34,2016-06-16 13:55:34,,1,,,t 34,2016-06-17 13:48:40,,1,,,f 34,2016-06-18 13:41:27,,1,,,t </code></pre>...
0
2016-07-07T10:09:07Z
38,243,190
<p>You can use regular expression to do the job:</p> <pre><code>import re for line in f: line = re.sub('\w$', lambda x: '"1"' if x.group(0) == 't' else '"0"', line) fo.write(line) </code></pre>
0
2016-07-07T10:29:25Z
[ "python", "csv" ]
Replace a column in a csv file using python?
38,242,806
<p>How to replace a column in <code>csv</code> file with a condition in <code>python</code>?</p> <p>My <code>csv</code> file contains:</p> <pre><code> 34,2016-06-14 13:37:10,,1,,,t 34,2016-06-15 13:48:20,,1,,,f 34,2016-06-16 13:55:34,,1,,,t 34,2016-06-17 13:48:40,,1,,,f 34,2016-06-18 13:41:27,,1,,,t </code></pre>...
0
2016-07-07T10:09:07Z
38,243,862
<p>Looking at your example there are 7 elements to the bits array, so you need to test <code>bits[6]</code> not <code>bits[5]</code>. If you know you always want the last one, <code>bits[-1]</code> would work.</p> <p>Also, I don't think your quoting <code>'"t"'</code> is correct. I fared better with <code>'t'</code>.<...
1
2016-07-07T11:04:09Z
[ "python", "csv" ]
Replace a column in a csv file using python?
38,242,806
<p>How to replace a column in <code>csv</code> file with a condition in <code>python</code>?</p> <p>My <code>csv</code> file contains:</p> <pre><code> 34,2016-06-14 13:37:10,,1,,,t 34,2016-06-15 13:48:20,,1,,,f 34,2016-06-16 13:55:34,,1,,,t 34,2016-06-17 13:48:40,,1,,,f 34,2016-06-18 13:41:27,,1,,,t </code></pre>...
0
2016-07-07T10:09:07Z
38,243,978
<p>Unless you insist on <code>python</code>, it would easily be done with <code>awk</code> as following:</p> <pre><code>awk '{$7= $7=="t" ? "1" : "0"}1' FS=',' OFS=',' month.csv </code></pre> <p>where replace 7th column with 0/1 using ternary and <code>FS</code> (field separator) and <code>OFS</code> (output field se...
0
2016-07-07T11:10:29Z
[ "python", "csv" ]
Numerical issue in odeint function depending on the initial values
38,242,851
<p>I tried to debug my code (which solves coupled ODEs). I found <strong>odeint function has specific limits of taking decimal values</strong> because of this issue (may be) my plots are different for different initial conditions. </p> <p>problem is in line 20: <code>x = np.linspace(-30., -50., 5)</code><br> problem ...
2
2016-07-07T10:11:32Z
38,247,475
<p>Indeed, the <code>odeint</code> solver is struggling with this ODE system. Apparently, the motion that this ODE describes is very non-uniform in time. A fix is to tell the solver to use tighter error control: </p> <pre><code>G = si.odeint(func1, state0, x, rtol=1e-10) </code></pre> <p>This yields a spiraling plot ...
0
2016-07-07T14:00:21Z
[ "python", "numpy", "scipy", "differential-equations", "odeint" ]
kivy error NameError: global name 'app' is not defined
38,242,866
<p>I wanted to make an App, with two languages(German and English) and settings, so I can switch between the languages. As the languages class is part of the App, I need to acsess it using app.Lanuage, but I got the error message above.</p> <pre><code>from kivy.app import App from kivy.lang import Builder from kivy.u...
0
2016-07-07T10:12:05Z
38,253,297
<p><strong>Example:</strong></p> <pre><code>from kivy.app import App from kivy.lang import Builder from kivy.uix.button import Button from kivy.uix.boxlayout import BoxLayout Builder.load_string(''' &lt;MyBtn&gt;: text: str(self)+self.a.test &lt;Test&gt;: Button: text: str(self)+app.test MyBtn: ''...
1
2016-07-07T18:56:41Z
[ "android", "python", "python-2.7", "kivy" ]
Spliting the values of column into new column within a dataframe to filter
38,242,910
<p>I have a dataframe, which looks as follows,</p> <pre><code>Head1 Header2 ABC SAP (+115590), GRN (+426250) EFG HES3 (-6350), CMT (-1902) HIJ CORT (-19440), API (+177) KLM AAD (-25488), DH(-1341) ,DSQ(+120001) SOS MFA (-11174), 13A2 (+19763) </code></pre> <p>And I need to split the second column with a co...
2
2016-07-07T10:14:28Z
38,243,781
<p>Try:</p> <pre><code>df = pd.DataFrame( [ ['ABC', 'SAP (+115590), GRN (+426250)'], ['EFG', 'HES3 (-6350), CMT (-1902)'], ['HIJ', 'CORT (-19440), API (+177)'], ['KLM', 'AAD (-25488), DH(-1341) ,DSQ(+120001)'], ['SOS', 'MFA (-11174), 13A2 (+19763)'], ], columns=['Head1...
2
2016-07-07T10:59:42Z
[ "python", "numpy", "pandas" ]
Topic modeling on the Devanagari (Hindi) text using Python
38,242,942
<p>Can anyone help me how to deal with this decoding problem in Python? I have got this output from the topic modeling of the hindi text in Python, Now I am not able to decode it in python to get the output in Devanagari (Hindi) language </p> <pre><code>[(0, u'0.573*"\u0915" + 0.360*"\u0930" + 0.304*"\u092e" + 0.270*"...
-1
2016-07-07T10:16:07Z
38,244,854
<p>The strings such as <code>"\u0915"</code> that are embedded into your data <em>are</em> Unicode escape sequences of Devanagari glyphs. These escape sequences are used to maximise the portability of the data. </p> <p>Here's some Python 2 code that uses a Regular Expression pattern to extract the numbers and glyphs f...
2
2016-07-07T11:55:49Z
[ "python", "unicode", "python-2.x" ]
How to make Pycharm faster/lighter?
38,242,978
<p>I really dig the idea of Pycharm and would love to use it. However, its tendency to consume the computer's processing power and lag is a large drawback.</p> <p>In the near future, I'll be running an introductory Python course and would like to recommend that the students install Pycharm as it seems to be the friend...
0
2016-07-07T10:17:33Z
38,244,391
<p>First of all: you can disable inspections. In right bottom, on status bar, next to memory usage indicator, there is a little Hector head - click it and select "syntax" level. I belive this will help a lot.</p> <p>If this won't help enough you can set "Power save mode". From <a href="https://www.jetbrains.com/help/p...
1
2016-07-07T11:33:07Z
[ "python", "ide", "pycharm" ]
How to make Pycharm faster/lighter?
38,242,978
<p>I really dig the idea of Pycharm and would love to use it. However, its tendency to consume the computer's processing power and lag is a large drawback.</p> <p>In the near future, I'll be running an introductory Python course and would like to recommend that the students install Pycharm as it seems to be the friend...
0
2016-07-07T10:17:33Z
38,244,454
<p>In the hardware end, upgrading your system is a fair choice. PyCharm recommends 1 GB of RAM as stated in the <a href="http://www.jetbrains.com/pycharm/download" rel="nofollow">system requirements</a> at the PyCharm website.</p> <p>You could disable a few of PyCharm's functionalities like disabling inspections. You ...
0
2016-07-07T11:36:36Z
[ "python", "ide", "pycharm" ]
How to make Pycharm faster/lighter?
38,242,978
<p>I really dig the idea of Pycharm and would love to use it. However, its tendency to consume the computer's processing power and lag is a large drawback.</p> <p>In the near future, I'll be running an introductory Python course and would like to recommend that the students install Pycharm as it seems to be the friend...
0
2016-07-07T10:17:33Z
38,251,566
<p>The slow performance of PyCharm is mainly due to small amount of RAM. I am running PyCharm on a machine with 2GB RAM. Here are my recommendations on making it work smoother.</p> <ol> <li><p>You can't really tweak PyCharm <strong>for performance</strong> balancing the power it provides. If you turn off the inspectio...
0
2016-07-07T17:18:24Z
[ "python", "ide", "pycharm" ]
Json unicode issue
38,242,988
<p>I have some non-ASCII characters in a json file. There is a list and that list has strings like <code>SMΛN</code>. When I read json file and print that list</p> <pre><code>with open ("strings.json") as f: t = json.load(f) print (t) </code></pre> <p>I got that non-ASCII string like <code>'SMΛN\n'</code>. ...
0
2016-07-07T10:18:04Z
38,254,877
<p>In Python 3, <code>open</code> defaults to using the encoding returned by <code>locale.getpreferredencoding()</code> which on US-localized Windows is <code>cp1252</code>.</p> <p>Open the file with UTF-8 encoding instead:</p> <pre><code>#coding:utf8 import json L = ['SMΛN'] # Generate an example file in UTF-8. wi...
0
2016-07-07T20:39:16Z
[ "python", "json", "windows", "unicode", "python-3.4" ]
How to determine coordinate of grid elements of an image
38,243,055
<p>Given an image of with a known dimension (eg. 14782 x5495 pixels) and a desired square size (e.g. width,height = 696 pixels) size, how can I get the coordinates of each element in the grid?</p> <p><a href="http://i.stack.imgur.com/vdF8J.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/vdF8J.jpg" alt="enter im...
3
2016-07-07T10:21:39Z
38,243,932
<p>For image with width <code>w</code>, height <code>h</code> and pixel buffer array <code>data</code>, the pixel coordinates at index <code>i</code> are given by <code>x = i % w, y = i / w</code>, where <code>%</code> is modulus and <code>/</code> is integer division.</p> <p>EDIT: by the index <code>i</code>, I mean ...
3
2016-07-07T11:07:35Z
[ "python", "image", "algorithm", "matplotlib" ]
How to determine coordinate of grid elements of an image
38,243,055
<p>Given an image of with a known dimension (eg. 14782 x5495 pixels) and a desired square size (e.g. width,height = 696 pixels) size, how can I get the coordinates of each element in the grid?</p> <p><a href="http://i.stack.imgur.com/vdF8J.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/vdF8J.jpg" alt="enter im...
3
2016-07-07T10:21:39Z
38,319,448
<p>Seems like this is what you want:</p> <pre><code>x = [i for i in range(696, 14782, 696) for j in range(696, 5495, 696)] y = [j for i in range(696, 14782, 696) for j in range(696, 5495, 696)] </code></pre> <p>to test it</p> <pre><code>import matplotlib.pyplot as plt img = imread('04_709_channel-3.tif') plt.ims...
6
2016-07-12T03:13:03Z
[ "python", "image", "algorithm", "matplotlib" ]
How to combine multiple feature points array in a single one
38,243,061
<p>In a single frame I have already detected multiple face via facecascade. I have also applied a loop to determine <code>p0</code> for each face via <code>goodFeaturesToTrack</code>. Now I want to combine all those <code>p0</code> so that I can pass it as an argument to <code>calcOpticalFlowPyrLK</code> function:</p> ...
0
2016-07-07T10:21:54Z
38,247,540
<p>you can use numpy.concatenate</p> <pre><code>import numpy as np p0 = np.array([[[479.0, 319.0]], [[407.0, 373.0]], [[334.0, 387.0]], [[343.0, 371.0]], [[369.0, 369.0]]]) p1 = np.array([[[279.0, 119.0]], [[207.0, 173.0]], [[134...
0
2016-07-07T14:03:31Z
[ "python", "opencv", "numpy" ]
How to apply sas like formatting in python?
38,243,071
<p>I am trying to create the cross tabulation frequency table in python as in 2 way frequency in SAS.</p> <p>In SAS,they have used PROC FORMAT to display few contents in the output as per requirement.</p> <p>How do I achieve this in python?For example,one of the datasets has got a column as age_group with categories ...
0
2016-07-07T10:22:52Z
38,243,317
<p>You can use the <code>cat.rename_categories()</code> method to rename the categories. If you want to work with the original levels consequently, you can use <code>cat.codes</code> to get the underlying integers. Here's a reproducible example:</p> <pre><code>df = pd.DataFrame({'age_group':["1","2","3","4","5","6","7...
0
2016-07-07T10:36:15Z
[ "python", "pandas" ]
Pandas reading CSVs and filtering dataframe based on filedate
38,243,140
<p>I'm trying to read a bunch of CSV-files into a single pandas dataframe. Some of the CSVs have data for multiple dates. I want only the data from each CSV that has a date equal to the modification date of each file.</p> <p>Here is my current attempt:</p> <pre><code>import os import datetime import pandas as pd from...
1
2016-07-07T10:27:05Z
38,249,849
<p>I would do it this way:</p> <pre><code>import os import glob import pandas as pd fmask = 'C:/Temp/.data/aaa/*.csv' all_files = glob.glob(fmask) # returns file's modification date (the time part will be truncated) def get_mdate(filename): return (pd.to_datetime(os.path.getmtime(filename), unit='s') ...
0
2016-07-07T15:44:51Z
[ "python", "date", "csv", "pandas" ]
Tensorflow: feed dict error: You must feed a value for placeholder tensor
38,243,194
<p>I have one bug I cannot find out the reason. Here is the code:</p> <pre><code>with tf.Graph().as_default(): global_step = tf.Variable(0, trainable=False) images = tf.placeholder(tf.float32, shape = [FLAGS.batch_size,33,33,1]) labels = tf.placeholder(tf.float32, shape = [FLAGS.batch_size,21,...
1
2016-07-07T10:29:27Z
38,245,070
<blockquote> <p>When I try to comment the code summary_op = tf.merge_all_summaries() and the code works fine. why is it the case?</p> </blockquote> <p><code>summary_op</code> is in operation. If exists (and this is you case) a summary operation related to the result of another operation that depends from the values ...
2
2016-07-07T12:07:33Z
[ "python", "tensorflow", "deep-learning" ]
How to animate a bar char being updated in Python
38,243,259
<p>I want to create an animated, stacked bar chart.</p> <p>There is a <a href="https://jakevdp.github.io/blog/2012/08/18/matplotlib-animation-tutorial/" rel="nofollow">great tutorial</a>, which shows how to animate line graphs.</p> <p>However, for animating bar charts, the BarContainer object, does not have any attri...
1
2016-07-07T10:33:20Z
38,258,747
<p><code>plt.bar</code> returns a list of Rectangles. The length of the list is equal to the number of bars. If you wanted to change the height of say the first bar, you can do <code>p1[0].set_height(new_height)</code> and similarly for <code>width</code> and a bunch of other Rectangle properties.</p> <p>As noted <a h...
0
2016-07-08T04:03:53Z
[ "python", "animation", "matplotlib" ]
How to animate a bar char being updated in Python
38,243,259
<p>I want to create an animated, stacked bar chart.</p> <p>There is a <a href="https://jakevdp.github.io/blog/2012/08/18/matplotlib-animation-tutorial/" rel="nofollow">great tutorial</a>, which shows how to animate line graphs.</p> <p>However, for animating bar charts, the BarContainer object, does not have any attri...
1
2016-07-07T10:33:20Z
38,607,026
<p>You'll want to call <code>plt.bar</code> outside of <code>animation()</code>, update the height of each bar with <code>Rectangle.set_height</code> as new data comes in.</p> <p>In practice, loop through each incoming set of y_heights zipped with the list of Rectangles returned by plt.bar() as seen below.</p> <pre><...
0
2016-07-27T07:54:57Z
[ "python", "animation", "matplotlib" ]
Getting complete datetime index of data frame in miliseconds using groupby method
38,243,300
<p>I have a dataframe (df) with the index as datetime index in "<code>%Y-%m-%d %H:%M:%S.%f</code>" format i.e <code>2012-06-16 15:53:42.457000</code>. </p> <p>I am trying to create groups of 1 second using groupby method i.e </p> <pre><code>x= df.groupby(pd.TimeGrouper('1S')) time=x.first().index[1] print time </cod...
1
2016-07-07T10:35:30Z
38,245,014
<p>I think this is a problem of formatting. </p> <pre><code>&gt; df.index[0].strftime('%Y-%m-%d %H:%M:%S.%f')[:-3] '2016-01-01 00:00:00.000' </code></pre> <p><a href="https://docs.python.org/3.4/library/datetime.html#strftime-and-strptime-behavior" rel="nofollow">Documentation here</a></p>
1
2016-07-07T12:04:23Z
[ "python", "python-2.7", "pandas", "dataframe", "datetimeindex" ]
Getting complete datetime index of data frame in miliseconds using groupby method
38,243,300
<p>I have a dataframe (df) with the index as datetime index in "<code>%Y-%m-%d %H:%M:%S.%f</code>" format i.e <code>2012-06-16 15:53:42.457000</code>. </p> <p>I am trying to create groups of 1 second using groupby method i.e </p> <pre><code>x= df.groupby(pd.TimeGrouper('1S')) time=x.first().index[1] print time </cod...
1
2016-07-07T10:35:30Z
38,257,236
<p>After spending few hours, i solved it. The functions such as <strong>groupby, rolling etc</strong> were giving the same problem. These functions uses a general datetime index for grouping which is mathematically the multiples of the defined frequency. There are possibilities to get <code>keyerror</code> if that inde...
0
2016-07-08T00:22:10Z
[ "python", "python-2.7", "pandas", "dataframe", "datetimeindex" ]
Why is there no argument when returning function in a decorator.
38,243,315
<p>Example: Fibonaci recursive function with memoize decorator. When calling function helper there is no argument. If function helper is defined to take an argument x therefore i expect calling the function with one argument. I would like to understand why is syntax like it is? </p> <pre><code>def memoize(f): me...
0
2016-07-07T10:36:15Z
38,243,384
<p>You do call the helper with the argument. Decorators are syntactic sugar for this</p> <pre><code>def fib(n): if n == 0: return 0 elif n == 1: return 1 else: return fib(n-1) + fib(n-2) fib = memoize(fib) </code></pre> <p>So your <code>fib</code> function is no longer the origin...
2
2016-07-07T10:40:28Z
[ "python", "function", "arguments", "decorator", "memoization" ]
Why is there no argument when returning function in a decorator.
38,243,315
<p>Example: Fibonaci recursive function with memoize decorator. When calling function helper there is no argument. If function helper is defined to take an argument x therefore i expect calling the function with one argument. I would like to understand why is syntax like it is? </p> <pre><code>def memoize(f): me...
0
2016-07-07T10:36:15Z
38,245,262
<p>I believe the syntax is like this so that it looks as streamlined as possible. You put a decorator object after the <code>@</code> (a function that takes one argument, and returns a function), and python calls it with the function you are defining. This</p> <pre><code>@memoize def fib(n): ... </code></pre> <p>...
0
2016-07-07T12:17:04Z
[ "python", "function", "arguments", "decorator", "memoization" ]
Get the string from the DataFrame column an assign to the other column in pandas
38,243,318
<p>I Have a input data frame with columns:</p> <pre><code>Template Template Name This is String This is String line This is Int This is Int Name This is String Name String Name is none Int is empty </code></pre> <p>Expected Output Dataframe:</p> <pre><code>Template Temp...
1
2016-07-07T10:36:24Z
38,243,390
<p>I think you need <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.Series.str.extract.html" rel="nofollow"><code>extract</code></a>:</p> <pre><code>df['Template Name'] = df.Template.str.extract('(String|Int)', expand=False) print (df) Template Template Name 0 This is String ...
2
2016-07-07T10:40:41Z
[ "python", "pandas" ]
Python: How to remove [' and ']?
38,243,368
<p>I want to remove <code>['</code> from start and <code>']</code> characters from the end of a string.</p> <p>This is my text:</p> <pre><code>"['45453656565']" </code></pre> <p>I need to have this text:</p> <pre><code>"45453656565" </code></pre> <p>I've tried to use <code>str.replace</code></p> <pre><code>text =...
-1
2016-07-07T10:39:35Z
38,243,426
<p>You need to strip your text by passing the unwanted characters to <code>str.strip()</code> method:</p> <pre><code>&gt;&gt;&gt; s = "['45453656565']" &gt;&gt;&gt; &gt;&gt;&gt; s.strip("[']") '45453656565' </code></pre> <p>Or if you want to convert it to integer you can simply pass the striped result to <code>int</...
7
2016-07-07T10:42:52Z
[ "python", "python-3.x" ]
Python: How to remove [' and ']?
38,243,368
<p>I want to remove <code>['</code> from start and <code>']</code> characters from the end of a string.</p> <p>This is my text:</p> <pre><code>"['45453656565']" </code></pre> <p>I need to have this text:</p> <pre><code>"45453656565" </code></pre> <p>I've tried to use <code>str.replace</code></p> <pre><code>text =...
-1
2016-07-07T10:39:35Z
38,243,469
<p>You could loop over the character filtering if the element is a digit:</p> <pre><code>&gt;&gt;&gt; number_array = "['34325235235']" &gt;&gt;&gt; int(''.join(c for c in number_array if c.isdigit())) 34325235235 </code></pre> <p>This solution works even for both <code>"['34325235235']"</code> and <code>'["343252352...
0
2016-07-07T10:45:10Z
[ "python", "python-3.x" ]
Python: How to remove [' and ']?
38,243,368
<p>I want to remove <code>['</code> from start and <code>']</code> characters from the end of a string.</p> <p>This is my text:</p> <pre><code>"['45453656565']" </code></pre> <p>I need to have this text:</p> <pre><code>"45453656565" </code></pre> <p>I've tried to use <code>str.replace</code></p> <pre><code>text =...
-1
2016-07-07T10:39:35Z
38,243,577
<p>Using <code>re.sub</code>:</p> <pre><code>&gt;&gt;&gt; my_str = "['45453656565']" &gt;&gt;&gt; import re &gt;&gt;&gt; re.sub("['\]\[]","",my_str) '45453656565' </code></pre>
0
2016-07-07T10:50:44Z
[ "python", "python-3.x" ]
Python: How to remove [' and ']?
38,243,368
<p>I want to remove <code>['</code> from start and <code>']</code> characters from the end of a string.</p> <p>This is my text:</p> <pre><code>"['45453656565']" </code></pre> <p>I need to have this text:</p> <pre><code>"45453656565" </code></pre> <p>I've tried to use <code>str.replace</code></p> <pre><code>text =...
-1
2016-07-07T10:39:35Z
38,244,574
<p>Instead of hacking your data by stripping brackets, you should edit the script that created it to print out just the numbers. E.g., instead of lazily doing </p> <pre><code>output.write(str(mylist)) </code></pre> <p>you can write</p> <pre><code>for elt in mylist: output.write(elt + "\n") </code></pre> <p>Then...
0
2016-07-07T11:42:00Z
[ "python", "python-3.x" ]
How to use python3 setup.py test with PyTest and PyQt5?
38,243,437
<p>Is it possible to follow Good Integration as here <a href="http://pytest.org/latest/goodpractices.html" rel="nofollow">http://pytest.org/latest/goodpractices.html</a> in a package that depends on PyQt5 ? (I am using Ubuntu 14.04, don't know if this impacts)</p> <p>I get the following with both suggested approaches:...
0
2016-07-07T10:43:49Z
38,260,542
<p>Running <code>py.test</code> in the command line performs the tests in your current Python environment.</p> <p>Running <code>python3 setup.py test</code> (with pytest-runner in accordance with pytest's 'Good Integration Practices') creates a pseudo-virtualenv. It pulls in any missing dependencies as eggs (storing t...
1
2016-07-08T06:50:03Z
[ "python", "python-3.x", "pyqt", "py.test", "pyqt5" ]
Python Basemap: Error using shadedrelief, bluemarble or etopo (false longitude format?)
38,243,506
<p>I want to plot a map of the southern hemisphere centered on the pacific with some stuff drawn onto it with python matplotlib basemap. </p> <p>Everything works fine unless I try to draw a background image with the basemap routines shadedrelief, bluemarble or etopo. The code (without the stuff i want to draw onto th...
1
2016-07-07T10:47:13Z
38,245,255
<p>It seems there was a bug in the basemap/<strong>init</strong> code. In fact, if you look at the latest version on github [see <a href="https://github.com/matplotlib/basemap/blob/master/lib/mpl_toolkits/basemap/__init__.py#L4139" rel="nofollow">https://github.com/matplotlib/basemap/blob/master/lib/mpl_toolkits/basema...
2
2016-07-07T12:16:50Z
[ "python", "matplotlib", "matplotlib-basemap" ]
Why do the `tkinter.ttk.Notebook` tabs get thinner and thinner?
38,243,547
<p>I am using a <code>tkinter.ttk.Notebook</code> and the tabs seem to get thinner with time. How do I overcome this? Is there a possibility to specify a uniform width for each tab?</p> <p><a href="http://i.stack.imgur.com/aMGIi.png" rel="nofollow"><img src="http://i.stack.imgur.com/aMGIi.png" alt="enter image descrip...
0
2016-07-07T10:49:14Z
38,244,653
<p>I don't know if it's possible to set a uniform width for each tab, but it seems that the tab width problem is style dependent:</p> <ul> <li>with style "alt" the tab name SEVEN is partially hidden: <a href="http://i.stack.imgur.com/ZKhOB.png" rel="nofollow"><img src="http://i.stack.imgur.com/ZKhOB.png" alt="notebook...
3
2016-07-07T11:45:41Z
[ "python", "python-3.x", "tkinter", "ttk" ]
How to apply function to multiple pandas dataframe
38,243,556
<p>df1, df2, df3,..., dfn have the same type of data from difference group of descriptors that can not be join. So what I have to do is apply the same function to each data frame manually. How can I apply the same function to multiple data frame?</p>
1
2016-07-07T10:49:42Z
38,243,626
<p>If the data frames have the same columns you could <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.concat.html" rel="nofollow"><code>concat</code></a> them to a single data frame, but otherwise there is not really a "smart" way of doing it:</p> <pre><code>df1, df2, df3 = (df.apply(...) for df ...
2
2016-07-07T10:52:39Z
[ "python", "function", "pandas", "dataframe" ]
Python openpyxl comment shape property
38,243,599
<p>I'm trying to set properties of comments (mainly the shape) in excel by openpyxl, but I cannot find examples. I'd like to set it with something like:</p> <pre><code>ws.cell(column = x, row = y).comment.NEEDED_METHOD_HERE = ... </code></pre> <p>If you have good examples or any idea what is the exact method, please ...
1
2016-07-07T10:51:42Z
38,244,724
<p>This currently (2016) cannot be done with openpyxl and may never be possible. </p>
1
2016-07-07T11:49:28Z
[ "python", "openpyxl" ]
Insert into table or create table from one command
38,243,613
<p>I'm trying to save a PySpark DataFrame as a table:</p> <pre><code>myDf.write.saveAsTable("myDf") </code></pre> <p>However, if I run the code twice I get</p> <pre><code>u'Table `myDf` already exists.;' </code></pre> <p>If I save it like this:</p> <pre><code>myDf.write.inserInto("myDf") </code></pre> <p>I will g...
0
2016-07-07T10:52:10Z
38,244,210
<p>Why can't you put an <code>if condition</code> to check if the table exists or not?</p> <p>If not, depending on your use case, you can probably use <code>registerDataFrameAsTable(df, tableName)</code> this registers the given DataFrame as a temporary table in the catalog, which exists only during the lifetime of t...
0
2016-07-07T11:23:03Z
[ "python", "apache-spark", "pyspark" ]
Insert into table or create table from one command
38,243,613
<p>I'm trying to save a PySpark DataFrame as a table:</p> <pre><code>myDf.write.saveAsTable("myDf") </code></pre> <p>However, if I run the code twice I get</p> <pre><code>u'Table `myDf` already exists.;' </code></pre> <p>If I save it like this:</p> <pre><code>myDf.write.inserInto("myDf") </code></pre> <p>I will g...
0
2016-07-07T10:52:10Z
38,246,340
<pre><code>myDf.write.mode("overwrite").saveAsTable("myDf") </code></pre> <p>It seems obviously an "Oh I wish I know it is so simple" scenario (happens to me all the time) but here is the <a href="https://spark.apache.org/docs/1.6.2/api/java/org/apache/spark/sql/SaveMode.html" rel="nofollow">ref</a> in case you need a...
0
2016-07-07T13:08:03Z
[ "python", "apache-spark", "pyspark" ]
Struggling to get logfile output in PySpark
38,243,631
<p>Following the question here: <a href="http://stackoverflow.com/questions/25407550/how-do-i-log-from-my-python-spark-script">How do I log from my Python Spark script</a>, I have been struggling to get:</p> <p>a) All output into a log file. b) Writing out to a log file from pyspark</p> <p>For a) I use the following ...
0
2016-07-07T10:52:53Z
38,263,673
<p>Works in my configuration:</p> <pre><code>log4jLogger = sc._jvm.org.apache.log4j LOGGER = log4jLogger.LogManager.getLogger(__name__) LOGGER.info("Hello logger...") </code></pre>
1
2016-07-08T09:51:02Z
[ "python", "logging", "apache-spark" ]
falied to install flask under virutalenv on windows -- [Error 2] The system cannot find the file specified
38,243,633
<p>I'm using python 2.7 on a windows box.I'm able to install flask using pip install, as you can see below:</p> <p><img src="http://i.stack.imgur.com/2gEWO.png" alt="cool"> However, after I created a virtualenv, I got below error when trying to do the same thing. </p> <p>scripts: </p> <pre><code>$pip install virtual...
6
2016-07-07T10:53:00Z
38,245,244
<p>ok. I figure it out. I don't think there is anything wrong in the way I install flask, as I already mentioned in my question, I am able to install it globally (without running within a virtualenv). the MarkupSafe package has an extension which is implement using c, and I don't have windows sdk installed on my loca...
1
2016-07-07T12:15:57Z
[ "python", "windows", "flask", "virtualenv" ]
falied to install flask under virutalenv on windows -- [Error 2] The system cannot find the file specified
38,243,633
<p>I'm using python 2.7 on a windows box.I'm able to install flask using pip install, as you can see below:</p> <p><img src="http://i.stack.imgur.com/2gEWO.png" alt="cool"> However, after I created a virtualenv, I got below error when trying to do the same thing. </p> <p>scripts: </p> <pre><code>$pip install virtual...
6
2016-07-07T10:53:00Z
38,254,280
<p>I had this problem yesterday. I resolved it by downloading the MarkupSafe <a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/" rel="nofollow">wheel</a> and installing with pip. The problem was way over my head. Something about compiler flags in order to suppress an error when generating the Speedups file, I think...
5
2016-07-07T19:59:48Z
[ "python", "windows", "flask", "virtualenv" ]
falied to install flask under virutalenv on windows -- [Error 2] The system cannot find the file specified
38,243,633
<p>I'm using python 2.7 on a windows box.I'm able to install flask using pip install, as you can see below:</p> <p><img src="http://i.stack.imgur.com/2gEWO.png" alt="cool"> However, after I created a virtualenv, I got below error when trying to do the same thing. </p> <p>scripts: </p> <pre><code>$pip install virtual...
6
2016-07-07T10:53:00Z
38,357,916
<p>I had this issue today and was able to resolve it by manually installing <a href="http://www.pocoo.org/projects/markupsafe" rel="nofollow">MarkupSafe</a> from a <a href="http://pythonwheels.com" rel="nofollow">wheel</a> file, per Lincoln's suggestion above. You can download the appropriate file <a href="http://www.l...
1
2016-07-13T17:13:39Z
[ "python", "windows", "flask", "virtualenv" ]
falied to install flask under virutalenv on windows -- [Error 2] The system cannot find the file specified
38,243,633
<p>I'm using python 2.7 on a windows box.I'm able to install flask using pip install, as you can see below:</p> <p><img src="http://i.stack.imgur.com/2gEWO.png" alt="cool"> However, after I created a virtualenv, I got below error when trying to do the same thing. </p> <p>scripts: </p> <pre><code>$pip install virtual...
6
2016-07-07T10:53:00Z
38,413,695
<p>This issue seems to be related with the setuptools version installed in your virtualenv. Downgrading to an older version fixed it for me.</p> <p>From your virtualenv:</p> <pre><code>pip install setuptools==21.2.1 pip install flask </code></pre>
15
2016-07-16T17:21:32Z
[ "python", "windows", "flask", "virtualenv" ]
falied to install flask under virutalenv on windows -- [Error 2] The system cannot find the file specified
38,243,633
<p>I'm using python 2.7 on a windows box.I'm able to install flask using pip install, as you can see below:</p> <p><img src="http://i.stack.imgur.com/2gEWO.png" alt="cool"> However, after I created a virtualenv, I got below error when trying to do the same thing. </p> <p>scripts: </p> <pre><code>$pip install virtual...
6
2016-07-07T10:53:00Z
38,425,868
<p>The setup.py of MarkupSafe is broken for Win7 on my system where there is no C compiler. (I keep a separate VM for VC++ work) I did this to get it working:</p> <pre><code>pip download MarkupSafe mkdir temp open MarkupSafe-0.23.tar.gz with 7-zip, extract all to temp cd temp edit setup.py line 119 to read: if 0: ...
1
2016-07-17T20:58:08Z
[ "python", "windows", "flask", "virtualenv" ]
Mongodb find with wrong result Int64 object
38,243,680
<p>I'm using MongoDB 3.2.1 / python 3.4 / pymongo / pandas 0.17 (although the latter two are probably completely irrelavant to this question).</p> <p>I'm having a really strange (and wrong) behavior with MongoDB find.</p> <p>I have a collection, containing a document like this: </p> <pre><code> { "_id" : Nu...
2
2016-07-07T10:55:03Z
38,244,422
<p>I think you're hitting some sort of limits within mongo NumberLong.</p> <p>I've opened a mongo console and this is the output</p> <pre><code>&gt; NumberLong(-1819413477243867792) NumberLong("-1819413477243867904") </code></pre> <p>So I would assume that if you find by NumberLong("-1819413477243867904") you would ...
0
2016-07-07T11:35:06Z
[ "python", "mongodb", "pandas" ]
Mongodb find with wrong result Int64 object
38,243,680
<p>I'm using MongoDB 3.2.1 / python 3.4 / pymongo / pandas 0.17 (although the latter two are probably completely irrelavant to this question).</p> <p>I'm having a really strange (and wrong) behavior with MongoDB find.</p> <p>I have a collection, containing a document like this: </p> <pre><code> { "_id" : Nu...
2
2016-07-07T10:55:03Z
38,248,537
<p>the answer could be trivial but all is connected with quotes <code>"</code> around value for number long.</p> <p>Inserting data and querying need to be 'quoted' </p> <pre><code>db.sofia.find({"_id" : NumberLong("-1819413477243867792")}).pretty() { "_id" : NumberLong("-1819413477243867792"), "targe...
0
2016-07-07T14:46:26Z
[ "python", "mongodb", "pandas" ]
What's the standard way to package a python project with dependencies?
38,243,682
<p>I have a python project that has a few dependencies (defined under <code>install_requires</code> in setup.py). My ops people requires a package to be self contained and only depend on a python installation. The litmus test would be that they're able to get a zip-file and then unzip and run it without an internet con...
1
2016-07-07T10:55:06Z
38,244,114
<p>In most cases you should be able to "vendor" all the dependencies. It's basically a crude version of virtualenv.</p> <p>For example look at how the <code>requests</code> package <a href="https://github.com/kennethreitz/requests/tree/master/requests/packages" rel="nofollow">includes chardet and urllib3</a> in its ow...
1
2016-07-07T11:17:26Z
[ "python", "setuptools" ]
What's the standard way to package a python project with dependencies?
38,243,682
<p>I have a python project that has a few dependencies (defined under <code>install_requires</code> in setup.py). My ops people requires a package to be self contained and only depend on a python installation. The litmus test would be that they're able to get a zip-file and then unzip and run it without an internet con...
1
2016-07-07T10:55:06Z
38,280,192
<p>It's possible to do this with recent versions of <code>pip</code> (I'm using 8.1.2). On the build machine:</p> <pre><code>pip install -r requirements.txt --prefix vendor </code></pre> <p>Then run it:</p> <pre><code>PYTHONPATH=vendor/lib/python2.7/site-packages python yourapp.py </code></pre> <p>(This is basicall...
0
2016-07-09T09:10:00Z
[ "python", "setuptools" ]
What's the standard way to package a python project with dependencies?
38,243,682
<p>I have a python project that has a few dependencies (defined under <code>install_requires</code> in setup.py). My ops people requires a package to be self contained and only depend on a python installation. The litmus test would be that they're able to get a zip-file and then unzip and run it without an internet con...
1
2016-07-07T10:55:06Z
40,119,217
<p>There are a few nuances to how pip works. Unfortunately, using <code>--prefix vendor</code> to store all the dependencies of the project doesn't work if any of those dependencies, or dependencies of dependencies are installed into a place where pip can find them. It will skip those dependencies and just install the ...
1
2016-10-18T22:36:24Z
[ "python", "setuptools" ]
Flask text & file upload in the same form - Results in an empty dictionary
38,243,791
<p>So I have an HTML form with a few input text fields, but now I want to include file uploading in the same form as well.</p> <p>I saw in other posts in here that using a FormData object would do the job for me. However when I implement it the dict that I receive in Flask is empty.</p> <p>Here is the HTML form. The ...
0
2016-07-07T10:59:52Z
38,246,604
<p>I found the solution. </p> <p>Instead of using <code>var thisformData = new FormData($('#form_withtabs'));</code></p> <p>I tried using <code>var form = document.querySelector('#form_withtabs'); var formData = new FormData(form); </code> At the end that solved my problem and Flask now receives everythin...
0
2016-07-07T13:20:41Z
[ "jquery", "python", "flask" ]
python smtp check if username and pass are correct
38,244,165
<p>Do you have any idea how would i check if username and password are typed correctly before sending smtp mail with python?</p> <p>meaning: connect to smpt server, give feedback on username and password</p>
1
2016-07-07T11:20:24Z
38,248,703
<p>You could using a try and except inside a while loop</p> <pre><code>#Inital user and passw need to be defined up here log=False while log==False: #to loop until a correct password is aqquired try: server.login(user, passw) #attempt to log into smtp server log=True #sets to true if log in is succ...
1
2016-07-07T14:53:52Z
[ "python", "smtp" ]
Python - Weird behaviour in array re-ordering
38,244,241
<p>I am trying to rearrange some arrays but it doesn't seem to always work properly:</p> <pre><code># Works fine arr = np.array([2,3,1]) idx1 = np.array([1,0,2]) arr[idx1] &gt;&gt; array([3, 2, 1]) # Doesn't work arr = np.array([2,3,1]) idx2 = np.array([2,0,1]) arr[idx2] &gt;&gt; array([1, 2, 3]) # Should have be...
-1
2016-07-07T11:24:57Z
38,244,402
<p><strong>index</strong> rebuilds your array with the <strong>index array</strong>. The <strong>index array</strong> contains a list of positions (indexes) of elements in the original array.</p> <blockquote> <p>Numpy arrays may be indexed with other arrays (or any other sequence- like object that can be converted...
0
2016-07-07T11:34:12Z
[ "python", "arrays" ]
Multiple inheritance in "broken" diamonds
38,244,247
<p>I was exploring how multiple inheritance might work in cases where one of the (two) parent classes doesn't inherit from the common base class. Here's the program:</p> <pre><code>'''Demomstration of MRO on 'broken' diamonds''' class Base: def hello(self): print('Base') class Left(Base): def hello(s...
0
2016-07-07T11:25:07Z
38,245,035
<p>Your <code>Base.hello</code> function is "broken" with respect to this test. Consider the <code>hello</code> functions in your MRO:</p> <pre><code>Child1.hello print('Child1') # PRINTED super().hello() # super() -&gt; Left Left.hello print('Left') # PRINTED super().hello() # super() -&gt; BASE...
2
2016-07-07T12:05:20Z
[ "python", "python-3.x" ]
JSON data to columns in a DataFrame
38,244,251
<p>I have data in the form of a pandas dataframe, which looks like this:</p> <pre><code>A B C ab {"app":"x","wid":10,"a42":5} e y {"hair":"x","wid":10,"a42":2} r </code></pre> <p>and I want to convert my dataframe like this:<br></p> <pre><code>A C app wid ...
0
2016-07-07T11:25:29Z
38,244,307
<p>try this:</p> <pre><code>In [143]: df.B.apply(pd.Series) Out[143]: a42 app hair wid 0 5 x NaN 10 1 2 NaN x 10 </code></pre>
1
2016-07-07T11:28:34Z
[ "python", "json", "pandas", "dataframe" ]
JSON data to columns in a DataFrame
38,244,251
<p>I have data in the form of a pandas dataframe, which looks like this:</p> <pre><code>A B C ab {"app":"x","wid":10,"a42":5} e y {"hair":"x","wid":10,"a42":2} r </code></pre> <p>and I want to convert my dataframe like this:<br></p> <pre><code>A C app wid ...
0
2016-07-07T11:25:29Z
38,244,328
<p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.from_records.html" rel="nofollow"><code>DataFrame.from_records</code></a> and <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.concat.html" rel="nofollow"><code>concat</code></a>:</p> <pre><code>import p...
1
2016-07-07T11:29:28Z
[ "python", "json", "pandas", "dataframe" ]
JSON data to columns in a DataFrame
38,244,251
<p>I have data in the form of a pandas dataframe, which looks like this:</p> <pre><code>A B C ab {"app":"x","wid":10,"a42":5} e y {"hair":"x","wid":10,"a42":2} r </code></pre> <p>and I want to convert my dataframe like this:<br></p> <pre><code>A C app wid ...
0
2016-07-07T11:25:29Z
38,245,283
<p>Try this;</p> <pre><code>df["B"] = df["B"].apply(lambda x : dict(eval(x)) ) or df["B"] = df["B"].map(eval) df2 = df["B"].apply(pd.Series ) result = pd.concat([df, df2], axis=1).drop('B', axis=1) </code></pre>
1
2016-07-07T12:18:04Z
[ "python", "json", "pandas", "dataframe" ]
How do i get my code to print one character name on seperate lines 10 times?
38,244,406
<p>Ok so I'm writing a code that generates ten Dungeon and dragons characters. I need to generate ten characters, their should be one character on each line. Here's the instructions from my teacher: "Modify the program to generate 10 names and store them in an array. Then Write a function, dumpFile that writes the arr...
-3
2016-07-07T11:34:18Z
38,244,615
<p><code>dumpfile</code> is called in each iteration of your loop. Put it after the loop instead. In addition (as I'm sure you know), you are not reading to the file <code>dumpfile</code>, only printing to terminal.</p> <p>You could do something like</p> <pre><code>names = '\n'.join(arr) #print(names) file.write(name...
0
2016-07-07T11:44:01Z
[ "python", "python-3.x", "python-3.5" ]
How do i get my code to print one character name on seperate lines 10 times?
38,244,406
<p>Ok so I'm writing a code that generates ten Dungeon and dragons characters. I need to generate ten characters, their should be one character on each line. Here's the instructions from my teacher: "Modify the program to generate 10 names and store them in an array. Then Write a function, dumpFile that writes the arr...
-3
2016-07-07T11:34:18Z
38,244,826
<p>Assuming that you have the default names on file "originalnames.txt", I would do something like this:</p> <pre><code>def readnames(file): with open(file) as f: return f.read().splitlines() def choosepos(max): from random import randint return randint(0, max-1) def main(): orignames = readnames('or...
0
2016-07-07T11:54:28Z
[ "python", "python-3.x", "python-3.5" ]
Issues getting nodal coordinates Abaqus Python API
38,244,521
<p>I am checking the elements beneath a surface for their labels &amp; the coordinates of their nodes in the following code,</p> <pre><code>mySurf = mdb.models['Model-1'].rootAssembly.surfaces['Surf-1'] surfEls = mySurf.elements[:] surfNodes = [] for eNode in mySurf.nodes: surfNodes.append(eNode.coordinates) </co...
0
2016-07-07T11:39:30Z
38,375,556
<p>The problem is that the <em>MeshSequenceObject</em> does not have method 'coordinates'. However, a member of <em>MeshSequenceObject</em> may have this method, if sequence contains nodes. Just apply it to each member of the sequence:</p> <pre><code>surfNodesCoords = [Node.coordinates for Node in SurfNodes] </code></...
1
2016-07-14T13:26:53Z
[ "python", "indexing", "abaqus" ]
Removing characters from a tuple python
38,244,671
<p>I have made a maths quiz in python. All my code is working fine however when I print the questions it is printing them in brackets and with commas and apostrophes.</p> <pre><code>question = number1, '+', number2 </code></pre> <p>That is the name of my tuple:</p> <pre><code>answer = int(input("What is {}?".format(...
-7
2016-07-07T11:46:48Z
38,244,751
<p>Not sure why you need to format twice </p> <pre><code>answer = int(input("What is {0} + {1}?".format(number1, number2))) </code></pre>
0
2016-07-07T11:50:43Z
[ "python" ]
Removing characters from a tuple python
38,244,671
<p>I have made a maths quiz in python. All my code is working fine however when I print the questions it is printing them in brackets and with commas and apostrophes.</p> <pre><code>question = number1, '+', number2 </code></pre> <p>That is the name of my tuple:</p> <pre><code>answer = int(input("What is {}?".format(...
-7
2016-07-07T11:46:48Z
38,244,812
<p>Your question should be</p> <pre><code>question = '{} {} {}'.format(number1, operator, number2) </code></pre>
1
2016-07-07T11:53:43Z
[ "python" ]
Removing characters from a tuple python
38,244,671
<p>I have made a maths quiz in python. All my code is working fine however when I print the questions it is printing them in brackets and with commas and apostrophes.</p> <pre><code>question = number1, '+', number2 </code></pre> <p>That is the name of my tuple:</p> <pre><code>answer = int(input("What is {}?".format(...
-7
2016-07-07T11:46:48Z
38,244,904
<p>About your error:</p> <p><code>question = number1, '+', number2</code> defines a tuple with 3 elements</p> <p>Example:</p> <pre><code>&gt;&gt;&gt; question = 2, '+', 4 &gt;&gt;&gt; print(question) (2, '+', 4) &gt;&gt;&gt; type(question) tuple </code></pre> <p>With <code>"What is {}?".format(question)</code> you ...
2
2016-07-07T11:58:38Z
[ "python" ]
Spyder-IDE how to leave argument inspection open
38,244,790
<p>Lets say I type the following in Spyder-IDE:</p> <pre><code>min( </code></pre> <p>Spyder will then automatically open the arguments list of the function min and give me:</p> <pre><code>Arguments min(iterable[, key=func]) </code></pre> <p>I find this very helpful but Spyder closes this list after 1.5sec. I would ...
3
2016-07-07T11:52:29Z
38,245,755
<p>If you're okay with having a "side" window, what you can do is go to Tools > Preferences > Object Inspector, and check off the Editor, Python Console, and IPython Console boxes, then click Apply/OK. Then navigate to View > Panes and click Object Inspector. It should pop up as another window next to your main text wi...
2
2016-07-07T12:41:54Z
[ "python", "ide", "parameter-passing", "spyder", "preference" ]
Running bash in subprocess breaks stdout of tty if interrupted while waiting on `read -s`?
38,244,830
<p>As @Bakuriu points out in the comments this is basically the same problem as in <a href="http://stackoverflow.com/questions/31808863/bash-ctrlc-during-input-breaks-current-terminal">BASH: Ctrl+C during input breaks current terminal</a> However, I can only reproduce the problem when bash is run as a subprocess of an...
2
2016-07-07T11:54:42Z
38,247,336
<p>It seems like this is related to the fact that <code>bash -c</code> starts a <strong>non-interactive</strong> shell. This probably prevents it from restoring the terminal state.</p> <p>To explicitly start an interactive shell you can just pass the <code>-i</code> option to bash.</p> <pre><code>$ cat test_read.py ...
1
2016-07-07T13:54:10Z
[ "python", "linux", "bash", "subprocess", "keyboardinterrupt" ]
Running bash in subprocess breaks stdout of tty if interrupted while waiting on `read -s`?
38,244,830
<p>As @Bakuriu points out in the comments this is basically the same problem as in <a href="http://stackoverflow.com/questions/31808863/bash-ctrlc-during-input-breaks-current-terminal">BASH: Ctrl+C during input breaks current terminal</a> However, I can only reproduce the problem when bash is run as a subprocess of an...
2
2016-07-07T11:54:42Z
38,247,537
<p>As I wrote in a comment on my question, when <code>read -s</code> is run, bash saves the current tty attributes, and installs an <code>add_unwind_protect</code> handler to restore the previous tty attributes when the stack frame for <code>read</code> exits.</p> <p>Normally, <code>bash</code> installs a handler for ...
1
2016-07-07T14:03:16Z
[ "python", "linux", "bash", "subprocess", "keyboardinterrupt" ]
How to access different data type element in a list?
38,245,082
<p>I have table varchar column with values, I'm trying to create &amp; access list element in Python for data cleaning. I have list ( Column sample values) like this:</p> <pre><code>Caller_ID = ['Ambulance',1,2,3,'Fire Crew',1,2] </code></pre> <p>i.e Ambulance followed by "1, 2, 3" means ambulance was contacted 3 tim...
-1
2016-07-07T12:08:12Z
38,245,327
<p>You can pick both strings and counts as you go through the list:</p> <pre><code>Caller_ID = ['Ambulance',1,2,3,'Fire Crew',1,2,'Police',1] Callers = [] # list to hold result current_caller, caller_count = "", 0 # temporary variables holding current element # iterate through the list, pick each name and count for ...
0
2016-07-07T12:20:00Z
[ "python" ]
How to access different data type element in a list?
38,245,082
<p>I have table varchar column with values, I'm trying to create &amp; access list element in Python for data cleaning. I have list ( Column sample values) like this:</p> <pre><code>Caller_ID = ['Ambulance',1,2,3,'Fire Crew',1,2] </code></pre> <p>i.e Ambulance followed by "1, 2, 3" means ambulance was contacted 3 tim...
-1
2016-07-07T12:08:12Z
38,245,495
<p>This can be easily done using <code>itertools.groupby</code> to group the integers together and separate them from the strings. The "trick" is to use <code>type</code> as the <code>groupby</code> key function.</p> <pre><code>from itertools import groupby Caller_ID = ['Ambulance', 1, 2, 3, 'Fire Crew', 1, 2, 'Polic...
2
2016-07-07T12:28:18Z
[ "python" ]