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
Can not use tensorflow in pycharm
39,220,524
<p>I can ran tensorflow in anaconda command line successfully, but when I ran it in pycharm, it complains for not finding tensorflow, but I do find it in the package of this python interpreter. Is there anything else I need to do ? Thanks</p> <p><a href="http://i.stack.imgur.com/gVOJe.png" rel="nofollow"><img src="htt...
0
2016-08-30T06:45:40Z
39,220,560
<p>Looking at the console, your <code>.py</code> file is <em>also</em> called <code>tensorflow</code>, so when you do <code>import tensorflow as tf</code>, you end up trying to import things from the same file.</p> <p>Rename your own file to something else, such as <code>tensorflow_test_1.py</code> or whatnot. :)</p>
5
2016-08-30T06:47:40Z
[ "python", "pycharm", "tensorflow" ]
incorrect date format when writing df to csv pandas
39,220,660
<p>I convert a string to date using pandas. When I write the DF to CSV, the date comes like '2016-08-15 instead of plain 2016-08-15. Unable to read it as date in ETL tool.Same is the case for all date fields.</p> <p>Any suggestion to get the date format correctly ?</p> <pre><code>df =pd.read_csv(r'/Users/tcssig/Docum...
-2
2016-08-30T06:53:07Z
39,223,813
<p>You can try this</p> <pre><code>df = pd.read_csv(r'/Users/tcssig/Documents/ABP_News_Aug01.csv') df['date'] = pd.to_datetime(df['date']) df.to_csv('/Users/tcssig/Documents/Sarang.csv') </code></pre> <p>(assuming name of the date field is 'date'</p>
0
2016-08-30T09:32:44Z
[ "python", "pandas" ]
python convolution with different dimension
39,220,929
<p>I'm trying to implement convolutional neural network in Python.<br> However, when I use signal.convolve or np.convolve, it can not do convolution on X, Y(X is 3d, Y is 2d). X are training minibatches. Y are filters. I don't want to do for loop for every training vector like:</p> <pre><code>for i in xrange(X.shape[2...
4
2016-08-30T07:06:42Z
39,226,689
<p>Scipy implements standard N-dimensional convolutions, so that the matrix to be convolved and the kernel are both N-dimensional.</p> <p>A quick fix would be to add an extra dimension to <code>Y</code> so that <code>Y</code> is 3-Dimensional:</p> <pre><code>result = signal.convolve(X, Y[..., None], 'valid') </code><...
5
2016-08-30T11:47:48Z
[ "python", "numpy", "scipy", "deep-learning" ]
How to use Python Selenium to get the data?
39,221,164
<p>The link is here : <a href="http://www.imei.info/phonedatabase/790-alcatel-9109-mb2/" rel="nofollow">http://www.imei.info/phonedatabase/790-alcatel-9109-mb2/</a></p> <p>I can already open this website using <code>Selenium-Webdriver</code> in Python. Now I'm trying to get the <code>battery type</code> from this webs...
0
2016-08-30T07:18:40Z
39,221,510
<p>use the below code to get the battery type:</p> <pre><code> batteryType = driver.find_element(By.XPATH, '//div[@class='cc' and contains(text(), 'Li-Ion')]').text() </code></pre> <p>use the .text() to get the string of an element.</p>
0
2016-08-30T07:37:18Z
[ "python", "html", "web", "selenium-webdriver" ]
How to use Python Selenium to get the data?
39,221,164
<p>The link is here : <a href="http://www.imei.info/phonedatabase/790-alcatel-9109-mb2/" rel="nofollow">http://www.imei.info/phonedatabase/790-alcatel-9109-mb2/</a></p> <p>I can already open this website using <code>Selenium-Webdriver</code> in Python. Now I'm trying to get the <code>battery type</code> from this webs...
0
2016-08-30T07:18:40Z
39,222,557
<p>You should try using <code>xpath</code> as below :-</p> <pre><code>type = driver.find_element_by_xpath("//*[text() = 'Battery:']/following-sibling::div").text </code></pre>
0
2016-08-30T08:35:11Z
[ "python", "html", "web", "selenium-webdriver" ]
Why does getaddrinfo not return all IP Addresses?
39,221,168
<p>I am trying to get all IP Addresses for: earth.all.vpn.airdns.org In Python: </p> <pre><code>def hostnamesToIps(hostnames): ip_list = [] for hostname in hostnames: try: ais = socket.getaddrinfo(hostname, None) for result in ais: #print (result[4][0]) ip_lis...
3
2016-08-30T07:18:46Z
39,222,389
<p>Tools like <code>dig</code>, <code>host</code> and <code>nslookup</code> query the default DNS server directly using UDP/TCP and their own implementation of DNS queries, whereas Python's <code>socket</code> module uses the DNS lookup interface of the operating system, which usually uses a more sophisticates lookup m...
2
2016-08-30T08:27:13Z
[ "python", "sockets" ]
dtypes changed when initialising a new DataFrame from another one
39,221,232
<p>Let's say that I have a DataFrame df1 with 2 columns: <code>a</code> with dtype <code>bool</code> and <code>b</code> with dtype <code>int64</code>. When I initialise a new DataFrame (<code>df1_bis</code>) from <code>df1</code>, columns <code>a</code> and <code>b</code> are automatically converted into objects, even ...
2
2016-08-30T07:23:15Z
39,221,301
<p>For me works:</p> <pre><code>df1_bis = pd.DataFrame(df1, columns=df1.columns, index=df1.index) #df1_bis = pd.DataFrame(df1) print (df1_bis) a b 0 True 0 print (df1_bis.dtypes) a bool b int64 dtype: object </code></pre> <p>But I think better is use <a href="http://pandas.pydata.org/pandas-docs/sta...
4
2016-08-30T07:26:44Z
[ "python", "pandas", "dataframe", "casting", "multiple-columns" ]
dtypes changed when initialising a new DataFrame from another one
39,221,232
<p>Let's say that I have a DataFrame df1 with 2 columns: <code>a</code> with dtype <code>bool</code> and <code>b</code> with dtype <code>int64</code>. When I initialise a new DataFrame (<code>df1_bis</code>) from <code>df1</code>, columns <code>a</code> and <code>b</code> are automatically converted into objects, even ...
2
2016-08-30T07:23:15Z
39,221,562
<p>It is <code>numpy</code> that is causing the problem. <code>pandas</code> is inferring the types from the numpy array. If you convert to a list, you won't have the problem.</p> <pre><code>df1_bis = pd.DataFrame(df1.values.tolist(), columns=df1.columns) print(df1_bis) print print(df1_bis.d...
4
2016-08-30T07:41:11Z
[ "python", "pandas", "dataframe", "casting", "multiple-columns" ]
Grouping by set . To group files with similar headers python
39,221,335
<p>I have derived an output from a directory structure which has a lot many csv files. The headers of these files are manually created and randomly placed. I have to get all those files which have similar headers together.</p> <pre><code>/A/B/C/D~b1.csv.0 Delim:, "First Name" "Last Name" Company EMAIL Phone F...
0
2016-08-30T07:28:29Z
39,222,320
<p>The following approach works by taking each of your CSV headers and converting them into a list of column entries. These are then sorted and converted to a tuple. This is then used as the key for a default dictionary. Each matching entry is appended to the list along with the original column ordering. </p> <p>The r...
1
2016-08-30T08:23:14Z
[ "python", "python-2.7" ]
No module named unusual_prefix_*
39,221,442
<p>I tried to run the <a href="https://github.com/apache/incubator-airflow/blob/master/airflow/example_dags/example_python_operator.py" rel="nofollow">Python Operator Example</a> in my Airflow installation. The installation has deployed webserver, scheduler and worker on the same machine and runs with no complaints for...
0
2016-08-30T07:34:00Z
39,222,486
<p>Using <code>donot_pickle=True</code> option (<a href="https://pythonhosted.org/airflow/cli.html" rel="nofollow">see Documentation</a>) I got rid of the error. Probably not the best solution, but good enough for my scenario.</p>
0
2016-08-30T08:32:00Z
[ "python", "pickle", "airflow" ]
What is the Redis equivalent of TransactionDB's getRange?
39,221,464
<p>The transactionDB python api says that,</p> <blockquote> <p>Database.get_range(begin, end[, limit, reverse, streaming_mode])</p> <p>Returns all keys k such that begin &lt;= k &lt; end and their associated values as a list of KeyValue objects. Note the exclusion of end from the range.</p> <p>This read...
2
2016-08-30T07:35:06Z
39,222,578
<p><a href="http://redis.io/topics/data-types#sorted-sets" rel="nofollow">Sorted sets</a> allow you to query by a <a href="http://redis.io/commands/zrange" rel="nofollow">range</a>. If you're storing say an object, you can use the sorted set to get the desired object ID's, then lookup the object information from a hash...
0
2016-08-30T08:36:20Z
[ "python", "redis", "jedis", "foundationdb" ]
What is the Redis equivalent of TransactionDB's getRange?
39,221,464
<p>The transactionDB python api says that,</p> <blockquote> <p>Database.get_range(begin, end[, limit, reverse, streaming_mode])</p> <p>Returns all keys k such that begin &lt;= k &lt; end and their associated values as a list of KeyValue objects. Note the exclusion of end from the range.</p> <p>This read...
2
2016-08-30T07:35:06Z
39,234,918
<p>TL;DR there isn't a direct equivalent and scanning the entire key space is always slow(er) - you should avoid it unless your intent is getting most/all of the keys anyway.</p> <p>There are two Redis commands that allow you to scan the keyspace - one is called <a href="http://redis.io/commands/scan" rel="nofollow"><...
1
2016-08-30T18:44:23Z
[ "python", "redis", "jedis", "foundationdb" ]
How to persist state when the crawler dies abruptly?
39,221,755
<p>this quetion is in reference to <a href="http://stackoverflow.com/questions/39211490/scrapy-spider-does-not-store-state-persistent-state">Scrapy spider does not store state (persistent state)</a></p> <p>I have followed the following link to persist state of the crawler <a href="http://doc.scrapy.org/en/latest/topic...
0
2016-08-30T07:50:15Z
39,222,056
<p>One way of doing this is seperating discovery and consumer logic by having two spiders. One to discovery product urls another to consume those urls and return results for every one of them. If for some reason the consumer dies mid run it can easily resume the crawl because discovery queue was not affected by this cr...
0
2016-08-30T08:07:18Z
[ "python", "scrapy", "web-crawler" ]
pandas keep numerical part
39,221,900
<p>I have a set of data like: </p> <pre><code> 0 1 0 type 1 type 2 1 type 3 type 4 </code></pre> <p>How can I transfer it to:</p> <pre><code> 0 1 0 1 2 1 3 4 </code></pre> <p>perfer using <code>apply</code>or <code>transform</code> function</p>
3
2016-08-30T07:58:09Z
39,221,940
<p><strong><em>Option 1</em></strong></p> <pre><code>df.stack().str.replace('type ', '').unstack() </code></pre> <p><strong><em>Option 2</em></strong></p> <pre><code>df.stack().str.split().str[-1].unstack() </code></pre> <p><strong><em>Option 3</em></strong></p> <pre><code># pandas version 0.18.1 + df.stack().str....
4
2016-08-30T08:00:36Z
[ "python", "string", "pandas", "replace", "numeric" ]
pandas keep numerical part
39,221,900
<p>I have a set of data like: </p> <pre><code> 0 1 0 type 1 type 2 1 type 3 type 4 </code></pre> <p>How can I transfer it to:</p> <pre><code> 0 1 0 1 2 1 3 4 </code></pre> <p>perfer using <code>apply</code>or <code>transform</code> function</p>
3
2016-08-30T07:58:09Z
39,222,003
<p>You can use <code>applymap</code> and a regex (<code>import re</code>):</p> <pre><code>df = df.applymap(lambda x: re.search(r'.*(\d+)', x).group(1)) </code></pre> <p>If you want the digits as integers:</p> <pre><code>df = df.applymap(lambda x: int(re.search(r'.*(\d+)', x).group(1))) </code></pre> <p>This will wo...
2
2016-08-30T08:04:19Z
[ "python", "string", "pandas", "replace", "numeric" ]
pandas keep numerical part
39,221,900
<p>I have a set of data like: </p> <pre><code> 0 1 0 type 1 type 2 1 type 3 type 4 </code></pre> <p>How can I transfer it to:</p> <pre><code> 0 1 0 1 2 1 3 4 </code></pre> <p>perfer using <code>apply</code>or <code>transform</code> function</p>
3
2016-08-30T07:58:09Z
39,222,004
<pre><code>&gt;&gt;&gt; df.apply(lambda x: x.str.replace('type ','').astype(int)) 0 1 0 1 2 1 3 4 </code></pre> <p>remove the <code>.astype(int)</code> if you don't need to convert to int</p>
3
2016-08-30T08:04:31Z
[ "python", "string", "pandas", "replace", "numeric" ]
pandas keep numerical part
39,221,900
<p>I have a set of data like: </p> <pre><code> 0 1 0 type 1 type 2 1 type 3 type 4 </code></pre> <p>How can I transfer it to:</p> <pre><code> 0 1 0 1 2 1 3 4 </code></pre> <p>perfer using <code>apply</code>or <code>transform</code> function</p>
3
2016-08-30T07:58:09Z
39,222,073
<p>Yoou can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.replace.html" rel="nofollow"><code>DataFrame.replace</code></a>:</p> <pre><code>print (df.replace({'type ': ''}, regex=True)) 0 1 0 1 2 1 3 4 </code></pre>
3
2016-08-30T08:08:10Z
[ "python", "string", "pandas", "replace", "numeric" ]
Python classes - run method when any other method is called
39,221,915
<p>I am writing a Python app which will use a config file, so I am delegating the control of the config file to a dedicated module, <code>configmanager</code>, and within it a class, <code>ConfigManager</code>.</p> <p>Whenever a method within <code>ConfigManager</code> is run, which will change my config file in some ...
0
2016-08-30T07:58:50Z
39,221,993
<p>The natural way to have:</p> <blockquote> <p><code>ConfigManager.get_config_file()</code> makes a value available to the method <code>ConfigManager.edit_config()</code>.</p> </blockquote> <p>is to have <code>get_config_file()</code> <em>return</em> that value.</p> <p>Just call <code>get_config_file()</code> w...
2
2016-08-30T08:03:48Z
[ "python" ]
Python classes - run method when any other method is called
39,221,915
<p>I am writing a Python app which will use a config file, so I am delegating the control of the config file to a dedicated module, <code>configmanager</code>, and within it a class, <code>ConfigManager</code>.</p> <p>Whenever a method within <code>ConfigManager</code> is run, which will change my config file in some ...
0
2016-08-30T07:58:50Z
39,244,597
<p>Since you get something from disk, you open a file. So, you could use the class with the <code>with</code> "function" of python. </p> <p>You should check the context managers. With that, you will be able to implement the functionality that you want each time that someone access the config file through the <code>__e...
0
2016-08-31T08:34:26Z
[ "python" ]
pandas handle column with different date time formats gracefully
39,221,996
<p>I have a column with a birthdate. Some are N.A, some <code>01.01.2016</code> but some contain <code>01.01.2016 01:01:01</code> Filtering the N.A. values works fine. But handling the different date formats seems clumsy. Is it possible to have pandas handle these gracefully and e.g. for a birthdate only interpret the ...
1
2016-08-30T08:03:55Z
39,222,137
<p><code>pd.to_datetime()</code> will handle multiple formats</p> <pre><code>&gt;&gt;&gt; ser = pd.Series(['NaT', '01.01.2016', '01.01.2016 01:01:01']) &gt;&gt;&gt; pd.to_datetime(ser) 0 NaT 1 2016-01-01 00:00:00 2 2016-01-01 01:01:01 dtype: datetime64[ns] </code></pre>
3
2016-08-30T08:11:50Z
[ "python", "date", "datetime", "pandas" ]
Replace NAT dates with data from another column Python Pandas
39,222,157
<p>I am facing difficulties replacing NAT dates with data from other column. I am using python pandas by the way.</p> <p>For example</p> <pre><code> Column1 Column2 02-12-2006 2006 05-12-2005 2005 NAT 2008 15-02-2015 2015 NAT ...
2
2016-08-30T08:13:17Z
39,222,205
<pre><code>df.Column1.combine_first(df.Column2) 0 2006-02-12 00:00:00 1 2005-05-12 00:00:00 2 2008 3 2015-02-15 00:00:00 4 2001 Name: Column1, dtype: object </code></pre> <hr> <h3>Better Answer</h3> <pre><code>df.Column1 = np.where(df.Column1.notnull(), ...
5
2016-08-30T08:16:24Z
[ "python", "pandas" ]
Django1.11 - URLconf does not appear to have any patterns
39,222,191
<p>I'm a new user of django and i have some difficulties. I follow a Django 1.8 tutorial and i have Django1.11. the problem is about urls.py files &amp; patterns</p> <p>Here my code, blog/urls.py:</p> <pre><code>from django.conf.urls import url from . import views urlpattern = [ url(r'^accueil/$', views.home, nam...
0
2016-08-30T08:15:35Z
39,222,221
<p>Django 1.11 is not released. You should use the actual released version, 1.10. Also, you should use the actual tutorial for your version.</p> <p>However, the problem is that both of your files should define <code>urlpatterns</code> with an s, not <code>urlpattern</code>.</p>
2
2016-08-30T08:17:27Z
[ "python", "django" ]
Django1.11 - URLconf does not appear to have any patterns
39,222,191
<p>I'm a new user of django and i have some difficulties. I follow a Django 1.8 tutorial and i have Django1.11. the problem is about urls.py files &amp; patterns</p> <p>Here my code, blog/urls.py:</p> <pre><code>from django.conf.urls import url from . import views urlpattern = [ url(r'^accueil/$', views.home, nam...
0
2016-08-30T08:15:35Z
39,222,357
<p>I think your need this page.<a href="https://docs.djangoproject.com/en/1.10/topics/http/urls/" rel="nofollow">URL dispatcher</a></p> <p>Your code is fault, I think your need to change it:</p> <pre><code>from django.conf.urls import url from . import views urlpatterns = [ url(r'^accueil/$', views.home, name='ho...
0
2016-08-30T08:25:11Z
[ "python", "django" ]
Send Email Issue - Google Compute Engine VM
39,222,288
<p>I am trying to send an Email from python code. The Code works fine when tested on my local Server. But when I deploy these changes on my Google Compute Engine VM, the Email sending stops and Connection Error starts coming.</p> <p>Error Trace:</p> <pre><code>File "/usr/local/lib/python2.7/dist-packages/django/core/...
0
2016-08-30T08:21:17Z
39,222,919
<p>You can't send mail directly from google cloud, port 587 is blocked. You're gonna have to find another solution; take a look at Mailgun.</p>
1
2016-08-30T08:55:10Z
[ "python", "django", "google-compute-engine" ]
Connecting signals to slots up the directory tree with PySide
39,222,294
<p>I am trying to separate UI components from functional code as much as I can, so my PySide is application structured like this</p> <pre><code>main.py package\ app.py __init__.py ui\ mainwindow.py __init__.py </code></pre> <p>Main is just a simple starter</p> <pre><code>if __name__ == '__mai...
0
2016-08-30T08:21:31Z
39,238,383
<p>Create a subclass for the top-level widget from Qt Designer. Using this approach, all of child widgets from Qt Designer will become attributes of the subclass:</p> <pre><code>import sys from PySide import QtCore, QtGui from ui.mainwindow import Ui_MainWindow class MainWindow(QtGui.QMainWindow, Ui_MainWindow): ...
1
2016-08-30T23:07:03Z
[ "python", "pyside", "signals-slots", "qt-designer" ]
Python split up data from print string
39,222,329
<p>This is my first post here, if my post dont follow the "standard" you know why. And iam realy new to python and programming, i am trying to learn as i go.</p> <p>I am using a script thats Controls my Husqvarna Automower</p> <p>In that script there is a line that i dont understand and i would like to change the out...
0
2016-08-30T08:23:48Z
39,225,338
<pre><code>dic_info = dict(mow.status()['mowerInfo']) mowerStatus = dic_info.get('mowerStatus') batteryPercent = dic_info.get('batteryPercent') </code></pre>
2
2016-08-30T10:42:01Z
[ "python" ]
Wikipedia table scraping using python
39,222,441
<p>I am trying to scrape tables from <a href="https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_population" rel="nofollow">wikipedia</a>. I wrote a table scrapper using tutorials available in the web which downloads table and save as pandas data frame.</p> <p>This is the code</p> <pre><code>from bs4...
0
2016-08-30T08:29:49Z
39,222,745
<p>As far as I can see, there is no such element on that page. The main table has <code>"class":"wikitable sortable"</code> but not the <code>jquery-tablesorter</code>.</p> <p>Make sure you know what element you are trying to select and check if your program sees the same elements you see, then make your selector.</p>...
0
2016-08-30T08:45:29Z
[ "python", "web-scraping", "beautifulsoup" ]
Wikipedia table scraping using python
39,222,441
<p>I am trying to scrape tables from <a href="https://en.wikipedia.org/wiki/List_of_countries_and_dependencies_by_population" rel="nofollow">wikipedia</a>. I wrote a table scrapper using tutorials available in the web which downloads table and save as pandas data frame.</p> <p>This is the code</p> <pre><code>from bs4...
0
2016-08-30T08:29:49Z
39,222,812
<p>The docs says you need to specify multiple classes like so:</p> <pre><code>soup.find("table", class_="wikitable sortable jquery-tablesorter") </code></pre> <p>Also, consider using requests instead of urllib2.</p>
0
2016-08-30T08:48:54Z
[ "python", "web-scraping", "beautifulsoup" ]
How to use Groupby with condition in Python
39,222,507
<p>I have a dataframe called merged_df_energy</p> <pre><code>merged_df_energy.info() &lt;class 'pandas.core.frame.DataFrame'&gt; Int64Index: 11232 entries, 0 to 11231 Data columns (total 17 columns): TIMESTAMP 11232 non-null datetime64[ns] P_ACT_KW 11232 non-null int64 PER...
2
2016-08-30T08:33:03Z
39,222,610
<p>I think you need before <code>groupby</code> <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow"><code>boolean indexing</code></a>:</p> <pre><code>merged_df_energy1 = merged_df_energy[merged_df_energy.PERIODE_TARIF == 'HP'] cols = ['0ACT_TIME_ETA_PRG_P2REF_RM', ...
2
2016-08-30T08:37:56Z
[ "python", "pandas", "dataframe", "group-by", "condition" ]
How to update a plot on Tkinter canvas?
39,222,641
<p>I have a tkinter app where I have different frames, each one with a different plot. I have an import function that allows me to select the data file that I want to plot.</p> <p>Right now, everything is working well if I import the file right at the start of the program, i.e. as soon as the subplot is created on the...
-1
2016-08-30T08:39:46Z
39,225,762
<p>Call the <code>draw()</code> method of the canvas.</p>
0
2016-08-30T11:03:06Z
[ "python", "matplotlib", "tkinter", "tkinter-canvas" ]
python - building a unique DB and counting the number of appearances
39,222,644
<p>Im reading a large file, where each row has 20 numbers. I want to end up with a 2D-array, where each row will be a unique row from the file, and in addition for each row I will have the number of times it appeared in the file.</p> <p>So I did this by building rowDB - a list of lists(where each sub-list is a 20 numb...
1
2016-08-30T08:39:56Z
39,223,079
<p>You could probably use <a href="https://docs.python.org/2/library/collections.html#counter-objects" rel="nofollow">Counter</a> for that, there are some good examples on the <a href="https://docs.python.org/2/library/collections.html#counter-objects" rel="nofollow">official documentation</a>.</p>
0
2016-08-30T09:01:47Z
[ "python", "arrays", "performance", "numpy", "unique" ]
python - building a unique DB and counting the number of appearances
39,222,644
<p>Im reading a large file, where each row has 20 numbers. I want to end up with a 2D-array, where each row will be a unique row from the file, and in addition for each row I will have the number of times it appeared in the file.</p> <p>So I did this by building rowDB - a list of lists(where each sub-list is a 20 numb...
1
2016-08-30T08:39:56Z
39,223,712
<p>You may use <code>tuple</code> to save each line data, and build <code>rowDB</code> using <a href="https://docs.python.org/2/library/collections.html#collections.OrderedDict" rel="nofollow">OrderedDict</a>, which maps line tuple to line number, then <code>is_uniq</code> is a simple and quick check as:</p> <pre><cod...
0
2016-08-30T09:28:32Z
[ "python", "arrays", "performance", "numpy", "unique" ]
Pandas, return df for which values of a certain column is null
39,222,718
<p>Im working from SQL code moving it to python, i have a <code>WHERE</code> condition saying where points Is <code>NULL</code></p> <p>I need to print my dataframe, data, such that the one column in question, points, contains all Null's</p> <p>eg.</p> <pre><code>name: age: points: Sean 12 3 Jack ...
1
2016-08-30T08:43:57Z
39,222,742
<p>Use <code>boolean indexing</code> if need filter where is value <code>0</code>:</p> <pre><code>df = pd.DataFrame({'points': {0: 3, 1: 0, 2: 2, 3: 0, 4: 0}, 'name': {0: 'Sean', 1: 'Jack', 2: 'Peter', 3: 'David', 4: 'Paul'}, 'age': {0: 12, 1: 14, 2: 11, 3: 16, 4: 15}}) print...
3
2016-08-30T08:45:13Z
[ "python", "sql", "pandas", "dataframe", null ]
How to secure Pybossa completely?
39,222,729
<p>I want to secure <code>/project/project1/1/results.json</code> end point of pybossa. This end point exposes our results to public without authentication.</p>
0
2016-08-30T08:44:20Z
39,243,742
<p>I'm the founder of Scifabric, the company that develops PYBOSSA. You can do that using Nginx, as PYBOSSA does not support it out of the box. PYBOSSA has been designed to be an open science/data hub, so all the data is available.</p> <p>We have a few plugins that have been developed for our customers, that specifica...
1
2016-08-31T07:51:27Z
[ "python", "crowdsourcing", "pybossa" ]
how to search for elements containing unicode/arabic letters?
39,222,991
<p>I am running the below code to find an element containing Unicode Arabic characters. The below code works just fine if I replace XXX with English letter, however, if I replace them with Arabic letters It won't. </p> <p>I checked the html page and it has "&lt; meta charset="utf-8" >" so I set the character set in my...
0
2016-08-30T08:58:13Z
39,223,201
<p>Try passing Text to be checked in <code>contains</code> (Replacement of 'XXX') from external file system like property file, excel etc. It would work. </p> <p>Whey there is 'u' before your xpath in the example you have given ? </p>
0
2016-08-30T09:07:43Z
[ "python", "selenium", "xpath", "unicode" ]
how to search for elements containing unicode/arabic letters?
39,222,991
<p>I am running the below code to find an element containing Unicode Arabic characters. The below code works just fine if I replace XXX with English letter, however, if I replace them with Arabic letters It won't. </p> <p>I checked the html page and it has "&lt; meta charset="utf-8" >" so I set the character set in my...
0
2016-08-30T08:58:13Z
39,223,652
<p>I think you are not using the correct unicode in the xpath, check the demo in <code>Ipython</code> here</p> <p>First I have selected one node to get the corresponding unicode for that arabic word, so after using that unicode modified the xpath as follows and this was the output.</p> <pre><code>In [1]: response.xp...
0
2016-08-30T09:26:20Z
[ "python", "selenium", "xpath", "unicode" ]
Python BS4 remove all div ID's Classes, Styles etc
39,223,076
<p>i'm trying to parse html content from site with BS4. I got my html fragment, but i need to remove all tags classes, ID's, styles etc. </p> <p>For example:</p> <pre><code>&lt;div class="applinks"&gt; &lt;div class="appbuttons"&gt; &lt;a href="https://geo.itunes.apple.com/ru/app/cloud-hub-file-manager-document/id972...
0
2016-08-30T09:01:41Z
39,223,223
<pre><code>import requests from bs4 import BeautifulSoup url = "https://lifehacker.ru/2016/08/29/app-store-29-august-2016/" r = requests.get(url) soup = BeautifulSoup(r.content) for tag in soup(): for attribute in ["class"]: # You can also add id,style,etc in the list del tag[attribute] </code></pre>
1
2016-08-30T09:08:43Z
[ "python", "html", "web-scraping", "tags", "beautifulsoup" ]
Python BS4 remove all div ID's Classes, Styles etc
39,223,076
<p>i'm trying to parse html content from site with BS4. I got my html fragment, but i need to remove all tags classes, ID's, styles etc. </p> <p>For example:</p> <pre><code>&lt;div class="applinks"&gt; &lt;div class="appbuttons"&gt; &lt;a href="https://geo.itunes.apple.com/ru/app/cloud-hub-file-manager-document/id972...
0
2016-08-30T09:01:41Z
39,224,931
<p>To remove all attributes from the tags in the scrapped data: </p> <pre><code>import requests from bs4 import BeautifulSoup def CleanSoup(content): for tags in content.findAll(True): tags.attrs = {} return content url = "https://lifehacker.ru/2016/08/29/app-store-29-august-2016/" r = requests.get...
0
2016-08-30T10:24:52Z
[ "python", "html", "web-scraping", "tags", "beautifulsoup" ]
SSO with Django 1.9 + djangosaml2 + ADFS 2.0
39,223,172
<p>I'm install and configure ADFS 2.0 as Idp and Django project as SP using djangosaml2. Django project deploing on IIS 7.5.</p> <p>django saml2 config:</p> <pre><code>SAML_CONFIG = { # full path to the xmlsec1 binary programm 'xmlsec_binary': 'C:\\Program Files\\xmlsec1\\xmlsec1-1.2.20-win32-x86\\bin\\xmlsec1.ex...
0
2016-08-30T09:06:13Z
39,294,970
<p>You need to send the NameID claim in the SAML assertion. Since you have not created this claim in the set of issuance rules, ADFS errors saying that the values of cl aims that it would be minting in the security token does not match the requested policy that you have configured (and sent in the SAML request). </p> ...
0
2016-09-02T14:35:53Z
[ "python", "django", "single-sign-on", "saml-2.0", "adfs2.0" ]
How to refresh text in Matplotlib?
39,223,286
<p>I wrote this code to read data from an excel file and to plot them. For a certain x-value, I desire to know the y-values of all the lines so I create a slider to change this x-value but I'm not able to refresh the text which prints the y-value.</p> <p>The code is this</p> <pre><code>import numpy as np from openpyx...
2
2016-08-30T09:11:31Z
39,228,262
<p>With matplotlib widgets, the update method works best if you create an artist object and adjust its value (like you do with <code>line</code> in your code). For a text object, you can use the <code>set_text</code> and <code>set_position</code> method to change what it displays and where. As an example,</p> <pre><co...
0
2016-08-30T13:03:02Z
[ "python", "python-3.x", "text", "matplotlib", "plot" ]
Executing vty commands in Juniper routers using PyEZ
39,223,408
<p>I have a requirement where, a <code>python</code> script running in a Juniper router shell needs to execute some commands in <code>vty</code> console of the FPC. I cannot use <code>vty ­c</code> because it may not work properly in all platforms. However, I can use <code>vty fpc0</code> and then execute the command ...
2
2016-08-30T09:16:08Z
39,223,474
<p>Using PyEZ StartShell utility we can do something like</p> <pre><code>from jnpr.junos.utils.start_shell import StartShell from jnpr.junos import Device dev = Device(host='xxxx', user='xxxx', password='xxxx') dev.open() with StartShell(dev) as ss: op = ss.run('vty fpc0', 'vty\)#') print op[1] op = ss.r...
3
2016-08-30T09:18:57Z
[ "python", "junos-automation", "pyez" ]
Executing vty commands in Juniper routers using PyEZ
39,223,408
<p>I have a requirement where, a <code>python</code> script running in a Juniper router shell needs to execute some commands in <code>vty</code> console of the FPC. I cannot use <code>vty ­c</code> because it may not work properly in all platforms. However, I can use <code>vty fpc0</code> and then execute the command ...
2
2016-08-30T09:16:08Z
39,296,260
<p>The <code>StartShell</code> class assumes the ability to make a new SSH connection to the target device using port 22. That might not always be a good assumption.</p> <p>An alternative to using <code>StartShell</code> is to use the RPC equivalent to the <code>request pfe execute</code> command. Here's an example:</...
3
2016-09-02T15:44:22Z
[ "python", "junos-automation", "pyez" ]
Pyinstaller throwing massive amount of errors yet created executable works
39,223,416
<p>Take a look at this output from the console: <a href="http://pastebin.com/Vy5BqfYL" rel="nofollow">http://pastebin.com/Vy5BqfYL</a></p> <p>My IDE is Pycharm and I'm using Pyinstaller with the single file executable. The PyInstaller is throwing massive amount of errors, yet the exe created seems to be working.</p> ...
0
2016-08-30T09:16:28Z
39,223,867
<p>Yes, you should be concerned because the binary will work for you but probably not in all targeted systems.</p> <p>The 'errors' you are reporting are warnings and not errors. Pyinstaller tells you that it can't find windows CRT. However if the binary works for you: </p> <ul> <li><p><em>probably you have the CRT in...
0
2016-08-30T09:35:25Z
[ "python", "pyinstaller", "console.log" ]
Using a list as a key to match to another
39,223,560
<p>I have 4 lists and I need to match them using the first two as a key:</p> <pre><code>keyNumbers = [3, 2, 1, 4, 5] keyLetters = ['E', 'D', 'C', 'B', 'A'] numbers = [3, 2, 4, 1, 5] letters = [] </code></pre> <p>I want it to work so that letters would be edited for It should also work with duplicated numbers or lette...
-2
2016-08-30T09:22:42Z
39,223,640
<p>Using all the four lists, you could do:</p> <pre><code>&gt;&gt;&gt; keyNumbers = [3, 2, 1, 4, 5] &gt;&gt;&gt; keyLetters = ['E', 'D', 'C', 'B', 'A'] &gt;&gt;&gt; numbers = [3, 2, 4, 1, 5] &gt;&gt;&gt; letters = [] &gt;&gt;&gt; temp = dict(zip(keyNumbers,keyLetters)) &gt;&gt;&gt; ','.join([temp[i] for i in numbers])...
0
2016-08-30T09:25:53Z
[ "python" ]
Using a list as a key to match to another
39,223,560
<p>I have 4 lists and I need to match them using the first two as a key:</p> <pre><code>keyNumbers = [3, 2, 1, 4, 5] keyLetters = ['E', 'D', 'C', 'B', 'A'] numbers = [3, 2, 4, 1, 5] letters = [] </code></pre> <p>I want it to work so that letters would be edited for It should also work with duplicated numbers or lette...
-2
2016-08-30T09:22:42Z
39,223,776
<p>You may achieve it by using <code>map</code> function:</p> <pre><code>&gt;&gt;&gt; keyNumbers = [1, 2, 3, 4, 5] &gt;&gt;&gt; keyLetters = ['E', 'D', 'C', 'B', 'A'] &gt;&gt;&gt; numbers = [3, 2, 4, 1, 5] &gt;&gt;&gt; map(lambda x: keyLetters[keyNumbers.index(x)], numbers) ['C', 'D', 'B', 'E', 'A'] </code></pre> <p>...
0
2016-08-30T09:31:11Z
[ "python" ]
Using a list as a key to match to another
39,223,560
<p>I have 4 lists and I need to match them using the first two as a key:</p> <pre><code>keyNumbers = [3, 2, 1, 4, 5] keyLetters = ['E', 'D', 'C', 'B', 'A'] numbers = [3, 2, 4, 1, 5] letters = [] </code></pre> <p>I want it to work so that letters would be edited for It should also work with duplicated numbers or lette...
-2
2016-08-30T09:22:42Z
39,223,842
<p>You can match the indexes</p> <pre><code>&gt;&gt;&gt; keyNumbers = [1, 2, 3, 4, 5] &gt;&gt;&gt; keyLetters = ['E', 'D', 'C', 'B', 'A'] &gt;&gt;&gt; numbers = [3, 2, 4, 1, 5] &gt;&gt;&gt; letters = [keyLetters[keyNumbers.index(i)] for i in numbers] &gt;&gt;&gt; letters ['C', 'D', 'B', 'E', 'A'] </code></pre>
0
2016-08-30T09:34:03Z
[ "python" ]
Using a list as a key to match to another
39,223,560
<p>I have 4 lists and I need to match them using the first two as a key:</p> <pre><code>keyNumbers = [3, 2, 1, 4, 5] keyLetters = ['E', 'D', 'C', 'B', 'A'] numbers = [3, 2, 4, 1, 5] letters = [] </code></pre> <p>I want it to work so that letters would be edited for It should also work with duplicated numbers or lette...
-2
2016-08-30T09:22:42Z
39,223,858
<p>Try this,</p> <pre><code>In [1]: zip_list = zip(keyNumbers,keyLetters) In [2]: [zip_list[i-1][1] for i in numbers] Out[1]: ['C', 'D', 'B', 'E', 'A'] </code></pre>
0
2016-08-30T09:34:56Z
[ "python" ]
Using a list as a key to match to another
39,223,560
<p>I have 4 lists and I need to match them using the first two as a key:</p> <pre><code>keyNumbers = [3, 2, 1, 4, 5] keyLetters = ['E', 'D', 'C', 'B', 'A'] numbers = [3, 2, 4, 1, 5] letters = [] </code></pre> <p>I want it to work so that letters would be edited for It should also work with duplicated numbers or lette...
-2
2016-08-30T09:22:42Z
39,225,458
<p>You can use this -></p> <pre><code>keyNumbers = [3, 2, 1, 4, 5] keyLetters = ['E', 'D', 'C', 'B', 'A'] numbers = [3, 2, 4, 1, 5] x=dict() for i,j in enumerate(keyNumbers): x[j]=keyLetters[i] y = [x[i] for i in numbers] print ','.join(y) </code></pre>
0
2016-08-30T10:47:58Z
[ "python" ]
Pandas : Delete rows based on other rows
39,223,638
<p>I have a pandas dataframe which looks like that :</p> <pre><code>qseqid sseqid qstart qend 2 1 125 345 4 1 150 320 3 2 150 450 6 2 25 300 8 2 50 500 </code></pre> <p>I would like to remove rows based on other rows valu...
6
2016-08-30T09:25:46Z
39,225,130
<pre><code>df = pd.DataFrame({'qend': [345, 320, 450, 300, 500], 'qseqid': [2, 4, 3, 6, 8], 'qstart': [125, 150, 150, 25, 50], 'sseqid': [1, 1, 2, 2, 2]}) def remove_rows(df): merged = pd.merge(df.reset_index(), df, on='sseqid') mask = ((merged['qstart_x'] &gt; merged['qstart_y']) &amp; (merge...
6
2016-08-30T10:33:11Z
[ "python", "pandas", "dataframe" ]
Should I import flask.ext.sqlalchemy or flask_sqlalchemy?
39,223,807
<p>When I learned Flask, I found some examples used <code>flask.ext.sqlalchemy</code> and some used <code>flask_sqlalchemy</code>. Which one should be used?</p>
0
2016-08-30T09:32:25Z
39,225,099
<p><a href="http://flask.pocoo.org/docs/0.11/extensiondev/" rel="nofollow">Flask Extension Development</a> guide says:</p> <blockquote> <p>As of Flask 0.11, most Flask extensions have transitioned to the new naming schema. The flask.ext.foo compatibility alias is still in Flask 0.11 but is now deprecated – you...
2
2016-08-30T10:31:44Z
[ "python", "flask", "flask-sqlalchemy" ]
Memory management in numpy arrays,python
39,223,838
<p>I get a memory error when processing very large(>50Gb) file (problem: RAM memory gets full).</p> <p>My solution is: I would like to read only 500 kilo bytes of data once and process( and delete it from memory and go for next 500 kb). Is there any other better solution? or If this solution seems better , how to do i...
1
2016-08-30T09:33:50Z
39,224,171
<h2>Quick answer</h2> <ul> <li><a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.memmap.html" rel="nofollow">Numpuy.memmap</a> allows presenting a large file on disk as a numpy array. Don't know if it allows mapping files larger than RAM+swap though. Worth a shot.</li> <li>[Presentation about out-of-m...
1
2016-08-30T09:48:44Z
[ "python", "arrays", "numpy", "memory" ]
Delete string in between special characters in python
39,223,859
<p>I have string something like this</p> <pre><code>mystring = "CBS Network Radio Panel;\ntitle2 New York OCT13W4, Panel Weighting;\n*options; mprint ls=max mprint;\n\n****************************************out; asd; ***hg;" </code></pre> <p>I want to delete the string between * and ; output should be</p> <pre><cod...
1
2016-08-30T09:34:58Z
39,223,919
<p>You may use</p> <pre><code>re.sub(r'\*[^;]*;', '', mystring) </code></pre> <p>See the <a href="https://ideone.com/Sq2jWS" rel="nofollow">Python demo</a>:</p> <pre><code>import re mystring = "CBS Network Radio Panel;\ntitle2 New York OCT13W4, Panel Weighting;\n*options; mprint ls=max mprint;\n\n*******************...
3
2016-08-30T09:37:32Z
[ "python", "regex" ]
How to read a file whose name includes '/' in python?
39,223,881
<p>Now I have a file named <code>Land/SeaMask</code> and I want to open it, but it cannot be recognized as a filename by programme, but as a directory, how to do it?</p>
-1
2016-08-30T09:35:57Z
39,225,526
<p>First of all I recommend you to find out how Python interpreter displays yours file name. You can do this simply using <a href="https://docs.python.org/2/library/os.html#os.listdir" rel="nofollow"><code>os</code> built-in module</a>: </p> <pre><code>import os os.listdir('path/to/directory') </code></pre> <p>You'll...
3
2016-08-30T10:51:23Z
[ "python", "file" ]
Need Consumer and Producer with duplicate filter python
39,223,923
<p>I have a script which send requests to social media site by doing following:</p> <p>It first scrapes the friends of the account inserted. It then continues to scrape all friends of the accounts found forever (Similar to how search engine crawlers work). Add them to a consumer queue which then adds them as a friend ...
0
2016-08-30T09:37:52Z
39,224,359
<p>Python also includes a data type for sets. A set is an unordered collection with no duplicate elements. Note: to create an empty set you have to use </p> <pre><code>set() </code></pre> <p>There is an ordered set recipe for this which is referred to from the Python 2 Documentation <a href="http://code.activestate....
0
2016-08-30T09:56:53Z
[ "python" ]
How SCons hardlinks sources in variant directory?
39,223,937
<p>I tested SCons default hardlink behavior. </p> <p>I am expecting that a modification in the hardlinked file in the variant dir is reflected also in the original file. But this doesn't happen.</p> <p>Is hardlinking really a default behavior as stated in SCons doc or it is just copying the files in the variant direc...
0
2016-08-30T09:38:32Z
39,229,122
<p>As stated in the corresponding <a href="https://docs.python.org/2/library/os.html?highlight=os.link#os.link" rel="nofollow">Python reference docs</a>, the underlying <code>os.link</code> method, that SCons tries to find and use internally to create hard links, is not available under Windows. The same holds true for ...
1
2016-08-30T13:39:16Z
[ "python", "scons" ]
Python - Reading line by line from file to Tkinter Text
39,224,328
<p>I decided I want to do some GUI programming with Python Tkinter,and I wanted to start with a Text Editor.I've written some code and everything seems to be looking fine but I have trouble inserting text to the Text widget.It doesn't insert all lines just a few.Anyone seems to know the answer?I'm starting with Tkinter...
-1
2016-08-30T09:55:36Z
39,226,463
<p>I fixed it.The thing was that the height was too big.I changed:<br> <code>textBox.place(x=16,y=16,height=684,width=650)</code><br> to<br> <code>textBox.place(x=16,y=16,height=580)</code><br> and everything went fine.Just as expected.</p>
0
2016-08-30T11:36:15Z
[ "python", "python-2.7", "tkinter", "textbox" ]
"Push" attribute from decorator to decorated function in Python
39,224,335
<p>Some basic question from beginner. Is there a way to "push" attribute to a decorated function not using function arguments ?</p> <pre><code>import sys from functools import wraps def decorator_(func): @wraps(func) def newfunc(): func.some_attr = 'some_attr' func() return newfunc @deco...
0
2016-08-30T09:55:58Z
39,224,462
<p>Depending on whether you use Python 2 or 3 you can inject variables into the <code>globals</code> of a function like this:</p> <h3>Python 2</h3> <pre><code>func.func_globals["some_attr"] = "some_value" </code></pre> <h3>Python 3</h3> <pre><code>func.__globals__["some_attr"] = "some_value" </code></pre>
0
2016-08-30T10:02:08Z
[ "python", "decorator" ]
"Push" attribute from decorator to decorated function in Python
39,224,335
<p>Some basic question from beginner. Is there a way to "push" attribute to a decorated function not using function arguments ?</p> <pre><code>import sys from functools import wraps def decorator_(func): @wraps(func) def newfunc(): func.some_attr = 'some_attr' func() return newfunc @deco...
0
2016-08-30T09:55:58Z
39,224,479
<p>If you set the attribute on <code>new_func</code> instead, you can access it simply as <code>decorated_function.some_attr</code>:</p> <pre><code>def decorator_(func): @wraps(func) def newfunc(): newfunc.some_attr = 'some_attr' func() return newfunc @decorator_ def decorated_function(): ...
0
2016-08-30T10:03:05Z
[ "python", "decorator" ]
Extracting information from a large specific header formatted file
39,224,453
<p>I am new to python. I have a large header formatted input file where header line starts with '>'. My file is like :</p> <pre><code>&gt;NC_23689 # # XYZ # Copyright (c) BLASC # # Predicted binding regions # No. Start End Length # 1 1 25 25 # 2...
0
2016-08-30T10:01:36Z
39,225,119
<p>Try this:</p> <pre><code>with open("file.txt") as f: first_time = True for line in f: line = line.rstrip() if line.startswith("&gt;"): if not first_time: if start_ends: print("{}: {}".format(header,", ".join(start_ends))) el...
0
2016-08-30T10:32:49Z
[ "python" ]
Python requests returns “cannot connect to proxy & error 10061”
39,224,501
<p>I have developed a desktop client using PyQt4, it connect to my web service by <a href="http://www.python-requests.org/en/master/" rel="nofollow">requests</a> lib. You know, <a href="http://www.python-requests.org/en/master/" rel="nofollow">requests</a> maybe one of the most useful http client, I think it should be ...
0
2016-08-30T10:04:13Z
39,280,225
<p>I notice there is a white space in URL, is that correct? I tested in my ipython with requests.. that the response was:</p> <pre><code>{ "timestamp": 1472760770, "success": true } </code></pre> <p>For HTTP and HTTPS.</p>
0
2016-09-01T20:17:19Z
[ "python", "tcp", "connection", "python-requests" ]
Matplotlib PatchCollection to Legend
39,224,611
<p>Currently, I am trying to make my own custom legend handler by creating a proxy artist (?) patch using PatchCollections and then following <a href="http://matplotlib.org/users/legend_guide.html" rel="nofollow">http://matplotlib.org/users/legend_guide.html</a> to make a custom handler.</p> <p>However I am running in...
0
2016-08-30T10:09:08Z
39,225,101
<p>From the example in this <a href="http://matplotlib.org/users/legend_guide.html#implementing-a-custom-legend-handler" rel="nofollow">section</a>, it looks like you need to define an object and express all coordinates in terms of the handlebox size,</p> <pre><code>import numpy as np import matplotlib.pyplot as plt i...
1
2016-08-30T10:31:51Z
[ "python", "matplotlib" ]
Ending script with if statement
39,224,706
<p>I'm very new to Python and want to know how to end a program with an if statement that prints a message, as this does not appear to be happening with my 'stand' variable when it is under &lt; 5000. The if statement bolded ** ** is the code I'm having trouble with and it still prints the message I want, however, the...
0
2016-08-30T10:14:14Z
39,224,794
<p>Use <code>break</code> to exit the loop.</p> <pre><code>if stand &gt; 0 or stand &lt; 5000: print("ERROR, ERROR") print("Launch cannot begin, the Mission Control and spectator stands are dangerously close at a distance of {}m.".format(mission)) break </code></pre> <p>Use <code>exit</code> to exit th...
1
2016-08-30T10:18:35Z
[ "python", "variables", "if-statement", "while-loop" ]
Ending script with if statement
39,224,706
<p>I'm very new to Python and want to know how to end a program with an if statement that prints a message, as this does not appear to be happening with my 'stand' variable when it is under &lt; 5000. The if statement bolded ** ** is the code I'm having trouble with and it still prints the message I want, however, the...
0
2016-08-30T10:14:14Z
39,224,830
<p>You can put your code in function. A function you can return the different values. While Calling the function you can check what function is returning. You can use if condition like </p> <pre><code>def func1(): while stand &lt;= 0 or mission &gt; 10000: try: stand = int(input("...
0
2016-08-30T10:20:27Z
[ "python", "variables", "if-statement", "while-loop" ]
Ending script with if statement
39,224,706
<p>I'm very new to Python and want to know how to end a program with an if statement that prints a message, as this does not appear to be happening with my 'stand' variable when it is under &lt; 5000. The if statement bolded ** ** is the code I'm having trouble with and it still prints the message I want, however, the...
0
2016-08-30T10:14:14Z
39,225,176
<p>We can use break statement inside if statement for termination. Instead of break we can write os.exit or sys.exit</p> <p>os._exit calls the C function _exit() which does an immediate program termination. Note the statement "can never return".</p> <p>sys.exit() is identical to raise SystemExit(). It raises a Python...
0
2016-08-30T10:35:31Z
[ "python", "variables", "if-statement", "while-loop" ]
How to assert operators < and >= are not implemented?
39,224,762
<p>Initially I was not using the <code>unittest</code> framework, so to test that two objects of the same class are not comparable using the operators <code>&lt;</code> and <code>&gt;=</code> I did something like:</p> <pre><code>try: o1 &lt; o2 assert False except TypeError: pass </code></pre> <p>after th...
2
2016-08-30T10:17:08Z
39,224,917
<p>Use <a href="https://docs.python.org/3/library/unittest.html#unittest.TestCase.assertRaises" rel="nofollow"><code>assertRaises</code></a> as a context manager:</p> <pre><code>with self.assertRaises(TypeError): o1 &lt; o2 </code></pre> <p><a href="http://effbot.org/zone/python-with-statement.htm" rel="nofollow"...
5
2016-08-30T10:24:15Z
[ "python", "unit-testing", "python-3.x", "exception", "python-unittest" ]
Eficient way to split a bytes array then convert it to string in Python
39,224,764
<p>I have a numpy bytes array containing characters, followed by <code>b''</code>, followed by others characters (including weird characters which raise Unicode errors when decoding):</p> <pre><code>bytes = numpy.array([b'f', b'o', b'o', b'', b'b', b'a', b'd', b'\xfe', b'\x95', b'', b'\x80', b'\x04', b'\x08' b'\x06'])...
2
2016-08-30T10:17:14Z
39,225,909
<p>I like your way, it is explicit, the <code>for</code> loop is understandable by all and it isn't all that slow compared to other approaches.</p> <p>Some suggestions I'd make would be to change your condition from <code>if c != b''</code> to <code>if c</code> since a non-empty byte object will be truthy and, *don't ...
4
2016-08-30T11:10:30Z
[ "python", "python-3.x", "numpy", "split" ]
Shared numpy array with multithreading
39,224,780
<p>I have a numpy array(matrix), which I want to fill with calculated values in asynchronously. As a result, I want to have matrix distances with calculated values, but at the end I receive matrix filled with default(-1) value. I understand, that something wrong with sharing distances between threads, but I can't figur...
0
2016-08-30T10:18:04Z
39,224,918
<p>You are using a <code>ProcessPoolExecutor</code>. This will fork new processes for performing work. These processes will not share memory, each instead getting a copy of the <code>distances</code> matrix.</p> <p>Thus any changes to their <em>copy</em> will certainly not be reflected in the original process.</p> ...
0
2016-08-30T10:24:16Z
[ "python", "multithreading" ]
Using poppler to extract annotations. g_free() / get_color() issue
39,224,812
<p>I borrowed this python code <a href="http://stackoverflow.com/questions/1106098/parse-annotations-from-a-pdf">here</a> (first answer by enno groper) to automate the extraction of annotations from pdfs. </p> <p>I want to make some modifications to the code. Trying to fetch the color of annotations with <code>annot_m...
0
2016-08-30T10:19:29Z
39,896,977
<p><code>annot_mapping.annot.get_color()</code> gives you a PopplerColor, which is a structure with three members (of type guint16): red, green, and blue. For example:</p> <pre><code>PopplerColor *color = poppler_annot_get_color (annot); g_printf ("%d\n", color-&gt;red); </code></pre> <p>gives you the red value of yo...
0
2016-10-06T13:11:50Z
[ "python", "pdf", "annotations", "poppler" ]
printing corresponding item in list to another list containing numbers
39,224,866
<p>My problem is this. These are the two lists</p> <pre><code>codes = ['a', 'b', 'c', 'a', 'e', 'f', 'g', 'a', 'i', 'j', 'a', 'l'] pas = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] </code></pre> <p>How would I find the position of all the 'a' in the codes list. And then print out the corresponding item in the pas list. ...
0
2016-08-30T10:22:01Z
39,224,933
<p>There are many ways to achieve it. Your example lists are:</p> <pre><code>&gt;&gt;&gt; codes = ['a', 'b', 'c', 'a', 'e', 'f', 'g', 'a', 'i', 'j', 'a', 'l'] &gt;&gt;&gt; pas = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] </code></pre> <p><strong>Approach 1:</strong> Using <code>enumerate</code>:</p> <pre><code>&gt;&gt;...
1
2016-08-30T10:24:56Z
[ "python", "list" ]
printing corresponding item in list to another list containing numbers
39,224,866
<p>My problem is this. These are the two lists</p> <pre><code>codes = ['a', 'b', 'c', 'a', 'e', 'f', 'g', 'a', 'i', 'j', 'a', 'l'] pas = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] </code></pre> <p>How would I find the position of all the 'a' in the codes list. And then print out the corresponding item in the pas list. ...
0
2016-08-30T10:22:01Z
39,224,944
<pre><code>&gt;&gt;&gt; pas = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] &gt;&gt;&gt; codes = ['a', 'b', 'c', 'a', 'e', 'f', 'g', 'a', 'i', 'j', 'a', 'l'] &gt;&gt;&gt; result = sorted(i for i,j in zip(pas,codes) if j=='a') &gt;&gt;&gt; for i in result: ... print i ... 1 4 8 11 </code></pre>
4
2016-08-30T10:25:25Z
[ "python", "list" ]
printing corresponding item in list to another list containing numbers
39,224,866
<p>My problem is this. These are the two lists</p> <pre><code>codes = ['a', 'b', 'c', 'a', 'e', 'f', 'g', 'a', 'i', 'j', 'a', 'l'] pas = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] </code></pre> <p>How would I find the position of all the 'a' in the codes list. And then print out the corresponding item in the pas list. ...
0
2016-08-30T10:22:01Z
39,225,198
<p>Just added another way to use numpy:</p> <pre><code>import numpy as np codes = np.array(['a', 'b', 'c', 'a', 'e', 'f', 'g', 'a', 'i', 'j', 'a', 'l']) pas = np.array([1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12]) index = np.where(codes=='a') values = pas[index] In [122]: print(values) [ 1 4 8 11] </code></pre>
0
2016-08-30T10:36:30Z
[ "python", "list" ]
printing corresponding item in list to another list containing numbers
39,224,866
<p>My problem is this. These are the two lists</p> <pre><code>codes = ['a', 'b', 'c', 'a', 'e', 'f', 'g', 'a', 'i', 'j', 'a', 'l'] pas = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] </code></pre> <p>How would I find the position of all the 'a' in the codes list. And then print out the corresponding item in the pas list. ...
0
2016-08-30T10:22:01Z
39,226,306
<pre><code>codes = ['a', 'b', 'c', 'a', 'e', 'f', 'g', 'a', 'i', 'j', 'a', 'l'] pas = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12] [pas[index] for index, element in enumerate(codes) if element == "a"] </code></pre>
0
2016-08-30T11:28:47Z
[ "python", "list" ]
How to set output for logging.handlers.SysLogHandler in YAML file in python
39,224,892
<p>I have following config file:</p> <pre><code>[loggers] keys=MYLogger [handlers] keys=fileHandler,streamHandler,sysHandler [formatters] keys=simpleFormatter [logger_MYLogger] level=INFO handlers=fileHandler qualname=MYLogger propagate=0 [handler_fileHandler] class=FileHandler formatter=simpleFormatter args=('myl...
1
2016-08-30T10:23:31Z
39,243,542
<p>The logging <a href="https://docs.python.org/3/library/logging.config.html#dictionary-schema-details" rel="nofollow">dictionary schema details</a> have the following to say about handlers:</p> <pre><code>handlers - the corresponding value will be a dict in which each key is a handler id and each value is a dict de...
0
2016-08-31T07:41:29Z
[ "python", "logging", "yaml", "syslog" ]
Send scapy packets through raw sockets in python
39,225,108
<p>Is it possible? If yes? How?</p> <p>This is my script (it doesn't work):</p> <pre><code>from scapy.all import * import socket try: s = socket.socket(socket.AF_INET, socket.SOCK_STREAM) p=IP(dst="192.168.1.254")/TCP(flags="S", sport=RandShort(), dport=80) s.connect(("192.168.1.254",80)) s.send(p) ...
2
2016-08-30T10:32:18Z
39,227,739
<p>To send a scapy packet using raw sockets you have to convert your packet to raw bytes first. For example a packet crafted using scapy like this:</p> <pre><code>p = IP(dst="192.168.1.254")/TCP(flags="S", sport=RandShort(),dport=80) </code></pre> <p>should be converted to raw bytes with <code>bytes(p)</code>. This w...
2
2016-08-30T12:37:50Z
[ "python", "sockets", "python-3.x", "scapy" ]
HTMLParser and BeautifulSoup not decoding HTML entities correctly
39,225,208
<p>I am trying to decode <code>HTML entities</code> from a section of <code>HTML</code> source code with both <code>HTMLParser</code> and <code>BeautifulSoup</code> </p> <p>However neither seems to work completely. Namely they don't decode slashes.</p> <p>My Python version is <code>2.7.11</code> with <code>BeautifulS...
0
2016-08-30T10:36:44Z
39,247,147
<p>Are you trying to decode the slashes from the url or the url's html?</p> <p>If you re trying to decode the slashes, they are not <a href="https://dev.w3.org/html5/html-author/charref" rel="nofollow">HTML entities</a>, but percent-encoded characters.</p> <p><code>urllib</code> has the method you need:</p> <pre><co...
0
2016-08-31T10:29:41Z
[ "python", "beautifulsoup", "html-entities", "html-parser" ]
python code- function does not work for arithmatic quiz and password does not work
39,225,244
<p>Please could I have some help with my code, as the function does not work for the <code>NumberError()</code> The point is that if when answering the maths quiz you type in a letter by mistake, it will say 'PLEASE TYPE IN A NUMBER', however I cannot get it to work as an error keeps coming up:</p> <pre><code>Tracebac...
0
2016-08-30T10:38:05Z
39,226,396
<p>You could test the input type rather than casting it as an int</p> <pre><code>i = input("Please answer the question: ") if(not type(i) is int): print('Please enter a NUMBER.') </code></pre>
1
2016-08-30T11:32:50Z
[ "python" ]
Why is ctypes so slow to convert a Python list to a C array?
39,225,263
<p>The bottleneck of my code is currently a conversion from a Python list to a C array using ctypes, as described <a href="http://stackoverflow.com/questions/4145775/how-do-i-convert-a-python-list-into-a-c-array-by-using-ctypes">in this question</a>.</p> <p>A small experiment shows that it is indeed very slow, in comp...
8
2016-08-30T10:38:40Z
39,225,698
<p>While this is not a definitive answer, the problem seems to be the constructor call with <code>*t</code>. Doing the following instead, decreases the overhead significantly:</p> <pre><code>array = (ctypes.c_uint32 * len(t))() array[:] = t </code></pre> <p>Test:</p> <pre><code>import timeit setup="from array impor...
3
2016-08-30T10:59:48Z
[ "python", "performance", "ctypes" ]
Why is ctypes so slow to convert a Python list to a C array?
39,225,263
<p>The bottleneck of my code is currently a conversion from a Python list to a C array using ctypes, as described <a href="http://stackoverflow.com/questions/4145775/how-do-i-convert-a-python-list-into-a-c-array-by-using-ctypes">in this question</a>.</p> <p>A small experiment shows that it is indeed very slow, in comp...
8
2016-08-30T10:38:40Z
39,231,670
<p>The solution is to use the <code>array</code> module and cast the address or use the from_buffer method...</p> <pre><code>import timeit setup="from array import array; import ctypes; t = [i for i in range(1000000)];" print(timeit.timeit(stmt="v = array('I',t);assert v.itemsize == 4; addr, count = v.buffer_info();p ...
2
2016-08-30T15:33:01Z
[ "python", "performance", "ctypes" ]
How do I replace the contents of a HTML document with random text using BeautifulSoup?
39,225,299
<p>Here is code that I've written.</p> <pre><code> from bs4 import BeautifulSoup import urllib import string, random def readHtml(): sock = urllib.urlopen('1041956_Page1.htm') soup = BeautifulSoup(sock,'html.parser') paraTags = soup.find_all('p') for para in paraTags: if(para.get_text() is ...
0
2016-08-30T10:40:11Z
39,225,434
<p>I am not sure but have you considered the case in which</p> <pre><code>&lt;p&gt;&lt;/p&gt; </code></pre> <p>is empty.</p> <p>So,</p> <pre><code>para.get_text() </code></pre> <p>will return None.</p>
0
2016-08-30T10:46:43Z
[ "python", "html", "python-2.7", "beautifulsoup" ]
How do I replace the contents of a HTML document with random text using BeautifulSoup?
39,225,299
<p>Here is code that I've written.</p> <pre><code> from bs4 import BeautifulSoup import urllib import string, random def readHtml(): sock = urllib.urlopen('1041956_Page1.htm') soup = BeautifulSoup(sock,'html.parser') paraTags = soup.find_all('p') for para in paraTags: if(para.get_text() is ...
0
2016-08-30T10:40:11Z
39,225,977
<p>Your <code>randomizeText()</code> isn't returning anything i.e. <code>None</code>. Make it:</p> <pre><code>def randomizeText(text): length = len(text) newWord = ''.join(random.choice(string.lowercase) for x in range(length)) print newWord return newWord </code></pre> <p>and <code>replace_with</cod...
1
2016-08-30T11:13:57Z
[ "python", "html", "python-2.7", "beautifulsoup" ]
How to extract and encode data of text file in Python 2.7?
39,225,320
<p>I know it's been asked a lot and I tried some things but I can't make it right:</p> <p>I have a text file like this:</p> <pre><code>From: VENCA &lt;email@infoclientes.venca.es&gt; Subject: =?ISO-8859-1?Q?=BFMaxi,_midi_o_mini=3F_=A1No_pases_d?= =?ISO-8859-1?Q?e_largo_porque_esto_te_interesa!?= Subject: =?UTF-8?Q?L...
2
2016-08-30T10:41:19Z
39,227,411
<pre><code>with open('infile.txt') as infile: try: while True: line1 = next(infile).rstrip() line2 = next(infile).rstrip() if line2.startswith('From:'): line1, line2 = line2, line1 print line1, '-', line2 except StopIteration: pa...
0
2016-08-30T12:24:15Z
[ "python", "python-2.7", "utf-8", "decode", "encode" ]
Read data from one csv and create another modified csv file
39,225,482
<p>I have a csv file called ipValues.csv which contains the following data:</p> <pre><code>IPs Values 192.168.1.231 c3s8b1p1 c3s8b1p2 c3s4b1p3 192.168.1.179 c1s1b1p1 c1s1b1p2 c1s3b1p1 c3s2b1p2 c3s2b1p3 192.168.1.195 c1s1b2p8 192.168.1.162 c1s4b7p8 c1s1...
-1
2016-08-30T10:49:13Z
39,226,443
<p>The following should get you started and help explain how to do things for use on a small file:</p> <pre><code>import csv with open('ipValues.csv', 'rb') as f_input, open('output.csv', 'wb') as f_output: csv_input = csv.reader(f_input) csv_output = csv.writer(f_output) next(csv_input) # skip heade...
1
2016-08-30T11:35:02Z
[ "python", "csv" ]
How to group list with index wise?
39,225,495
<p>I have a list of list where i need to group elements by using user input ( see <code>split</code> variable in code ) and create new list. I have tried but instead of grouping, elements are concatenated separately </p> <pre><code>split = 3 # user input data = [[1,2], [3,4], [5,6], [7,8], [9,10], [11,12], [13,14], [...
2
2016-08-30T10:49:35Z
39,225,615
<p>Using numpy:</p> <pre><code>data = [[1,2], [3,4], [5,6], [7,8], [9,10], [11,12], [13,14], [15,16], [17,18]] import numpy as np print np.array(data).reshape((split,-1)).tolist() </code></pre> <p>Output:</p> <pre><code>[[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12], [13, 14, 15, 16, 17, 18]] </code></pre>
2
2016-08-30T10:55:51Z
[ "python", "list", "group" ]
How to group list with index wise?
39,225,495
<p>I have a list of list where i need to group elements by using user input ( see <code>split</code> variable in code ) and create new list. I have tried but instead of grouping, elements are concatenated separately </p> <pre><code>split = 3 # user input data = [[1,2], [3,4], [5,6], [7,8], [9,10], [11,12], [13,14], [...
2
2016-08-30T10:49:35Z
39,225,635
<p>You can try this -></p> <pre><code>split = 3 data = [[1,2], [3,4], [5,6], [7,8], [9,10], [11,12], [13,14], [15,16], [17,18]] z=[] x=[] for i,j in enumerate(data): if i!=0 and i%split==0: z.append(x) x=[] for k in j: x.append(k) z.append(x) print z </code></pre>
1
2016-08-30T10:57:04Z
[ "python", "list", "group" ]
How to group list with index wise?
39,225,495
<p>I have a list of list where i need to group elements by using user input ( see <code>split</code> variable in code ) and create new list. I have tried but instead of grouping, elements are concatenated separately </p> <pre><code>split = 3 # user input data = [[1,2], [3,4], [5,6], [7,8], [9,10], [11,12], [13,14], [...
2
2016-08-30T10:49:35Z
39,225,651
<p>Here is one way using list comprehension:</p> <pre><code>&gt;&gt;&gt; sp = 3 &gt;&gt;&gt; fragment = len(data)//sp &gt;&gt;&gt; [[t for item in data[i:i+fragment] for t in item] for i in range(0, len(data), fragment)] [[1, 2, 3, 4, 5, 6], [7, 8, 9, 10, 11, 12], [13, 14, 15, 16, 17, 18]] </code></pre> <p>And here i...
3
2016-08-30T10:57:49Z
[ "python", "list", "group" ]
How to group list with index wise?
39,225,495
<p>I have a list of list where i need to group elements by using user input ( see <code>split</code> variable in code ) and create new list. I have tried but instead of grouping, elements are concatenated separately </p> <pre><code>split = 3 # user input data = [[1,2], [3,4], [5,6], [7,8], [9,10], [11,12], [13,14], [...
2
2016-08-30T10:49:35Z
39,225,669
<p>you can just use <code>z.extend(d)</code> instead of <code>append</code></p>
0
2016-08-30T10:58:38Z
[ "python", "list", "group" ]
How to group list with index wise?
39,225,495
<p>I have a list of list where i need to group elements by using user input ( see <code>split</code> variable in code ) and create new list. I have tried but instead of grouping, elements are concatenated separately </p> <pre><code>split = 3 # user input data = [[1,2], [3,4], [5,6], [7,8], [9,10], [11,12], [13,14], [...
2
2016-08-30T10:49:35Z
39,225,752
<p>You can do this in basic Python like this:</p> <pre><code>import itertools flatlist = [*itertools.chain(*data)] groupsize = int(len(flatlist) / split) data2 = [flatlist[i:i+groupsize] for i in range(0, len(flatlist), groupsize)] print(data2) </code></pre> <p>And the output is</p> <pre><code>[[1, 2, 3, 4, 5, 6], ...
3
2016-08-30T11:02:45Z
[ "python", "list", "group" ]
pdf_multivariate_gauss() function in Python
39,225,650
<p>Which are the necessary modules for execution of the function pdf_multivariate_gauss() in IPython? </p> <p>I try to execute the below code but i get errors like "Import Error" and "Name Error".</p> <p><strong><em>Code:</em></strong></p> <pre><code>import numpy as np from matplotlib import pyplot as plt from matpl...
-2
2016-08-30T10:57:47Z
39,226,973
<p>As far as I can tell, there is no such thing as pdf_multivariate_gauss (as pointed out already). There is a python implementation of this in <code>scipy</code>, however: <a href="http://docs.scipy.org/doc/scipy-0.18.0/reference/generated/scipy.stats.multivariate_normal.html" rel="nofollow">scipy.stats.multivariate_n...
1
2016-08-30T12:02:13Z
[ "python", "numpy", "matplotlib", "scipy", "ipython" ]
OLA API Integration giving error as invalid partner key
39,225,859
<p>I wanted to use OLA APIs for my project. So I followed the <a href="https://developers.olacabs.com/docs/overview" rel="nofollow">official docs</a> of OLA and tried something as follow using python requests. This request expects response for ride estimate from source to destination.</p> <pre><code>import requests ...
2
2016-08-30T11:08:06Z
39,592,477
<p>You need to use the following url while testing(sandbox):</p> <p><a href="http://sandbox-t.olacabs.com/v1/products" rel="nofollow">http://sandbox-t.olacabs.com/v1/products</a></p>
1
2016-09-20T11:07:22Z
[ "android", "python", "api" ]
How to convert hex string into Japanese and write it to the file in Python 2.7?
39,225,973
<p>I am trying to convert a hex string into Japanese(codec: SHIFT-JIS) and write the Japanese output to a file using Python 2.7. However, all I have got is the original hex string in the file. Can someone tell me where I did wrong? Here is the code I use:</p> <pre><code>fd = open(path,'w') temp_str ='\x8d\xc5\x82\xe0\...
0
2016-08-30T11:13:45Z
39,226,333
<p>The string seems to be encoded in UTF-16BE:</p> <pre><code>&gt;&gt;&gt; print temp_str.decode('utf_16_be') 跅苠趂譍苈覤苅芠苁芽芼腶老 </code></pre> <p>But it also seems malformed, ie, it was cut halfway. You should first convert the string to Unicode by decoding the bytes:</p> <pre><code>uni_str = te...
1
2016-08-30T11:30:04Z
[ "python", "python-2.7" ]
How to convert hex string into Japanese and write it to the file in Python 2.7?
39,225,973
<p>I am trying to convert a hex string into Japanese(codec: SHIFT-JIS) and write the Japanese output to a file using Python 2.7. However, all I have got is the original hex string in the file. Can someone tell me where I did wrong? Here is the code I use:</p> <pre><code>fd = open(path,'w') temp_str ='\x8d\xc5\x82\xe0\...
0
2016-08-30T11:13:45Z
39,226,418
<p>Maybe you should open file in "wb" instead "w" mode?</p>
1
2016-08-30T11:33:47Z
[ "python", "python-2.7" ]
issue while installing python module (pbr)
39,225,976
<p>I just deiscover CKAn and I am trying to install it on a Ubuntu 14.04. I install it from source.</p> <p>AT a step we have to install the Python module that CKAn requires.</p> <pre><code>pip install -r /usr/lib/ckan/default/src/ckan/requirements.txt </code></pre> <p>I first got an error</p> <blockquote> <p>Comm...
0
2016-08-30T11:13:51Z
39,279,800
<p>I ran into this same error trying to install something else with pip (<code>httplib2.ca_certs_locater-0.2.0</code> IIRC).</p> <p>My issue turned out to be caused by a really old version of <code>pbr</code>, which happened to be the same as the one that's blowing up for you - 0.11.0. In my case, I had what I can on...
0
2016-09-01T19:49:21Z
[ "python", "pip", "ckan" ]
issue while installing python module (pbr)
39,225,976
<p>I just deiscover CKAn and I am trying to install it on a Ubuntu 14.04. I install it from source.</p> <p>AT a step we have to install the Python module that CKAn requires.</p> <pre><code>pip install -r /usr/lib/ckan/default/src/ckan/requirements.txt </code></pre> <p>I first got an error</p> <blockquote> <p>Comm...
0
2016-08-30T11:13:51Z
39,341,117
<p>This worked for me:</p> <ol> <li><p>Uninstall the previous pbr version via <code>pip uninstall pbr</code>.</p></li> <li><p>Removed the version from the requirements file: <code>/usr/lib/ckan/default/src/ckan/requirements.txt</code> this line <code>pbr==0.11.0</code> by this line <code>pbr</code></p></li> <li><p>Ins...
0
2016-09-06T05:16:18Z
[ "python", "pip", "ckan" ]
how to convert header row into new columns in python pandas?
39,226,024
<p>I am having following dataframe:</p> <pre><code>A,B,C 1,2,3 </code></pre> <p>I have to convert above dataframe like following format:</p> <pre><code>cols,vals A,1 B,2 c,3 </code></pre> <p>How to create column names as a new column in pandas?</p>
1
2016-08-30T11:16:30Z
39,226,046
<p>You can transpose by <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.T.html" rel="nofollow"><code>T</code></a>:</p> <pre><code>import pandas as pd df = pd.DataFrame({'A': {0: 1}, 'C': {0: 3}, 'B': {0: 2}}) print (df) A B C 0 1 2 3 print (df.T) 0 A 1 B 2 C 3 df1 = df...
1
2016-08-30T11:17:51Z
[ "python", "python-2.7", "pandas", "dataframe", "transpose" ]
Tkinter new windows won't close properly
39,226,126
<p>I want my GUI to have a 'new window' option that will be just the same as the first one.</p> <p>The problem is that it also has an exit(quit) button that won't work as it should - whenever I open the new window and then press the button, in the first click nothing happens and in the second one it closes both window...
1
2016-08-30T11:21:27Z
39,226,445
<p>In a Tkinter-Application there may only be one Tk-object. If the object is destroyed or destroyed by the garbage collector, Tkinter will be disabled. Use Toplevel for other other windows instead.</p> <p>Try this instead:</p> <pre><code>from Tkinter import * from ttk import * class Application(object): def __...
1
2016-08-30T11:35:11Z
[ "python", "python-2.7", "tkinter" ]
python error AttributeError: 'str' object has no attribute 'setdefault'
39,226,131
<p>I'm trying to run the django project using this command.</p> <pre><code>python manage.py runserver 8080 </code></pre> <p>But everytime I'm trying to run I faced the such a error.</p> <pre><code>Traceback (most recent call last): File "manage.py", line 10, in &lt;module&gt; execute_from_command_line(sys.argv) File...
1
2016-08-30T11:21:41Z
39,226,434
<p>Each element in the DATABASES dict must itself be a dict. You have overwritten the 'default' entry to just be a string. </p> <p>Since you are using sqlite3 and the default database name, you should just revert to the original version of the setting:</p> <pre><code>DATABASES = { 'default': { 'ENGINE': '...
3
2016-08-30T11:34:28Z
[ "python", "django" ]
python error AttributeError: 'str' object has no attribute 'setdefault'
39,226,131
<p>I'm trying to run the django project using this command.</p> <pre><code>python manage.py runserver 8080 </code></pre> <p>But everytime I'm trying to run I faced the such a error.</p> <pre><code>Traceback (most recent call last): File "manage.py", line 10, in &lt;module&gt; execute_from_command_line(sys.argv) File...
1
2016-08-30T11:21:41Z
39,226,549
<p>It's better if you show us your settings.py to check if it is ok. </p> <p>Remember to use python3 instead of python. Sometimes I got strange errors for this reason. </p> <p>python3 manage.py runserver 8080</p>
0
2016-08-30T11:40:52Z
[ "python", "django" ]
aiohttp failed response.json() with status 500
39,226,140
<p>Server proxies requests. </p> <pre><code>@asyncio.coroutine def send_async_request(method, url, data, timeout): with ClientSession() as session: response = yield from asyncio.wait_for( session.request(method, url, data=data), timeout=timeout ) return response </code></pre> <...
1
2016-08-30T11:21:56Z
39,228,541
<p>500 errors may occur at any time especially if the server is under high load or unstable. Make your code more resilient by catching the exception. Then you might retry or just return the response. </p> <pre><code>@asyncio.coroutine def send_async_request(method, url, data, timeout): with ClientSession() as sess...
0
2016-08-30T13:14:44Z
[ "python", "json", "python-asyncio", "aiohttp" ]
aiohttp failed response.json() with status 500
39,226,140
<p>Server proxies requests. </p> <pre><code>@asyncio.coroutine def send_async_request(method, url, data, timeout): with ClientSession() as session: response = yield from asyncio.wait_for( session.request(method, url, data=data), timeout=timeout ) return response </code></pre> <...
1
2016-08-30T11:21:56Z
39,232,014
<p>Please check <code>Content-Length</code> for 500 response. Looks like aiohttp tries to read json body but the body is shorter than specified in headers.</p>
0
2016-08-30T15:48:36Z
[ "python", "json", "python-asyncio", "aiohttp" ]
How to match every word in the list having single sentence using python
39,226,172
<p>how to match the below case 1 in python.. i want each and every word in the sentence to be matched with the list. </p> <pre><code>l1=['there is a list of contents available in the fields'] &gt;&gt;&gt; 'there' in l1 False &gt;&gt;&gt; 'there is a list of contents available in the fields' in l1 True </code></pre>
-1
2016-08-30T11:23:21Z
39,226,230
<p>Simple way</p> <pre><code>l1=['there is a list of contents available in the fields'] &gt;&gt;&gt; 'there' in l1[0] True </code></pre> <p>Better way wil be to iterate to all element of list.</p> <pre><code>l1=['there is a list of contents available in the fields'] print(bool([i for i in l1 if 'there' in i])) </cod...
1
2016-08-30T11:25:39Z
[ "python" ]