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 |
|---|---|---|---|---|---|---|---|---|---|
unionAll resulting in StackOverflow | 38,187,333 | <p>I've made some progress with my own question (<a href="http://stackoverflow.com/questions/38185627/how-to-load-a-dataframe-from-a-python-requests-stream-that-is-downloading-a-csv">how to load a dataframe from a python requests stream that is downloading a csv file?</a>) on StackOverflow, but I'm receiving a StackOve... | 1 | 2016-07-04T14:42:22Z | 38,187,688 | <p>You shouldn't iteratively merge distributed data structures without controlling number of partitions. You'll find a complete explanation what is going on in <a href="http://stackoverflow.com/q/34461804/1560062">Stackoverflow due to long RDD Lineage</a> but unfortunately <code>DataFrames</code> are slightly trickier:... | 1 | 2016-07-04T15:03:18Z | [
"python",
"apache-spark",
"pyspark"
] |
how can i list MySQL databases in a Python array | 38,187,338 | <p>i am working on a piece of software that can store clients and the jobs we are doing for them in a MySQL database, however for the UI to work the way i want it to i need to have every one of the databases or tables in an array to reference later. for example</p>
<pre><code>MysqlTables = [customers,clients,jobs]
Mys... | 1 | 2016-07-04T14:42:44Z | 38,188,607 | <p>I wrote something very similar for a project I did, where I basically had a database interface in the GUI, and I allowed the user to edit and add entries to the database without having to go into the MySql Workbench. </p>
<p>You're going to need two functions to interact with your database, one to retrieve the entr... | 0 | 2016-07-04T15:56:46Z | [
"python",
"mysql",
"database",
"user-interface",
"pyqt4"
] |
Using groupby ("1d") and first_valid_index together | 38,187,371 | <p><a href="http://stackoverflow.com/questions/38183182/ignore-np-where-after-first-match-for-pandas-time-series-data/38183664#38183664">This</a> post shows how to use <code>first_valid_index</code> to find the first occurrence of a value in a dataframe column. How do I use first_valid_index along with a daily groupby... | 2 | 2016-07-04T14:44:47Z | 38,187,421 | <p>IIUC you can use <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.core.groupby.GroupBy.first.html#pandas.core.groupby.GroupBy.first" rel="nofollow"><code>first</code></a> on your <code>groupby</code> object:</p>
<pre><code>In [95]:
df.groupby(grouper).first()
Out[95]:
test_1
2014-0... | 2 | 2016-07-04T14:47:39Z | [
"python",
"pandas"
] |
Error in loop with python | 38,187,412 | <p>I have list <code>lst = [1, 2, 3, 4, 5, 6, 3, 5, 3]</code> and to every iteration, where <code>elem == 3</code> I want to print strings before that, while elem not is 3 again.
I want to get </p>
<pre><code>2 3:
0 1
1 2
6 3:
3 4
4 5
5 6
8 3:
7 5
</code></pre>
<p>But I don't know, how to go to previous string</p>
<... | 0 | 2016-07-04T14:47:15Z | 38,187,484 | <p>Something like this?</p>
<pre><code> lst = [1, 2, 3, 4, 5, 6, 3, 5, 3]
previous = []
for i, el in enumerate(lst):
if lst[i] == 3:
print i, el,":"
for p in previous:
print p[0] , p[1]
previous = []
else:
previous.append((i,el... | 1 | 2016-07-04T14:51:43Z | [
"python",
"loops"
] |
Error in loop with python | 38,187,412 | <p>I have list <code>lst = [1, 2, 3, 4, 5, 6, 3, 5, 3]</code> and to every iteration, where <code>elem == 3</code> I want to print strings before that, while elem not is 3 again.
I want to get </p>
<pre><code>2 3:
0 1
1 2
6 3:
3 4
4 5
5 6
8 3:
7 5
</code></pre>
<p>But I don't know, how to go to previous string</p>
<... | 0 | 2016-07-04T14:47:15Z | 38,188,022 | <p>You might try implementing with slices as in:</p>
<pre><code>lst = [1, 2, 3, 4, 5, 6, 3, 5, 3]
start_pos = 0
for idx, val in enumerate(lst):
if val == 3:
print idx,val,":"
for p_idx, p_val in enumerate(lst[start_pos:idx]):
print p_idx+start_pos,p_val
start_pos = idx+1
</code... | 1 | 2016-07-04T15:20:22Z | [
"python",
"loops"
] |
Difference between two snippets of code? | 38,187,423 | <p>Is there any difference in terms of performance in doing this:</p>
<pre><code>for i in range(T):
arr = [int(arr_temp) for arr_temp in input().strip().split(' ')]
</code></pre>
<p>and this:</p>
<pre><code>for i in range(T):
arr = input().strip().split(' ')
arr = list(map(int, arr))
</code></pre>
<... | 0 | 2016-07-04T14:47:45Z | 38,187,598 | <p>According to IPython's <code>%timeit</code> function, <code>map</code> is a bit faster:</p>
<pre><code>In [16]: s = ' '.join(map(str, range(1000)))
In [17]: %timeit [int(c) for c in s.split()]
10000 loops, best of 3: 171 µs per loop
In [18]: %timeit list(map(int, s.split()))
10000 loops, best of 3: 138 µs per l... | 2 | 2016-07-04T14:57:21Z | [
"python",
"performance",
"python-3.x"
] |
order of executing shell_exec in php | 38,187,486 | <p>I want to execute 2 scripts: <code>s1</code> and <code>s2</code>. <code>s2</code> must be executed <em>after</em> <code>s1</code>.
The time of execution of <code>s1</code> is 2800 seconds, and I need to execute <code>s2</code> <em>after</em> <code>s1</code>. Should I put <code>sleep(3000)</code> in my php between th... | 0 | 2016-07-04T14:51:50Z | 38,187,585 | <p>From the <a href="http://php.net/manual/en/function.exec.php" rel="nofollow">exec</a> manual page:</p>
<blockquote>
<p>If a program is started with this function, in order for it to continue running in the background, the output of the program must be redirected to a file or another output stream. Failing to do s... | 1 | 2016-07-04T14:57:02Z | [
"php",
"python"
] |
Send commands to subprocess.Popen() process | 38,187,493 | <p>I need to pass commands to a process on <code>subprocess.Popen()</code> but when I do, it only works if I use <code>stdin.close()</code> afterwards. My code is below.</p>
<pre><code>sprocess.stdin.write('/stop'.encode())
sprocess.stdin.flush()
sprocess.stdin.close()
sprocess.stdout.close()
</code></pre>
<p>Works, ... | 0 | 2016-07-04T14:52:12Z | 38,187,706 | <p>Note that <code>sprocess.stdin.write('/stop'.encode())</code> will not add a newline! Your subprocess is probably expecting a <em>line</em> of input, signified by either a newline or EOF. Closing <code>stdin</code> will send that EOF.</p>
<p>Try sending <code>sprocess.stdin.write('/stop\n'.encode())</code> instead.... | 1 | 2016-07-04T15:04:01Z | [
"python",
"python-3.x",
"asynchronous",
"subprocess",
"popen"
] |
Command 'sbt assembly' taking long to build Spark | 38,187,544 | <p>I have just installed the pyspark in my pc. I have used the command 'sbt assembly' to build it but it's showing some progress for more than an hour in the terminal but didn't complete the process.</p>
| 0 | 2016-07-04T14:54:28Z | 38,209,473 | <p>Be patient spark take much time to compile and build source manually.</p>
| 0 | 2016-07-05T17:40:40Z | [
"python",
"pyspark"
] |
LinkedList in Python | 38,187,587 | <p>I am looking for a solution for the following problem. I have an Excel file that I read with Pandas. Column A contains an identifier and column B also contains Identiers, but the identifiers in column B are linked to the identifier in Column A. example:</p>
<p><code>+----------+----------+
| Column A | Column B |
+... | 2 | 2016-07-04T14:57:07Z | 38,187,695 | <p>Maybe a defaultdict with set?</p>
<pre><code>from collections import defaultdict
ident_pair_dict = defaultdict(set)
for ind, row in df.iterrows(): # df is the pandas dataframe you read
ident_pair_dict[row['Column A']].add(row['Column B'])
</code></pre>
| 2 | 2016-07-04T15:03:33Z | [
"python",
"python-3.x"
] |
LinkedList in Python | 38,187,587 | <p>I am looking for a solution for the following problem. I have an Excel file that I read with Pandas. Column A contains an identifier and column B also contains Identiers, but the identifiers in column B are linked to the identifier in Column A. example:</p>
<p><code>+----------+----------+
| Column A | Column B |
+... | 2 | 2016-07-04T14:57:07Z | 38,187,993 | <p>Since you are using pandas to read, you can construct the dictionary with pandas methods:</p>
<pre><code>df.groupby('Column A')['Column B'].agg(lambda x: list(x)).to_dict()
Out[42]:
{'ID1': ['ID5', 'ID6', 'ID7'],
'ID2': ['ID8', 'ID9'],
'ID3': ['ID8', 'ID9', 'ID10', 'ID11']}
</code></pre>
| 2 | 2016-07-04T15:18:41Z | [
"python",
"python-3.x"
] |
LinkedList in Python | 38,187,587 | <p>I am looking for a solution for the following problem. I have an Excel file that I read with Pandas. Column A contains an identifier and column B also contains Identiers, but the identifiers in column B are linked to the identifier in Column A. example:</p>
<p><code>+----------+----------+
| Column A | Column B |
+... | 2 | 2016-07-04T14:57:07Z | 38,189,914 | <p>Try this: </p>
<pre><code>dict(df.groupby('Column A')['Column B'].apply(list))
</code></pre>
| 0 | 2016-07-04T17:43:23Z | [
"python",
"python-3.x"
] |
Multiindex print 2nd level index labels on right side of a table | 38,187,658 | <p>Taking this example from <a href="http://pandas.pydata.org/pandas-docs/stable/advanced.html" rel="nofollow">http://pandas.pydata.org/pandas-docs/stable/advanced.html</a></p>
<pre><code>In [10]: arrays = [np.array(['bar', 'bar', 'baz', 'baz', 'foo', 'foo', 'qux', 'qux']),
....: np.array(['one', 'two', '... | 1 | 2016-07-04T15:01:19Z | 38,187,710 | <p>Not quite the same but you can call <code>reset_index</code> passing the second level and then reorder the columns using fancy indexing using <code>ix</code> and passing a list of the desired column order:</p>
<pre><code>In [100]:
df.reset_index(level=1).ix[:,list(df) + ['level_1']]
Out[100]:
0 ... | 1 | 2016-07-04T15:04:06Z | [
"python",
"pandas"
] |
Django adds square Brackets in querying sql server | 38,187,707 | <p>I am trying to connect to azure sql service from my django on mac osx.
When I do following</p>
<pre><code>from photo_mapper.models import Restaurant
rest_query = Restaurant.objects.all().query
print rest_query
SELECT [ate_it.restaurant].[id], [ate_it.restaurant].[name], [ate_it.restaurant].[area], [ate_it.restaura... | 0 | 2016-07-04T15:04:02Z | 38,191,666 | <p>This is because of the pyodbc. It generates the quoted name of table, index or column.
Modify this function quote_name in pyodbc/operations.py
Change this line <br />
<code>return '[%s]' % name</code> to <code>return name</code></p>
| 0 | 2016-07-04T20:15:07Z | [
"python",
"sql-server",
"django",
"pyodbc",
"freetds"
] |
tornado how to use WebSockets with wsgi | 38,187,728 | <p>I am trying to make a game server with python, using tornado.</p>
<p>The problem is that WebSockets don't seem to work with wsgi.</p>
<pre><code>wsgi_app = tornado.wsgi.WSGIAdapter(app)
server = wsgiref.simple_server.make_server('', 5000, wsgi_app)
server.serve_forever()
</code></pre>
<p>After looking trough this... | 0 | 2016-07-04T15:05:18Z | 38,191,340 | <p><code>HTTPServer</code> needs a <code>tornado.web.Application</code>, which is not the same as a WSGI application (which you could use with <code>WSGIContainer</code>). </p>
<p>It is recommended that if you need both WSGI and websockets that you run them in two separate processes with an IPC mechanism of your choic... | 0 | 2016-07-04T19:43:33Z | [
"python",
"python-2.7",
"tornado",
"wsgi"
] |
How to count the number of group elements with pandas | 38,187,777 | <p>I have a dataframe and just want count the number of elements in each group. I know, I can use the groupby().count() to get all the counts of all the columns, but it is too much for me, I just want the number of elements in each group. How can I do this?</p>
<p>Here is the example:</p>
<pre><code>mydf = pd.DataFra... | 1 | 2016-07-04T15:07:23Z | 38,187,803 | <p>You want <code>size</code> to count the number of each fruit:</p>
<pre><code>In [102]:
mydf.groupby('fruit').size()
Out[102]:
fruit
apple 2
banana 1
dtype: int64
</code></pre>
| 2 | 2016-07-04T15:08:25Z | [
"python",
"pandas"
] |
Parsing hierarchical information from XML to sqlite | 38,187,781 | <p>The scripts that I post will be long so I beg your patience. I believe it is easy to solve for people who are familiar with the complexity of XML structure. I have a highly hierarchical XML file. I would love to make sqlite database based on it. The two files I have so far extract sibling information from a XML file... | 1 | 2016-07-04T15:07:34Z | 38,189,828 | <p>Whenever working with nested, hierarchical XML files that need to be flattened for two-dimensional formats like database tables, consider an XSLT solution. As information, <a href="https://www.w3.org/Style/XSL/" rel="nofollow">XSLT</a> is a special-purpose programming language designed to transform XML files and lik... | 1 | 2016-07-04T17:35:33Z | [
"python",
"xml",
"sqlite"
] |
How to control size of widgets in Qt/PyQt/PySide grid layout | 38,187,788 | <p>I am struck with a foolish but annoying question. I would like to set different sizes for two list widgets on a grid layout, one above the other. So, I would like to set 60% of the form space to the upper widget and 40% to the lower widget. I attempted to use setRowStretch, without success.</p>
<p>Here is my code:<... | 0 | 2016-07-04T15:07:50Z | 38,190,328 | <p>The first parameter of the <code>rowStretch</code> method is the row number, the second is the stretch factor. So you need two calls to <code>rowStretch</code>, like this:</p>
<pre><code>import sys
from PyQt4.QtCore import *
from PyQt4.QtGui import *
def window():
app = QApplication(sys.argv)
win = QWidget... | 1 | 2016-07-04T18:16:08Z | [
"python",
"pyqt",
"pyqt4"
] |
How would you put back a list that you've split and transformed back to the original file? | 38,187,802 | <p>I am trying to isolate date from date/time which is a column in the original csv file. I've isolated the column and change it to just date but I am having a tough time putting it back to the original file:</p>
<pre><code>def isolateDate(csv_file):
file_in = open(csv_file, "rU")
reader = csv.reader(file_in)
... | 0 | 2016-07-04T15:08:25Z | 38,188,183 | <p>You will need to read in all the rows from the file, modify the 4th column (index 3) and then rewrite back to file:</p>
<pre><code>with open(csv_file, "r") as file_in:
reader = csv.reader(file_in)
header = next(reader)
rows = [row[0:3] + [row[3].split()[0]] + row[4:] for row in reader]
# ... | 1 | 2016-07-04T15:30:07Z | [
"python",
"python-2.7",
"csv"
] |
infinite loop in Hangman game in Python | 38,187,835 | <p>I am trying to build a simple Hangman game, but the following program is creating an infinite loop when the letter entered by the user is not part of the word to guess (it's printing <code>"*"</code> indefinitely). What is missing here? Any advice would be appreciated.</p>
<pre><code>import re
import random
folder... | -3 | 2016-07-04T15:10:36Z | 38,188,718 | <p>So, the biggest issue was the scope of the continue_game variable. Since it was declared outside of the function. "while continue_game" always evaluates the same.</p>
<p>To fix, add <code>global continue_game</code> in the method definition.</p>
<p>below is code that will break out of the loop. to test I created ... | 0 | 2016-07-04T16:05:40Z | [
"python",
"infinite-loop"
] |
infinite loop in Hangman game in Python | 38,187,835 | <p>I am trying to build a simple Hangman game, but the following program is creating an infinite loop when the letter entered by the user is not part of the word to guess (it's printing <code>"*"</code> indefinitely). What is missing here? Any advice would be appreciated.</p>
<pre><code>import re
import random
folder... | -3 | 2016-07-04T15:10:36Z | 38,189,864 | <p>As there are others answering, why not hand out another try, from where the OP could continue? So here another version fixing also the overwrite error of previous found letters in subsequent iterations.Note also, that the append of letters found in a list may be what one wants, or maybe not, as the <code>o</code> in... | 1 | 2016-07-04T17:38:30Z | [
"python",
"infinite-loop"
] |
How to get scraped items from main script using scrapy? | 38,187,891 | <p>I hope to get a list of scraped items in main script instead of using scrapy shell. </p>
<p>I know there is a method <code>parse</code> in class <code>FooSpider</code> I define, and this method return a list of <code>Item</code>. Scrapy framework calls this method. But, how can I get this returned list by myself?</... | 2 | 2016-07-04T15:13:46Z | 38,259,269 | <p>If what you want is to work with/process/transform or store the items you should look into the <a href="http://doc.scrapy.org/en/latest/topics/item-pipeline.html" rel="nofollow">Item Pipeline</a> and the usual scrapy crawl would do the trick.</p>
| 0 | 2016-07-08T05:09:38Z | [
"python",
"scrapy"
] |
Plotting multiple lines from columns of Dataframe (python/pandas)? | 38,187,919 | <p>I have large (~1 million) data set that looks something like this...</p>
<pre><code>Age Wavelength Luminosity
1 96 100
1 97 150
1 98 100
2 96.5 90
2 97 160
2 97.5 120
...
</code></pre>
<p>I have it in a dataframe cur... | -3 | 2016-07-04T15:15:11Z | 38,188,490 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/version/0.16.2/generated/pandas.core.groupby.DataFrameGroupBy.plot.html" rel="nofollow">pandas.core.groupby.DataFrameGroupBy.plot</a></p>
<pre><code>In[1]: import pandas as pd
In[2]: import numpy as np
In[3]: dataset = pd.DataFrame({"Age": np.random.random... | 0 | 2016-07-04T15:49:05Z | [
"python",
"pandas",
"matplotlib",
"dataframe",
"astronomy"
] |
Python: comparing strings with numerals. Decoding radio call-signs | 38,187,938 | <p>I've got a feeling that the core concept of this might be a repeat question but I can't find it.</p>
<p>Okay, I have a bunch of radio callsigns and want to find the country of origin from <a href="http://www.arrl.org/international-call-sign-series" rel="nofollow">here</a>.</p>
<p>I've tried to do basic comparison ... | 3 | 2016-07-04T15:15:58Z | 38,187,999 | <p>Functions like <code>sorted()</code> allow you to provide your own <code>cmp</code> function - you just have to implement it. But you're free to say that numbers are over letters and the usual sorting algorithm will take care of the rest.</p>
<p>If you just want to compare things rather than sort, you'll have to im... | 1 | 2016-07-04T15:19:02Z | [
"python",
"sorting",
"order"
] |
Python: comparing strings with numerals. Decoding radio call-signs | 38,187,938 | <p>I've got a feeling that the core concept of this might be a repeat question but I can't find it.</p>
<p>Okay, I have a bunch of radio callsigns and want to find the country of origin from <a href="http://www.arrl.org/international-call-sign-series" rel="nofollow">here</a>.</p>
<p>I've tried to do basic comparison ... | 3 | 2016-07-04T15:15:58Z | 38,188,453 | <p>You could create a <code>dict</code> mapping characters to their positions in the "correct" ordering and then compare the lists of positions:</p>
<pre><code>import string
order = {e: i for i, e in enumerate(string.ascii_uppercase + string.digits)}
positions = lambda s: [order[c] for c in s]
def cmp_callsign(first,... | 1 | 2016-07-04T15:46:59Z | [
"python",
"sorting",
"order"
] |
Python: comparing strings with numerals. Decoding radio call-signs | 38,187,938 | <p>I've got a feeling that the core concept of this might be a repeat question but I can't find it.</p>
<p>Okay, I have a bunch of radio callsigns and want to find the country of origin from <a href="http://www.arrl.org/international-call-sign-series" rel="nofollow">here</a>.</p>
<p>I've tried to do basic comparison ... | 3 | 2016-07-04T15:15:58Z | 38,188,560 | <p>You can simply write your own key function, like this:</p>
<pre><code>def radio_order(s):
def character_sorting_order(a):
if a.isnumeric():
return ord('z') + 1 + int(a)
else:
return ord(a)
return tuple(map(character_sorting_order, s))
print('z1' < 'zA' < 'za') ... | 0 | 2016-07-04T15:54:06Z | [
"python",
"sorting",
"order"
] |
Python: comparing strings with numerals. Decoding radio call-signs | 38,187,938 | <p>I've got a feeling that the core concept of this might be a repeat question but I can't find it.</p>
<p>Okay, I have a bunch of radio callsigns and want to find the country of origin from <a href="http://www.arrl.org/international-call-sign-series" rel="nofollow">here</a>.</p>
<p>I've tried to do basic comparison ... | 3 | 2016-07-04T15:15:58Z | 38,189,006 | <p>You can use <a href="http://stackoverflow.com/a/13626849/2077270">string.translate</a> a couple times, though it might be costly... Basically, map the strings to a value that will be compared correctly using the default python comparison operators. </p>
<pre><code>import string
python_order = '0123456789' + string... | 0 | 2016-07-04T16:25:41Z | [
"python",
"sorting",
"order"
] |
Python 3 - tkinter , ignore socket.herror and continue | 38,187,950 | <p>I try to resolve hosts using socket module via GUI I made using Tkinter
here is part of the code , the main issue is the error I receive while resolving routers name </p>
<pre><code>for line in p.stdout:
fiw = open("1.txt", '+a')
line = str(line)
if "Received = 1" in line:
... | 0 | 2016-07-04T15:16:45Z | 38,188,562 | <p>i think that you should take a look at this <a href="http://stackoverflow.com/questions/18994334/make-python-code-continue-after-exception">thread</a></p>
<p>an exception is like a break point, it breaks your for loop..</p>
<p>try it like this : </p>
<pre><code>for line in p.stdout:
try:
fiw = open("1.... | -2 | 2016-07-04T15:54:25Z | [
"python",
"windows",
"python-3.x",
"networking",
"tkinter"
] |
Python 3 - tkinter , ignore socket.herror and continue | 38,187,950 | <p>I try to resolve hosts using socket module via GUI I made using Tkinter
here is part of the code , the main issue is the error I receive while resolving routers name </p>
<pre><code>for line in p.stdout:
fiw = open("1.txt", '+a')
line = str(line)
if "Received = 1" in line:
... | 0 | 2016-07-04T15:16:45Z | 38,188,892 | <p>You have try ... except around the wrong thing,
instead of </p>
<pre><code>hostad = socket.gethostbyaddr(ip3 +str(i))
if hostad:
try:
print(hostad)
except socket.herror:
print(hostad)
</code></pre>
<p>it should be like </p>
<pre><code>try:
hostad = socket.gethostbyaddr(ip3 +str(i))
... | 0 | 2016-07-04T16:16:48Z | [
"python",
"windows",
"python-3.x",
"networking",
"tkinter"
] |
How to parallelize this embarrassingly parallel loop with Python | 38,188,021 | <p>I have an embarrassingly parallel loop:</p>
<pre><code># Definitions
def exhaustiveExplorationsWithSimilarityAll(inputFolder, outputFolder, similarityMeasure):
phasesSpeedupDictFolder=parsePhasesSpeedupDictFolder(inputFolder)
avgSpeedupProgramDict=computeAvgSpeedupProgram(phasesSpeedupDictFolder)
param... | 0 | 2016-07-04T15:20:10Z | 38,188,861 | <p>You are still calling <code>exhaustiveExplorationsWithSimilarity</code> (serially) inside your loop, but then you are passing the result to <code>delayed</code></p>
<p>From the docs <a href="https://pythonhosted.org/joblib/parallel.html#common-usage" rel="nofollow">https://pythonhosted.org/joblib/parallel.html#comm... | 1 | 2016-07-04T16:14:53Z | [
"python",
"parallel-processing",
"joblib"
] |
Python: How to keep a variable in memory such that it can be called from other python scripts? | 38,188,144 | <p>There is a module named tzwhere in python. When I load it in the tz variable as in:-</p>
<pre><code>from tzwhere import tzwhere
tz = tzwhere.tzwhere(shapely=True)
</code></pre>
<p>The line above takes about 45 seconds to load up and its scope is until that particular python session is stopped. So after this line I... | 2 | 2016-07-04T15:27:48Z | 38,188,975 | <p>You could probably use the <code>pickle</code> module which can store class instances in files.</p>
<p>Try something like this:</p>
<pre><code> from tzwhere import tzwhere
tz = tzwhere.tzwhere(shapely=True)
import pickle
# Dump the variable tz into file save.p
pickle.dump( tz, open( "save.p", "wb" ) )
</code... | 0 | 2016-07-04T16:23:38Z | [
"python"
] |
Python: How to keep a variable in memory such that it can be called from other python scripts? | 38,188,144 | <p>There is a module named tzwhere in python. When I load it in the tz variable as in:-</p>
<pre><code>from tzwhere import tzwhere
tz = tzwhere.tzwhere(shapely=True)
</code></pre>
<p>The line above takes about 45 seconds to load up and its scope is until that particular python session is stopped. So after this line I... | 2 | 2016-07-04T15:27:48Z | 38,189,129 | <p>You cannot share any python object in memory even after python has closed. You can, however, save the state of the object (if the library does support it, if it doesn't, this solution will not work) with <code>pickle</code>. <code>pickle</code> is a library that ships with python, and can save the state of most obje... | 0 | 2016-07-04T16:33:56Z | [
"python"
] |
Django: Parent Model with multiple child model types | 38,188,147 | <p>I've created a set of Django model for a CMS to show a series of <code>Product</code>s.</p>
<p>Each page contains a series of rows, so I have a generic</p>
<pre><code>class ProductRow(models.Model):
slug = models.SlugField(max_length=100, null=False, blank=False, unique=True, primary_key=True)
name = models.Ch... | 0 | 2016-07-04T15:28:00Z | 38,188,987 | <p>This is generally (read "always") a bad design to have something like this:</p>
<pre><code>class MyModel(models.Model):
...
row_1 = models.ForeignKey(...)
row_2 = models.ForeignKey(...)
row_3 = models.ForeignKey(...)
row_4 = models.ForeignKey(...)
row_5 = models.ForeignKey(...)
</code></pre>... | 2 | 2016-07-04T16:24:24Z | [
"python",
"django",
"inheritance",
"model"
] |
Django: Parent Model with multiple child model types | 38,188,147 | <p>I've created a set of Django model for a CMS to show a series of <code>Product</code>s.</p>
<p>Each page contains a series of rows, so I have a generic</p>
<pre><code>class ProductRow(models.Model):
slug = models.SlugField(max_length=100, null=False, blank=False, unique=True, primary_key=True)
name = models.Ch... | 0 | 2016-07-04T15:28:00Z | 38,189,517 | <p>Your <code>type()</code> method doesn't work because you're using <a href="https://docs.djangoproject.com/en/1.9/topics/db/models/#multi-table-inheritance" rel="nofollow">multi-table inheritance</a>: each of <code>ProductRow</code>'s children is a separate model connected to <code>ProductRow</code> using an automati... | 0 | 2016-07-04T17:08:28Z | [
"python",
"django",
"inheritance",
"model"
] |
Run a sync sequence of commands in sublime plugin | 38,188,271 | <p>I've been trying to write a very simple plugin for Sublime Text (3) but being new to the topic either I am missing something or something is not working as expected. </p>
<p>I want to create a command that move the current tab to a specified group (for example group 0 for simplification). Right after that I want t... | 1 | 2016-07-04T15:35:23Z | 38,193,242 | <p>Your initial code worked fine for me, until I tried it on the last remaining view in the second group.</p>
<p>As <a href="http://stackoverflow.com/users/5963435/r-stein"><strong>r-stein</strong></a> mentioned in the comments, it seems that the blank view created by SublimeText in the empty group is interfering with... | 2 | 2016-07-04T23:12:45Z | [
"python",
"sublimetext3",
"sublimetext",
"sublime-text-plugin"
] |
MD5 Cracker not working python3 | 38,188,312 | <pre><code>md = input("MD5 Hash: ")
if len(md) != 32:
print("Don't MD5 Hash.")
else:
liste = input("Wordlist: ")
ac = open(liste).readlines()
for new in ac:
hs = hashlib.md5(new.encode()).hexdigest()
if hs == md:
print("MD5 HASH CRACKED : ", new)
print("Sorry :( Don't Cr... | -3 | 2016-07-04T15:37:39Z | 38,188,438 | <p>The lines from your file include a newline. That newline is significant:</p>
<pre><code>>>> from hashlib import md5
>>> md5(b'ahmet').hexdigest()
'cdb5efc9c72196c1bd8b7a594b46b44f'
>>> md5(b'ahmet\n').hexdigest()
'ac5bd810592f14278b5e06fc20d88c23'
</code></pre>
<p>Remove the newline firs... | 2 | 2016-07-04T15:46:04Z | [
"python",
"python-3.x",
"md5",
"python-3.5"
] |
Sampling rate issue with Librosa | 38,188,359 | <p>When doing a STFT, and then an inverse STFT (iSTFT) on a 16 bits 44.1 khz audio file with the library <a href="https://github.com/librosa/librosa" rel="nofollow">Librosa</a> :</p>
<pre><code>import librosa
y, sr = librosa.load('test.wav', mono=False)
y1 = y[0,]
S = librosa.core.stft(y1)
z1 = librosa.core.istft(S, ... | 1 | 2016-07-04T15:40:35Z | 38,922,296 | <p>The <code>librosa.load()</code> function enables target sampling, wherein the audio file you import can be re-sampled to the target sample rate specified by the keyword argument <code>sr</code>. </p>
<p>If you want to use the original sample rate, you have to explicitly set the the target sample rate to None: <code... | 1 | 2016-08-12T16:08:28Z | [
"python",
"audio",
"signal-processing",
"librosa"
] |
Pandas: Join dataframes on selected columns | 38,188,420 | <p>I have two data frames as following </p>
<pre><code> Data Set A
ID type msg
1 High Lets do
2 Low whats it
3 Medium thats it
Data Set B
ID Accounttype
2 Facebook
3 Linkedin
</code></pre>
<p>How can I get an updated table with help of join in pandas, it should look like
an </p>
<pre><co... | 0 | 2016-07-04T15:44:44Z | 38,189,994 | <p>Seems there is no direct way to do it, so following is suggested </p>
<pre><code> a=b.merge(account,how='left',on='ID')
</code></pre>
<p>create a list of columns you want in final data set</p>
<pre><code> list=['ID','Account','type','msg']
final=a[[col for col in list if col in b.columns]]
</code></pre>
<p>It... | 0 | 2016-07-04T17:48:54Z | [
"python",
"pandas",
"join",
"merge"
] |
Pandas: Join dataframes on selected columns | 38,188,420 | <p>I have two data frames as following </p>
<pre><code> Data Set A
ID type msg
1 High Lets do
2 Low whats it
3 Medium thats it
Data Set B
ID Accounttype
2 Facebook
3 Linkedin
</code></pre>
<p>How can I get an updated table with help of join in pandas, it should look like
an </p>
<pre><co... | 0 | 2016-07-04T15:44:44Z | 38,190,292 | <p>Try this:</p>
<pre><code> df4
# ID type msg
# 0 1 High Letsdo
# 1 2 Low whatsit
# 2 3 Medium thatsit
df3:
# ID Accounttype xxx
# 0 2 Facebook 24
# 1 3 Linkedin 44
df4.merge(df3[['ID','Accounttype']],how='left').fillna("")
# ID ... | 1 | 2016-07-04T18:13:30Z | [
"python",
"pandas",
"join",
"merge"
] |
Can Django map multiple LDAP authentications onto a single User object? | 38,188,431 | <p>I am authenticating Django users against an Active Directory (LDAP) database using <a href="https://pythonhosted.org/django-auth-ldap/" rel="nofollow">django-auth-ldap</a>.</p>
<p>Our convention for <code>sAMAccountName</code> (typically the unique identifier for an AD account) is <code>firstname.surname</code>. It... | 1 | 2016-07-04T15:45:37Z | 38,227,509 | <p>django-auth-ldap has a <a href="https://pythonhosted.org/django-auth-ldap/reference.html#django_auth_ldap.backend.LDAPBackend.get_or_create_user" rel="nofollow">documented mechanism</a> to let you customize the user-creation process. By subclassing the backend and overriding this method, you can can map LDAP users t... | 1 | 2016-07-06T15:12:08Z | [
"python",
"django",
"ldap",
"django-auth-ldap"
] |
Connect to Azure Service Bus with Python | 38,188,454 | <p>I have a mixed (C#, Python) system communicating asynchronously through Azure Service Bus queues. Everything was working fine but now I'm getting strange error messages in my Python consumer (which is basically a copy and paste from: <a href="https://azure.microsoft.com/en-gb/documentation/articles/service-bus-pytho... | 0 | 2016-07-04T15:47:09Z | 38,188,738 | <p>Just answering my own question in case somebody stumbles into the same problem. My requirements.txt file was not up to date with the latest Python Azure module (of course, I checked the wrong Python env and so I was "sure" it wasn't that :-)). Once I updated the dependencies, things started working again.</p>
| 1 | 2016-07-04T16:06:53Z | [
"python",
"azure",
"azureservicebus"
] |
Having trouble simulating orbits in Visual Python | 38,188,475 | <p>This is the code i have written in VPython so Far, I'm new to Vpython and i'm not that experienced in python so cut me some slack please, The error I get is:</p>
<blockquote>
<pre><code>Traceback (most recent call last): File "C:\Users\Makka Pakka\Documents\Planetary Orbits.py", line 28
SUVAT(EarthInitialV,D... | -2 | 2016-07-04T15:48:19Z | 38,215,049 | <p>Besides the physics equations not being correct,
the error is caused by adding a number (a component) and a vector (3 components). To make it work, you need to rewrite the function as</p>
<pre><code>def SUVAT(A,B):
global EarthFinalV
EarthFinalV = sqrt((A) + 2*Acceleration*(B))
</code></pre>
<p>Then in the... | 0 | 2016-07-06T01:09:06Z | [
"python",
"vpython"
] |
Getting return value problems with unittest patch() in python | 38,188,597 | <p>I am trying to use mock.patch to unittest my code, however I am getting a strange result. This is the important part of the code:</p>
<pre><code>@mock.patch('benchmark.scenarios.networking.feature.ssh')
@mock.patch('benchmark.scenarios.networking.feature.subprocess.call')
def test_run_for_success(self, mock_subproc... | -1 | 2016-07-04T15:56:12Z | 38,188,626 | <p>You are using <code>mock.return_value</code> wrong, and on the wrong object; whenever you want to set the return value for <code>foo()</code>, use <code>foo.return_value</code>, not <code>foo().return_value</code>. Moreover, <code>mock_subprocess</code> points to <code>subprocess.call</code> <em>already</em>, don't ... | 2 | 2016-07-04T15:58:20Z | [
"python",
"unit-testing",
"mocking",
"python-unittest"
] |
|, > and < in numpy datatype | 38,188,619 | <p>This could be a very silly question but I tried to google keywords like <code>less and greater signs in data type of numpy</code> and found no reference.</p>
<p>In the <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.recarray.html" rel="nofollow">doc</a> of <code>numpy</code>, </p>
<pre><code>x =... | 4 | 2016-07-04T15:57:54Z | 38,188,707 | <p>The keywords <code><</code> and <code>></code> stand for <a href="https://en.wikipedia.org/wiki/Endianness" rel="nofollow">byte ordering</a>, aka <em>endianness</em>. It is the order in which bytes from numbers are stored (when numbers are compossed of more than 1 byte, e.g. int16, int32, float32...). <a href=... | 6 | 2016-07-04T16:04:46Z | [
"python",
"numpy"
] |
NoReverseMatch for Dynamic URLs Django Template | 38,188,674 | <p>In my urls.py I have set the url for editing a post to be its slug/edit </p>
<pre><code>url(r'^(?P<slug>[\w-]+)/edit/$', post_update, name='update'),
</code></pre>
<p>When calling <code>href="{% url 'posts:update' %}</code> from the template, I get following error: </p>
<pre><code>NoReverseMatch at /posts/t... | 0 | 2016-07-04T16:01:42Z | 38,188,728 | <p>You are missing the object's slug:</p>
<pre><code>href="{% url 'posts:update' 'object-slug-here' %}
</code></pre>
<p>You can see some options to print an url using <a href="https://docs.djangoproject.com/es/1.9/ref/templates/builtins/#url" rel="nofollow">Django's url template tag</a>.</p>
| 0 | 2016-07-04T16:06:24Z | [
"python",
"django",
"django-templates"
] |
Generalize a function for an ODE solver | 38,188,686 | <p>I have the next system of equations:</p>
<pre><code>#dY0=/dt = k1*S - k2*Y1*Y0
#dY1/dt = k3*S - k4*Y1
</code></pre>
<p>Where S(t) is a staircase function that increases by one unit at t = 4, 8, 12 and so on. My code is the following:</p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
from scipy.int... | 1 | 2016-07-04T16:02:45Z | 38,188,733 | <p><code>stp</code> has a well defined relationship with respect to parameter <code>t</code>. You can replace all <code>t < 20</code> with an integer division:</p>
<pre><code>def stp(t):
if t < 20:
return float(t//4)
else:
return 5.0
</code></pre>
<p>And generally, for all ranges, including ... | 3 | 2016-07-04T16:06:40Z | [
"python",
"ode"
] |
cumsum pandas up to specific value - python pandas | 38,188,851 | <p>Cumsum until value exceeds certain number:</p>
<p>Say that we have two Data frames A,B that look like this:</p>
<pre><code>A = pd.DataFrame({"type":['a','b','c'], "value":[100, 50, 30]})
B = pd.DataFrame({"type": ['a','a','a','a','b','b','b','c','c','c','c','c'], "value": [10,50,45,10,45,10,5,6,6,8,12,10]})
</code... | 0 | 2016-07-04T16:14:26Z | 38,189,050 | <p>Merging the two data frame before hand should help:</p>
<pre><code>import pandas as pd
df = pd.merge(B, A, on = 'type')
df['cumsum'] = df.groupby('type')['value_x'].cumsum()
B[(df.groupby('type')['cumsum'].shift().fillna(0) < df['value_y'])].groupby('type').count()
# type value
# a 3
# b 2
# ... | 1 | 2016-07-04T16:29:29Z | [
"python",
"pandas"
] |
cumsum pandas up to specific value - python pandas | 38,188,851 | <p>Cumsum until value exceeds certain number:</p>
<p>Say that we have two Data frames A,B that look like this:</p>
<pre><code>A = pd.DataFrame({"type":['a','b','c'], "value":[100, 50, 30]})
B = pd.DataFrame({"type": ['a','a','a','a','b','b','b','c','c','c','c','c'], "value": [10,50,45,10,45,10,5,6,6,8,12,10]})
</code... | 0 | 2016-07-04T16:14:26Z | 38,189,459 | <p>Assuming <code>B['type']</code> to be sorted as with the sample case, here's a NumPy based solution -</p>
<pre><code>IDs = np.searchsorted(A['type'],B['type'])
count_cumsum = np.bincount(IDs,B['value']).cumsum()
upper_bound = A['value'] + np.append(0,count_cumsum[:-1])
Bv_cumsum = np.cumsum(B['value'])
grp_start = ... | 0 | 2016-07-04T17:02:44Z | [
"python",
"pandas"
] |
Building Python 3 on OS X: [Python/importlib.h] Error 133 | 38,188,855 | <p>I am trying to build Python (3.5.2) on OS X El Capitan (10.11.5). However, I run into an error when I try to <code>make</code> it. The error seems to be related to <code>_freeze_importlib</code>.</p>
<pre><code>/usr/local/src/Python-3.5.2 $ make
if test "no" != "yes"; then \
./Programs/_freeze_importlib \
... | 4 | 2016-07-04T16:14:35Z | 38,191,382 | <p>Fixed.</p>
<p>In the output of <code>./configure</code>, I noticed a reference to <code>/Applications/Xcode-beta.app/Contents/Developer/</code>. I installed Xcode 8 (beta) a few days ago. After switching back to the regular Command Line Tools (with Xcode 7.3.1)</p>
<pre><code>sudo xcode-select -s /Applications/Xco... | 4 | 2016-07-04T19:48:03Z | [
"python",
"osx",
"python-3.x",
"osx-elcapitan"
] |
Building Python 3 on OS X: [Python/importlib.h] Error 133 | 38,188,855 | <p>I am trying to build Python (3.5.2) on OS X El Capitan (10.11.5). However, I run into an error when I try to <code>make</code> it. The error seems to be related to <code>_freeze_importlib</code>.</p>
<pre><code>/usr/local/src/Python-3.5.2 $ make
if test "no" != "yes"; then \
./Programs/_freeze_importlib \
... | 4 | 2016-07-04T16:14:35Z | 39,606,779 | <p>I think a better solution is <code>xcode-select --install</code>.</p>
<p>If you update Xcode to 8(beta), you have to run <code>xcode-select --install</code> again to install all the build tools with it.</p>
<p>I ran into the same issue as yours and I can successfully install python through brew with Xcode8 after r... | 2 | 2016-09-21T02:52:58Z | [
"python",
"osx",
"python-3.x",
"osx-elcapitan"
] |
Install of .whl python file not working | 38,188,859 | <p>I just installed Python 2.7.12 (32bit) on Windows 10 (64bit) workstation.</p>
<p>Now, I am trying to install pywin32-220.1-cp27-cp27m-win32.whl from this <a href="http://www.lfd.uci.edu/~gohlke/pythonlibs/" rel="nofollow">Python Library Website</a>.</p>
<p>Attempted to install by </p>
<pre><code>pip install pywin... | 1 | 2016-07-04T16:14:52Z | 38,188,954 | <p>pip likes to check for updates after doing what the command requires: if you are offline or behind a proxy it is going to take a very long time. </p>
<p>Add option <code>--disable-pip-version-check</code> to all pip command lines.</p>
| 0 | 2016-07-04T16:22:19Z | [
"python",
"pip",
"pywin"
] |
Python/BeautifulSoup - Getting specific attribute in the same tag/element | 38,188,952 | <p>I am new to Python and BeautifulSoup. So please forgive me if I'm using the wrong terminology.</p>
<p>I am trying to get a specific 'text' from a div tag/element that has multiple attributes in the same .</p>
<pre><code><div class="property-item" data-id="183" data-name="Brittany Apartments" data-street_number=... | 0 | 2016-07-04T16:22:06Z | 38,189,036 | <p>If you want to get the <code>data-name</code> and <code>data-path</code> attributes, you can simply use the <em>dictionary-like access</em> to <code>Tag</code>'s attributes:</p>
<pre><code>for btnMoreDetails in citySoup.findAll(attrs={"class":"property-item"}):
print(btnMoreDetails["data-name"])
print(btnMo... | 2 | 2016-07-04T16:28:14Z | [
"python",
"beautifulsoup"
] |
Python/BeautifulSoup - Getting specific attribute in the same tag/element | 38,188,952 | <p>I am new to Python and BeautifulSoup. So please forgive me if I'm using the wrong terminology.</p>
<p>I am trying to get a specific 'text' from a div tag/element that has multiple attributes in the same .</p>
<pre><code><div class="property-item" data-id="183" data-name="Brittany Apartments" data-street_number=... | 0 | 2016-07-04T16:22:06Z | 38,189,133 | <p>Once you have extracted the element (which <code>findAll</code> does one at a time) you can access attributes as though they were dictionary keys. So for example the following code:</p>
<pre><code>data = """<div class="property-item" data-id="183" data-name="Brittany Apartments" data-street_number="240" data-str... | 1 | 2016-07-04T16:34:14Z | [
"python",
"beautifulsoup"
] |
python sklearn KDTree with haversine distance | 38,188,960 | <p>I try to create a KD tree of WGS84 coordinates and find neighbors within a certain radius</p>
<pre><code>from sklearn.neighbors.dist_metrics import DistanceMetric
from sklearn.neighbors.kd_tree import KDTree
T = KDTree([[47.8665, 8.90123]], metric=DistanceMetric.get_metric('haversine'))
</code></pre>
<p>But ge... | -1 | 2016-07-04T16:22:39Z | 38,189,145 | <p><code>KDTree.valid_metrics</code></p>
<p>Output - </p>
<pre><code>['p',
'l1',
'chebyshev',
'manhattan',
'minkowski',
'cityblock',
'l2',
'euclidean',
'infinity']
</code></pre>
<p>Which tells, you can't use <code>haversine</code> with KDTree. The reason behind it is <code>haversine</code> distance gives you... | 0 | 2016-07-04T16:35:25Z | [
"python",
"scikit-learn",
"kdtree"
] |
python sklearn KDTree with haversine distance | 38,188,960 | <p>I try to create a KD tree of WGS84 coordinates and find neighbors within a certain radius</p>
<pre><code>from sklearn.neighbors.dist_metrics import DistanceMetric
from sklearn.neighbors.kd_tree import KDTree
T = KDTree([[47.8665, 8.90123]], metric=DistanceMetric.get_metric('haversine'))
</code></pre>
<p>But ge... | -1 | 2016-07-04T16:22:39Z | 38,211,329 | <p>The k-d-tree can (to the best of my knowledge) only be used with Minkowski norms.</p>
<p>There are other trees such as the ball tree in sklearn, or the covertree in ELKI that work with Haversine distance because it is a metric.</p>
| 0 | 2016-07-05T19:34:33Z | [
"python",
"scikit-learn",
"kdtree"
] |
More elegant way to deal with multiple KeyError Exceptions | 38,188,990 | <p>I have the following function, which reads a <code>dict</code> and affects some values to local variables, which are then returned as a tuple.</p>
<p>The problem is that some of the desired keys may not exist in the dictionary.</p>
<p>So far I have this code, it does what I want but I wonder if there is a more ele... | 0 | 2016-07-04T16:24:32Z | 38,189,552 | <p>You could instead iterate through the keys and <code>try</code> for each <code>key</code>, on success append it to a list and on failure append a <code>" "</code>:</p>
<pre><code>ret = []
for key in {'country', 'type', 'startAddress', 'endAddress', 'parentHandle'}:
try:
ret.append(data[key])
except ... | 1 | 2016-07-04T17:11:33Z | [
"python",
"json",
"python-3.x",
"rdap"
] |
More elegant way to deal with multiple KeyError Exceptions | 38,188,990 | <p>I have the following function, which reads a <code>dict</code> and affects some values to local variables, which are then returned as a tuple.</p>
<p>The problem is that some of the desired keys may not exist in the dictionary.</p>
<p>So far I have this code, it does what I want but I wonder if there is a more ele... | 0 | 2016-07-04T16:24:32Z | 38,189,633 | <p>Just use <code>dict.get</code>. Each use of:</p>
<pre><code>try:
country = data['country']
except KeyError:
country = ''
</code></pre>
<p>can be equivalently replaced with:</p>
<pre><code>country = data.get('country', '')
</code></pre>
| 2 | 2016-07-04T17:18:48Z | [
"python",
"json",
"python-3.x",
"rdap"
] |
More elegant way to deal with multiple KeyError Exceptions | 38,188,990 | <p>I have the following function, which reads a <code>dict</code> and affects some values to local variables, which are then returned as a tuple.</p>
<p>The problem is that some of the desired keys may not exist in the dictionary.</p>
<p>So far I have this code, it does what I want but I wonder if there is a more ele... | 0 | 2016-07-04T16:24:32Z | 38,190,490 | <p>Thx ShadowRanger, with you answer I went to the following code, which is indeed more confortable to read :</p>
<p>def getNetwork(self, search):</p>
<pre><code>data = self.get('ip',search)
handle = data.get('handle', '')
name = data.get('name', '')
country = data.get('country','')
type ... | 0 | 2016-07-04T18:30:05Z | [
"python",
"json",
"python-3.x",
"rdap"
] |
'Manager' object has no attribute 'active' | 38,189,065 | <p>i want to create a search field for my form...
please help </p>
<p>models.py</p>
<pre><code>from __future__ import unicode_literals
from django.db import models
from django.core.urlresolvers import reverse
from django.conf import settings
from django.db import models
from django.db.models.signals import pre_save
... | 0 | 2016-07-04T16:30:29Z | 38,189,465 | <p>Your <code>Post.objects.active()</code> does not exists in the default Model's Manager, that's why you get that error message. You have created a custom Model Manager, but you are not using it. You need to set it to your <code>Post</code> model:</p>
<pre><code>class Post(models.Model):
from1 = models.CharField... | 2 | 2016-07-04T17:03:18Z | [
"python",
"html",
"django",
"sqlite3"
] |
Convert comma separated string to array in pyspark dataframe | 38,189,088 | <p>I have a dataframe as below where ev is of type string.</p>
<pre><code>>>> df2.show()
+---+--------------+
| id| ev|
+---+--------------+
| 1| 200, 201, 202|
| 1|23, 24, 34, 45|
| 1| null|
| 2| 32|
| 2| null|
+---+--------------+
</code></pre>
<p>Is there a way... | 1 | 2016-07-04T16:31:35Z | 38,189,294 | <p>You can use built-in <code>split</code> function:</p>
<pre><code>from pyspark.sql.functions import col, split
df = sc.parallelize([
(1, "200, 201, 202"), (1, "23, 24, 34, 45"), (1, None),
(2, "32"), (2, None)]).toDF(["id", "ev"])
df.select(col("id"), split(col("ev"), ",\s*").alias("ev"))
</code></pre>
<p... | 3 | 2016-07-04T16:47:03Z | [
"python",
"apache-spark",
"dataframe",
"pyspark",
"apache-spark-sql"
] |
Deep learning Udacity course: Prob 2 assignment 1 (notMNIST) | 38,189,153 | <p>After reading <a href="https://discussions.udacity.com/t/assingment-1-1-notmnist-ipynb-well-convert-the-entire-dataset-into-a-3d-array-image-index-x-y-of-floating-point-values-normalized-to-have-approximately-zero-mean-and-standard-deviation-0-5-to-make-training-easier-down-the-road/45902" rel="nofollow">this</a> an... | 2 | 2016-07-04T16:35:49Z | 38,189,381 | <p>Do this as below:</p>
<pre><code>#define a function to conver label to letter
def letter(i):
return 'abcdefghij'[i]
# you need a matplotlib inline to be able to show images in python notebook
%matplotlib inline
#some random number in range 0 - length of dataset
sample_idx = np.random.randint(0, len(train_data... | 1 | 2016-07-04T16:55:37Z | [
"python",
"matplotlib",
"machine-learning",
"computer-vision",
"deep-learning"
] |
azure ml experiment return different results than webservice | 38,189,399 | <p>same input is used in two cases, but different result is returned from python module</p>
<p>here is the python script that return the result to the webservice:</p>
<pre><code>import pandas as pd
import sys
def get_segments(dataframe):
dataframe['segment']=dataframe['segment'].astype('str')
segments =... | 3 | 2016-07-04T16:57:16Z | 38,290,069 | <p>After discussion with the product team from Microsoft. the issue was resolved.
the product team rolled out an update to the web service first, and only later to the ML-Studio, which fixed an issue with categorical attributes in "Execute python script".
the issue was in a earlier stage of the flow and has nothing to ... | 0 | 2016-07-10T08:30:23Z | [
"python",
"web-services",
"azure",
"cortana-intelligence",
"azure-ml"
] |
How can I execute in parallel Selenium Python tests with unittest | 38,189,461 | <p>For example I have two tests:</p>
<pre><code>class Test(unittest.TestCase):
def setUp(self):
self.driver = webdriver.Firefox()
self.driver.get("http://google.com")
def tearDown(self):
self.driver.quit()
def test_selenium_1(self):
search_field = self.driver.find_element_by_id("lst-ib")
sear... | 0 | 2016-07-04T17:02:49Z | 38,205,381 | <p>I created Runner for these purposes.</p>
<p>And now I can execute tests in parallel by modules, classes and methods.</p>
<pre><code>import unittest
from concurrent.futures import ThreadPoolExecutor
class Runner():
def parallel_execution(self, *name, options='by_module'):
"""
name - name of t... | 0 | 2016-07-05T13:57:49Z | [
"python",
"unit-testing",
"selenium",
"parallel-processing"
] |
Simple Python Regex Substitution | 38,189,528 | <p>I'm attempting to change a portion of a url using the re.sub() function in python. I assumed it was straightforward, but it doesn't seem to modify my test string in any way.</p>
<p>I have:</p>
<pre><code>line = ' <h3><a href="40_On-Site_Storage_High_Lift_Pumping_Caustic_Storage/31-BUV-4021/DETAILS/... | 0 | 2016-07-04T17:09:43Z | 38,189,600 | <p><code>out = re.sub(r'href=".*?/', 'href="30_Actiflo_and_Filters/', line)</code> worked for me.</p>
| 0 | 2016-07-04T17:16:08Z | [
"python",
"regex",
"python-2.7",
"url"
] |
Simple Python Regex Substitution | 38,189,528 | <p>I'm attempting to change a portion of a url using the re.sub() function in python. I assumed it was straightforward, but it doesn't seem to modify my test string in any way.</p>
<p>I have:</p>
<pre><code>line = ' <h3><a href="40_On-Site_Storage_High_Lift_Pumping_Caustic_Storage/31-BUV-4021/DETAILS/... | 0 | 2016-07-04T17:09:43Z | 38,189,725 | <p>The reason your regex is not working is that your url contains character <code>-</code> which is not included and also you don't need comma in the character class, so <code>[\w_-]*</code> should work fine:</p>
<pre><code>re.sub(r'href="[\w_-]*/','href="30_Actiflo_and_Filters/', line)
# ' <h3><a href... | 0 | 2016-07-04T17:27:17Z | [
"python",
"regex",
"python-2.7",
"url"
] |
Simple Python Regex Substitution | 38,189,528 | <p>I'm attempting to change a portion of a url using the re.sub() function in python. I assumed it was straightforward, but it doesn't seem to modify my test string in any way.</p>
<p>I have:</p>
<pre><code>line = ' <h3><a href="40_On-Site_Storage_High_Lift_Pumping_Caustic_Storage/31-BUV-4021/DETAILS/... | 0 | 2016-07-04T17:09:43Z | 38,189,853 | <p>Here is a simple and sweet solution:</p>
<pre><code>outline = re.sub(r'(is)href="(.*?)/','30_Actiflo_and_Filters/',str(line))
</code></pre>
<p>Since your targetted string is alphanumeric, <code>\w</code> won't help. You may try <code>[0-9a-zA-Z]*</code>.</p>
| 0 | 2016-07-04T17:37:48Z | [
"python",
"regex",
"python-2.7",
"url"
] |
Parsing Google Earth KML file in Python (lxml, namespaces) | 38,189,578 | <p>I am trying to parse a <a href="https://developers.google.com/kml/documentation/" rel="nofollow">.kml</a> file into Python using the xml module (after failing to make this work in BeautifulSoup, which I use for HTML). </p>
<p>As this is my first time doing this, I followed the official <a href="http://lxml.de/1.3/t... | 0 | 2016-07-04T17:13:57Z | 38,234,569 | <p>Here is my solution.
So, the most important thing to do is read <a href="https://msdn.microsoft.com/en-us/library/aa468565.aspx" rel="nofollow">this</a> as posted by Tomalak. It's a really good description of namespaces and easy to understand. </p>
<p>We are going to use <a href="http://www.w3schools.com/xsl/xpath... | 0 | 2016-07-06T22:05:55Z | [
"python",
"xml",
"xpath",
"lxml",
"xml-namespaces"
] |
Pandas not working in Downloads Directory | 38,189,657 | <p>When I enter my <code>Downloads</code> directory on Mac OSX (10.9.5), I entered Python from my terminal and tried to import pandas using <code>import pandas as pd</code></p>
<pre><code>name:Downloads name$ python
Python 2.7.5 (default, Mar 9 2014, 22:15:05)
[GCC 4.2.1 Compatible Apple LLVM 5.0 (clang-500.0.68)] o... | 0 | 2016-07-04T17:21:06Z | 38,189,785 | <p>It looks like you have a file called <code>token.py</code> in your Downloads directory.
It is getting imported instead of the <code>token.py</code> module from the standard library:</p>
<pre><code> File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/tokenize.py", line 30, in <module>... | 1 | 2016-07-04T17:32:29Z | [
"python",
"osx",
"pandas"
] |
Two variables in Python have same id, but not lists or tuples | 38,189,660 | <p>Two variables in Python have the same <code>id</code>:</p>
<pre><code>a = 10
b = 10
a is b
>>> True
</code></pre>
<p>If I take two <code>list</code>s:</p>
<pre><code>a = [1, 2, 3]
b = [1, 2, 3]
a is b
>>> False
</code></pre>
<p>according to <a href="http://stackoverflow.com/questions/27460234/t... | 26 | 2016-07-04T17:21:10Z | 38,189,759 | <p>Immutable objects don't have the same <code>id</code>, and as a mater of fact this is not true for any type of objects that you define separately. Every time you define an object in Python, you'll create a new object with a new identity.</p>
<p>But there are some exceptions for small integers (between -5 and 256) a... | 30 | 2016-07-04T17:30:08Z | [
"python",
"python-3.x",
"tuples",
"identity",
"python-internals"
] |
Two variables in Python have same id, but not lists or tuples | 38,189,660 | <p>Two variables in Python have the same <code>id</code>:</p>
<pre><code>a = 10
b = 10
a is b
>>> True
</code></pre>
<p>If I take two <code>list</code>s:</p>
<pre><code>a = [1, 2, 3]
b = [1, 2, 3]
a is b
>>> False
</code></pre>
<p>according to <a href="http://stackoverflow.com/questions/27460234/t... | 26 | 2016-07-04T17:21:10Z | 38,189,766 | <p><strong>Immutable <code>!=</code> same object.</strong><sup>*</sup></p>
<p><a href="https://docs.python.org/3.5/reference/datamodel.html#data-model" rel="nofollow">An immutable object is simply an object whose state cannot be altered;</a> and that is all. <em>When a new object is created, <strong>a new address will... | 17 | 2016-07-04T17:30:50Z | [
"python",
"python-3.x",
"tuples",
"identity",
"python-internals"
] |
Two variables in Python have same id, but not lists or tuples | 38,189,660 | <p>Two variables in Python have the same <code>id</code>:</p>
<pre><code>a = 10
b = 10
a is b
>>> True
</code></pre>
<p>If I take two <code>list</code>s:</p>
<pre><code>a = [1, 2, 3]
b = [1, 2, 3]
a is b
>>> False
</code></pre>
<p>according to <a href="http://stackoverflow.com/questions/27460234/t... | 26 | 2016-07-04T17:21:10Z | 38,189,778 | <p>Take a look at this code:</p>
<pre><code>>>> a = (1, 2, 3)
>>> b = (1, 2, 3)
>>> c = a
>>> id(a)
178153080L
>>> id(b)
178098040L
>>> id(c)
178153080L
</code></pre>
<p>In order to figure out why <code>a is c</code> is evaluated as <code>True</code> whereas <code... | 12 | 2016-07-04T17:31:49Z | [
"python",
"python-3.x",
"tuples",
"identity",
"python-internals"
] |
Python Datetime strptime ValueError: does not match format | 38,189,696 | <p>having a little trouble pulling the date from a file of mine.</p>
<p>Date strings are in the format: <code>"06/08/2016</code> # Note the parenthesis</p>
<p>and my strptime command is: <code>date = datetime.datetime.strptime(text[0], '\"%m/%d/%Y').date()</code></p>
<p>but I get the following as an error:</p>
<pre... | -2 | 2016-07-04T17:23:53Z | 38,189,756 | <p>The error message tells me that your string data is literally</p>
<pre><code>"Date
</code></pre>
<p>and not</p>
<pre><code>"06/08/2016
</code></pre>
<p>as claimed. Otherwise, your code should work. </p>
| 2 | 2016-07-04T17:29:52Z | [
"python",
"datetime",
"strptime"
] |
Python Datetime strptime ValueError: does not match format | 38,189,696 | <p>having a little trouble pulling the date from a file of mine.</p>
<p>Date strings are in the format: <code>"06/08/2016</code> # Note the parenthesis</p>
<p>and my strptime command is: <code>date = datetime.datetime.strptime(text[0], '\"%m/%d/%Y').date()</code></p>
<p>but I get the following as an error:</p>
<pre... | -2 | 2016-07-04T17:23:53Z | 38,191,015 | <p>This way?</p>
<pre><code>text = '"06/08/2016'
format = '"%m/%d/%Y'
date = datetime.datetime.strptime(text, format).date()
</code></pre>
| 0 | 2016-07-04T19:15:08Z | [
"python",
"datetime",
"strptime"
] |
nested dictionary generation based on values from other dictionaries | 38,189,722 | <p>I have two input datasets one is list (list1) containing list of dictionaries with keys and count values, </p>
<pre><code>list1 = [{u'key': u'1', u'count': 2}, {u'key': u'2', u'count': 1}, {u'key': u'3', u'count': 5}]
</code></pre>
<p>and other one is dictionary (dict1) with numbers(string) as key and status strin... | 0 | 2016-07-04T17:27:12Z | 38,189,999 | <p>This should work, by converting list1 to a proper dictionary, and sorting dict1 into a list. (Hence you had it the opposite of the way it should have been to begin with). It then creates a generator that can be used to yield a dictionary. </p>
<p>This also assumes that every key in dict1 is also found in list1. Not... | 1 | 2016-07-04T17:49:20Z | [
"python",
"dictionary"
] |
nested dictionary generation based on values from other dictionaries | 38,189,722 | <p>I have two input datasets one is list (list1) containing list of dictionaries with keys and count values, </p>
<pre><code>list1 = [{u'key': u'1', u'count': 2}, {u'key': u'2', u'count': 1}, {u'key': u'3', u'count': 5}]
</code></pre>
<p>and other one is dictionary (dict1) with numbers(string) as key and status strin... | 0 | 2016-07-04T17:27:12Z | 38,190,000 | <pre><code>from operator import itemgetter as get
def convert(key_counts, key_to_status, total):
counts = map(get('count'), key_counts)
keys = map(get('key'), key_counts)
status_counts = zip(map(key_to_status.get, keys), counts)
totals = [total] + counts[:-1]
return { status: {'count': count, 'perc... | 0 | 2016-07-04T17:49:22Z | [
"python",
"dictionary"
] |
Cannot bind <Control-bracketleft>, <Control-bracketright> in tkinter.ttk.Notebook (Python 3.5.1) | 38,189,745 | <p>I want to provide users with multiple keybinds for tab traversal in a tkinter.ttk.Notebook object. I'm using the following code: </p>
<pre><code>self.notebook = ttk.Notebook(self)
self.notebook.enable_traversal()
self.notebook.bind('<Control-Key-Prior>', self.priorTab)
self.notebook.bind('<Control-Key-Nex... | 1 | 2016-07-04T17:29:12Z | 38,196,910 | <p>There is probably nothing wrong with the bindings. If you bind to the notebook itself then it must have focus for the bindings to register ( select a tab to gain focus ). If you want the bindings to toggle the notebook tab no matter what has focus then bind to the top-level window ( in this example root )</p>
<p>Ex... | 0 | 2016-07-05T06:49:28Z | [
"python",
"tkinter",
"ttk"
] |
ValueError time data 'Fri Mar 11 15:59:57 EST 2016' does not match format '%a %b %d %H:%M:%S %Z %Y' | 38,189,867 | <p>I am trying to simply create a datetime object from the following date: 'Fri Mar 11 15:59:57 EST 2016' using the format: '%a %b %d %H:%M:%S %Z %Y'.</p>
<p>Here's the code.</p>
<pre><code>from datetime import datetime
date = datetime.strptime('Fri Mar 11 15:59:57 EST 2016', '%a %b %d %H:%M:%S %Z %Y')
</code></pre>
... | 4 | 2016-07-04T17:38:42Z | 38,189,982 | <p>For the %Z specifier, <code>strptime</code> only recognises "UTC", "GMT" and whatever is in <code>time.tzname</code> (so whether it recognises "EST" will depend on the time zone of your computer). This is <a href="http://bugs.python.org/issue22377" rel="nofollow">issue 22377</a>.</p>
<p>See: <a href="http://stackov... | 7 | 2016-07-04T17:48:22Z | [
"python",
"datetime",
"strptime"
] |
Python - Can't pass tuple as an argument to another module | 38,189,921 | <p>First of all, I should tell I'm totally newbie in Python!
So, I may be trying to do something impossible, or something that should be done in a different way. I can't find on the Internet any example about it.</p>
<p>I have two modules in .py. The server.py and the delay_simulator.py. I want to pass a tuple as an a... | 1 | 2016-07-04T17:44:08Z | 38,190,050 | <p>If you want to pass the variable from one module to the next you need to encapsulate it in a function. Try this:</p>
<p>server.py (just part of the code)</p>
<pre><code>import delay_simulator
from collections import namedtuple
pkt = namedtuple("pkt", ["seq_num", "pkt_type", "data"])
. . .
# !!! - Here is where I c... | 0 | 2016-07-04T17:53:59Z | [
"python"
] |
OpenCV Dense Optical Flow Matrix | 38,189,951 | <p>I have another question regarding the output matrix of OpenCVs Dense optical Flow function (Farneback).
I have asked a question similar to this recently </p>
<p>(<a href="http://stackoverflow.com/questions/38131822/what-is-output-from-opencvs-dense-optical-flow-farneback-function-how-can-th">What is output from Ope... | 1 | 2016-07-04T17:45:57Z | 38,206,647 | <p><strong>Fast answer:</strong> For every pixel, you are getting the displacement value on both <code>X</code> and <code>Y</code> axes. </p>
<p>I think you are mixing two different things here:<br>
As I mentioned in your last post and as we see here, your matrix dimensions are <code>(480, 640, 2)</code>. Don't mix b... | 0 | 2016-07-05T14:56:08Z | [
"python",
"opencv",
"matrix",
"opticalflow"
] |
What is the point of using max function for two lists? | 38,189,969 | <p>I am reading a code about kangaroo race;<br>
It gets an input of x1 v1 and x2 v2. Like shown bleow.<br>
I want to figure out what is the difference of using max(X,Y) and min(X,Y);<br> where we could make max(x1,x2) and min(x1, x2); <br>
Please help me to understand it.</p>
<pre><code>x1, v1, x2, v2 = map(int, raw_... | 1 | 2016-07-04T17:47:24Z | 38,190,001 | <p>By default (without the optional <code>key</code> argument), passing lists into <a href="https://docs.python.org/2/library/functions.html#min" rel="nofollow"><code>min</code></a>/<a href="https://docs.python.org/2/library/functions.html#max" rel="nofollow"><code>max</code></a> returns the list that has the largest f... | 2 | 2016-07-04T17:49:42Z | [
"python",
"list"
] |
How to implement crontab that executes Python that imports a module | 38,190,141 | <p>So I have a Python file that runs just fine from the terminal/command-line. The Python file uses a module that was imported using pip. I've set up my crontab file like so to run at 1:15pm every weekday:</p>
<p><code>15 13 * * 1-5 python ~/Personal/Code/Python/HelloWorld.py</code></p>
<p>My problem is two-fold. Fir... | 0 | 2016-07-04T18:00:57Z | 38,190,314 | <p>Not to be mean, but your problem is one-fold: you don't understand <a href="https://en.wikipedia.org/wiki/Cron" rel="nofollow">Cron</a>.</p>
<p>Cron is a scheduling tool. It's to tell your computer "Hey, take care of this every so often, okay?" It's an automated process <em>that does not interact with you</em> afte... | 1 | 2016-07-04T18:15:13Z | [
"python",
"python-2.7",
"cron",
"pip",
"crontab"
] |
Adding a list to a one2many | 38,190,167 | <p>For my use case,I'm trying to add all the product category list to a contact at creation time. </p>
<pre><code>class product_category(models.Model):
_inherit = "product.category"
is_checked = fields.Boolean('Don', help="Check this box if this contact make Donation.")
resRelId ... | 0 | 2016-07-04T18:03:17Z | 38,195,085 | <p>You are trying to write to a one2many field. That's not how you write to a One2many.</p>
<p>This is a handy tip of various ways of adding and deleting from a one2many:</p>
<pre><code>(0, 0, { values }) link to a new record that needs to be created with the given values dictionary
(1, ID, { values }) update ... | 0 | 2016-07-05T04:14:43Z | [
"python",
"openerp"
] |
Adding a list to a one2many | 38,190,167 | <p>For my use case,I'm trying to add all the product category list to a contact at creation time. </p>
<pre><code>class product_category(models.Model):
_inherit = "product.category"
is_checked = fields.Boolean('Don', help="Check this box if this contact make Donation.")
resRelId ... | 0 | 2016-07-04T18:03:17Z | 38,195,296 | <p>There is an easiest way to do this.</p>
<pre><code>@api.model
def create(self, values):
## Here categ is a list containing category ids.
categs = self.env['product.category'].search([]).ids
values.update({'categs':[(6, 0, categs or [])]})
return super(res_partner, self).create(values)
</code></pre>
| 0 | 2016-07-05T04:42:25Z | [
"python",
"openerp"
] |
Same callback to multiple buttons in kivy | 38,190,210 | <p>I'm trying to use the same callback to multiple buttons, I wanted something that returned a boolean value to use the callback like it's done here, but I couldn't find something like this. Is there a way to do it without binding a different function to each button?</p>
<pre><code>import kivy
from kivy.app import App... | 2 | 2016-07-04T18:06:23Z | 38,191,910 | <p>If you see that you're repeating your code it's often mean that you need a loop. Also the method you're binding receive as a first argument instance of button that called it.</p>
<pre><code>import kivy
from kivy.app import App
from kivy.uix.screenmanager import Screen
from kivy.uix.gridlayout import GridLayout
from... | 2 | 2016-07-04T20:35:40Z | [
"python",
"kivy",
"python-3.5"
] |
Scrape data from html tags which recieve text through ajax using scrapy | 38,190,218 | <p>I am trying to scrape details about mobiles listed on 'amazon.in' from this link:<a href="http://www.amazon.in/Smartphones/b?ie=UTF8&node=1805560031" rel="nofollow">here</a> using scrapy.</p>
<p>Here is my code:</p>
<pre><code>from scrapy.spiders import CrawlSpider, Rule
from scrapy.linkextractors import LinkE... | 0 | 2016-07-04T18:06:57Z | 38,190,506 | <p>Nothing is loaded with ajax calls, your xpath is wrong, the following css selector gets all the reviews:</p>
<pre><code>In [13]: response.css("#container a[href*='#customerReviews']::text").extract()
Out[13]:
[u'9,812',
u'32',
u'32',
u'17,301',
u'1,408',
u'99',
u'9,816',
u'9,808',
u'17,298',
u'91',
u'91'... | 0 | 2016-07-04T18:30:44Z | [
"python",
"html",
"ajax",
"web-scraping",
"scrapy"
] |
How to set Template Language to Django in Pycharm Mac Osx Community Edition 5? | 38,190,229 | <p>I have tried following <a href="https://www.jetbrains.com/help/pycharm/2016.1/configuring-template-languages.html" rel="nofollow">https://www.jetbrains.com/help/pycharm/2016.1/configuring-template-languages.html</a>.</p>
<p>But i don't find any Template Language node any where in pycharm5 edition. Please help if th... | 0 | 2016-07-04T18:07:54Z | 38,205,597 | <p>Django template syntax highlighting support is only available in PyCharm Professional Edition.</p>
| 0 | 2016-07-05T14:08:01Z | [
"python",
"django",
"osx",
"pycharm"
] |
How does one initialize a variable with tf.get_variable and a numpy value in TensorFlow? | 38,190,365 | <p>I wanted to initialize some of the variable on my network with numpy values. For the sake of the example consider:</p>
<pre><code>init=np.random.rand(1,2)
tf.get_variable('var_name',initializer=init)
</code></pre>
<p>when I do that I get an error:</p>
<pre><code>ValueError: Shape of a new variable (var_name) must... | 0 | 2016-07-04T18:19:09Z | 38,190,747 | <p>The following works :</p>
<pre><code>init = tf.constant(np.random.rand(1, 2))
tf.get_variable('var_name', initializer=init)
</code></pre>
<p>The documentation for <code>get_variable</code> is a little lacking indeed. Just for your reference, the <code>initializer</code> argument has to be either a TensorFlow <code... | 2 | 2016-07-04T18:53:36Z | [
"python",
"numpy",
"tensorflow"
] |
Adding a .txt to an already zipped file | 38,190,370 | <p>I have created this small python program to automate some processes I want to run. Long story short I use python to pass some information and parameters to a outside program. The outside program does its thing and zips up the results. What I am trying to do is add a "licence.txt" file to the already zipped results. ... | 0 | 2016-07-04T18:19:30Z | 38,190,553 | <p>I don't see why yours would do that but try this, it is a bit simpler:</p>
<pre><code>import zipfile
for filepath in data:
with zipfile.ZipFile(filepath, 'a') as myzip:
myzip.write('license.txt')
</code></pre>
| 0 | 2016-07-04T18:34:20Z | [
"python",
"zipfile"
] |
Installation of python google api in Ubuntu | 38,190,468 | <p>Below command is used for installing Google-API in python for Linux.</p>
<pre><code> pip install --upgrade google-api-python-client
</code></pre>
<p>Below errors are shown by above command</p>
<blockquote>
<p>File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main</p>
<p>status = sel... | 1 | 2016-07-04T18:28:38Z | 38,190,691 | <p>Always remember there would be many errors and disparencies if you try to install packages without virtual environment in python.</p>
<p>I would like you to create a virtual environment as specified in the link and then try it out.</p>
<p><a href="http://docs.python-guide.org/en/latest/dev/virtualenvs/" rel="nofol... | 1 | 2016-07-04T18:46:53Z | [
"python",
"google-api",
"ubuntu-14.04"
] |
Installation of python google api in Ubuntu | 38,190,468 | <p>Below command is used for installing Google-API in python for Linux.</p>
<pre><code> pip install --upgrade google-api-python-client
</code></pre>
<p>Below errors are shown by above command</p>
<blockquote>
<p>File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main</p>
<p>status = sel... | 1 | 2016-07-04T18:28:38Z | 38,205,896 | <pre><code>1) sudo -E pip install --upgrade pip
2) sudo -E pip install --upgrade google-api-python-client
</code></pre>
<p>Than environmental variables using flag -E is better </p>
| 1 | 2016-07-05T14:21:45Z | [
"python",
"google-api",
"ubuntu-14.04"
] |
Pandas: Find first occurrence - on daily basis in a timeseries | 38,190,472 | <p>I'm struggling with this so any input appreciated. I want to iterate over the values in a dataframe column and return the first instance when a value is seen every day. Groupby looked to be a good option for this but when using <code>df.groupby(grouper).first()</code> with <code>grouper</code> set at daily the fo... | 0 | 2016-07-04T18:28:49Z | 38,191,071 | <p>Try this, using this data: </p>
<pre><code>rng = pd.DataFrame( {'test_1': [None, None,None, None, 1,1, 1 , None, None, None,1 , None, None, None,]}, index = pd.date_range('4/2/2014', periods=14, freq='BH'))
rng
test_1
2014-04-02 09:00:00 NaN
2014-04-02 10:00:00 NaN
2014-04-02 11:00:00 ... | 0 | 2016-07-04T19:20:10Z | [
"python",
"pandas",
"time-series"
] |
Who work random_state of shuffle in sklearn.utils? | 38,190,476 | <p>what is the random_state parameter in <code>shuffle</code> in <code>sklearn.utils</code>? any one can explain random_state with some sample?</p>
| 0 | 2016-07-04T18:29:02Z | 38,210,891 | <p>The <code>shuffle</code> is used to shuffle your matrices randomly. Programmatically, random sequences are generated using a seed number. You are guaranteed to have the same random sequence if you use the same seed. The <code>random_state</code> parameter allows you to provide this random seed to sklearn methods. Th... | 0 | 2016-07-05T19:08:13Z | [
"python",
"scikit-learn",
"shuffle"
] |
opencv python color detection with boolean output | 38,190,498 | <p>i use this Script for color detection:</p>
<p># import the necessary packages</p>
<pre><code> import numpy as np
import argparse
import cv2
</code></pre>
<p># construct the argument parse and parse the arguments</p>
<pre><code>ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", help = "pat... | 0 | 2016-07-04T18:30:21Z | 38,193,461 | <p>here my own solution:</p>
<p># import the necessary packages</p>
<pre><code>import shutil
import numpy as np
import argparse
import cv2
</code></pre>
<p># construct the argument parse and parse the arguments</p>
<pre><code>ap = argparse.ArgumentParser()
ap.add_argument("-i", "--image", help = "path to the image"... | 0 | 2016-07-04T23:48:37Z | [
"python",
"opencv",
"color-detection"
] |
Base class methods to be used by all derived classes except one | 38,190,535 | <p>I have a situation where a base class method (the <code>__init__</code> method in Python) does a lot of work. The derived classes override <code>__init__</code> to simply set an object variable and then delegate to the base class <code>__init__</code>. This works fine but now I have a situation. </p>
<p>I have some... | 0 | 2016-07-04T18:32:20Z | 38,190,750 | <p>The clearest solution would be to use a default argument:</p>
<pre><code>class Base:
def __init__(self, *, doAction1=True):
if doAction1:
Action 1...
Action 2...
</code></pre>
<p>Then in class <code>A</code> you can have:</p>
<pre><code>def __init__(self):
Some init code....
sup... | 3 | 2016-07-04T18:53:50Z | [
"python",
"class",
"oop",
"inheritance"
] |
Base class methods to be used by all derived classes except one | 38,190,535 | <p>I have a situation where a base class method (the <code>__init__</code> method in Python) does a lot of work. The derived classes override <code>__init__</code> to simply set an object variable and then delegate to the base class <code>__init__</code>. This works fine but now I have a situation. </p>
<p>I have some... | 0 | 2016-07-04T18:32:20Z | 38,192,693 | <p>Class attribute that can be overridden - similar to default argument in <code>__init__</code>. (Python v2.7 class definition).</p>
<pre><code>class Foo(object):
action1 = True
action2 = True
def __init__(self):
if self.action1:
print('action1')
if self.action2:
print('action2... | 0 | 2016-07-04T21:58:20Z | [
"python",
"class",
"oop",
"inheritance"
] |
Base class methods to be used by all derived classes except one | 38,190,535 | <p>I have a situation where a base class method (the <code>__init__</code> method in Python) does a lot of work. The derived classes override <code>__init__</code> to simply set an object variable and then delegate to the base class <code>__init__</code>. This works fine but now I have a situation. </p>
<p>I have some... | 0 | 2016-07-04T18:32:20Z | 38,207,077 | <p>When making design decisions, it is often worth considering whether inheritance is the right way to go. Think deeply about whether your really do need inheritance, or whether it's just going to make things complicated. </p>
<p>If you were to decide that inheritance is not actually needed (the current issue you are ... | 0 | 2016-07-05T15:15:55Z | [
"python",
"class",
"oop",
"inheritance"
] |
Generate character count of sequences | 38,190,538 | <p>I have a string like '<strong>....(((...((...</strong>' for which I have to generate another string '<strong>ss(4)h5(3)ss(3)h2(2)ss(3)</strong>'.</p>
<p>'.' corresponds to 'ss' and the number of continous '.' is in the bracket.</p>
<p>'(' corresponds to 'h5' and the number of continuos '(' is in the bracket.</p>
... | 3 | 2016-07-04T18:32:42Z | 38,190,613 | <p>I donât know about modifying your existing code, but to me this can be done very succinctly and pythonically using <a href="https://docs.python.org/3.5/library/itertools.html#itertools.groupby" rel="nofollow"><code>itertools.groupby</code></a>. Note that Iâm not sure if the <code>'h2'</code> in your expected out... | 4 | 2016-07-04T18:40:37Z | [
"python",
"string"
] |
Generate character count of sequences | 38,190,538 | <p>I have a string like '<strong>....(((...((...</strong>' for which I have to generate another string '<strong>ss(4)h5(3)ss(3)h2(2)ss(3)</strong>'.</p>
<p>'.' corresponds to 'ss' and the number of continous '.' is in the bracket.</p>
<p>'(' corresponds to 'h5' and the number of continuos '(' is in the bracket.</p>
... | 3 | 2016-07-04T18:32:42Z | 38,190,765 | <p>@Kelvin 's answer is great, however if you want to define a function yourself, you could do it like this:</p>
<pre class="lang-py prettyprint-override"><code>def h5ss(x):
names = {".": "ss", "(": "h5"}
count = 0
current = None
out = ""
for i in x:
if i == current:
count += 1
... | 1 | 2016-07-04T18:55:29Z | [
"python",
"string"
] |
Python3 wifi module returns object, not list of wifi networks | 38,190,545 | <p>I just installed the wifi library, and started following the guide <a href="https://wifi.readthedocs.io/en/latest/scanning.html" rel="nofollow">here</a>, but when I type</p>
<pre><code>>>> from wifi import Cell, Scheme
>>> Cell.all('wlan0')
</code></pre>
<p>The output I get isn't a list, but an o... | 1 | 2016-07-04T18:33:33Z | 38,190,560 | <p>The <code>all</code> method of <code>Cell</code> returns a <code>map(...)</code>. In Python 2.x this will <em>automatically</em> return a list, but Python 3.x returns a <code>map</code> object (an iterator) which can be converted into a list by calling <code>list</code> on it.</p>
<p>So you can see the full list of... | 2 | 2016-07-04T18:34:43Z | [
"python",
"python-3.x",
"networking",
"wifi"
] |
How can I scrape data that is locked by a button? | 38,190,635 | <p>I'm trying to fetch some info from a website, without success.</p>
<p>The problem is that the data is shown only after clicking a certain button.</p>
<p><a href="http://i.stack.imgur.com/i45mi.png" rel="nofollow"><img src="http://i.stack.imgur.com/i45mi.png" alt="first_page"></a></p>
<p>The info that I want is lo... | 2 | 2016-07-04T18:41:41Z | 38,190,838 | <p>As you can see when using Google Chrome's Dev tools in the "Network" tab, it sends a a POST request to <code>http://www.doctoralia.com.br/noindex/doctor-phone</code>. This POST request is protected against CSRF, so it will be very hard to fake this request in order to get the data.</p>
<p>Since <code>BeautifulSoup<... | 2 | 2016-07-04T19:01:17Z | [
"jquery",
"python",
"html",
"web-scraping",
"beautifulsoup"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.