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 |
|---|---|---|---|---|---|---|---|---|---|
pyspark expected zero arguments for construction of ClassDict (for pyspark.mllib.linalg.DenseVector) | 38,249,291 | <p>I get the error "expected zero arguments for construction of ClassDict (for pyspark.mllib.linalg.DenseVector)" by trying this:</p>
<p>I have a function which I convert to a udf for transforming values of a column from a dataframe. Like this:</p>
<pre><code>def func(vector):
#does something
return Vector.den... | 2 | 2016-07-07T15:19:02Z | 38,250,007 | <p>Given the part of the you provided the obvious issue is that you declare incorrect return type. Catalyst type of <code>Vector</code> is <code>VectorUDT</code> not <code>ArrayType(FloatType())</code></p>
<pre><code>from pyspark.mllib.linalg import Vectors, VectorUDT
from pyspark.sql.types import ArrayType, FloatType... | 1 | 2016-07-07T15:51:59Z | [
"python",
"apache-spark",
"pyspark",
"apache-spark-sql",
"spark-dataframe"
] |
python pandas, outer product by row, (N, k) dataframe to (N,k,k) Panel | 38,249,411 | <p>Say I have a few assets</p>
<pre><code>rtns = pd.util.testing.makeTimeDataFrame(5000) # 5000 x 4
stds = pd.rolling_std(rtns, 20) # 5000 x 4
corMat = pd.ewmcorr(rtns, com = 50) # 5000 x 4 x 4
</code></pre>
<p>For whatever reason, I want to calculate std and correlation separately and reconstruct the covariance matr... | 1 | 2016-07-07T15:24:40Z | 38,250,256 | <p>You can preserve the index of <code>v</code> with:</p>
<pre><code>out[d] = pd.DataFrame(np.outer(v, v), v.index, v.index) * corMat[d]
</code></pre>
| 1 | 2016-07-07T16:04:13Z | [
"python",
"pandas"
] |
Flag similarities between dataframes in new column | 38,249,414 | <p>I would like to compare two pandas DataFrames of different length and identify matching index numbers. When values match I would like to flag those values in a new column.</p>
<pre><code>df1:
Index Column 1
41660 Apple
41935 Banana
42100 Strawberry
42599 Pineapple
df2:
Index Column 1
42599 Pin... | 3 | 2016-07-07T15:24:58Z | 38,249,501 | <p>If these are really the index then you can use <code>intersection</code> on the indices:</p>
<pre><code>In [61]:
df1.loc[df1.index.intersection(df2.index), 'flag'] = True
df1
Out[61]:
Column 1 flag
Index
41660 Apple NaN
41935 Banana NaN
42100 Strawberry NaN
42599 Pin... | 3 | 2016-07-07T15:28:26Z | [
"python",
"pandas",
"jupyter"
] |
Flag similarities between dataframes in new column | 38,249,414 | <p>I would like to compare two pandas DataFrames of different length and identify matching index numbers. When values match I would like to flag those values in a new column.</p>
<pre><code>df1:
Index Column 1
41660 Apple
41935 Banana
42100 Strawberry
42599 Pineapple
df2:
Index Column 1
42599 Pin... | 3 | 2016-07-07T15:24:58Z | 38,249,628 | <p>+1 to @EdChum's answer. If you can live with a different value than <code>True</code> in your matching column try:</p>
<pre><code>>>> df1.merge(df2,how='outer',indicator='Flag')
Index Column Flag
0 41660 Apple left_only
1 41935 Banana left_only
2 42100 Strawberry left_only
3... | 2 | 2016-07-07T15:34:17Z | [
"python",
"pandas",
"jupyter"
] |
Flag similarities between dataframes in new column | 38,249,414 | <p>I would like to compare two pandas DataFrames of different length and identify matching index numbers. When values match I would like to flag those values in a new column.</p>
<pre><code>df1:
Index Column 1
41660 Apple
41935 Banana
42100 Strawberry
42599 Pineapple
df2:
Index Column 1
42599 Pin... | 3 | 2016-07-07T15:24:58Z | 38,249,736 | <p>Use the isin()-method: </p>
<pre><code>import pandas as pd
df1 = pd.DataFrame(data=[
[41660, 'Apple'],
[41935, 'Banana'],
[42100, 'Strawberry'],
[42599, 'Pineapple'],
]
, columns=['Index', 'Column 1'])
df2 = pd.DataFrame(data=[
[42599, 'Pineapp... | 2 | 2016-07-07T15:39:57Z | [
"python",
"pandas",
"jupyter"
] |
Extract RGB or 6 digit code from Seaborn palette | 38,249,454 | <p>Seaborn has an option to create nice color palettes. I wish to use these palettes to generate colors that work well together in a map where countries are shaded according to some property. The following code produces 8 shades of purple from light to dark. Note also the ability to specify the number of colors is requ... | 1 | 2016-07-07T15:26:41Z | 38,249,914 | <p>The values you are getting are percentages of 255, the max RGB value.
Just multiply each triplet of values by 255 (and round off, if you like) to get the RGB values.</p>
<pre><code>for color in color_list:
for value in color:
value *= 255
</code></pre>
<p>Then store those in a new list to have your lis... | 1 | 2016-07-07T15:48:01Z | [
"python",
"rgb",
"seaborn"
] |
Extract RGB or 6 digit code from Seaborn palette | 38,249,454 | <p>Seaborn has an option to create nice color palettes. I wish to use these palettes to generate colors that work well together in a map where countries are shaded according to some property. The following code produces 8 shades of purple from light to dark. Note also the ability to specify the number of colors is requ... | 1 | 2016-07-07T15:26:41Z | 38,256,967 | <p>If by "6 digit code" you mean a hex code, you can also do:</p>
<pre><code>pal = sns.color_palette(...)
pal.as_hex()
</code></pre>
| 0 | 2016-07-07T23:47:29Z | [
"python",
"rgb",
"seaborn"
] |
Converting timestamps from a csv to seconds using python | 38,249,498 | <p>I have sensor data(acclerometer,compass) saved in a csv file with their time stamps hh-mm-ss format. I wanted to convert the time stamp into seconds to plot the compass reading at a particular second.
ex:
I want to convert</p>
<pre><code>11-26-32 -> 0 sec
11-26-33 -> 1 sec
11-26-34 -> 2 sec
</code></pre>
... | 0 | 2016-07-07T15:28:21Z | 38,249,834 | <p>Convert the times to <code>datetime</code> objects and use the difference of the <code>datetime</code> objects from the initial time to find the number of seconds. <code>total_seconds</code> returns the number of seconds for the <code>timedelta</code>:</p>
<pre><code>from datetime import datetime as dt
times = ['1... | 0 | 2016-07-07T15:44:15Z | [
"python",
"csv",
"pandas",
"matplotlib",
"data-analysis"
] |
Converting timestamps from a csv to seconds using python | 38,249,498 | <p>I have sensor data(acclerometer,compass) saved in a csv file with their time stamps hh-mm-ss format. I wanted to convert the time stamp into seconds to plot the compass reading at a particular second.
ex:
I want to convert</p>
<pre><code>11-26-32 -> 0 sec
11-26-33 -> 1 sec
11-26-34 -> 2 sec
</code></pre>
... | 0 | 2016-07-07T15:28:21Z | 38,250,085 | <p>Pandas solution:</p>
<p>assuming that you have the following CSV file:</p>
<pre><code>Time,val
11-26-32,11
11-26-33,31
11-26-34,33
11-26-35,10
11-26-39,7
</code></pre>
<p><strong>Solution:</strong></p>
<pre><code>import pandas as pd
In [225]: filename = r'C:\Temp\.data\a.csv'
In [226]: df = pd.read_csv(filenam... | 0 | 2016-07-07T15:56:11Z | [
"python",
"csv",
"pandas",
"matplotlib",
"data-analysis"
] |
Automate Excel datas to a Word Document with Python | 38,249,549 | <p>Here's my problem : I have 1000 names and addresses on an Excel Sheet and I have to write a letter on Word for every single names .</p>
<p>Example of the letter below (red sign). </p>
<p>I would like to automate the process by using python. Could you give me your ideas about it ? How would you start and what packa... | -2 | 2016-07-07T15:30:35Z | 38,255,723 | <p>There are many options of course, but something that would work is to use the <code>openpyxl</code> package to open and read the Excel file and then use <code>python-docx</code> to write the letter file.</p>
| 0 | 2016-07-07T21:39:30Z | [
"python",
"excel",
"ms-word",
"python-docx"
] |
Permission in django. | 38,249,607 | <p>In hierarchical level of organisation how to provide permission at department level as data about each employee will be in same table. </p>
<p>here S(Employee) is basic unit in whole organization.<a href="http://i.stack.imgur.com/XgdI8.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/XgdI8.jpg" alt="hierarchy... | 0 | 2016-07-07T15:33:34Z | 38,250,221 | <p>Does it have to be django?</p>
<p>This traversal style layout looks more like a job for pyramid.</p>
<p><a href="https://pypi.python.org/pypi/django-mptt" rel="nofollow">https://pypi.python.org/pypi/django-mptt</a>
seems a good starting point for your tree structure, but with the permission system you are on your ... | 0 | 2016-07-07T16:02:25Z | [
"python",
"django",
"database",
"django-models",
"django-admin"
] |
Permission in django. | 38,249,607 | <p>In hierarchical level of organisation how to provide permission at department level as data about each employee will be in same table. </p>
<p>here S(Employee) is basic unit in whole organization.<a href="http://i.stack.imgur.com/XgdI8.jpg" rel="nofollow"><img src="http://i.stack.imgur.com/XgdI8.jpg" alt="hierarchy... | 0 | 2016-07-07T15:33:34Z | 38,250,936 | <p>Let's assume your managers' user object have a foreign key named unit to the level they represent (B1, C3, ...)</p>
<p>First you need a way to get all the employee who are descendants. Like cleder mentioned, django-mptt will make your life way easier for that. Simply run <code>user.unit.get_leafnodes()</code> with ... | 0 | 2016-07-07T16:40:04Z | [
"python",
"django",
"database",
"django-models",
"django-admin"
] |
Reading multi-dimensional arrays from text file and storing the data in multi-dimensional arrays | 38,249,636 | <p>I am trying to read multi-dimensional arrays from file HD.txt and store the data in arrays for computation. HD.txt looks like the following:</p>
<pre><code> [[[27],[0],[0],[0],[0],[0],[0]],
[[0],[0],[0],[0],[0],[0],[0]],
[[0],[0],[0],[0],[0],[0],[0]]]
[[102],[0],[0],[0],[0],[0]]
</code></pre>
<p>I would like... | 0 | 2016-07-07T15:34:52Z | 38,250,090 | <p>When using <code>line.split()</code> you need a character that is in between each of the values. Since <code>HD.txt</code> has commas in between each value you can simply remove each <code>[</code> and <code>]</code> character then call <code>split()</code>. Below is an example.</p>
<pre><code>arrayOne = []
arrayTw... | 0 | 2016-07-07T15:56:18Z | [
"python",
"arrays"
] |
Reading multi-dimensional arrays from text file and storing the data in multi-dimensional arrays | 38,249,636 | <p>I am trying to read multi-dimensional arrays from file HD.txt and store the data in arrays for computation. HD.txt looks like the following:</p>
<pre><code> [[[27],[0],[0],[0],[0],[0],[0]],
[[0],[0],[0],[0],[0],[0],[0]],
[[0],[0],[0],[0],[0],[0],[0]]]
[[102],[0],[0],[0],[0],[0]]
</code></pre>
<p>I would like... | 0 | 2016-07-07T15:34:52Z | 38,250,834 | <p>As you have control on the data generation, I advice you to remove the brackets and simply display data separated by spaces (for columns) and returns (for rows). It would lead you to this content for <code>HD.txt</code> :</p>
<pre><code>27 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 0 0 0 0
102 0 0 0 0 0
</code></pre>
<p>The... | 0 | 2016-07-07T16:33:21Z | [
"python",
"arrays"
] |
Error linking python lib with swig and g++ | 38,249,701 | <p>I try the compilation of a wrapper of c++ code in python 2.7 with SWIG. (Please correct my formulation if wrong). This code uses to work on another machine, and all libraries (especially -lpython27) stand where they should be, </p>
<p>PATH variables include (among others) : "C:\Python27\Lib\site-packages;C:\Python2... | 0 | 2016-07-07T15:37:58Z | 38,252,418 | <p>Move the <code>-lpython27</code> after the <code>.o</code> files on the last compile line. The python27 library is loaded and then no dependencies are required because the <code>.o</code> files have not been looked at, so the symbols are not retained. See <a href="http://stackoverflow.com/questions/45135/why-does-th... | 1 | 2016-07-07T18:07:45Z | [
"python",
"c++",
"g++",
"mingw",
"swig"
] |
Using Python write to CSV | 38,249,705 | <p>My objective is to gather all product descriptions from <a href="http://turnpikeshoes.com" rel="nofollow">http://turnpikeshoes.com</a> into a CSV, Separated by row. I have been successful getting the descriptions into a text file, and loop through sites for each product but I'm currently stuck on creating a CSV. Ple... | -1 | 2016-07-07T15:38:17Z | 38,249,772 | <p>When you open a file like this:</p>
<pre><code>with open('list.csv','wb') as f:
writer = csv.writer(f)
</code></pre>
<p>The file is automatically closed once you exit the <code>with</code> block.</p>
<p>You probably want to indent the <code>for</code> loop so that it is inside the <code>with</code>.</p>
| 3 | 2016-07-07T15:42:03Z | [
"python",
"csv"
] |
Python library to translate multi-byte characters into 7-bit ASCII in Python | 38,249,708 | <p>Is there a python library that provides translation of multi-byte non-ASCII characters into some reasonable form of 7-bit displayable ASCII. This is intended to avoid hard-coding the <code>charmap</code> as given in the <a href="http://stackoverflow.com/a/38178064/257924">answer</a> to <a href="http://stackoverflow... | 0 | 2016-07-07T15:38:32Z | 38,249,916 | <p>You may consider the <a href="https://docs.python.org/2/library/unicodedata.html" rel="nofollow">unicodedata</a> python package. I think one of the methods you may find interesting is <code>normalize</code> (see also example of usage given by <a href="https://www.peterbe.com/plog/unicode-to-ascii" rel="nofollow">pet... | 3 | 2016-07-07T15:48:10Z | [
"python",
"encoding",
"python-requests"
] |
Python library to translate multi-byte characters into 7-bit ASCII in Python | 38,249,708 | <p>Is there a python library that provides translation of multi-byte non-ASCII characters into some reasonable form of 7-bit displayable ASCII. This is intended to avoid hard-coding the <code>charmap</code> as given in the <a href="http://stackoverflow.com/a/38178064/257924">answer</a> to <a href="http://stackoverflow... | 0 | 2016-07-07T15:38:32Z | 38,249,965 | <p><code>str.encode()</code> has an optional 'error' parameter that can replace un-encodable characters instead of throwing an error. Is that what you are looking for?</p>
<p><a href="https://docs.python.org/3/howto/unicode.html#converting-to-bytes" rel="nofollow">https://docs.python.org/3/howto/unicode.html#convertin... | 1 | 2016-07-07T15:50:27Z | [
"python",
"encoding",
"python-requests"
] |
Python library to translate multi-byte characters into 7-bit ASCII in Python | 38,249,708 | <p>Is there a python library that provides translation of multi-byte non-ASCII characters into some reasonable form of 7-bit displayable ASCII. This is intended to avoid hard-coding the <code>charmap</code> as given in the <a href="http://stackoverflow.com/a/38178064/257924">answer</a> to <a href="http://stackoverflow... | 0 | 2016-07-07T15:38:32Z | 38,546,340 | <p>(Note: This answer pertains to Python 2.7.11+.)</p>
<p>The answer at <a href="http://stackoverflow.com/a/1701378/257924">http://stackoverflow.com/a/1701378/257924</a> refers to the Unidecode package and is what I was looking for. In using that package, I also discovered the ultimate source of my confusion which is ... | 0 | 2016-07-23T20:55:17Z | [
"python",
"encoding",
"python-requests"
] |
Tkinter not working in cmd (working in IDLE) | 38,249,755 | <p>I am trying to display a directory selection dialog box (for getting a path and then for saving downloaded stuff).The code runs fine in IDLE but when i try to run it in CMD i get this error</p>
<p><code>NameError: name 'Tk' is not defined</code></p>
<p>I am using tkinter for gui.</p>
<p>Code Snippet</p>
<pre><co... | 0 | 2016-07-07T15:41:00Z | 38,250,155 | <p>The statement <code>from tkinter import filedialog</code> only imports the <code>filedialog</code> module from <code>tkinter</code>. If you want the usual Tkinter stuff, you have to import that too. I'd recommend <code>import tkinter as tk</code> and then referring to it with e.g. <code>root = tk.Tk()</code> so you ... | 0 | 2016-07-07T15:58:56Z | [
"python",
"cmd",
"tkinter",
"tk"
] |
Python How to get a specific code in website using re | 38,249,763 | <p>I'm trying to make python challange.
<a href="http://www.pythonchallenge.com/pc/def/ocr.html" rel="nofollow">http://www.pythonchallenge.com/pc/def/ocr.html</a>
Ok. I know, I can just copy paste the code from source to a txt file and make things like that but I want to take it from net for improving myself. (+ I have... | 1 | 2016-07-07T15:41:19Z | 38,249,974 | <p>Not sure what you mean by "that mess". You should include all of the details of the challenge within this post, instead of linking users to the pythonchallenge post.</p>
<p>Either way, if you set the regex to be in single-line mode, <code>//s</code>, then the dot character, <code>.</code>, should match newlines, <c... | 1 | 2016-07-07T15:50:48Z | [
"python",
"html",
"regex",
"python-2.7",
"web"
] |
Python How to get a specific code in website using re | 38,249,763 | <p>I'm trying to make python challange.
<a href="http://www.pythonchallenge.com/pc/def/ocr.html" rel="nofollow">http://www.pythonchallenge.com/pc/def/ocr.html</a>
Ok. I know, I can just copy paste the code from source to a txt file and make things like that but I want to take it from net for improving myself. (+ I have... | 1 | 2016-07-07T15:41:19Z | 38,250,089 | <p>You can solve:</p>
<pre><code>codes = re.findall("/<!--(.*?)-->/s",str(x.content))
</code></pre>
<p>"s" find with whitespace and breakline</p>
| 1 | 2016-07-07T15:56:16Z | [
"python",
"html",
"regex",
"python-2.7",
"web"
] |
Python How to get a specific code in website using re | 38,249,763 | <p>I'm trying to make python challange.
<a href="http://www.pythonchallenge.com/pc/def/ocr.html" rel="nofollow">http://www.pythonchallenge.com/pc/def/ocr.html</a>
Ok. I know, I can just copy paste the code from source to a txt file and make things like that but I want to take it from net for improving myself. (+ I have... | 1 | 2016-07-07T15:41:19Z | 38,250,304 | <p>I would use an <em>HTML parser</em> instead. You can <a href="http://stackoverflow.com/a/3507360/771848">find comments</a> in HTML with <a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/" rel="nofollow"><code>BeautifulSoup</code></a>.</p>
<p>Working code:</p>
<pre><code>import requests
from bs4 import... | 2 | 2016-07-07T16:06:02Z | [
"python",
"html",
"regex",
"python-2.7",
"web"
] |
Celery - How to log parent task id? | 38,249,803 | <p>I want to log the backtrace of sorts of tasks in the logs - can this be done? Results have parents and can even output a graph, but I can't see a parent task or task id in the Task or request itself. Do I have to pass parent's task id manually to each subtask?</p>
<p>Corollary: is it safe to set the task_id to the ... | 0 | 2016-07-07T15:43:15Z | 38,250,053 | <p>There is no need to pass parent <code>task_id</code> manually.</p>
<p>If you have simple chain like this</p>
<pre><code>@app.task()
def task1():
return('task1')
@app.task()
def task2():
return('task2')
c = chain(task1.si(), task2.si())
</code></pre>
<p>You can see parents task id </p>
<pre><code>In [17... | 1 | 2016-07-07T15:54:18Z | [
"python",
"celery"
] |
Cannot get LabelFrame widget to display on ttk notebook (python 3.5.1) | 38,249,833 | <p>I have an application in which the (tkinter) LabelFrame widget on the tab of a ttk Notebook will not update itself. In a much simplified version of that program (code extracts below) the widget will not even appear on the GUI. </p>
<p>Everything else on the GUI works properly, including updating the tab titles, ... | 0 | 2016-07-07T15:44:15Z | 38,252,939 | <p>Your title is misleading because you place the LabelFrame in a Frame, not directly on a Notebook tab. Your problem is that the labelframe does not appear in its parent frame. The Notebook is irrelevant and all associated code should have been deleted before posting.</p>
<p>Even the frame is irrelevant in that the... | 0 | 2016-07-07T18:36:20Z | [
"python",
"python-3.x",
"user-interface",
"tkinter",
"ttk"
] |
confluent-kafka python avro messages | 38,249,925 | <p>So, I can successfully use the python confluent-kafka api to consume messages from Kafka that are text encoded.</p>
<p>When I try to consume Avro encoded (binary) messages, I get a UnicodeDecodeError exception on:</p>
<pre><code>msg = kafka_consumer.poll(timeout=2.0)
</code></pre>
<p>Obviously, Avro encoded value... | 0 | 2016-07-07T15:48:23Z | 38,253,475 | <p>On irc, #kafka, one of the developers said this is a bug in the 3.0 release of confluent-python, it's been fixed in the master branch, and the fix will be in the next point release.</p>
| 1 | 2016-07-07T19:08:30Z | [
"python",
"apache-kafka",
"kafka-consumer-api"
] |
Finding largest closed 3D contour plot | 38,249,949 | <p>I have a scatter plot and many contour plots. There are many contours,some closed some not. How can I identify the values of the largest closed contour from [this].<a href="http://i.stack.imgur.com/oejhs.jpg" rel="nofollow">1</a></p>
| 2 | 2016-07-07T15:49:28Z | 38,252,648 | <p>Finding the biggest closed contour can be done as follows; note though that this assumes that by "biggest" you meant largest point-to-point distance. </p>
<p>Other size metrics could be easily substituted in though. </p>
<p>Note also that if you use the <code>extend3d=True</code> version, you would need to manipul... | 3 | 2016-07-07T18:18:32Z | [
"python",
"numpy",
"matplotlib"
] |
Install pip for python 3.5 | 38,249,961 | <p><strong>SOLUTION</strong> My user did not own permissions to the pip directory, I reinstalled Python 3.5 using the <code>sudo -H</code> flag</p>
<p>I'm trying to install Tensorflow for python 3.5 using pip3 -- for reasons described in <a href="https://github.com/tensorflow/tensorflow/issues/3196#issuecomment-231114... | 1 | 2016-07-07T15:50:06Z | 38,250,442 | <p>Check: /usr/local/lib/python3.5/dist-packages</p>
<p>You'll either have Pip there or easy_install(part of Pythons setup tools), which can be used to install Pip:</p>
<pre><code>sudo apt-get install python3-setuptools
sudo python3.5 easy_install.py pip
</code></pre>
<p>Or you can try:</p>
<pre><code>python3.5 -m ... | 1 | 2016-07-07T16:12:14Z | [
"python",
"ubuntu",
"installation",
"pip",
"tensorflow"
] |
add a subplot to the plot produced by a previous function | 38,249,983 | <p>I've written a function that reads data from a csv file and plots it. Now I need to add a subplot with another part of the data from the same file, so I've tried to write a function that calls the first function and adds a subplot. When I do this, I get the two to show up as different figures. How can I suppress thi... | 1 | 2016-07-07T15:51:03Z | 38,250,314 | <p>I am not sure whether you need to use matplotlib.gridspec specifically or not, but you can use subplot2grid to make the job easy.</p>
<pre><code>import matplotlib.pyplot as plt
def timex():
time = [1, 2, 3, 4, 5]
x = [1, 2, 3, 4, 5]
y = [1, 1, 1, 1, 1]
ax1 = plt.subplot2grid((1,2), (0,0))
ax1.... | 2 | 2016-07-07T16:06:29Z | [
"python",
"matplotlib"
] |
Mapping a range of warc.gz files, EMR | 38,250,004 | <p>I have been running a streaming step in AWS/EMR with a mapper and reducer written in Python to map some of the archives in Common Crawl for sentiment analysis. </p>
<p>I am moving from the older common crawl textData format to the newer warc.gz format and I need to know how I might go about specifying a range of wa... | 1 | 2016-07-07T15:51:51Z | 38,252,238 | <p>I'm pretty sure you can use the same method you were using previously. To just read the two files you would use:</p>
<p><code>s3://aws-publicdatasets/common-crawl/crawl-data/CC-MAIN-2016-07/segments/1454702039825.90/warc/CC-MAIN-20160205195359-0000[0-1]-ip-10-236-182-209.ec2.internal.warc.gz</code></p>
<p>Also sin... | 0 | 2016-07-07T17:57:35Z | [
"python",
"hadoop",
"elastic-map-reduce"
] |
Mapping a range of warc.gz files, EMR | 38,250,004 | <p>I have been running a streaming step in AWS/EMR with a mapper and reducer written in Python to map some of the archives in Common Crawl for sentiment analysis. </p>
<p>I am moving from the older common crawl textData format to the newer warc.gz format and I need to know how I might go about specifying a range of wa... | 1 | 2016-07-07T15:51:51Z | 38,981,619 | <p>You can download the list of warc file of july 2016 via </p>
<pre><code>https://commoncrawl.s3.amazonaws.com/crawl-data/CC-MAIN-2016-30/warc.paths.gz
https://commoncrawl.s3.amazonaws.com/crawl-data/CC-MAIN-2016-30/wat.paths.gz
https://commoncrawl.s3.amazonaws.com/crawl-data/CC-MAIN-2016-30/wet.paths.gz
</code></pre... | 0 | 2016-08-16T18:03:52Z | [
"python",
"hadoop",
"elastic-map-reduce"
] |
How to compare two numpy arrays and add missing values to the other with a tweak | 38,250,074 | <p>I have two numpy arrays of different dimension. I want to add those additional elements of the bigger array to the smaller array, only the 0th element and the 1st element should be given as 0. </p>
<p>For example :</p>
<p>a = [ [2,4],[4,5], [8,9],[7,5]]</p>
<p>b = [ [2,5], [4,6]]</p>
<p>After adding the missing ... | 2 | 2016-07-07T15:55:44Z | 38,250,484 | <pre><code>#####For explanation#####
#basic set operation to get the missing elements
c = set([i[0] for i in a]) - set([i[0] for i in b])
#c will just store the missing elements....
#then just append the elements
for i in c:
b.append([i, 0])
</code></pre>
<p>Output - </p>
<pre><code>[[2, 5], [4, 6], [8, 0], [7,... | 2 | 2016-07-07T16:14:22Z | [
"python",
"arrays",
"numpy"
] |
How to compare two numpy arrays and add missing values to the other with a tweak | 38,250,074 | <p>I have two numpy arrays of different dimension. I want to add those additional elements of the bigger array to the smaller array, only the 0th element and the 1st element should be given as 0. </p>
<p>For example :</p>
<p>a = [ [2,4],[4,5], [8,9],[7,5]]</p>
<p>b = [ [2,5], [4,6]]</p>
<p>After adding the missing ... | 2 | 2016-07-07T15:55:44Z | 38,251,141 | <p>You can use <a href="http://docs.scipy.org/doc/numpy/reference/generated/numpy.in1d.html" rel="nofollow"><code>np.in1d</code></a> to look for matching rows from <code>b</code> in <code>a</code> to get a mask and based on the mask choose rows from <code>a</code> or set to zeros. Thus, we would have a vectorized appro... | 1 | 2016-07-07T16:51:49Z | [
"python",
"arrays",
"numpy"
] |
How to compare two numpy arrays and add missing values to the other with a tweak | 38,250,074 | <p>I have two numpy arrays of different dimension. I want to add those additional elements of the bigger array to the smaller array, only the 0th element and the 1st element should be given as 0. </p>
<p>For example :</p>
<p>a = [ [2,4],[4,5], [8,9],[7,5]]</p>
<p>b = [ [2,5], [4,6]]</p>
<p>After adding the missing ... | 2 | 2016-07-07T15:55:44Z | 38,252,052 | <p>First we should clear up one misconception. <code>c</code> does not have to be a <code>copy</code>. A new variable assignment is sufficient.</p>
<pre><code>c = b
...
c= np.insert(c, len(c), [a[j,0], 0], axis = 0)
</code></pre>
<p><code>np.insert</code> is not modifying any of its inputs. Rather it makes a n... | 1 | 2016-07-07T17:47:23Z | [
"python",
"arrays",
"numpy"
] |
Pandas filter performing slow due to too many groups | 38,250,077 | <p>I have a large df which I need to alter. For one computation I want to group my data on pborderid and then only keep the rows which have a duplicate value in to_wpadr.</p>
<p>Here is an example of my df.</p>
<pre><code> pborderid pbcarid wsid to_wpadr colli pk_end_time
10 76079450 61838497 ... | 2 | 2016-07-07T15:55:50Z | 38,250,228 | <p>I don't know if it'll be faster, but you can try using <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.duplicated.html" rel="nofollow"><code>DataFrame.duplicated</code></a> to filter in only the duplicates.</p>
<pre><code>ap = ot[ot.duplicated(subset=['pborderid', 'to_wpadr'], keep=F... | 2 | 2016-07-07T16:02:54Z | [
"python",
"pandas"
] |
Pandas filter performing slow due to too many groups | 38,250,077 | <p>I have a large df which I need to alter. For one computation I want to group my data on pborderid and then only keep the rows which have a duplicate value in to_wpadr.</p>
<p>Here is an example of my df.</p>
<pre><code> pborderid pbcarid wsid to_wpadr colli pk_end_time
10 76079450 61838497 ... | 2 | 2016-07-07T15:55:50Z | 38,253,669 | <p>Inspired by <a href="http://stackoverflow.com/a/38145104/3293881"><code>this solution</code></a>, we can replace <code>groupby</code> operation in this case too. The implementation would look something like this -</p>
<pre><code># Create numerical IDs for relevant columns and a combined one
ID1 = np.unique(df['pbor... | 0 | 2016-07-07T19:20:13Z | [
"python",
"pandas"
] |
Set default values for sympy lambdify arguments | 38,250,106 | <p>I know that sympyâs <a href="http://docs.sympy.org/dev/modules/utilities/lambdify.html" rel="nofollow"><code>lambdify</code></a> function can create a lambda with arguments <code>variables</code> and body <code>expression</code> like this:</p>
<pre><code>lambdify(variables, expression)
</code></pre>
<p>so</p>
<... | 2 | 2016-07-07T15:56:47Z | 38,259,720 | <p>The fact that it works with strings is an accident. The way lambdify works is it creates a string form of the expression, then evals the string <code>"lambda %s: (%s)" % (', '.join(map(str, args)), expr)</code> (it's actually a little more complicated than that in general, but that's the basic idea). So if args is <... | 0 | 2016-07-08T05:51:01Z | [
"python",
"sympy"
] |
dcos client installation failure - import concurrent.futures ImportError: No module named concurrent.futures | 38,250,107 | <p>I just completed the installation of the dcos environment in the lab environment, and when I try to install the dcos client in on centos7 linux machine I got</p>
<pre><code>**[root@rmavmdock5 dcos]# bash install.sh . http://10.120.1.187**
Installing DC/OS CLI from PyPI...
New python executable in /root/dcos/bin/py... | 1 | 2016-07-07T15:56:48Z | 38,258,105 | <p>the virtualenv env doesn't have futures. install via the virtual env pip, not the system one.</p>
<p>from the dcos dir:</p>
<p><code>bin/pip install futures</code></p>
<p>then do your <code>bash install.sh . <url></code> again</p>
| 1 | 2016-07-08T02:31:58Z | [
"python",
"dcos"
] |
Unable to loop through multiple pages to scrape data | 38,250,216 | <p>I need to move to the next url link (each page has about 20 rows which I need to extract, following which the same needs to be added to the next set of results from the following urls).</p>
<p>There are about 360 urls and I would like to extract data by running through all of them. My code is below. I would like to... | 0 | 2016-07-07T16:02:04Z | 38,251,926 | <p>I made some changes to your code. I set up the original url with a variable I called skip. skip will be incremented by 20 each time through</p>
<pre><code>from urlparse import urljoin
import requests
from bs4 import BeautifulSoup
import csv
list_of_rows = []
skip = 0
next_page = 'http://cricket.inhs.uiuc.edu/ed... | 0 | 2016-07-07T17:39:50Z | [
"python",
"html",
"web-scraping",
"beautifulsoup"
] |
Python: Saving and reusing variables | 38,250,223 | <p>Hello i have something to ask can i save a variable somehow in a file??
For example:</p>
<pre><code> #1.py
Money = 0
#2.py
importvariable(Money, 1.py)
print(Money)
0
Money = 5
exportvariable(Money, 1.py)
#3.py
importvariable(Money, 1.py)
</code></pre>
<p>Thats just an examp... | -2 | 2016-07-07T16:02:34Z | 38,250,346 | <p>You can read and write to files using python file handling API (<a href="https://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files" rel="nofollow">https://docs.python.org/2/tutorial/inputoutput.html#reading-and-writing-files</a>). But you should use a separate data file to store your data and sho... | 0 | 2016-07-07T16:08:04Z | [
"python",
"variables"
] |
Evaluate variable assignment | 38,250,238 | <p>I am aware of Python's ternary operator:</p>
<pre><code>result = a if b else c
</code></pre>
<p>But what if a and b are the same thing? Let me exemplify it:</p>
<pre><code>tasks = ["foo", "bar"]
def tasksLeft():
return tasks
tasks.remove('foo')
my_tasks = tasksLeft() if tasksLeft() else 'no tasks left'
</cod... | 4 | 2016-07-07T16:03:16Z | 38,250,297 | <p>In Python the logical operators return one of their operands (the first one that can be used to determine the result of the overall expression), so you can use the <code>or</code> operator:</p>
<pre><code>my_tasks = tasksLeft() or 'no tasks left'
</code></pre>
| 5 | 2016-07-07T16:05:51Z | [
"python",
"python-3.5"
] |
formatting the return in python - print out different types of values | 38,250,280 | <p>I have the following code</p>
<pre><code>$ipython
> import csv
> with open('q1_4.csv', 'rb') as csvfile:
reader = csv.reader(csvfile, delimiter = ' ', quotechar = '|')
for row in reader:
print [tuple(row)]
</code></pre>
<p>In each row, I have four values, each of which is a string, a nu... | 0 | 2016-07-07T16:05:11Z | 38,250,407 | <p>If formatting is all you are concerned about </p>
<pre><code>with open('q1_4.csv', 'rb') as csvfile:
reader = csv.reader(csvfile, delimiter = ' ', quotechar = '|')
for row in reader:
print '"{}", {}, {}, {}'.format(*row)
</code></pre>
<p>Test:</p>
<pre><code>>>> row = ["string", "1", "2",... | 0 | 2016-07-07T16:11:01Z | [
"python"
] |
Update package of anaconda python | 38,250,284 | <p>I'm working with <em>python 3.4</em>. I use anaconda to install my data-science's packages and I need the statsmodels <strong><em>0.8</em></strong> : </p>
<p><a href="https://pypi.python.org/pypi/statsmodels/" rel="nofollow">https://pypi.python.org/pypi/statsmodels/</a></p>
<p>but on anaconda there is only the sta... | 0 | 2016-07-07T16:05:16Z | 38,250,856 | <p>IF a package is available on PyPi, you can use </p>
<pre><code>conda skeleton pypi package
</code></pre>
<p>to create a condo-recipe for that package, then</p>
<pre><code>conda build package
conda install --use-local package
</code></pre>
<p>to build and install the package</p>
| 1 | 2016-07-07T16:34:51Z | [
"python",
"version",
"updates",
"anaconda"
] |
python pandas filtering involving lists | 38,250,323 | <p>I am currently using Pandas in python 2.7. My dataframe looks similar to this:</p>
<pre><code>>>> df
0
1 [1, 2]
2 [2, 3]
3 [4, 5]
</code></pre>
<p>Is it possible to filter rows by values <em>in</em> column 1? For example, if my filter value is 2, the filter should return a dataframe containing ... | 0 | 2016-07-07T16:07:09Z | 38,250,382 | <p>You can use <a href="http://pandas.pydata.org/pandas-docs/stable/indexing.html#boolean-indexing" rel="nofollow"><code>boolean indexing</code></a>:</p>
<pre><code>import pandas as pd
df = pd.DataFrame({'0':[[1, 2],[2, 3], [4, 5]]})
print (df)
0
0 [1, 2]
1 [2, 3]
2 [4, 5]
print (df['0'].apply(lambda x: 2... | 2 | 2016-07-07T16:09:43Z | [
"python",
"pandas"
] |
python pandas filtering involving lists | 38,250,323 | <p>I am currently using Pandas in python 2.7. My dataframe looks similar to this:</p>
<pre><code>>>> df
0
1 [1, 2]
2 [2, 3]
3 [4, 5]
</code></pre>
<p>Is it possible to filter rows by values <em>in</em> column 1? For example, if my filter value is 2, the filter should return a dataframe containing ... | 0 | 2016-07-07T16:07:09Z | 38,250,608 | <p>You can also use boolean indexing with a list comprehension:</p>
<pre><code>>>> df[[2 in row for row in df['0']]]
0
0 [1, 2]
1 [2, 3]
</code></pre>
| 1 | 2016-07-07T16:20:12Z | [
"python",
"pandas"
] |
Spyder 'runfile' is not defined | 38,250,361 | <p>I am trying to run a script in <code>Spyder</code>, but am getting the following error:</p>
<pre><code>NameError: name 'runfile' is not defined.
</code></pre>
<p>I tried a variety of things, like updating the PYTHONPATH variable, but nothing seems to be helping.<br>
I have Python 2.7, Anaconda 2.4, and Spyder 2.3.... | 0 | 2016-07-07T16:08:46Z | 38,254,636 | <p>The source of this was an issue with the import of sitecustomize. This was apparent when you clicked on All Programs>Anaconda>Anaconda Prompt in the Windows Start Menu. This entry offered some insight with that: <a href="http://stackoverflow.com/questions/30034114/how-to-reset-spyder-ide-python-2-7-graphic-user-in... | 0 | 2016-07-07T20:25:28Z | [
"python",
"python-2.7",
"anaconda",
"spyder"
] |
json.loads not working in django | 38,250,384 | <p>I have a object(or string ? I am not sure..) in my mysql database, and I want to turn it back to python dictionary in views and then process it and then send back to html.</p>
<p>so here is my code in views.py:</p>
<pre><code>def measure_detail(request, measurement_id):
_ClickedPts = ClickedPts.objects.g... | 0 | 2016-07-07T16:09:45Z | 38,250,959 | <p>Your string isn't a proper JSON string, and actually looks like a Python JSON object. You would be better off using ast.literal_eval to convert this string to a Python JSON Object. Just call ast.literal_val(_ClickedPts) instead of json.loads(_ClickedPts) to get what you want.</p>
<p><a href="https://docs.python.org... | 0 | 2016-07-07T16:41:17Z | [
"python",
"json",
"django"
] |
json.loads not working in django | 38,250,384 | <p>I have a object(or string ? I am not sure..) in my mysql database, and I want to turn it back to python dictionary in views and then process it and then send back to html.</p>
<p>so here is my code in views.py:</p>
<pre><code>def measure_detail(request, measurement_id):
_ClickedPts = ClickedPts.objects.g... | 0 | 2016-07-07T16:09:45Z | 38,271,832 | <p>The following code works:</p>
<pre><code>test = ClickedPts.objects.values('pts')
test = test[0]['pts']
test = ast.literal_eval(test)
#print type(test)
#print test
</code></pre>
| 0 | 2016-07-08T16:47:52Z | [
"python",
"json",
"django"
] |
Django include template tag in for loop only catches first iteration | 38,250,436 | <p>I have a comments section on some pages on my site that I build with a <code>{% for ... %}</code> loop (and another nested loop for comment replies. The section was hacked together, and I am still learning web development and Django, so please forgive any frustrating sloppiness or weirdness. I am not concerned with ... | 3 | 2016-07-07T16:12:00Z | 38,295,419 | <p>It looks like all your edit modals will have the same id <code>id="editModal"</code> as well as your reply modals <code>id="replyModal"</code> if you are showing them based on id probably you will always open the first DOM element with that id. You could try appending a unique identifier like <code>forloop.counter</... | 2 | 2016-07-10T18:53:21Z | [
"python",
"django",
"loops",
"django-templates",
"closures"
] |
Django include template tag in for loop only catches first iteration | 38,250,436 | <p>I have a comments section on some pages on my site that I build with a <code>{% for ... %}</code> loop (and another nested loop for comment replies. The section was hacked together, and I am still learning web development and Django, so please forgive any frustrating sloppiness or weirdness. I am not concerned with ... | 3 | 2016-07-07T16:12:00Z | 38,316,120 | <p>As <a href="http://stackoverflow.com/questions/38250436/django-include-template-tag-in-for-loop-only-catches-first-iteration#comment64007215_38250436">emulbreh postulates</a>, a modal is in fact rendered for every comment. However, all of the modals have the same ID, so regardless of which commentâs edit button wa... | 2 | 2016-07-11T20:58:59Z | [
"python",
"django",
"loops",
"django-templates",
"closures"
] |
Calculate coefficients in a multivariate linear regression | 38,250,707 | <p>I am trying to calculate the coefficients using multivariate linear regression. I am using the <code>statsmodels</code> library to calculate the coefficients. The problem is that with this code I get the error <code>ValueError: endog and exog matrices are different sizes</code>. I get this error because with this ex... | 0 | 2016-07-07T16:25:57Z | 38,259,152 | <p>Assuming each list in <code>x</code> corresponds to each value of <code>y</code>:</p>
<pre><code>x = [[0.0, 1102249463.0, 44055788.0, 9.0, 2.0, 32000.0, 49222464.0],
[0.0, 1102259506.0, 44049537.0, 9.0, 2.0, 32000.0, 49222464.0],
[0.0, 1102249463.0, 44055788.0, 9.0, 2.0, 32000.0, 49222464.0],
[0.0, 1... | 1 | 2016-07-08T04:57:53Z | [
"python",
"numpy",
"linear-regression",
"statsmodels"
] |
How to split data into 3 sets (train, validation and test)? | 38,250,710 | <p>I have a pandas dataframe and I wish to divide it to 3 seprate sets. I know that using <a href="http://scikit-learn.org/stable/modules/generated/sklearn.cross_validation.train_test_split.html">train_test_split</a> from <code>sklearn.cross_validation</code>, one can divide the data in two sets (train and test). Howev... | 11 | 2016-07-07T16:26:26Z | 38,251,063 | <h3>Note:</h3>
<p>Function was written to handle seeding of randomized set creation. You should not rely on set splitting that doesn't randomize the sets.</p>
<pre><code>import numpy as np
import pandas as pd
def train_validate_test_split(df, train_percent=.6, validate_percent=.2, seed=None):
np.random.seed(see... | 7 | 2016-07-07T16:47:10Z | [
"python",
"pandas",
"dataframe",
"machine-learning",
"scikit-learn"
] |
How to split data into 3 sets (train, validation and test)? | 38,250,710 | <p>I have a pandas dataframe and I wish to divide it to 3 seprate sets. I know that using <a href="http://scikit-learn.org/stable/modules/generated/sklearn.cross_validation.train_test_split.html">train_test_split</a> from <code>sklearn.cross_validation</code>, one can divide the data in two sets (train and test). Howev... | 11 | 2016-07-07T16:26:26Z | 38,251,213 | <p>Numpy solution (thanks to <a href="http://stackoverflow.com/questions/38250710/how-to-split-data-into-3-sets-train-development-and-test/38251213?noredirect=1#comment63923795_38251213">root</a> for the randomizing hint) - we will split our data set into the following parts: (60% - train set, 20% - validation set, 20%... | 10 | 2016-07-07T16:56:12Z | [
"python",
"pandas",
"dataframe",
"machine-learning",
"scikit-learn"
] |
Python- load data on first instance of class | 38,250,738 | <p>I have a python class that will need to reference a large data set. I need to create thousands of instances of the class so I don't want to load the data set every time. It would be straightforward to put the data in another class that has to be created first and passed to the other one as an argument:</p>
<pre><co... | 0 | 2016-07-07T16:27:36Z | 38,250,818 | <p>If the dataset is shared between all instances of the class, make it a class variable.</p>
<pre><code>class Dataset():
def __init__(self, filename):
# load dataset...
class Class_using_dataset():
def __init__(self)
# use the dataset and do other stuff
Class_using_dataset.ds = Dataset('file... | 1 | 2016-07-07T16:32:04Z | [
"python"
] |
Python- load data on first instance of class | 38,250,738 | <p>I have a python class that will need to reference a large data set. I need to create thousands of instances of the class so I don't want to load the data set every time. It would be straightforward to put the data in another class that has to be created first and passed to the other one as an argument:</p>
<pre><co... | 0 | 2016-07-07T16:27:36Z | 38,250,941 | <p>You can either load the dataset into a class variable at the time the <code>Class_using_dataset</code> class is parsed, or when the user creates the first instance of the class.</p>
<p>The first strategy simply requires you to move the line loading the dataset into the class itself.</p>
<pre><code>class Dataset():... | 1 | 2016-07-07T16:40:12Z | [
"python"
] |
Extending JSONEncoder to call __json__ for serialization? | 38,250,765 | <p>I'd like to extend the <code>JSONEncoder</code> to call <code>__json__</code> of an object to convert it to something serializable.</p>
<p>I've tried this:</p>
<pre><code>import json
class Foo(object):
def __json__(self):
return dict(a=1, b=2)
class MyJSONEncoder(json.JSONEncoder):
"""
U... | 0 | 2016-07-07T16:29:10Z | 38,250,766 | <p>I found my error:</p>
<pre><code>class MyJSONEncoder(DjangoJSONEncoder):
"""
Use __json__ attr or callable of object for JSON serialization.
""" ... | 1 | 2016-07-07T16:29:10Z | [
"python",
"json",
"serialization"
] |
Use Python and JSON to recursively get all keys associated with a value | 38,250,937 | <p>Giving data organized in JSON format (code example bellow) how can we get the path of keys and sub-keys associated with a given value?</p>
<p>i.e.</p>
<p>Giving an input "23314" we need to return a list with:
Fanerozoico, Cenozoico, Quaternario, Pleistocenico, Superior.</p>
<p>Since data is a json file, using pyt... | -2 | 2016-07-07T16:40:05Z | 38,252,470 | <p>It's a little hard to understand exactly what you are after here, but it seems like for some reason you have a bunch of nested json and you want to search it for an <code>id</code> and return a list that represents the path down the json nesting. If so, the quick and easy path is to recurse on the dictionary (that y... | 0 | 2016-07-07T18:10:22Z | [
"python",
"json"
] |
Use Python and JSON to recursively get all keys associated with a value | 38,250,937 | <p>Giving data organized in JSON format (code example bellow) how can we get the path of keys and sub-keys associated with a given value?</p>
<p>i.e.</p>
<p>Giving an input "23314" we need to return a list with:
Fanerozoico, Cenozoico, Quaternario, Pleistocenico, Superior.</p>
<p>Since data is a json file, using pyt... | -2 | 2016-07-07T16:40:05Z | 38,252,498 | <p>Based on the assumption that you need the full dictionary path until a key named <strong>id</strong> has a particular value, here's a recursive solution that iterates the whole dict. Bear in mind that:</p>
<ul>
<li>The code is not optimized at all</li>
<li>For huge json objects it might yield <em>StackOverflow</em>... | 0 | 2016-07-07T18:11:50Z | [
"python",
"json"
] |
Running script in bash from a virtualenv | 38,250,973 | <p>I am trying to run script in bash from python, but I am currently working in a virtualenv, and when my script calls on a specific program, I get "usr/bin/env: luajit: No such file or directory". </p>
<p>When I run the same script inside a separate bash window (outside the virtualenv), it runs perfectly.</p>
<p>I ... | 0 | 2016-07-07T16:41:59Z | 38,251,314 | <p>The answer lies in environment variables. <code>PATH</code> should contain the location where your <code>luajit</code> is.</p>
<p>See <a href="http://stackoverflow.com/questions/9554087/setting-an-environment-variable-in-virtualenv">setting an environment variable in virtualenv</a> for some ways to automatically se... | 1 | 2016-07-07T17:01:25Z | [
"python",
"bash",
"virtualenv"
] |
Paramiko script with error | 38,251,099 | <p>I've found the following script on internet:</p>
<pre><code> import paramiko
from paramiko import client
class ssh:
client = None
def __init__(self, address, username, password):
# Let the user know we're connecting to the server
print("Connecting to server.")
# Create a new SSH client
sel... | 1 | 2016-07-07T16:49:35Z | 38,251,644 | <p>Turns out you need to upgrade setuptools and then re-install the package. Seems the older version breaks something on installing the python cryptography package. </p>
<p>Try the following...</p>
<pre><code>pip install -U setuptools
pin install -U paramiko
</code></pre>
<p><a href="https://github.com/pyca/crypto... | 0 | 2016-07-07T17:22:50Z | [
"python",
"ssh",
"raspberry-pi",
"paramiko"
] |
Paramiko script with error | 38,251,099 | <p>I've found the following script on internet:</p>
<pre><code> import paramiko
from paramiko import client
class ssh:
client = None
def __init__(self, address, username, password):
# Let the user know we're connecting to the server
print("Connecting to server.")
# Create a new SSH client
sel... | 1 | 2016-07-07T16:49:35Z | 38,266,967 | <p>I solved my problem with this:</p>
<pre><code> # Make the connection
self.client.connect(address, port = 22, username=username, password=password, look_for_keys=False)
</code></pre>
<p>because the port before wasn't specificate</p>
| 0 | 2016-07-08T12:41:14Z | [
"python",
"ssh",
"raspberry-pi",
"paramiko"
] |
Python 3.5: Open an image with underscore in file name? | 38,251,155 | <p>I have a script (seen below) that opens a collection of images. It took me a while to figure this out, but I realized that the script can't seem to open any of the image files with an underscore in the name. An example of my image directory is as follows: </p>
<p><code>Images\img1.jpg</code></p>
<p><code>Images\im... | 0 | 2016-07-07T16:52:36Z | 38,255,288 | <p>OKAY! So. It appears that I've been working with corrupted image files the entire time, hence the errors. </p>
| 0 | 2016-07-07T21:08:18Z | [
"python",
"python-3.x",
"python-imaging-library",
"python-import",
"skimage"
] |
Adding information into a tensor in TensorFlow | 38,251,175 | <p>Currently I have a neural network that convolutes and pools images. However, right before I make my densely connected layer, I want to add some information. Currently, I reshape my image to a flat tensor with <code>tf.reshape(image, [width * length * channels])</code>, but I was wondering how I could append a couple... | 0 | 2016-07-07T16:53:26Z | 38,253,233 | <p>You can reshape to a vector using <a href="https://www.tensorflow.org/versions/r0.9/api_docs/python/array_ops.html#reshape" rel="nofollow">tf.reshape</a> with <code>-1</code>:</p>
<pre><code>tf.reshape(image, [-1])
</code></pre>
<p>and append the new values as Tensors using <a href="https://www.tensorflow.org/vers... | 1 | 2016-07-07T18:52:57Z | [
"python",
"arrays",
"neural-network",
"tensorflow",
"conv-neural-network"
] |
How to deallocate a typed numpy array? Is setting callback_free_data a viable option? | 38,251,216 | <p>While using an open source Cython library I found a memory leak. The leak seems to come from a typed numpy array, which is not freed from the memory when it goes out of scope. The declaration is the following:</p>
<pre><code>cdef np.ndarray[object, ndim=1] my_array = np.empty(my_size, dtype=object)
</code></pre>
<... | 2 | 2016-07-07T16:56:18Z | 38,286,051 | <p>The problem (solved in the comments) turned out not to be the deallocation of the numpy array. Instead, the numpy array held a bunch of <code>Fiboheap</code> objects, which themselves held pointers to a bunch of Python objects. It's these objects that weren't freed.</p>
<p>When the Python object pointers in the <co... | 1 | 2016-07-09T20:26:12Z | [
"python",
"numpy",
"memory-leaks",
"cython"
] |
Python - Crontab script not showing Pillow Images | 38,251,222 | <p>My crontab is</p>
<pre><code>@reboot /home/cin/new.sh
</code></pre>
<p>In new.sh I have</p>
<pre><code>#!/bin/bash
python3 new.py
</code></pre>
<p>In new.py I open images with the Pillow module and play music, but when I boot it only plays the music. Any help is appreciated. </p>
<p>EDIT: The music plays perfec... | 0 | 2016-07-07T16:56:32Z | 38,859,984 | <p>In the bash script, write <code>export DISPLAY=":0.0</code>. </p>
| 0 | 2016-08-09T20:37:20Z | [
"python",
"linux",
"crontab",
"boot",
"pillow"
] |
Create a list of tuples with adjacent list elements if a condition is true | 38,251,245 | <p>I am trying to create a list of tuples where the tuple contents are the number <code>9</code> and the number before it in the list. </p>
<p><strong>Input List:</strong></p>
<pre><code>myList = [1, 8, 9, 2, 4, 9, 6, 7, 9, 8]
</code></pre>
<p><strong>Desired Output:</strong></p>
<pre><code>sets = [(8, 9), (4, 9),... | 26 | 2016-07-07T16:57:49Z | 38,251,312 | <p>Cleaner Pythonic approach:</p>
<pre><code>>>> [(x,y) for x,y in zip(myList, myList[1:]) if y == 9]
[(8, 9), (4, 9), (7, 9)]
</code></pre>
<hr>
<p>What is the code above doing:</p>
<ul>
<li><code>zip(some_list, some_list[1:])</code> would generate a list of pairs of adjacent elements.</li>
<li>Now with t... | 37 | 2016-07-07T17:01:19Z | [
"python",
"list",
"python-3.x",
"tuples",
"list-comprehension"
] |
Create a list of tuples with adjacent list elements if a condition is true | 38,251,245 | <p>I am trying to create a list of tuples where the tuple contents are the number <code>9</code> and the number before it in the list. </p>
<p><strong>Input List:</strong></p>
<pre><code>myList = [1, 8, 9, 2, 4, 9, 6, 7, 9, 8]
</code></pre>
<p><strong>Desired Output:</strong></p>
<pre><code>sets = [(8, 9), (4, 9),... | 26 | 2016-07-07T16:57:49Z | 38,251,318 | <p>You were pretty close, I'll show you an alternative way that might be more intuitive if you're just starting out:</p>
<pre><code>sets = [(myList[i-1], myList[i]) for i in range(len(myList)) if myList[i] == 9]
</code></pre>
<p>Get the index in the range of the list lenght, and if the value at the position <code>i</... | 7 | 2016-07-07T17:01:45Z | [
"python",
"list",
"python-3.x",
"tuples",
"list-comprehension"
] |
Create a list of tuples with adjacent list elements if a condition is true | 38,251,245 | <p>I am trying to create a list of tuples where the tuple contents are the number <code>9</code> and the number before it in the list. </p>
<p><strong>Input List:</strong></p>
<pre><code>myList = [1, 8, 9, 2, 4, 9, 6, 7, 9, 8]
</code></pre>
<p><strong>Desired Output:</strong></p>
<pre><code>sets = [(8, 9), (4, 9),... | 26 | 2016-07-07T16:57:49Z | 38,251,331 | <p>Part of your issue is that <code>myList[i:i]</code> will always return an empty list. The end of a slice is exclusive, so when you do <code>a_list[0:0]</code> you're trying to take the elements of <code>a_list</code> that exist <strong>between</strong> index 0 and index 0.</p>
<p>You're on the right track, but you ... | 17 | 2016-07-07T17:02:14Z | [
"python",
"list",
"python-3.x",
"tuples",
"list-comprehension"
] |
Create a list of tuples with adjacent list elements if a condition is true | 38,251,245 | <p>I am trying to create a list of tuples where the tuple contents are the number <code>9</code> and the number before it in the list. </p>
<p><strong>Input List:</strong></p>
<pre><code>myList = [1, 8, 9, 2, 4, 9, 6, 7, 9, 8]
</code></pre>
<p><strong>Desired Output:</strong></p>
<pre><code>sets = [(8, 9), (4, 9),... | 26 | 2016-07-07T16:57:49Z | 38,251,568 | <p>You can also do it without slicing by creating iterators:</p>
<pre><code>l = myList = [1,8,9,2,4,9,6,7,9,8]
it1, it2 = iter(l), iter(l)
# consume first element from it2 -> leaving 8,9,2,4,9,6,7,9,8
next(it2, "")
# then pair up, (1,8), (8,9) ...
print([(i, j) for i,j in zip(it1, it2) if j == 9])
</code></pre>
<... | 5 | 2016-07-07T17:18:28Z | [
"python",
"list",
"python-3.x",
"tuples",
"list-comprehension"
] |
Create a list of tuples with adjacent list elements if a condition is true | 38,251,245 | <p>I am trying to create a list of tuples where the tuple contents are the number <code>9</code> and the number before it in the list. </p>
<p><strong>Input List:</strong></p>
<pre><code>myList = [1, 8, 9, 2, 4, 9, 6, 7, 9, 8]
</code></pre>
<p><strong>Desired Output:</strong></p>
<pre><code>sets = [(8, 9), (4, 9),... | 26 | 2016-07-07T16:57:49Z | 38,253,584 | <p>It is really surprising that no one has added a functional approach. </p>
<p>Another alternative answer is using a <a href="https://docs.python.org/3/library/functions.html#filter"><code>filter</code></a>. This builtin function returns an iterator (list in Python2) consisting of all the elements present in the list... | 5 | 2016-07-07T19:14:51Z | [
"python",
"list",
"python-3.x",
"tuples",
"list-comprehension"
] |
Create a list of tuples with adjacent list elements if a condition is true | 38,251,245 | <p>I am trying to create a list of tuples where the tuple contents are the number <code>9</code> and the number before it in the list. </p>
<p><strong>Input List:</strong></p>
<pre><code>myList = [1, 8, 9, 2, 4, 9, 6, 7, 9, 8]
</code></pre>
<p><strong>Desired Output:</strong></p>
<pre><code>sets = [(8, 9), (4, 9),... | 26 | 2016-07-07T16:57:49Z | 38,258,062 | <p>My solution is similar to one of Jim's advanced with zero-index check</p>
<pre><code>myList = [9, 1, 8, 9, 2, 4, 9, 6, 7, 9, 8]
[(myList[i-1], x) for i, x in enumerate(myList) if x==9 and i!=0]
# [(8, 9), (4, 9), (7, 9)]
</code></pre>
| 1 | 2016-07-08T02:24:15Z | [
"python",
"list",
"python-3.x",
"tuples",
"list-comprehension"
] |
How can I manage the location of the "NavigationToolbar2TkAgg" toolbar? | 38,251,317 | <p>I'm learning how to use matplotlib, and now I have a problem. When I create a <code>Figure</code> in "tkinter project" and give it a subplot, I use <code>NavigationToolbar2TkAgg</code> to create a toolbar. This toolbar appears at the top of the graph. How can I set it to other locations, like the bottom or the left?... | 0 | 2016-07-07T17:01:42Z | 38,260,910 | <p>When a <code>NavigationToolbar2TkAgg</code> is instantiated by</p>
<pre><code>toolbar = NavigationToolbar2TkAgg(canvas, window)
</code></pre>
<p>method <code>NavigationToolbar2TkAgg._init_toolbar</code> is called. It sets <code>window</code> as the parent widget and at the end of the method calls <code>self.pack(s... | 0 | 2016-07-08T07:15:20Z | [
"python",
"matplotlib",
"tkinter",
"toolbar"
] |
I don't understand why my function doesn't happen | 38,251,336 | <p>I am trying to write a typing challenge game where the player has to type a word as fast as possible within the time limit. At the end of the <code>game()</code> function it is supposed to execute the <code>round1()</code> function when the timer gets to <code>0</code>. However, nothing happens and it just stays on ... | -2 | 2016-07-07T17:02:34Z | 38,251,623 | <p>You are getting into the function <code>round1</code>, but once you are there, you are caught in an infinite loop because the variable <code>useless</code> will never change.</p>
<p>Even if you take out the <code>while</code> loop, you will never be able to win because you do not take input in until after the timer... | 1 | 2016-07-07T17:21:57Z | [
"python",
"function",
"python-3.x"
] |
I don't understand why my function doesn't happen | 38,251,336 | <p>I am trying to write a typing challenge game where the player has to type a word as fast as possible within the time limit. At the end of the <code>game()</code> function it is supposed to execute the <code>round1()</code> function when the timer gets to <code>0</code>. However, nothing happens and it just stays on ... | -2 | 2016-07-07T17:02:34Z | 38,251,662 | <p>Try this code from round 1 on:</p>
<pre><code>def round1():
import sys, select
global rounds
global word
global timer
print ("Type", word)
input, out, error = select.select( [sys.stdin], [], [], timer)
if (input):
attempt = sys.stdin.readline().strip()
if attempt == word:... | 0 | 2016-07-07T17:23:56Z | [
"python",
"function",
"python-3.x"
] |
I don't understand why my function doesn't happen | 38,251,336 | <p>I am trying to write a typing challenge game where the player has to type a word as fast as possible within the time limit. At the end of the <code>game()</code> function it is supposed to execute the <code>round1()</code> function when the timer gets to <code>0</code>. However, nothing happens and it just stays on ... | -2 | 2016-07-07T17:02:34Z | 38,251,901 | <p>I was playing a bit with your game you're doing too many overhead and mistakes
there so I just changed it's structure to simplify:</p>
<pre><code>import random
import time
current_milli_time = lambda:int(time.time() * 1000)
timer = 20 #suppose user has 20 secs to enter a word
counting = 10
requested_word = ""
choi... | 0 | 2016-07-07T17:38:51Z | [
"python",
"function",
"python-3.x"
] |
Spotipy -- accessing tracks from a public playlist without authentication | 38,251,356 | <p>I want to search through public playlists and get the tracks. So far I have code which can get the names of the playlists but not the tracks:</p>
<pre><code>import spotipy
import sys
sp = spotipy.Spotify()
if len(sys.argv) > 1:
artist_name = ' '.join(sys.argv[1:])
results = sp.search(q=artist_name, limi... | 1 | 2016-07-07T17:03:52Z | 38,329,729 | <p>This is a typical OAuth confusion. There are potentially three parties involved here.</p>
<ul>
<li>Your application (that tiny little python snippet above)</li>
<li>Spotify Web API</li>
<li>A Spotify user</li>
</ul>
<p>If your app wanted to find and delete a Spotify user's playlists that begin with X, the Spotify ... | 0 | 2016-07-12T13:03:38Z | [
"python",
"spotify",
"spotipy"
] |
How to find location of Pandas installed on Windows | 38,251,498 | <p>I am looking to review the source code for Pandas and cannot seem to find it on my computer using a simple system search. I installed the package through Anaconda. Is there a common place that libraries installed through Anaconda are located, or is there a script I can run in Terminal to provide the location of wh... | 0 | 2016-07-07T17:13:06Z | 38,253,345 | <p>You can find the location by looking at </p>
<pre><code>import pandas
pandas.__path__
</code></pre>
| 1 | 2016-07-07T18:59:38Z | [
"python",
"pandas",
"anaconda"
] |
Inadequate indexing of pandas array | 38,251,519 | <p>I've got a pandas <code>DataFrame</code> in the <code>result</code> variable and want to extract some rows from it, specifically, group them by pairs of <code>id</code>s and select rows, corresponding to minimum <code>score</code>s.</p>
<p>Here is the code:</p>
<pre><code>gb = result.groupby(['id1', 'id2'], sort=F... | 1 | 2016-07-07T17:15:01Z | 38,251,594 | <p><code>result</code> must have duplicate labels in its index. For example,</p>
<pre><code>import numpy as np
import pandas as pd
result = pd.DataFrame({'X':np.arange(6)}, index=list('ABAAEF'))
print(result)
# X
# A 0
# B 1
# A 2
# A 3
# E 4
# F 5
</code></pre>
<p>One index label, <code>'A'</code>, corresp... | 3 | 2016-07-07T17:20:42Z | [
"python",
"pandas",
"dataframe",
"anaconda"
] |
django regular expression only to match alphanumeric not underscore | 38,251,597 | <p>I have a model field where I want user only to enter alphanumeric character.
I have set regex like:</p>
<pre><code>validators.RegexValidator(r'^[\w]+$'
</code></pre>
<p>It also takes <code>_</code> but I only want to take <code>aplha numeric characters</code> not <code>_</code>.
What might be the regex for it ?</p... | 0 | 2016-07-07T17:20:47Z | 38,251,625 | <p>We usually use a simple <code>[A-Za-z0-9]</code> regex which is essentially <code>\w</code> but without the underscore (assuming you are not setting any specific locales or a unicode flag):</p>
<blockquote>
<p><code>\w</code></p>
<p>When the <code>LOCALE</code> and <code>UNICODE</code> flags are not specifie... | 1 | 2016-07-07T17:22:03Z | [
"python",
"regex",
"django"
] |
django regular expression only to match alphanumeric not underscore | 38,251,597 | <p>I have a model field where I want user only to enter alphanumeric character.
I have set regex like:</p>
<pre><code>validators.RegexValidator(r'^[\w]+$'
</code></pre>
<p>It also takes <code>_</code> but I only want to take <code>aplha numeric characters</code> not <code>_</code>.
What might be the regex for it ?</p... | 0 | 2016-07-07T17:20:47Z | 38,251,631 | <p>You could use this regex:</p>
<pre><code>[A-Za-z0-9]+
</code></pre>
<p>If you don't want uppercase avoid A-Z</p>
| 0 | 2016-07-07T17:22:18Z | [
"python",
"regex",
"django"
] |
django regular expression only to match alphanumeric not underscore | 38,251,597 | <p>I have a model field where I want user only to enter alphanumeric character.
I have set regex like:</p>
<pre><code>validators.RegexValidator(r'^[\w]+$'
</code></pre>
<p>It also takes <code>_</code> but I only want to take <code>aplha numeric characters</code> not <code>_</code>.
What might be the regex for it ?</p... | 0 | 2016-07-07T17:20:47Z | 38,251,696 | <p>To disallow <code>_</code> with <code>\w</code>, you may use the opposite class <code>\W</code> (<strong>non-word shorthand character class</strong>) in a <a href="http://www.regular-expressions.info/charclass.html#negated" rel="nofollow"><strong>negated character class</strong></a> and exclude a <code>_</code> by a... | 1 | 2016-07-07T17:25:53Z | [
"python",
"regex",
"django"
] |
python websocket-client, only receive most recent message in queue | 38,251,600 | <p>I'm running websocket-client on a raspberry pi to control a servo using data sent by a leap motion websocket server. The volume of data sent over the websocket connection by the leap motion is so high that there is a long delay with the pi catching up to the most recent message which only gets worse the longer it ru... | 0 | 2016-07-07T17:20:54Z | 38,358,305 | <p>Since the Leap service sends data at roughly 110 frames per second, you have about 9ms to do any processing. If you exceed this, then you will get behind. The easiest solution is probably to create an artificial app frame rate. For each loop, if you haven't reached the time for the next update, then you just get the... | 1 | 2016-07-13T17:35:51Z | [
"python",
"websocket",
"raspberry-pi",
"leap-motion"
] |
Creating multiple instances of bouncing ball pygame | 38,251,714 | <p>So I am new to pygame and I made a program that will make a ball bounce according to gravity, and it works perfectly but now I want to be able to make infinite of them by creating one wherever I click. I know how to get the coordinates of the click, but I don't know how to create multiple circles. Would I somehow us... | 0 | 2016-07-07T17:26:59Z | 38,273,536 | <p>I would encourage you to experiment with classes and methods. Once you have a class Ball, you can make a list of the Ball objects and process them all at once. You could then use the <code>.append()</code> list method to add a new Ball on mouse click.</p>
<p>I would suggest you use variables such as:
pos_x,
pos_y,
... | 1 | 2016-07-08T18:50:56Z | [
"python",
"variables",
"pygame"
] |
Jupyter Notebook - Cannot read property of undefined | 38,251,723 | <p>I have cloned Jupyter notebook from Git repository and installed it in new separate conda environment for development purposes. I have installed correctly as given in <a href="https://github.com/jupyter/notebook/blob/master/CONTRIBUTING.rst" rel="nofollow">https://github.com/jupyter/notebook/blob/master/CONTRIBUTING... | 0 | 2016-07-07T17:27:18Z | 38,712,585 | <p>This error is platform specific. There might be some problem on my dev-master. For windows, try following commands:</p>
<pre><code>git log
git checkout 4.2.0
</code></pre>
<p>With these commands, you will have fresh checkout and also for webpack build. After that, try following commands:</p>
<pre><code>python set... | 0 | 2016-08-02T05:46:21Z | [
"javascript",
"python",
"jupyter-notebook"
] |
How to use regular expressions over multiple lines with Python 3.5? | 38,251,735 | <p>If i have the following</p>
<pre><code>string = '''This is a
multiline string
for example purposes
more stuff'''
</code></pre>
<p>I want to use regex to find just the two middle lines, how would I do that?</p>
| -1 | 2016-07-07T17:10:26Z | 38,251,908 | <p>You can use <code>.*</code> to capture a whole line minus the newline character and <code>\n</code> to capture the newline character. For example:</p>
<pre><code>import re
string = '''This is a
multiline string
for example purposes
more stuff'''
r = re.search('^.*\n(.*)\n(.*)\n.*$', string)
print r.gr... | 0 | 2016-07-07T17:39:04Z | [
"python",
"regex"
] |
How to use regular expressions over multiple lines with Python 3.5? | 38,251,735 | <p>If i have the following</p>
<pre><code>string = '''This is a
multiline string
for example purposes
more stuff'''
</code></pre>
<p>I want to use regex to find just the two middle lines, how would I do that?</p>
| -1 | 2016-07-07T17:10:26Z | 38,251,968 | <p>Generally if you want to search for matches of a <code>regex</code> over a string that has multiple lines, meaning it includes <code>\n</code>, you use the multiline modifier.</p>
<p><code>re.compile(r'<YOUR REGEX>', re.MULTILINE)</code></p>
<p><a href="https://regex101.com/r/pK4aR8/1" rel="nofollow">https:/... | 0 | 2016-07-07T17:42:17Z | [
"python",
"regex"
] |
Dijkstra algorithm: how are set and sum used? | 38,251,755 | <p>I don't understand this line of code</p>
<pre><code>self.vertices = set(sum(([e.start, e.end] for e in edges2), []))
</code></pre>
<p>from <a href="http://rosettacode.org/wiki/Dijkstra%27s_algorithm#Python" rel="nofollow">rosettacode.org</a></p>
<p><code>print(edges2)</code> shows:</p>
<pre><code>[Edge(start='a'... | 0 | 2016-07-07T17:29:07Z | 38,252,383 | <p>It looks as though this code examines all the edges in <code>edges2</code> and makes a list (really a set) of each vertex that is touched by one of those edges.</p>
<pre><code>for e in edges2
</code></pre>
<p>is going to iterate through each element of edges2</p>
<pre><code>([e.start, e.end] for e in edges2)
</c... | 2 | 2016-07-07T18:05:35Z | [
"python"
] |
perl snmpwalk to string | 38,251,759 | <p>Normally I work with Python but I have a project in Perl. So: What is the process for directing the results of an snmpwalk to a string? I would like to search the string to see if it contains a smaller string.</p>
<p>Here is what I have so far:</p>
<pre><code>foreach (@list){
chomp($_);
system("s... | 0 | 2016-07-07T17:29:31Z | 38,251,849 | <p><code>system</code> function doesn't return the function output, use <code>qx//</code> or backticks, so your snmpwalk call line will look like this:</p>
<p><code>my $output = qx/snmpwalk -v 2c -c community-string $_ oid-hidden/;</code></p>
<p>And then you do with the output variable what you need, for more info ... | 2 | 2016-07-07T17:35:31Z | [
"python",
"perl"
] |
How to display out of range values on image histogram? | 38,251,786 | <p>I want to plot the RGB histograms of an image using <code>numpy.histogram</code>.</p>
<p>(See my function <code>draw_histogram</code> below)</p>
<p>It works well for a regular range of [0, 255] :</p>
<pre><code>import numpy as np
import matplotlib.pyplot as plt
im = plt.imread('Bulbasaur.jpeg')
draw_histogram(im... | 2 | 2016-07-07T17:31:22Z | 38,252,776 | <p>You should pass x values to 'plt.plot'</p>
<p>I changed:</p>
<pre><code>plt.plot(hist, color=col)
</code></pre>
<p>to this:</p>
<pre><code>plt.plot(np.arange(minimum,maximum),hist, color=col)
</code></pre>
<p>With this change, the graph began to appear normally. Essentially, plt.plot was trying to start plottin... | 1 | 2016-07-07T18:26:05Z | [
"python",
"numpy",
"image-processing",
"histogram",
"rgb"
] |
Counting files Mac vs Windows Python | 38,251,811 | <p>I have a code that is intended to count files from a directory and read lines from a .txt file. </p>
<p>The code works fine on my Mac but will not work on Windows (even when I change the path). This is the code on Windows:</p>
<pre><code>import glob
path = 'E:\calpy_em27_neu\spectra_out_demo\140803\*'
files = glob... | 0 | 2016-07-07T17:32:56Z | 38,251,885 | <p>Perhaps you need to escape the backslash character. Try one of these:</p>
<pre><code>path = r'E:\calpy_em27_neu\spectra_out_demo\140803\*'
path = 'E:\\calpy_em27_neu\\spectra_out_demo\\140803\\*'
path = 'E:/calpy_em27_neu/spectra_out_demo/140803/*'
</code></pre>
| 2 | 2016-07-07T17:37:55Z | [
"python",
"windows",
"osx",
"glob"
] |
Round to two decimal places only if repeating python | 38,251,874 | <p>I was wondering if anybody knew of a quick way in python to check and see if a fraction gives a repeating decimal.</p>
<p>I have a small function that takes in two numbers and divides them. If the quotient is a repeating decimal I would like to round to 2 decimal places and if the quotient is not repeating I would... | 2 | 2016-07-07T17:36:59Z | 38,252,446 | <blockquote>
<p>repeating decimal</p>
</blockquote>
<p>There are only 10 fractions that can be written as some repeated digit - <code>.(0)</code>, <code>.(1)</code>, ... <code>.(9)</code>. Thus, if you only care about repeating pattern starting right after decimal point, you only need to check against those cases.</... | -1 | 2016-07-07T18:08:45Z | [
"python",
"rounding",
"fractions"
] |
Round to two decimal places only if repeating python | 38,251,874 | <p>I was wondering if anybody knew of a quick way in python to check and see if a fraction gives a repeating decimal.</p>
<p>I have a small function that takes in two numbers and divides them. If the quotient is a repeating decimal I would like to round to 2 decimal places and if the quotient is not repeating I would... | 2 | 2016-07-07T17:36:59Z | 38,252,612 | <p>Use the <a href="https://docs.python.org/2/library/fractions.html" rel="nofollow"><code>fractions</code></a> module, which implements exact rational arithmetic:</p>
<pre><code>import fractions
# fractions.Fraction instances are automatically put in lowest terms.
ratio = fractions.Fraction(numerator, denominator)
<... | 1 | 2016-07-07T18:16:56Z | [
"python",
"rounding",
"fractions"
] |
Round to two decimal places only if repeating python | 38,251,874 | <p>I was wondering if anybody knew of a quick way in python to check and see if a fraction gives a repeating decimal.</p>
<p>I have a small function that takes in two numbers and divides them. If the quotient is a repeating decimal I would like to round to 2 decimal places and if the quotient is not repeating I would... | 2 | 2016-07-07T17:36:59Z | 38,252,697 | <p>Try this: Just use brute force. Since you want only 2 decimal places. Just divide and then test it when it is rounded to 0 and 1 decimal place and see where it stops being unique. If it is not unique at this point, then round to 2 decimal places.</p>
<pre><code>def f(x):
if x == round(x,0):
return '{:.0... | 0 | 2016-07-07T18:21:23Z | [
"python",
"rounding",
"fractions"
] |
Round to two decimal places only if repeating python | 38,251,874 | <p>I was wondering if anybody knew of a quick way in python to check and see if a fraction gives a repeating decimal.</p>
<p>I have a small function that takes in two numbers and divides them. If the quotient is a repeating decimal I would like to round to 2 decimal places and if the quotient is not repeating I would... | 2 | 2016-07-07T17:36:59Z | 38,252,718 | <p>Just a workaround using regex :)</p>
<pre><code>import re
result = str(800/600)
# result = str(900/600)
repeating_pair = re.escape(result.split('.')[1][:2])
check_within = result.split('.')[1][2:]
if re.match(repeating_pair, check_within):
print("{:.2f}".format(float(result)))
else:
print("{:.1f}".format... | 0 | 2016-07-07T18:22:33Z | [
"python",
"rounding",
"fractions"
] |
Pandas timestamp conversion | 38,251,906 | <p>I work with pandas. I have the following data:</p>
<pre><code>useradClick.head(n=5)
Out[291]:
timestamp userId adCategory adCount
0 2016-05-26 15:13:22 611 electronics 1
1 2016-05-26 15:17:24 1874 movies 1
2 2016-05-26 15:22:52 2139 computers 1
3 2016-0... | 0 | 2016-07-07T17:39:03Z | 38,252,040 | <p>Pandas expects the format to be in '%d%m%Y' (daymonthyear) without spaces.
Your format is 2016-05-26 00:00:00 '%y-%m-%d %h:%m:%s'. Try</p>
<pre><code>useradClickv1 = useradClick.select(pd.to_datetime('timestamp',format='%y-%m-%d %h:%m:%s'))
</code></pre>
| 0 | 2016-07-07T17:46:31Z | [
"python",
"pandas",
"timestamp",
"data-conversion"
] |
Pandas timestamp conversion | 38,251,906 | <p>I work with pandas. I have the following data:</p>
<pre><code>useradClick.head(n=5)
Out[291]:
timestamp userId adCategory adCount
0 2016-05-26 15:13:22 611 electronics 1
1 2016-05-26 15:17:24 1874 movies 1
2 2016-05-26 15:22:52 2139 computers 1
3 2016-0... | 0 | 2016-07-07T17:39:03Z | 38,252,455 | <p><strong>UPDATE:</strong></p>
<pre><code>cols = ['timestamp','userId','adCategory']
adclicksDF = pd.read_csv('/home/cloudera/Eglence/ad-clicks.csv',
uscols=cols,
parse_dates=['timestamp'],
skipinitialspace=True).assign(adCount=1)
#adclicksDF[... | 1 | 2016-07-07T18:09:15Z | [
"python",
"pandas",
"timestamp",
"data-conversion"
] |
Logic behind Form(request.POST or None) | 38,251,922 | <p>What's the logic behind <code>request.POST or None</code>? I haven't seen such thing in Python projects except Django. </p>
<p>Since <code>or</code> operator returns <strong>True</strong> or <strong>False</strong> values, how is it possible that if <code>request.POST</code> isn't <code>None</code>, the <code>Form</... | 0 | 2016-07-07T17:39:44Z | 38,251,971 | <p>The use of <code>or</code> in this case does not evaluate to <code>True</code> or <code>False</code>, but returns one of the objects.</p>
<p>Keep in mind that <code>or</code> is evaluated from left to right.</p>
<p>When the QueryDict <code>request.POST</code> is empty, it takes a Falsy value, so the item on <em>RH... | 2 | 2016-07-07T17:42:31Z | [
"python",
"django"
] |
How to pd.concat dataframes with respect to column-values instead of an index? | 38,251,974 | <p>I have a dataframe of metadata represented as <code>DF_0</code> and then a dataframe of actual data (<code>DF_1</code>). I want to use <code>pd.concat</code> on my dataframes but not with respect to indices. The indices of <code>DF_0</code> are arbitrary and the indices of <code>DF_1</code> correspond to the values... | 0 | 2016-07-07T17:42:40Z | 38,252,155 | <p>you are looking for <code>axis=1</code> parameter of the <a href="http://pandas.pydata.org/pandas-docs/stable/generated/pandas.concat.html" rel="nofollow">concat()</a> method.</p>
<p><a href="http://pandas.pydata.org/pandas-docs/stable/merging.html" rel="nofollow">Here</a> is a good explanation with examples of dif... | 1 | 2016-07-07T17:53:20Z | [
"python",
"pandas",
"dataframe",
"concatenation"
] |
How to pd.concat dataframes with respect to column-values instead of an index? | 38,251,974 | <p>I have a dataframe of metadata represented as <code>DF_0</code> and then a dataframe of actual data (<code>DF_1</code>). I want to use <code>pd.concat</code> on my dataframes but not with respect to indices. The indices of <code>DF_0</code> are arbitrary and the indices of <code>DF_1</code> correspond to the values... | 0 | 2016-07-07T17:42:40Z | 38,252,277 | <p>You want to merge along the <code>attr_1</code> column of <code>DF_0</code> and the index of <code>DF_1</code>:</p>
<pre><code>DF_X = pd.merge(DF_0, DF_1, left_on='attr_1', right_index=True)
print(DF_X)
</code></pre>
<p>Output:</p>
<pre><code> attr_0 attr_1 attr_2 other_0 other_1 other_2
0 0 1 ... | 2 | 2016-07-07T17:59:28Z | [
"python",
"pandas",
"dataframe",
"concatenation"
] |
How to pd.concat dataframes with respect to column-values instead of an index? | 38,251,974 | <p>I have a dataframe of metadata represented as <code>DF_0</code> and then a dataframe of actual data (<code>DF_1</code>). I want to use <code>pd.concat</code> on my dataframes but not with respect to indices. The indices of <code>DF_0</code> are arbitrary and the indices of <code>DF_1</code> correspond to the values... | 0 | 2016-07-07T17:42:40Z | 38,252,391 | <p>Your problem isn't with <code>pd.concat</code> its with understanding what you want. You can clear this up by thinking through what the final result should look like given the samples you've shown <code>DF_0</code> and <code>DF_1</code>.</p>
<p>If <code>attr_1</code> is the same as <code>DF_1</code>s index then:</p... | 1 | 2016-07-07T18:06:06Z | [
"python",
"pandas",
"dataframe",
"concatenation"
] |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.