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
How can I read an imported object's code?
39,936,673
<p>I don't know what attributes an object supports. How can I open up the module and figure out what's going on "under the hood"?</p> <p>For example, I want to figure out what attributes the <code>datetime</code> object from the <code>datetime</code> module has in its <code>__init__</code>:</p> <pre><code>import date...
-2
2016-10-08T19:46:52Z
39,936,722
<p>I find the <code>dir</code> function to be the most useful when dealing with unknown and undocumented objects (<a href="https://docs.python.org/2/library/datetime.html" rel="nofollow"><code>datetime</code> is well documented</a>, btw).</p> <p>But if it weren't documented:</p> <pre><code>&gt;&gt;&gt; import datetim...
0
2016-10-08T19:52:28Z
[ "python" ]
How can I read an imported object's code?
39,936,673
<p>I don't know what attributes an object supports. How can I open up the module and figure out what's going on "under the hood"?</p> <p>For example, I want to figure out what attributes the <code>datetime</code> object from the <code>datetime</code> module has in its <code>__init__</code>:</p> <pre><code>import date...
-2
2016-10-08T19:46:52Z
39,936,813
<p>In your terminal, type <code>pydoc (whatever)</code> and you should be able to see all the variables and functions it has. If it's undocumented, <code>dir([whatever])</code> is the way to go. In any situation, obviously Google. BTW, to clarify the terms in your question, <code>datetime</code> is a <em>module</em>. Y...
0
2016-10-08T20:01:51Z
[ "python" ]
What is the equivalent of matlab's wkeep in Python?
39,936,676
<p>If I want to extract a vector of certain size from a matrix, how do I do it?</p> <p>I'm looking for something that does exactly the same thing as <a href="http://in.mathworks.com/help/wavelet/ref/wkeep.html" rel="nofollow"><code>wkeep</code></a> in matlab</p>
0
2016-10-08T19:47:30Z
39,936,959
<p>It turns out that a lot of the use-cases of <code>wkeep</code> can be written more idomatically:</p> <pre><code>X[1:3,1:4] # wkeep(X, [2, 3]) </code></pre> <p>If you don't actually need it to be centered, you could use:</p> <pre><code>X[:2, :4] # wkeep(X, [2, 3], 'l') X[-2:, -4:] # wkeep(X, [2, 3], 'r') ...
4
2016-10-08T20:18:46Z
[ "python", "matlab", "numpy" ]
How to compute a hash of a sqlite database file without causing harm
39,936,697
<p>I have a function like the following that I want to use to compute the hash of a sqlite database file, in order to compare it to the last backup I made to detect any changes.</p> <pre> def get_hash(file_path): # http://stackoverflow.com/a/3431838/1391717 hash_sha1 = hashlib.sha1 with open(file_path, "rb...
0
2016-10-08T19:49:55Z
39,938,696
<p>The sqlite3 database files, can and may be read by many different readers at the same time. There is no problem with concurrency in that respect with sqlite3. The problems which is native to sqlite3 concerns writing to the file, only one writer is allowed. </p> <p>So if you only read your fine. </p> <p>If you are ...
0
2016-10-09T00:09:34Z
[ "python", "sqlite", "sqlite3" ]
how to view encrypted image as is without decryption
39,936,706
<pre><code>#encrypting an image using AES import binascii from Crypto.Cipher import AES def pad(s): return s + b"\0" * (AES.block_size - len(s) % AES.block_size) filename = 'path to input_image.jpg' with open(filename, 'rb') as f: content = f.read() #converting the jpg to hex, trimming whitespaces and padding. ...
-1
2016-10-08T19:51:32Z
39,937,726
<p>The question here is how to display encrypted image as an image without decrypting it.</p> <p>The encrypted contents are not an image and cannot be unambiguously represented as an image. The best that can be done is to treat it as a bitmap, i.e. each binary value represents the intensity of some color at some coord...
2
2016-10-08T21:51:11Z
[ "python", "cryptography", "pillow", "pycrypto" ]
My Code failed with error "AttributeError: 'NoneType' object has no attribute 'add'"
39,936,831
<p>I have this pieces of code that crawled a site, extract all the needed url from the site, format the url into required format, then at a point where i am suppose to add it to a set for further proccessing. I encounter the following error, "AttributeError: 'NoneType' object has no attribute 'add'" The part of the cod...
-2
2016-10-08T20:03:20Z
39,954,813
<p>Do not inherit from <code>BeautifulSoup</code>; rather, use aggregation and its query interface instead! The <code>BeautifulSoup.__init__</code> will call your overridden <code>handle_starttag</code>, before <code>self.pdf_url_links</code> is initialized.</p> <p>The <code>BeautifulSoup</code> class has a <code>__ge...
3
2016-10-10T09:05:47Z
[ "python" ]
My Code failed with error "AttributeError: 'NoneType' object has no attribute 'add'"
39,936,831
<p>I have this pieces of code that crawled a site, extract all the needed url from the site, format the url into required format, then at a point where i am suppose to add it to a set for further proccessing. I encounter the following error, "AttributeError: 'NoneType' object has no attribute 'add'" The part of the cod...
-2
2016-10-08T20:03:20Z
39,982,020
<p>The problem was caused by the way BeautifulSoup constructor works.</p> <pre><code>class Finder(bs4.BeautifulSoup): def __init__(self, m, page_url): super().__init__(m, 'html.parser') self.page_url = page_url self.pdf_url_links = set() </code></pre> <p>As soon as <code>BeautifulSoup.__init__</...
1
2016-10-11T16:21:01Z
[ "python" ]
Matplotlib "pick_event" not working in embedded graph with FigureCanvasTkAgg
39,936,869
<p>I'm trying to handle some events to perform user interactions with embedded subplots into a Tkinter frame. Like in this <a href="http://matplotlib.org/examples/user_interfaces/embedding_in_tk.html" rel="nofollow">example</a></p> <p>Works fine with "key_press_event" and "button_press_event", but does not work with "...
0
2016-10-08T20:08:02Z
39,938,402
<p>Well, I solved it...</p> <p>Most events we just need to use <code>mpl_connect</code> method to the magic happen. My mistake is that I didn't notice that we need to say explictly that our plot is "pickable" putting a argument <code>picker=True</code> to only triggers the event if clicked exacly into the artist, and ...
0
2016-10-08T23:20:48Z
[ "python", "events", "matplotlib", "tkinter" ]
Stepping into RFE and getting 'DataFrame object is not callable" error
39,936,914
<p>I'm trying to use RFE for the first time and banging my head against a "DataFrame object is not callable" error.</p> <p>Here is my code</p> <pre><code>X, y = df5(n_samples=875, n_features=10, random_state=0) estimator = SVR(kernel="linear") selector = RFE(LinearRegression, step=1, cv=5) selector = selector.fit(X, ...
0
2016-10-08T20:13:49Z
39,971,197
<p>If you want select columns first figure out the information about your dataframe then select required features.</p> <pre><code># the next 2 lines is to initialize DataFrame object (just for the example) &gt;&gt;&gt; from pandas import DataFrame &gt;&gt;&gt; df = DataFrame.from_dict({'one': range(10), 'two': range(1...
0
2016-10-11T05:55:04Z
[ "python", "scikit-learn", "rfe" ]
Python 3 permutations Scrabble
39,936,976
<p>I'm struggling a bit with an effective way of debugging Python, and the consequent lack of understanding and optimization.</p> <p>I'm in the process of writing a Scrabble game in Python as an experiment, and I suspect I'm going about it all wrong. Namely, I'm failing to understand how to handle the blank tiles (rep...
0
2016-10-08T20:21:08Z
39,937,280
<p>This should work, and be acceptably fast. I tried to comment the tricky parts, do not hesitate to ask if there are some bits of the code you do not understand. </p> <pre><code>import itertools import string import numpy as np #takes a list of words as input ['door', 'chair', 'wall'], and returns the words alphabet...
0
2016-10-08T20:55:56Z
[ "python", "python-3.x" ]
Pandas plot dataframe by index, how it works?
39,936,983
<p>Given the data:</p> <pre><code>Column1; Column2; Column3 1; 4; 6 2; 2; 6 3; 3; 8 4; 1; 1 5; 4; 2 </code></pre> <p>With the following code I get the following graphic:</p> <pre><code>import pandas as pd import matplotlib.pyplot as plt df = pd.read_csv('test0.csv',delimiter='; ', engine='python') df.plot(0,0) plt.s...
0
2016-10-08T20:21:44Z
39,937,159
<p>When you specify <code>x</code> and <code>y</code> by ordinal position, you'll reach <a href="https://github.com/pydata/pandas/blob/master/pandas/tools/plotting.py#L2449" rel="nofollow">this bit of code</a> when calling <code>df.plot(x, y)</code>:</p> <pre><code> if isinstance(data, DataFrame): if x is n...
1
2016-10-08T20:40:41Z
[ "python", "python-2.7", "pandas", "matplotlib", "dataframe" ]
Pandas plot dataframe by index, how it works?
39,936,983
<p>Given the data:</p> <pre><code>Column1; Column2; Column3 1; 4; 6 2; 2; 6 3; 3; 8 4; 1; 1 5; 4; 2 </code></pre> <p>With the following code I get the following graphic:</p> <pre><code>import pandas as pd import matplotlib.pyplot as plt df = pd.read_csv('test0.csv',delimiter='; ', engine='python') df.plot(0,0) plt.s...
0
2016-10-08T20:21:44Z
39,937,162
<p>Whatever column is used as <code>x</code> is removed from the DataFrame before <code>y</code> is looked up. (Or, more technically, <code>x</code> is set as the index, which means its no longer available as a column.) So if you do <code>.plot(x=0, y=0)</code>, the <code>x=0</code> means "use the first positional co...
3
2016-10-08T20:40:47Z
[ "python", "python-2.7", "pandas", "matplotlib", "dataframe" ]
Pandas plot dataframe by index, how it works?
39,936,983
<p>Given the data:</p> <pre><code>Column1; Column2; Column3 1; 4; 6 2; 2; 6 3; 3; 8 4; 1; 1 5; 4; 2 </code></pre> <p>With the following code I get the following graphic:</p> <pre><code>import pandas as pd import matplotlib.pyplot as plt df = pd.read_csv('test0.csv',delimiter='; ', engine='python') df.plot(0,0) plt.s...
0
2016-10-08T20:21:44Z
39,937,408
<p>According to the <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.plot.html" rel="nofollow">documentation</a>, you can define <em>m</em> and <em>n</em> (<em>x</em> and <em>y</em> in the documentation) like this:</p> <pre><code>df.plot(df.columns[1],df.columns[2]) </code></pre> <ul> <...
1
2016-10-08T21:08:34Z
[ "python", "python-2.7", "pandas", "matplotlib", "dataframe" ]
Is aiopg supprted for python 3.6 now?
39,937,084
<p>Today I tried to use new version of Python (3.6). I installed <code>aiopg</code> by pip (via PyCharm interpreter section tool). And after I tried to import <code>aiopg</code>, exception was happend:</p> <pre><code>from aiopg.sa import create_engine File "C:\Python36\lib\site-packages\aiopg\__init__.py", line 5, i...
1
2016-10-08T20:32:03Z
39,944,760
<p><code>aiopg==0.11</code> has a regression but brand new <code>aiopg==0.12</code> should work on Windows.</p>
1
2016-10-09T14:34:04Z
[ "python", "python-asyncio" ]
Seaborn boxplot: TypeError: unsupported operand type(s) for /: 'str' and 'int'
39,937,140
<p>I try to make vertical seaborn boxplot like this</p> <pre><code>import pandas as pd df = pd.DataFrame({'a' : ['a', 'b' , 'b', 'a'], 'b' : [5, 6, 4, 3] }) import seaborn as sns import matplotlib.pylab as plt %matplotlib inline sns.boxplot( x= "b",y="a",data=df ) </code></pre> <p>i get </p> <p><a href="http://i.st...
1
2016-10-08T20:37:52Z
39,937,451
<p>For seaborn's boxplots it is important to keep an eye on the x-axis and y-axis assignments, when switching between horizontal and vertical alignment:</p> <pre><code>%matplotlib inline import pandas as pd import seaborn as sns df = pd.DataFrame({'a' : ['a', 'b' , 'b', 'a'], 'b' : [5, 6, 4, 3] }) # horizontal boxpl...
2
2016-10-08T21:14:38Z
[ "python", "seaborn" ]
What's the most efficient way to find factors in a list?
39,937,160
<h2>What I'm looking to do:</h2> <p>I need to make a function that, given a list of positive integers (there can be duplicate integers), counts all triples (in the list) in which the third number is a multiple of the second and the second is a multiple of the first:</p> <p>(The same number cannot be used twice in one...
4
2016-10-08T20:40:43Z
39,937,284
<p>Right now your algorithm has O(N^3) running time, meaning that every time you double the length of the initial list the running time goes up by 8 times.</p> <p>In the worst case, you cannot improve this. For example, if your numbers are all successive powers of 2, meaning that every number divides every number grat...
3
2016-10-08T20:56:33Z
[ "python", "algorithm" ]
What's the most efficient way to find factors in a list?
39,937,160
<h2>What I'm looking to do:</h2> <p>I need to make a function that, given a list of positive integers (there can be duplicate integers), counts all triples (in the list) in which the third number is a multiple of the second and the second is a multiple of the first:</p> <p>(The same number cannot be used twice in one...
4
2016-10-08T20:40:43Z
39,937,498
<p>the key insight is:</p> <p>if <strong>a</strong> divides <strong>b</strong>, it means <strong>a</strong> "fits into <strong>b</strong>". if <strong>a</strong> doesn't divide <strong>c</strong>, then it means "<strong>a</strong> doesn't fit into <strong>c</strong>". And if <strong>a</strong> can't fit into <strong>c...
3
2016-10-08T21:19:31Z
[ "python", "algorithm" ]
What's the most efficient way to find factors in a list?
39,937,160
<h2>What I'm looking to do:</h2> <p>I need to make a function that, given a list of positive integers (there can be duplicate integers), counts all triples (in the list) in which the third number is a multiple of the second and the second is a multiple of the first:</p> <p>(The same number cannot be used twice in one...
4
2016-10-08T20:40:43Z
39,947,574
<p>This is the best answer that I was able to come up with so far. It's fast, but not quite fast enough. I'm still posting it because I'm probably going to abandon this question and don't want to leave out any progress I've made.</p> <pre><code>def answer(l): num_dict = {} ans_set = set() for a2, a in enu...
0
2016-10-09T19:20:12Z
[ "python", "algorithm" ]
Matplotlib - contour and quiver plot in projected polar coordinates
39,937,249
<p>I need to plot contour and quiver plots of scalar and vector fields defined on an uneven grid in (r,theta) coordinates.</p> <p>As a minimal example of the problem I have, consider the contour plot of a <em><a href="https://en.wikipedia.org/wiki/Stream_function" rel="nofollow">Stream function</a></em> for a magneti...
0
2016-10-08T20:51:03Z
39,937,952
<p>If <code>psi = m * np.sin(theta_matrix)**2 / r_matrix</code> then psi increases as theta goes from 0 to pi/2 and psi decreases as r increases.</p> <p>So a contour line for psi should increase in r as theta increases. That results in a curve that goes counterclockwise as it radiates out from the center. This is cons...
1
2016-10-08T22:19:52Z
[ "python", "numpy", "matplotlib", "contour", "polar-coordinates" ]
requests.exceptions.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:590)
39,937,288
<p>I have a script that's made in python as below</p> <pre><code>#!/bin/env python2.7 # Run around 1059 as early as 1055. # Polling times vary pick something nice. # Ghost checkout timer can be changed by # adjusting for loop range near bottom. # Fill out personal data in checkout payload dict. import sys, json, ti...
-1
2016-10-08T20:56:53Z
39,937,538
<p>As can be seen from <a href="https://www.ssllabs.com/ssltest/analyze.html?d=www.supremenewyork.com" rel="nofollow">the SSLLabs report</a> the server supports only TLS 1.2 and supports only very few ciphers. Given a path like <code>/Users/...</code> in your error output I assume that you are using Mac OS X. The versi...
0
2016-10-08T21:24:01Z
[ "python", "ssl", "handshake", "sslv3" ]
How to save a list of words and the positions of these words in the sentence as a file
39,937,357
<p>My Code: (Python: v3.5.2)</p> <pre><code>import time import sys def Word_Position_Finder(): chosen_sentence = input("Make a simple sentence: ").upper() print("") print(chosen_sentence) print("") sentence_list = chosen_sentence.split() if len(chosen_sentence) == 0: print("Your sente...
-1
2016-10-08T21:04:31Z
39,937,436
<p>Iterate over the list containing the words of sentence. For each word, check that whether it exists in the other list containing words for finding the positions. Use <a href="https://docs.python.org/2/library/collections.html#collections.defaultdict" rel="nofollow"><code>collections.defaultdict</code></a> to store t...
1
2016-10-08T21:12:05Z
[ "python" ]
Adding Specific Value to Nested Lists
39,937,428
<p>I'm having a comprehension issue on a specific problem. I have a preexisting nested list, and I want to match and append one value from a different list to the end of each nested list. A quick example of what I've tried, but where I'm stuck: </p> <pre><code> initial_values = [["First", 1], ["Second", 2], ["Third", ...
1
2016-10-08T21:10:53Z
39,937,449
<p>It seems like you want to go through both lists with a single iteration. You could achieve that using zip:</p> <pre><code>for sublist, i in zip(initial_values, other_values): sublist.append(i) </code></pre>
1
2016-10-08T21:14:21Z
[ "python", "list" ]
Adding Specific Value to Nested Lists
39,937,428
<p>I'm having a comprehension issue on a specific problem. I have a preexisting nested list, and I want to match and append one value from a different list to the end of each nested list. A quick example of what I've tried, but where I'm stuck: </p> <pre><code> initial_values = [["First", 1], ["Second", 2], ["Third", ...
1
2016-10-08T21:10:53Z
39,937,452
<p>You can use <a href="https://docs.python.org/2/library/functions.html#zip" rel="nofollow"><code>zip</code></a> to match elements of the same index from different lists. From there on, you're a simple list concatenation away:</p> <pre><code>[a + [b] for a,b in zip(initial_values, other_values)] </code></pre>
2
2016-10-08T21:14:39Z
[ "python", "list" ]
Adding Specific Value to Nested Lists
39,937,428
<p>I'm having a comprehension issue on a specific problem. I have a preexisting nested list, and I want to match and append one value from a different list to the end of each nested list. A quick example of what I've tried, but where I'm stuck: </p> <pre><code> initial_values = [["First", 1], ["Second", 2], ["Third", ...
1
2016-10-08T21:10:53Z
39,937,463
<p>Built-in function <a href="https://docs.python.org/3/library/functions.html#zip" rel="nofollow">zip</a> will match first item in first list with first item in second list etc.</p> <pre><code>initial_values = [["First", 1], ["Second", 2], ["Third", 3], ["Fourth", 4]] other_values = [1,2,3,4] for initials, other in ...
0
2016-10-08T21:15:34Z
[ "python", "list" ]
Adding Specific Value to Nested Lists
39,937,428
<p>I'm having a comprehension issue on a specific problem. I have a preexisting nested list, and I want to match and append one value from a different list to the end of each nested list. A quick example of what I've tried, but where I'm stuck: </p> <pre><code> initial_values = [["First", 1], ["Second", 2], ["Third", ...
1
2016-10-08T21:10:53Z
39,937,472
<p>Your double for-loop takes each sublist in turn (the outer for-loop) and appends every element of <code>other_values</code> to it (the inner for-loop). What you want instead is to add each element of <code>other_values</code> to the corresponding sublist (i.e. the sublist at the same position/index). Therefore, what...
1
2016-10-08T21:16:44Z
[ "python", "list" ]
Adding Specific Value to Nested Lists
39,937,428
<p>I'm having a comprehension issue on a specific problem. I have a preexisting nested list, and I want to match and append one value from a different list to the end of each nested list. A quick example of what I've tried, but where I'm stuck: </p> <pre><code> initial_values = [["First", 1], ["Second", 2], ["Third", ...
1
2016-10-08T21:10:53Z
39,937,537
<p>If you want to use for loop you can try </p> <pre><code>initial_values = [["First", 1], ["Second", 2], ["Third", 3], ["Fourth", 4]] other_values = [1,2,3,4] for i in range(0,len(other_values)): initial_values[i].append(other_values[i]) print initial_values </code></pre> <p>output:<br> <code>[['First', 1, 1]...
1
2016-10-08T21:24:01Z
[ "python", "list" ]
Adding Specific Value to Nested Lists
39,937,428
<p>I'm having a comprehension issue on a specific problem. I have a preexisting nested list, and I want to match and append one value from a different list to the end of each nested list. A quick example of what I've tried, but where I'm stuck: </p> <pre><code> initial_values = [["First", 1], ["Second", 2], ["Third", ...
1
2016-10-08T21:10:53Z
39,937,561
<p>One of the alternative to achieve it using <a href="https://docs.python.org/2/library/functions.html#map" rel="nofollow"><code>map()</code></a> as:</p> <pre><code>&gt;&gt;&gt; map(lambda x: x[0] + [x[1]], zip(initial_values, other_values)) [['First', 1, 1], ['Second', 2, 2], ['Third', 3, 3], ['Fourth', 4, 4]] </cod...
1
2016-10-08T21:26:47Z
[ "python", "list" ]
Iam having trouble with Python command “ cascPath = sys.argv[1] ” i get error IndexError: list index out of range
39,937,634
<p>I am using a Raspberry Pi 3 Model B, with Raspbian, opencv 2.x and Python 3 installed.</p> <p>I want to access my USB Webcam and take a picture with it. I've found tons of code but none are of any use. I found one which is better but when I run the command</p> <pre><code>cascPath = sys.argv[1] </code></pre> <p>I ...
0
2016-10-08T21:36:18Z
39,937,737
<p>This code try to recognize faces on image and <code>sys.argv[1]</code> expects you run script with path to XML file which help recognize faces.</p> <p>If you don't want to recognize faces then you need only this code to display on monitor video from camera.</p> <pre><code>import cv2 import sys video_capture = cv...
0
2016-10-08T21:52:59Z
[ "python", "opencv", "debian", "webcam", "raspberry-pi3" ]
Pandas plot without specifying index
39,937,650
<p>Given the data:</p> <pre><code>Column1; Column2; Column3 1; 4; 6 2; 2; 6 3; 3; 8 4; 1; 1 5; 4; 2 </code></pre> <p>I can plot it via:</p> <pre><code>import pandas as pd import matplotlib.pyplot as plt df = pd.read_csv('test0.csv',delimiter='; ', engine='python') titles = list(df) for title in titles: if title...
0
2016-10-08T21:39:29Z
39,937,721
<p>I am not sure what you are trying to achieve but you could reset index and set it as you would like:</p> <pre><code>In[11]: df Out[11]: Column1 Column2 Column3 0 1 4 6 1 2 2 6 2 3 3 8 3 4 1 1 4 5 4 ...
0
2016-10-08T21:50:09Z
[ "python", "python-2.7", "pandas", "matplotlib", "dataframe" ]
Infinite Loop Exits Automatically while Using multithreading and Queues
39,937,666
<p>I'm trying to run a function that has an infinite loop (to check data after few seconds of delay) using multithreading. Since I read data from a csv file, I'm also using Queues.</p> <p>My current function fine when I do not use multithreading/queues but when I use them, the function only loops once and then stops.<...
0
2016-10-08T21:41:12Z
39,961,822
<p>For anyone that is facing the same issue, here's how I solved it.</p> <p>I removed q.task_done() from the while loop and put it outside the while loop. This is working as intended but I'm not sure if this is the right approach.</p>
0
2016-10-10T15:36:05Z
[ "python", "multithreading" ]
Get Text from Span returns empty string
39,937,692
<p>I'm trying to get the text from the span inside this div with python and selenium:</p> <pre><code>&lt;div class="product-name"&gt; &lt;span class="h1" itemprop="name"&gt;TEXT&lt;/span&gt; &lt;/div&gt; </code></pre> <p>I've tried this, however, this returns an empty string:</p> <pre><code>line = dr.find_elemen...
0
2016-10-08T21:46:11Z
39,938,510
<p>You should try using <code>css_selector</code> to find desire element in one find statement as below :-</p> <pre><code>line = dr.find_element_by_css_selector('div.product-name &gt; span').text </code></pre> <p>If you're still getting empty string try using <code>get_attribute("textContent")</code> as :-</p> <pre>...
1
2016-10-08T23:41:45Z
[ "python", "selenium", "web-scraping", "phantomjs" ]
Get Text from Span returns empty string
39,937,692
<p>I'm trying to get the text from the span inside this div with python and selenium:</p> <pre><code>&lt;div class="product-name"&gt; &lt;span class="h1" itemprop="name"&gt;TEXT&lt;/span&gt; &lt;/div&gt; </code></pre> <p>I've tried this, however, this returns an empty string:</p> <pre><code>line = dr.find_elemen...
0
2016-10-08T21:46:11Z
39,938,549
<p>I find bs4 more intuitive, prehaps this would suite better? </p> <pre><code> from bs4 import BeautifulSoup as bs4 def main(): html = """&lt;div class="product-name"&gt; &lt;span class="h1" itemprop="name"&gt;TEXT&lt;/span&gt; &lt;/div&gt;""" soup = bs4(html, "html.parser") p...
0
2016-10-08T23:47:20Z
[ "python", "selenium", "web-scraping", "phantomjs" ]
Resample 2d coordinates with values in pandas
39,937,695
<p>I have a data frame in pandas containing x coordinates, y coordinates, and values. I would like to "downsample" my coordinates and add the values appropriately.</p> <pre><code>df = pd.DataFrame({'x': [1,2,3,4,1,2,3,4,1,2,3,4,1,2,3,4], 'y': [1,1,1,1, 2,2,2,2, 3,3,3,3, 4,4,4,4], ...
1
2016-10-08T21:46:32Z
39,938,725
<p>Try this</p> <pre><code>g = df.groupby([df.x.sub(1) // 2 * 2 + 1.5, df.y.sub(1) // 2 * 2 + 1.5]) g.v.sum().reset_index() </code></pre> <p><a href="http://i.stack.imgur.com/NDeOt.png" rel="nofollow"><img src="http://i.stack.imgur.com/NDeOt.png" alt="enter image description here"></a></p>
1
2016-10-09T00:16:58Z
[ "python", "python-3.x", "pandas" ]
How to use another function to get point values from a list
39,937,798
<p>So I am not sure how I am to go about doing this problem, but from my understanding I am suppose to use another function to get points from a list of 52 numbers and then I am suppose to return a list that contains the sum of the points from the different integers from the list.</p> <p>What the question asks:</p> <...
1
2016-10-08T22:01:20Z
39,937,817
<p>you need to append the results of the inside of your loop, not overwrite:</p> <pre><code>def getPointTotal(aList): points = [] for i in aList: points += getPoints(i) return aList, points </code></pre>
1
2016-10-08T22:03:37Z
[ "python", "list", "python-3.x" ]
find the numerical index of a list of characters in ascending alphabetical order
39,937,805
<p>I am writing a cryptography program that does columnar transposition. a person enters a key as a string, eg, key = 'ZEBRAS' I need to determine the numerical index corresponding to each letter, in ascending alphabetical order. for example, </p> <ul> <li><strong>Z E B R A S</strong></li> <li><strong>6 3 2 4 1 5</s...
0
2016-10-08T22:02:06Z
39,937,846
<p>Create a temp list to store the sorted word, and extract the position from the temp list. Below is the sample code:</p> <pre><code>&gt;&gt;&gt; word = 'ZEBRAS' &gt;&gt;&gt; sorted_word = sorted(word) &gt;&gt;&gt; sorted_word ['A', 'B', 'E', 'R', 'S', 'Z'] &gt;&gt;&gt; index_string = [sorted_word.index(a)+1 for a ...
0
2016-10-08T22:07:35Z
[ "python", "sorting", "cryptography" ]
find the numerical index of a list of characters in ascending alphabetical order
39,937,805
<p>I am writing a cryptography program that does columnar transposition. a person enters a key as a string, eg, key = 'ZEBRAS' I need to determine the numerical index corresponding to each letter, in ascending alphabetical order. for example, </p> <ul> <li><strong>Z E B R A S</strong></li> <li><strong>6 3 2 4 1 5</s...
0
2016-10-08T22:02:06Z
39,937,860
<p>Create a dictionary from sorted &amp; unique group of letters &amp; indices from 1 to length of the string (you need unicity or several indexes will be generated if there are several occurrences of a letters (as shown below, I have added an S to the word):</p> <pre><code>s="ZEBRASS" us=set(s) sl=dict(zip(sorted(us)...
1
2016-10-08T22:08:40Z
[ "python", "sorting", "cryptography" ]
Isolating pandas columns using boolean logic in python
39,937,810
<p>I am trying to grab the rows of a data frame that satisfy one or both of the following boolean statements:</p> <pre><code>1) df['colName'] == 0 2) df['colName'] == 1 </code></pre> <p>I've tried these, but neither one works (throws errors):</p> <pre><code>df = df[df['colName']==0 or df['colName']==1] df = df[df['c...
1
2016-10-08T22:02:57Z
39,937,861
<p>you are missing <code>()</code></p> <pre><code>df = df[(df['colName']==0) | (df['colName']==1)] </code></pre> <p>this will probably raise a copy warning but will still works.</p> <p>if you don't want the copy warning, use an indexer such has:</p> <pre><code>indexer = df[(df['colName']==0) | (df['colName']==1)].i...
1
2016-10-08T22:08:43Z
[ "python", "pandas", "dataframe" ]
Isolating pandas columns using boolean logic in python
39,937,810
<p>I am trying to grab the rows of a data frame that satisfy one or both of the following boolean statements:</p> <pre><code>1) df['colName'] == 0 2) df['colName'] == 1 </code></pre> <p>I've tried these, but neither one works (throws errors):</p> <pre><code>df = df[df['colName']==0 or df['colName']==1] df = df[df['c...
1
2016-10-08T22:02:57Z
39,938,562
<p>You could clean up what you've done using <code>eq</code> instead of <code>==</code></p> <pre><code>df[df.colName.eq(0) | df.colName.eq(1)] </code></pre> <p>For this case, I recommend using <code>isin</code></p> <pre><code>df[df.colName.isin([0, 1])] </code></pre> <p>Using <code>query</code> also works but is sl...
1
2016-10-08T23:49:47Z
[ "python", "pandas", "dataframe" ]
How to encode flickr short url (base58) in python?
39,937,823
<p>How to encode short URLs of Flickr photos? There is no documentation about the <code>base58</code> method on the <a href="https://www.flickr.com/services/api/misc.urls.html" rel="nofollow">official API page about urls</a>.</p> <p>I can't find examples in Python that are just a function, there are only complicated c...
0
2016-10-08T22:04:58Z
39,937,824
<pre><code>def b58encode(fid): CHARS = '123456789abcdefghijkmnopqrstuvwxyzABCDEFGHJKLMNPQRSTUVWXYZ' CHAR_NUM = len(CHARS) encoded = '' fid = int(fid) while fid &gt;= CHAR_NUM: div, mod = divmod(fid, CHAR_NUM) encoded = CHARS[mod] + encoded fid = div return CHARS[fid] + encoded print(b58encode(...
0
2016-10-08T22:04:58Z
[ "python", "url", "flickr", "flickr-api" ]
Trying to understand how to use the any() function
39,937,873
<p>I want to pick many given numbers and compare them to a number I chose, how do i do this using the <code>any</code> or <code>all</code> command , I tried this and it didn't work, any input would be appreciated: </p> <pre><code>import random v = int(input("What number are you looking for ?")) a1 = int(input("What i...
0
2016-10-08T22:10:57Z
39,937,929
<p>Because you're using <code>any</code> wrong. To achieve what you want, supply the condition to <code>any</code>:</p> <pre><code>if any(v == i for i in [a, b, c]): print('We got a hit') </code></pre> <p>This will check that there's a value in the list <code>[a, b, c]</code> which equals <code>v</code>.</p> <p>Y...
2
2016-10-08T22:17:21Z
[ "python", "python-3.x" ]
How can I compare 2 dictionaries?
39,937,876
<p>I have two dictionaries</p> <pre><code>dict_a = {'x' : 2, 'y' : 3.5, 'z' : 4} dict_b = {'bob' : ['x', 'y'], 'john' : ['z', 'x'], 'bill' : ['y']} </code></pre> <p>I want to compare the two dictionaries and create a new one with the keys from <code>dict_b</code> and values from <code>dict_a</code>if the values from ...
0
2016-10-08T22:11:14Z
39,937,906
<p>This can be done with a simple dict comprehension:</p> <pre><code>&gt;&gt;&gt; {k: [dict_a.get(x,x) for x in v] for k, v in dict_b.items()} {'bob': [2, 3.5], 'john': [4, 2], 'bill': [3.5]} </code></pre> <p>This replaces values with those from <code>dict_a</code> if they exist. Otherwise, keeps those from <code>dic...
1
2016-10-08T22:15:18Z
[ "python", "if-statement", "dictionary" ]
How can I compare 2 dictionaries?
39,937,876
<p>I have two dictionaries</p> <pre><code>dict_a = {'x' : 2, 'y' : 3.5, 'z' : 4} dict_b = {'bob' : ['x', 'y'], 'john' : ['z', 'x'], 'bill' : ['y']} </code></pre> <p>I want to compare the two dictionaries and create a new one with the keys from <code>dict_b</code> and values from <code>dict_a</code>if the values from ...
0
2016-10-08T22:11:14Z
39,937,916
<p>well like so:</p> <pre><code>new_dict = {name: [dict_a[k] for k in dict_b[name]] for name in` dict_b.keys()} </code></pre>
4
2016-10-08T22:16:21Z
[ "python", "if-statement", "dictionary" ]
How can I compare 2 dictionaries?
39,937,876
<p>I have two dictionaries</p> <pre><code>dict_a = {'x' : 2, 'y' : 3.5, 'z' : 4} dict_b = {'bob' : ['x', 'y'], 'john' : ['z', 'x'], 'bill' : ['y']} </code></pre> <p>I want to compare the two dictionaries and create a new one with the keys from <code>dict_b</code> and values from <code>dict_a</code>if the values from ...
0
2016-10-08T22:11:14Z
39,937,979
<pre><code>if guess == i in dict_a.values(): </code></pre> <p>This does not do what you expect it to do. Python here chains the operators, so your test is equivalent to the following:</p> <pre><code>(guess == i) and (i in dict_a.values()) </code></pre> <p>So it’s not like executing a for loop here where you iterat...
2
2016-10-08T22:22:51Z
[ "python", "if-statement", "dictionary" ]
Understand vim in pyvmomi
39,937,883
<p>I would like to understand vim in pyvmomi.<br> I understand that vim is imported like this: <code>from pyvmomi import vim</code><br> I tried to find where vim is defined in pyvmomi, but I have not found it yet. </p> <p>I tried the following steps:</p> <pre><code>&gt;&gt;&gt; inspect.getfile(vim) Traceback (most ...
0
2016-10-08T22:12:28Z
39,971,735
<p>For the most part those objects are found here: <a href="https://github.com/vmware/pyvmomi/blob/master/pyVmomi/ServerObjects.py" rel="nofollow">https://github.com/vmware/pyvmomi/blob/master/pyVmomi/ServerObjects.py</a> and <a href="https://github.com/vmware/pyvmomi/blob/master/pyVmomi/QueryTypes.py" rel="nofollow">...
0
2016-10-11T06:45:37Z
[ "python", "vim", "pyvmomi" ]
Creating cdata of type `REAL (* vertices)[DIM]` in CFFI
39,937,895
<p>I'm trying to build a python interface around some existing <a href="http://www.cs.ox.ac.uk/stephen.cameron/distances/" rel="nofollow">C code</a> with CFFI. As usual with C code trimmed for performance, it is fraught with extensive macros and typedefs.</p> <p>ATM I am working on replicating following struct</p> <p...
0
2016-10-08T22:14:21Z
39,938,016
<p>Apparently <code>ptr_vertices = ffi.new("REAL[][3]", self.vertices )</code> is the way to go. For now it appears to work.</p>
0
2016-10-08T22:27:29Z
[ "python", "c", "cffi" ]
Creating cdata of type `REAL (* vertices)[DIM]` in CFFI
39,937,895
<p>I'm trying to build a python interface around some existing <a href="http://www.cs.ox.ac.uk/stephen.cameron/distances/" rel="nofollow">C code</a> with CFFI. As usual with C code trimmed for performance, it is fraught with extensive macros and typedefs.</p> <p>ATM I am working on replicating following struct</p> <p...
0
2016-10-08T22:14:21Z
39,938,023
<p>If you are creating a single item, use <code>ffi.new('REAL(*)[3]', [1, 2, 3])</code>. The parenthesis around the <code>*</code> is important.</p> <p>In C, the type <code>REAL(*)[3]</code> means a pointer to array (size=3) of REAL, while <code>REAL*[3]</code> means an array (size=3) of pointer to real. See <a href="...
1
2016-10-08T22:27:56Z
[ "python", "c", "cffi" ]
Scrapy doesn`t make POST-requests
39,937,918
<p>I write my Scrapy spider which should handle some site with AJAX. In theory it should work OK and moreover it works OK when I use it manually with fetch() in Scrapy shell, but when I run "scrapy crawl ..." I don`t see any POST requests in log and no items are scraped. What can it be and what is the source of the pro...
0
2016-10-08T22:16:24Z
39,950,062
<p>The request returned by the <code>parseProdPage</code> method is not used inside the <code>parseCat</code> method. You should start by <em>yielding</em> that: <code>yield self.parseProdPage(response)</code></p> <p>Also, you probably want to set <code>dont_filter=True</code> in that same request, otherwise most of t...
0
2016-10-10T01:03:47Z
[ "python", "ajax", "scrapy" ]
My PyQt app runs fine inside Idle but throws an error when trying to run from cmd
39,937,950
<p>So I'm learning PyQt development and I typed this into a new file inside IDLE:</p> <pre><code>import sys from PyQt4.QtCore import * from PyQt4.QtGui import * def window(): app = QApplication(sys.argv) win = QDialog() b1 = QPushButton(win) b1.setText("Button1") b1.move(50,20) b1.clicked.conne...
0
2016-10-08T22:19:30Z
39,974,456
<p>This is because when running from the command line you're using a different version of Python to the one in IDLE (with different installed packages). You can find which Python is being used by running the following from the command line:</p> <pre><code>python -c "import sys;print(sys.executable)" </code></pre> <p>...
0
2016-10-11T09:41:02Z
[ "python", "cmd", "pyqt", "pyqt4", "python-3.4" ]
Given a Dictionary and a list of letters, find all possible words that can be created with the letters
39,937,958
<p>The function scoreList(Rack) takes in a list of letters. You are also given a global variable Dictionary: <code>["a", "am", "at", "apple", "bat", "bar", "babble", "can", "foo", "spam", "spammy", "zzyzva"]</code>. </p> <p>Using a list of letters find all possible words that can be made with the letters that are in t...
0
2016-10-08T22:20:47Z
39,938,119
<p>Below is the sample code to achieve this:</p> <pre><code>score = [["a", 1], ["b", 3], ["c", 3], ["d", 2], ["e", 1], ["f", 4], ["g", 2], ["h", 4], ["i", 1], ["j", 8], ["k", 5], ["l", 1], ["m", 3], ["n", 1], ["o", 1], ["p", 3], ["q", 10], ["r", 1], ["s", 1], ["t", 1], ["u", 1], [...
0
2016-10-08T22:41:22Z
[ "python", "list", "dictionary" ]
Given a Dictionary and a list of letters, find all possible words that can be created with the letters
39,937,958
<p>The function scoreList(Rack) takes in a list of letters. You are also given a global variable Dictionary: <code>["a", "am", "at", "apple", "bat", "bar", "babble", "can", "foo", "spam", "spammy", "zzyzva"]</code>. </p> <p>Using a list of letters find all possible words that can be made with the letters that are in t...
0
2016-10-08T22:20:47Z
39,938,259
<p>You can use <code>itertools</code> to generate all possible permutations of words from a set of characters, but note if your input list becomes large this will become a lengthy and memory consuming process.</p> <pre><code>import itertools d = dict([ ["a", 1], ["b", 3], ["c", 3], ["d", 2], ["e", 1], ["...
1
2016-10-08T23:01:02Z
[ "python", "list", "dictionary" ]
Adding values to JSON in Python2.7
39,937,986
<p>I have been tasked with combining data from two different sources into one JSON to be used by a web service. I decided to go with flask which I have found to be so easy to use. Anyway, I am retrieving JSON that looks like this ( via urlib2 )....</p> <pre><code>[ [{ "timestamp": 1474088400000, "e...
-2
2016-10-08T22:23:50Z
39,938,054
<p>First, you should read the json into Python objects:</p> <pre><code>data = json.loads(jsonstring) </code></pre> <p>Then get to the object to be modified. The data looks like <code>[ [ {... 'breakdown': ...} ] ]</code>, so it is a list of lists of dictionaries. I guess you want all of them:</p> <pre><code>for d in...
1
2016-10-08T22:33:54Z
[ "python", "json", "python-2.7" ]
Adding values to JSON in Python2.7
39,937,986
<p>I have been tasked with combining data from two different sources into one JSON to be used by a web service. I decided to go with flask which I have found to be so easy to use. Anyway, I am retrieving JSON that looks like this ( via urlib2 )....</p> <pre><code>[ [{ "timestamp": 1474088400000, "e...
-2
2016-10-08T22:23:50Z
39,938,242
<ol> <li><p>Load the <code>json</code> string</p> <pre><code>json_data = json.loads(json_string) </code></pre></li> <li><p>Iterate over the object and <code>append</code> to the <code>"breakdown"</code> key</p> <pre><code>for item in json_data: for json_dict in item: json_dict["breakdown"].append({"type":...
1
2016-10-08T22:59:15Z
[ "python", "json", "python-2.7" ]
Python Composite Desing Pattern - RecursionError: maximum recursion depth exceeded
39,938,021
<p>so i was a bit going trough some design patterns books and i decided to make my own in python (the book is for Java), and i stumbled on this issue which i cannot solve,what am i missing here?</p> <p>So why do i get here recursion error?</p> <pre><code>class Component: _components = [] def __init__(self, ...
0
2016-10-08T22:27:42Z
39,938,051
<p><code>_components</code> should be an instance variable, not a class variable. As it is, adding the components to the computer adds them to <em>all</em> the other components. That is, every component is a component of every other component, which results in an infinite loop.</p> <pre><code>class Component: def...
1
2016-10-08T22:33:38Z
[ "python", "recursion", "composite" ]
Ziping files with python. Windows cant unzip
39,938,077
<p>I have this ziping script in python :</p> <pre><code> def zipdir(self,path, ziph): # ziph is zipfile handle paths = os.listdir(path) for p in paths: p = os.path.join(path, p) # Make the path relative if os.path.isfile(p): # Recursive case ziph.write(...
0
2016-10-08T22:36:26Z
39,995,888
<p>Found the Problem. The zipping went fine. I send the zip over email and set a wrong header-element.</p>
0
2016-10-12T10:05:27Z
[ "python", "zip" ]
How to generate random number with a large number of decimals in Python?
39,938,080
<p>How it's going?</p> <p>I need to generate a random number with a large number of decimal to use in advanced calculation.</p> <p>I've tried to use this code:</p> <pre><code>round(random.uniform(min_time, max_time), 1) </code></pre> <p>But it doesn't work for length of decimals above 15.</p> <p>If I use, for e.g:...
1
2016-10-08T22:36:42Z
39,938,147
<h2>100 decimals</h2> <p>The first problem is how to create a number with 1000 decimals at all.</p> <p>This won't do:</p> <pre><code>&gt;&gt;&gt; 1.23456789012345678901234567890 1.2345678901234567 </code></pre> <p>Those are floating point numbers which have limitations far from 100 decimals.</p> <p>Luckily, in Pyt...
1
2016-10-08T22:45:36Z
[ "python", "random", "numbers" ]
python class import issue
39,938,100
<p>I am new to python and doing some programming for school I have written code for a roster system and I am supposed to use dictionaries. I keep getting error No module named 'players_Class' Can someone tell me what I am doing wrong</p> <pre><code>class Players: def __init__(self, name, number, jersey): ...
0
2016-10-08T22:38:46Z
39,938,154
<p>you have unused </p> <pre><code>import players_Class </code></pre> <p>statement in your code. just erase it!</p>
0
2016-10-08T22:46:45Z
[ "python", "python-3.x" ]
python wsgi pymorphy2 error iternal
39,938,122
<p>trying to return value of pymorphy2 using apache with wsgi module &amp; getting error 500 log says TypeError: sequence of byte string values expected, value of type Parse found</p> <p>i dont know what to do! in Python im rookie</p> <p>my python code is</p> <pre><code>import pymorphy2 import cgi morph = pymorphy...
-2
2016-10-08T22:41:45Z
39,938,844
<p>As you can see, you need to return sequence of byte string but you are returning word which is of type <code>Parse</code>. if you want the response to be exactly the same as the thing you get from the console, try</p> <pre><code>words = str(morphid[0]).encode() </code></pre> <p>It will return the string of the res...
0
2016-10-09T00:42:44Z
[ "python", "wsgi" ]
Python: Ending line every N characters when writing to text file
39,938,160
<p>I am reading the webpage at "<a href="https://google.com" rel="nofollow">https://google.com</a>" and writing as a string to a notepad file. In the notepad file, I want to break and make a newline every N characters while writing, so that I don't have to scroll horizontally in notepad. I have looked up a number of ...
1
2016-10-08T22:47:22Z
39,938,187
<p>This will split each line at 100 characters:</p> <pre><code>for line in webfile: while len(line) &gt; 100: # split the line f.write(line[:100]) # write the first 100 characters f.write('\n') # write the newline character line = line[100:] # remember the remainder of th...
0
2016-10-08T22:50:50Z
[ "python" ]
Python: Ending line every N characters when writing to text file
39,938,160
<p>I am reading the webpage at "<a href="https://google.com" rel="nofollow">https://google.com</a>" and writing as a string to a notepad file. In the notepad file, I want to break and make a newline every N characters while writing, so that I don't have to scroll horizontally in notepad. I have looked up a number of ...
1
2016-10-08T22:47:22Z
39,938,217
<p>Better yet, use the <a href="https://docs.python.org/2.7/library/textwrap.html" rel="nofollow">textwrap</a> library. Then you can use</p> <pre><code>textwrap.fill(str(line)) </code></pre> <p>and get breaks on whitespace and other useful additions.</p>
2
2016-10-08T22:55:16Z
[ "python" ]
Regular Expression to replace some dots with commas in customers' comments
39,938,210
<p>I need to write a Regular Expression to replace <code>'.'</code> with <code>','</code> in some patients' comments about drugs. They were supposed to use comma after mentioning a side effect, but some of them used dot. for example: </p> <pre><code>text = "the drug side-effects are: night mare. nausea. night sweat. b...
1
2016-10-08T22:54:25Z
39,939,223
<p>You can use the following pattern:</p> <pre><code>\.(\s*(?!(?:i|she)\b)\w+(?:\s+\w+)?\s*)(?=[^\w\s]|$) </code></pre> <p>This matches a dot, then captures one or two words where the first one is none of your mentioned pronouns (you will need to expand that list most likely). This has to be followed by a character t...
1
2016-10-09T02:01:18Z
[ "python", "regex" ]
Error with useing .split() with user input in python
39,938,294
<p>So I am trying to make a basic address book in python that can save contacts and load them using pickle, but for some reason I get an error when I try to put in a contact My code is:</p> <pre><code>import pickle class Contact: def __init__(self, firstname, lastname, phonenumber, adress): self.firstname...
0
2016-10-08T23:05:15Z
39,938,371
<p>I think you're looking for <a href="https://docs.python.org/2/library/functions.html#raw_input" rel="nofollow"><code>raw_input</code></a>. Unlike in Python 3, in Python 2.x, <a href="https://docs.python.org/2/library/functions.html#input" rel="nofollow"><code>input</code></a> parses and evaluates the string as a Pyt...
0
2016-10-08T23:15:36Z
[ "python", "python-2.7" ]
How can I get this Python function to return a string instead of a list containing one string?
39,938,296
<p>How can I get this Python function to return a string instead of a list containing one string?</p> <pre><code>def num_vowels(s): """ returns the number of vowels in the string s input: s is a string of 0 or more lowercase letters """ if s == '': return 0 else: num_in_rest = n...
-2
2016-10-08T23:05:23Z
39,938,336
<p>your <code>most_vowels()</code> function is using a <a href="http://www.secnetix.de/olli/Python/list_comprehensions.hawk" rel="nofollow">list comprehension</a> to filter out matching values and return a new list. You could output the string directly in two ways.</p> <p>The first way is to index the first result fro...
1
2016-10-08T23:09:52Z
[ "python", "string" ]
How can I get this Python function to return a string instead of a list containing one string?
39,938,296
<p>How can I get this Python function to return a string instead of a list containing one string?</p> <pre><code>def num_vowels(s): """ returns the number of vowels in the string s input: s is a string of 0 or more lowercase letters """ if s == '': return 0 else: num_in_rest = n...
-2
2016-10-08T23:05:23Z
39,938,338
<p>You can get the answer straight from <a href="https://docs.python.org/2/library/functions.html#max" rel="nofollow"><strong><code>max</code></strong></a> by comparing the number of vowels instead of the usual ordering for strings, by passing <code>num_vowels</code> as <code>key</code>:</p> <pre><code>def most_vowels...
0
2016-10-08T23:10:06Z
[ "python", "string" ]
How can I get this Python function to return a string instead of a list containing one string?
39,938,296
<p>How can I get this Python function to return a string instead of a list containing one string?</p> <pre><code>def num_vowels(s): """ returns the number of vowels in the string s input: s is a string of 0 or more lowercase letters """ if s == '': return 0 else: num_in_rest = n...
-2
2016-10-08T23:05:23Z
39,938,360
<p>Your <code>most_vowels</code> function sort of reinvents the wheel. Python already given you a much simpler facility for this this - using <a href="https://docs.python.org/2/library/functions.html#max" rel="nofollow"><code>max</code></a> with an optional <code>key</code> argument, and just picking the word with the ...
0
2016-10-08T23:13:28Z
[ "python", "string" ]
Iterating over Dataframe
39,938,299
<p>I'm trying to iterate over a dataframe where the "Filename" column is consisted of strings. I have the following, however, I get the following Error.</p> <p>result is a different Dataframe</p> <pre><code>k = 1 l = 0 for row in df.iterrows(): if k % 3 == 0: result.loc[l, 'H2'] = row['Filename'] ...
1
2016-10-08T23:05:45Z
39,938,362
<p>when you iter through df with <code>df.iterrows()</code> it will return a tuple for each row where row[0] is the index of the row and row[1] is a Series.</p> <p>so you could do:</p> <pre><code>row[1]['Filename'] </code></pre> <p>personally I like to iter using <code>.itertuples()</code> which returns named tuple ...
3
2016-10-08T23:13:37Z
[ "python", "pandas", "dataframe" ]
Iterating over Dataframe
39,938,299
<p>I'm trying to iterate over a dataframe where the "Filename" column is consisted of strings. I have the following, however, I get the following Error.</p> <p>result is a different Dataframe</p> <pre><code>k = 1 l = 0 for row in df.iterrows(): if k % 3 == 0: result.loc[l, 'H2'] = row['Filename'] ...
1
2016-10-08T23:05:45Z
39,938,482
<p>The simple fix to your problem is to unpack the tuple coming from <code>iterrows</code></p> <pre><code>k = 1 l = 0 for i, row in df.iterrows(): if k % 3 == 0: result.loc[l, 'H2'] = row['Filename'] l += 1 elif k % 2 == 0: result.loc[l, 'H1'] = row['Filename'] else: result....
3
2016-10-08T23:37:45Z
[ "python", "pandas", "dataframe" ]
Jinja convert string to integer
39,938,323
<p>I am trying to convert a string that has been parsed using a regex into a number so I can multiply it, using Jinja2. This file is a template to be used within an ansible script.</p> <p>I have a series of <code>items</code> which all take the form of <code>&lt;word&gt;&lt;number&gt;</code> such as <code>aaa01</code>...
0
2016-10-08T23:08:27Z
39,940,452
<p>You need to cast string to int after regex'ing number:</p> <pre><code>{% set number = get_host_number() | int %} </code></pre> <p>And then there is no need in <code>| int</code> inside <code>get_host_range</code> macro.</p>
2
2016-10-09T05:48:14Z
[ "python", "ansible", "jinja2" ]
delete pixel from the raster image with specific range value
39,938,330
<p><strong>update :</strong> any idea how to delete pixel from specific range value raster image with using <code>numpy/scipy</code> or <code>gdal</code>?</p> <p><strong>or how to can create new raster with some class using raster calculation expressions</strong>(better)</p> <p>for example i have a raster image with...
0
2016-10-08T23:09:15Z
39,945,591
<p>Rasters are 2-D arrays of values, with each value being stored in a pixel (which stands for picture element). Each pixel must contain some information. It is not possible to delete or remove pixels from the array because rasters are usually encoded as a simple 1-dimensional string of bits. Metadata commonly helps ex...
1
2016-10-09T16:00:00Z
[ "python", "numpy", "image-processing", "scipy", "gdal" ]
Why is are the dicts in this list of dicts empty?
39,938,350
<p>As the title implies; I'm unsure as to why the dictionaries in this list of dictionaries are empty. I print the dictionaries out before I append them to the list and they all have 4 keys/values. </p> <p>Please ignore the 'scrappiness' of the code- I always go through a process of writing it out basically and then r...
0
2016-10-08T23:11:27Z
39,938,406
<p>I presume you mean this:</p> <pre><code> print len(self.data_dict) self.master_list.append(self.data_dict) print self.data_dict self.data_dict.clear() </code></pre> <p>The <code>dict</code> is empty because <em>you clear it</em>. Everything is a reference in Python.</p> <pre><code>&gt;&gt;&gt; d = {k:v for k,v...
2
2016-10-08T23:22:55Z
[ "python", "python-2.7" ]
Using strip() method and punctuation in Python
39,938,435
<p>I've been trying to solve this problem for a few hours now and can't come with the right solution, this is the question:</p> <p>Write a loop that creates a new word list, using a string method to strip the words from the list created in Problem 3 of all leading and trailing punctuation. Hint: the string lib...
0
2016-10-08T23:29:29Z
39,938,622
<p>You've got a couple bits in your code that... well, I'm not really sure why they're there, to be honest, haha. Let's work through this together!</p> <p>I'm assuming you have been given some text: <code>text = "My hovercraft is full of eels!"</code>. Let's split this into words, make the words lowercase, and remove ...
0
2016-10-09T00:00:02Z
[ "python", "strip" ]
how do you add values from a list separately if one variable has two possible outcomes
39,938,449
<p>This assignment calls another function:</p> <pre><code>def getPoints(n): n = (n-1) % 13 + 1 if n == 1: return [1] + [11] if 2 &lt;= n &lt;= 10: return [n] if 11 &lt;= n &lt;= 13: return [10] </code></pre> <p>So my assignment wants me to add the sum of all possible points fr...
3
2016-10-08T23:31:25Z
39,938,882
<p>You make a mistake in storing all the values returned from <code>getPoints()</code>. You should store only the possible totals for the points returned so far. You can store all those in a set, and update them with the all the possible values returned from <code>getPoints()</code>. A set will automatically remove dup...
4
2016-10-09T00:50:11Z
[ "python", "list", "python-3.x", "sum" ]
how do you add values from a list separately if one variable has two possible outcomes
39,938,449
<p>This assignment calls another function:</p> <pre><code>def getPoints(n): n = (n-1) % 13 + 1 if n == 1: return [1] + [11] if 2 &lt;= n &lt;= 10: return [n] if 11 &lt;= n &lt;= 13: return [10] </code></pre> <p>So my assignment wants me to add the sum of all possible points fr...
3
2016-10-08T23:31:25Z
39,939,038
<p>Rory Daulton's answer is a good one, and it efficiently gives you the different totals that are possible. I want to offer another approach which is not necessarily better than that one, just a bit different. The benefit to my approach is that you can see the sequence of scores that lead to a given total, not only th...
1
2016-10-09T01:23:00Z
[ "python", "list", "python-3.x", "sum" ]
Checking if a sequence has consecutive identical characters
39,938,475
<p>For this function I'm trying to have it return "True" when a sequence has consecutive identical characters and have it return "False" when a sequence doesn't. For example, <code>neighboring_twins(1,2,1,4,1)</code> should return <code>False</code> while <code>neighboring_twins(1,2,3,3,5)</code> should return <code>Tr...
1
2016-10-08T23:36:12Z
39,938,531
<p>The <code>pairwise</code> function from <a href="https://docs.python.org/2/library/itertools.html#recipes" rel="nofollow">itertools' recipies</a> will return a list of pairs of consecutive items. From here on, you're just a list comprehension away of what you need:</p> <pre><code>from itertools import tee, izip def...
0
2016-10-08T23:44:22Z
[ "python", "loops", "character", "sequence" ]
Checking if a sequence has consecutive identical characters
39,938,475
<p>For this function I'm trying to have it return "True" when a sequence has consecutive identical characters and have it return "False" when a sequence doesn't. For example, <code>neighboring_twins(1,2,1,4,1)</code> should return <code>False</code> while <code>neighboring_twins(1,2,3,3,5)</code> should return <code>Tr...
1
2016-10-08T23:36:12Z
39,938,545
<p>You are getting syntax errors because <code>if ii</code> is asking the Python interpreter to check the variable <code>ii</code> and see if it's true or not. I would recommend iterating through the list and checking the next element to see if it equals the next. <code>enumerate()</code> will be useful for you.</p> <...
0
2016-10-08T23:47:06Z
[ "python", "loops", "character", "sequence" ]
How to check if number is prime if no divisibles
39,938,694
<p>I'm new to programming, I need to know if it's possible to print a string like "This is a prime number" if there were no results for i</p> <pre><code>n = int(input("Digite um número inteiro positivo: ")) for i in range(2,n): if n % i == 0: print(i) </code></pre> <p>For example if I typed 5 Nothing sh...
0
2016-10-09T00:09:31Z
39,938,721
<pre><code>def isPrime(num): for i in range(2, num): if num % i == 0: return False return True def getFactors(n): myList = [] for i in range(2, n): if n % i == 0: myList.append(i) return myList num = 17 num2 = 20 if isPrime(num): print("prime") else: ...
0
2016-10-09T00:15:40Z
[ "python", "python-3.x" ]
How to check if number is prime if no divisibles
39,938,694
<p>I'm new to programming, I need to know if it's possible to print a string like "This is a prime number" if there were no results for i</p> <pre><code>n = int(input("Digite um número inteiro positivo: ")) for i in range(2,n): if n % i == 0: print(i) </code></pre> <p>For example if I typed 5 Nothing sh...
0
2016-10-09T00:09:31Z
39,938,723
<pre><code>n = int(input("Digite um número inteiro positivo: ")) printed = False for i in range(2,n): if n % i == 0: print(i) printed = True if not printed: print(n,"is a prime number") </code></pre> <p>This uses a "flag" variable to show if a value was printed.</p>
3
2016-10-09T00:16:21Z
[ "python", "python-3.x" ]
How to check if number is prime if no divisibles
39,938,694
<p>I'm new to programming, I need to know if it's possible to print a string like "This is a prime number" if there were no results for i</p> <pre><code>n = int(input("Digite um número inteiro positivo: ")) for i in range(2,n): if n % i == 0: print(i) </code></pre> <p>For example if I typed 5 Nothing sh...
0
2016-10-09T00:09:31Z
39,938,741
<p>A crude way to do it would be adding something like a counter which checks the number of factors.</p> <pre><code>n=int(input("Digite um número inteiro positivo:")) counter=0 for i in range(2,n): if(n%i==0): print(i) counter+=1 if(counter==0): print "n is prime" </code></pre>
0
2016-10-09T00:19:51Z
[ "python", "python-3.x" ]
How to check if number is prime if no divisibles
39,938,694
<p>I'm new to programming, I need to know if it's possible to print a string like "This is a prime number" if there were no results for i</p> <pre><code>n = int(input("Digite um número inteiro positivo: ")) for i in range(2,n): if n % i == 0: print(i) </code></pre> <p>For example if I typed 5 Nothing sh...
0
2016-10-09T00:09:31Z
39,940,326
<p>You could also set the range of the loop to only check values from 2 to n//2 because anything past that would be unnecessary for checking if prime. </p> <pre><code>def isPrime(n): for i in range(2,**n//2**): if n % i == 0: return 'This number is not Prime.' else: return 'This num...
0
2016-10-09T05:26:21Z
[ "python", "python-3.x" ]
Use two rows from a pandas dataframe to select a location in another dataframe
39,938,821
<p>I Have first dataframe <code>df1</code> as below. Here <code>col_b</code> is any number between h1 and h24 and doesn't contain all of 1 to 24 for each corresponding date: </p> <pre><code>Date col_b 20101101 h1 20101101 h2 20101101 h3 20101102 h1 20101102 h3 20101103 h2 20101104 h1 201011...
1
2016-10-09T00:38:24Z
39,939,023
<p>use <code>DataFrame.lookup()</code>:</p> <pre><code>import numpy as np import pandas as pd df2 = pd.DataFrame(np.random.randint(0, 10, (5, 3)), columns=list("ABC"), index=pd.date_range("2016/01/01", "2016/05/01", freq="MS")) df = pd.DataFrame({"date":df2.index[np.random.randi...
1
2016-10-09T01:19:56Z
[ "python", "pandas", "dataframe" ]
Confusing bug with brackets on my function
39,938,830
<pre><code>def cube_of(valz):         '''Returns the cube of values'''         if len(valz) == 0:             return 0         else:             new_val = [valz[0] ** 3]             return  [new_val] + [cube_of(valz[1:])]  </code></pre> <p>So I am making t...
1
2016-10-09T00:40:46Z
39,938,853
<p><code>cube_of(valz[1:])</code> is already a list. There's no need to wrap it in brackets.</p> <pre><code>return [new_val] + cube_of(valz[1:]) </code></pre>
2
2016-10-09T00:44:09Z
[ "python", "recursion" ]
Confusing bug with brackets on my function
39,938,830
<pre><code>def cube_of(valz):         '''Returns the cube of values'''         if len(valz) == 0:             return 0         else:             new_val = [valz[0] ** 3]             return  [new_val] + [cube_of(valz[1:])]  </code></pre> <p>So I am making t...
1
2016-10-09T00:40:46Z
39,938,857
<p>Your code could be simplified</p> <p>using <em>list comprehension:</em></p> <pre><code>def cube_of(valz): return [item**3 for item in valz] </code></pre> <p><em>Recursive</em> approach:</p> <pre><code>def cube_of(valz): return [valz[0]**3] + cube_of(valz[1:]) if valz else [] </code></pre> <p>Sam...
2
2016-10-09T00:45:12Z
[ "python", "recursion" ]
Confusing bug with brackets on my function
39,938,830
<pre><code>def cube_of(valz):         '''Returns the cube of values'''         if len(valz) == 0:             return 0         else:             new_val = [valz[0] ** 3]             return  [new_val] + [cube_of(valz[1:])]  </code></pre> <p>So I am making t...
1
2016-10-09T00:40:46Z
39,938,874
<p>If <code>valz</code> is empty you should return empty list instead of <code>0</code> - <code>return []</code></p> <p><code>new_valz</code> is a list so you don't need brackets. <code>cube_of</code> returns list so you don't need brackets too.</p> <pre><code>def cube_of(valz): '''Returns the cube of values'...
1
2016-10-09T00:48:45Z
[ "python", "recursion" ]
Confusing bug with brackets on my function
39,938,830
<pre><code>def cube_of(valz):         '''Returns the cube of values'''         if len(valz) == 0:             return 0         else:             new_val = [valz[0] ** 3]             return  [new_val] + [cube_of(valz[1:])]  </code></pre> <p>So I am making t...
1
2016-10-09T00:40:46Z
39,938,896
<p><code>cube_of(valz)</code> already returns an initial segment of the list in the <code>else</code> part of the branch, i.e. <code>[new_val]</code>. Therefore, in order for its overall return value to be of type list, it should return lists in all its branches.</p> <p>You should change the function like this:</p> <...
0
2016-10-09T00:53:05Z
[ "python", "recursion" ]
Python - Make S3 images public as they are uploaded?
39,938,839
<p>I'm using this code to upload images to S3 from python but I need them to be public right away instead of changing permissions manually.</p> <pre><code>im2.save(out_im2, 'PNG') conn = boto.connect_s3(keys) b = conn.get_bucket('example') k = b.new_key('example.png') k.set_contents_from_string(out_im2.getvalue()) </...
0
2016-10-09T00:42:07Z
39,940,799
<h2>Using ACLs</h2> <p>Try:</p> <pre><code>k.set_acl('public-read') </code></pre> <p>According to <a href="http://boto.cloudhackers.com/en/latest/s3_tut.html#setting-getting-the-access-control-list-for-buckets-and-keys" rel="nofollow">the boto documentation</a> this is how you set a canned ACL on an individual item....
2
2016-10-09T06:43:17Z
[ "python", "amazon-web-services", "amazon-s3", "boto" ]
Lines in a file is not displayed (python)
39,938,862
<p>I'm a python beginner. So I encountered this problem. The file has 100 songs, each song with an id(X), title(T), time sig(M) and key sig(K), the format of the text file is the same throughout the file. However it skipped 8 lines. Some of the tunes in the file has several titles, but only one is to be displayed </p>...
2
2016-10-09T00:45:42Z
39,938,949
<p>You use <code>next(file)</code> which reads next line so you skip some lines.</p>
0
2016-10-09T01:03:56Z
[ "python" ]
Display "long" pandas dataframe in jupyter notebook with "foldover"?
39,938,870
<p>Let's say I have a pandas dataframe with many columns:</p> <p><a href="http://i.stack.imgur.com/bjFlz.png" rel="nofollow"><img src="http://i.stack.imgur.com/bjFlz.png" alt="enter image description here"></a></p> <p>I can view all of the columns by scrolling left/right. However, this is a bit inconvenient and I was...
1
2016-10-09T00:47:55Z
39,939,301
<p>try this:</p> <pre><code>In [135]: df = pd.DataFrame(np.random.rand(3, 30), columns=list(range(30))) In [136]: pd.options.display.expand_frame_repr=True In [137]: pd.options.display.max_columns = None In [138]: pd.options.display.width = 80 In [139]: df Out[139]: 0 1 2 3 ...
0
2016-10-09T02:16:20Z
[ "python", "pandas", "ipython", "jupyter", "jupyter-notebook" ]
Display "long" pandas dataframe in jupyter notebook with "foldover"?
39,938,870
<p>Let's say I have a pandas dataframe with many columns:</p> <p><a href="http://i.stack.imgur.com/bjFlz.png" rel="nofollow"><img src="http://i.stack.imgur.com/bjFlz.png" alt="enter image description here"></a></p> <p>I can view all of the columns by scrolling left/right. However, this is a bit inconvenient and I was...
1
2016-10-09T00:47:55Z
39,939,393
<p>In addition to setting max cols like you did, I'm importing <code>display</code></p> <pre><code>import pandas as pd pd.set_option('display.max_columns', None) from IPython.display import display </code></pre> <p>creating a frame then a simple for loop to display every 30 cols</p> <pre><code>df = pd.DataFrame([ra...
1
2016-10-09T02:29:45Z
[ "python", "pandas", "ipython", "jupyter", "jupyter-notebook" ]
get TypeError when i import my own .py file
39,938,890
<p>I am doing a sort program.i have two files called bubble(a bubble sort program) and cal_time(calculate the time),and they are in the same directory.</p> <p>The problem is ,bubble work alone fluently. however,when i import bubble to my cal_time file and callback bubble sort,the interpreter show me the error messag...
2
2016-10-09T00:52:19Z
39,938,941
<p>Your issue lies here:</p> <pre><code>result.append(random.random) </code></pre> <p>You are appending the method <code>random.random</code> onto the list – which has the type <code>builtin_function_or_method</code> (thus resulting in the error you are receiving – how would you compare functions?).</p> <p>Inst...
2
2016-10-09T01:02:10Z
[ "python", "module" ]
get TypeError when i import my own .py file
39,938,890
<p>I am doing a sort program.i have two files called bubble(a bubble sort program) and cal_time(calculate the time),and they are in the same directory.</p> <p>The problem is ,bubble work alone fluently. however,when i import bubble to my cal_time file and callback bubble sort,the interpreter show me the error messag...
2
2016-10-09T00:52:19Z
39,939,032
<p>In <code>generate_random_list()</code> function, you are doing <code>random.random</code>. Since it is a function, you should write it as <code>random.random()</code>. Hence, the code of your <code>generate_random_list()</code> function should be:</p> <pre><code>def generate_random_list(): result = [] for i...
0
2016-10-09T01:21:31Z
[ "python", "module" ]
Regular Expression removing <![CDATA[
39,938,929
<p>I have this regular expression: </p> <pre><code>&lt;/title&gt;[\s]*&lt;description[^&gt;]*&gt;(.*?)&lt;img </code></pre> <p>which takes the string: </p> <pre><code>&lt;title&gt;Insane price of last Ford Falcon V8s&lt;/title&gt; &lt;description&gt;&lt;![CDATA[FORD dealers are charging a staggering $30,000 ...
-4
2016-10-09T00:59:58Z
39,939,656
<p>Regular expressions are really mighty tool. This includes a high risk of getting bugs into your code, especially when you do not know how to handle them exactly (it seems this is the case here).</p> <p>You should always go with Python's built-in string class first and <em>only</em> use RegEx, if it is necessary.</p...
0
2016-10-09T03:16:13Z
[ "python", "html", "regex", "cdata" ]
Script to download manually generated excel file on reference website?
39,938,930
<p>I am specifically looking at the ReferenceUSA website. To download information, one has to manually select all the items, then click download, and then on another page click to generate a CSV file. Is there anyway to automate this kind of process?</p>
1
2016-10-09T01:00:14Z
39,939,360
<p>You could try Selenium, here is an example to open a web page, and click a button.</p> <pre><code>&gt;&gt;&gt; from selenium import webdriver &gt;&gt;&gt; browser = webdriver.Chrome() ## now web browser opened &gt;&gt;&gt; browser.get("https://www.python.org") ## now python.org web page opened </code></pre> <p>T...
0
2016-10-09T02:25:18Z
[ "python", "automation" ]
How to display non-English language gotten by Facebook API
39,938,973
<p>I'm getting some facebook posts that have a mixture of English and and a non-English language (Khmer to be exact). </p> <p>Here's how the non-English is displayed when I print the data to screen or save it to file: \u178a\u17c2\u179b\u1787\u17b6\u17a2\u17d2. I would rather have it display as ឈឹម បញ្ចá...
-1
2016-10-09T01:08:25Z
39,939,040
<p>This should be it:</p> <pre><code>print(u'\u1787\u17b6\u17a2\u17d2') #python3 print u'\u1787\u17b6\u17a2\u17d2' #python2.7 </code></pre> <p>Output: ជាអ្</p>
1
2016-10-09T01:23:43Z
[ "python", "facebook", "facebook-graph-api", "translation" ]
How to display non-English language gotten by Facebook API
39,938,973
<p>I'm getting some facebook posts that have a mixture of English and and a non-English language (Khmer to be exact). </p> <p>Here's how the non-English is displayed when I print the data to screen or save it to file: \u178a\u17c2\u179b\u1787\u17b6\u17a2\u17d2. I would rather have it display as ឈឹម បញ្ចá...
-1
2016-10-09T01:08:25Z
39,939,064
<p>In pycharm I added:</p> <ol> <li><p>(at top) # -<em>- coding: utf-8 -</em>-</p></li> <li><p>import sys reload(sys) sys.setdefaultencoding('utf8')</p></li> <li>s = json.dumps(posts['data'],ensure_ascii=False)</li> <li>json_file.write(s.decode('utf-8'))</li> </ol>
0
2016-10-09T01:29:02Z
[ "python", "facebook", "facebook-graph-api", "translation" ]
How to display non-English language gotten by Facebook API
39,938,973
<p>I'm getting some facebook posts that have a mixture of English and and a non-English language (Khmer to be exact). </p> <p>Here's how the non-English is displayed when I print the data to screen or save it to file: \u178a\u17c2\u179b\u1787\u17b6\u17a2\u17d2. I would rather have it display as ឈឹម បញ្ចá...
-1
2016-10-09T01:08:25Z
39,939,072
<p>Try this if you want to save the info in a file:</p> <pre><code>import codecs string = 'ឈឹម បញ្ចពណ៌' with codecs.open('yourfile', 'w', encoding='utf-8') as f: f.write(string) </code></pre>
0
2016-10-09T01:30:49Z
[ "python", "facebook", "facebook-graph-api", "translation" ]
Command works in CMD but not Subprocess
39,939,027
<p>I have created a VLC command that converts an opus file to mp3. This command works in windows CMD but does not work in a subprocess in Python 3.5. I have tried various configuration of the command but with no success, there is no error message I am just greeted with a VLC dummy command line window with no process. T...
1
2016-10-09T01:20:42Z
39,939,050
<p>Every argument of the command has to be its own element of the list:</p> <pre><code>p = subprocess.Popen(["C:/Program Files (x86)/VideoLAN/VLC/vlc.exe", "-I", "dummy", "-vvv", "E:\\some_dir\\a.opus", "--", "sout=#transcode{acode...
1
2016-10-09T01:26:23Z
[ "python", "subprocess", "vlc" ]
Ocatave Symbolic "Python cannot import SymPy"
39,939,093
<p>After installing octave, sympy (through anaconda), and the symbolic package, I'm trying to run this line in octave as part of a script:</p> <pre><code>syms nn nb x </code></pre> <p>When I do I get this message:</p> <pre><code>warning: the 'syms' function belongs to the symbolic package from Octave Forge which you...
3
2016-10-09T01:35:07Z
39,962,759
<p>It looks like you have an old version of SymPy. Try upgrading to the newest version (1.0 at the time of writing). </p>
0
2016-10-10T16:30:59Z
[ "python", "osx", "octave", "sympy" ]
Python transpose sqlite table
39,939,099
<p>I have an sqlite database with a table organized like:</p> <p>itemdata</p> <pre><code>date_time | item_code | value 3/13/2015 12:23 | fridge21 | 345.45 3/13/2015 12:23 | heater12 | 12.34 3/13/2015 12:23 | fan02 | 63.78 3/13/2015 12:24 | fridge21 | 345.47 </code></pre> <p>I would like to retrieve the...
0
2016-10-09T01:36:06Z
39,939,153
<p>Use <code>pivot</code> against a raw dataframe that loads the sqllite table:</p> <pre><code>df.pivot('date_time', 'item_code', 'value') </code></pre>
3
2016-10-09T01:47:49Z
[ "python", "sqlite", "pandas" ]
How to write a table without database in HTML in Django
39,939,156
<p>I just want to write a table in HTML in Django, where the data is not from Database. It seems <a href="https://django-tables2.readthedocs.io/en/latest/" rel="nofollow">django-tables2</a> is a good package that I can use in Django. However, my data is not from Database, so maybe it's not necessary to use Django model...
0
2016-10-09T01:48:34Z
39,939,391
<p>One way would be to use <a href="http://pandas.pydata.org" rel="nofollow">pandas</a> to load the data, and then use the <code>DataFrame.to_html()</code> to output the data into an html table. See the example below:</p> <pre><code>import pandas as pd data = [{'column1': 1, 'column2': 2}] df = pd.DataFrame(data) htm...
0
2016-10-09T02:29:40Z
[ "python", "django", "django-tables2" ]
How to write a table without database in HTML in Django
39,939,156
<p>I just want to write a table in HTML in Django, where the data is not from Database. It seems <a href="https://django-tables2.readthedocs.io/en/latest/" rel="nofollow">django-tables2</a> is a good package that I can use in Django. However, my data is not from Database, so maybe it's not necessary to use Django model...
0
2016-10-09T01:48:34Z
39,943,562
<p>You don't need to return Django objects to create templates, you can use any data. The <a href="https://docs.djangoproject.com/en/1.10/topics/http/shortcuts/#render" rel="nofollow">render()</a> function allows you to combine context with the regular HttpResponse. You pass it the request which was given to the view c...
1
2016-10-09T12:21:10Z
[ "python", "django", "django-tables2" ]
Dictionary of numpy array in python
39,939,168
<p>I want to create a data structure of empty numpy array something of this sort:</p> <pre><code>d[1].foo = numpy.arange(x) d[1].bar = numpy.arange(x) d[2].foo = numpy.arange(x) d[2].bar = numpy.arange(x) </code></pre> <p>What would be the best option ... a list of dictionaries containing numpy arrays?</p>
0
2016-10-09T01:50:22Z
39,939,252
<p>If I define a simple class like: </p> <pre><code>class MyObj(object): pass . </code></pre> <p>I could create a dictionary with several of these objects:</p> <pre><code>In [819]: d={1:MyObj(), 2:MyObj()} </code></pre> <p>and then assign attributes to each object</p> <pre><code>In [820]: d[1].foo=np....
1
2016-10-09T02:07:13Z
[ "python", "numpy" ]