QuestionId int64 74.8M 79.8M | UserId int64 56 29.4M | QuestionTitle stringlengths 15 150 | QuestionBody stringlengths 40 40.3k | Tags stringlengths 8 101 | CreationDate stringdate 2022-12-10 09:42:47 2025-11-01 19:08:18 | AnswerCount int64 0 44 | UserExpertiseLevel int64 301 888k | UserDisplayName stringlengths 3 30 ⌀ |
|---|---|---|---|---|---|---|---|---|
75,192,381 | 547,231 | Change x- and y-numbering in imshow | <p>I would like to plot a function of two variables in python. Similar to <a href="https://glowingpython.blogspot.com/2012/01/how-to-plot-two-variable-functions-with.html" rel="nofollow noreferrer">this article</a>, we can obtain an output like</p>
<p><a href="https://i.sstatic.net/tLJNd.png" rel="nofollow noreferrer">... | <python><plot><imshow> | 2023-01-21 09:37:57 | 1 | 18,343 | 0xbadf00d |
75,192,220 | 10,380,766 | NumPy convolve method has slight variance between equivalent for loop method for Volume Weighted Average Price | <p>I have a method for calculating the volume weighted average price given a stock. On the one hand, I have a readable, traditional for loop. However, it is very very slow.</p>
<p>I have tried to implement a version using numpy array method <code>convolve</code>. It performs SIGNIFICANTLY better (see RESULTS below), bu... | <python><numpy> | 2023-01-21 09:07:50 | 2 | 1,020 | Hofbr |
75,192,169 | 2,398,574 | How to intercept the instantiated class name from the function? | <p>I encountered an issue in one of my projects, I managed to reduce it to a simplest example possible. Consider the following</p>
<pre class="lang-py prettyprint-override"><code>class A:
def f(self):
return 'I am f()'
class B(A):
def g(self):
return 'I am g()'
a = A()
b = B()
print(a.f.__qua... | <python><oop><inheritance><instance> | 2023-01-21 08:58:30 | 2 | 1,563 | Marek |
75,192,128 | 470,081 | Django deployment and virtual environment | <p>I am aware that there are many questions regarding Django and virtual environments, but I cannot wrap my head around the use of virtual environments with respect to deploying my Django app (locally) via uwsgi/nginx.</p>
<p>My setup includes a virtual environment (with Django and uwsgi), my Django app, nginx and Post... | <python><django><virtualenv> | 2023-01-21 08:51:50 | 1 | 461 | janeden |
75,192,055 | 3,876,796 | Incompatible shape error when using tf.map_fn to apply a python function on tensors | <p>While building some code to train a tensorflow deep model, I am using tensorflow tf.map_fn and tf.py_function as a wrapper to apply a scipy python function as a loss function mapping each 2 rows of a batch of 2 probability vectors p and q of shape [batch_size,num_classes]. When using KL_divergence over this batch of... | <python><arrays><tensorflow><machine-learning><scipy.stats> | 2023-01-21 08:36:54 | 1 | 1,124 | Othmane |
75,191,942 | 8,207,701 | 'float' object has no attribute 'rolling' when using lambda function | <p>So I'm trying to calculate the z score using the lambda function.</p>
<p>Here's the code,</p>
<pre><code>zscore_fun_improved = lambda x: ((x - x.rolling(window=200, min_periods=20).mean()) / x.rolling(window=200, min_periods=20).std())
df.Close.apply(zscore_fun_improved)
</code></pre>
<p>But it gives me the followin... | <python><pandas><dataframe><numpy> | 2023-01-21 08:10:38 | 1 | 1,216 | Bucky |
75,191,903 | 14,256,643 | python how to combine two list by matching parent_id | <p>variation_product have attribute parent_product_id and I want to combine parent_product and variation_product into a single list by matching parent_product_id attribute. how to do that?</p>
<p>here my data look like:</p>
<pre><code> {
"parent_product": [
{
"parent_product_id... | <python><python-3.x><dictionary> | 2023-01-21 08:01:36 | 2 | 1,647 | boyenec |
75,191,564 | 5,053,475 | - This pattern is interpreted as a regular expression, and has match groups - but with no capturing group | <p>I'm migrating a script to a new python env,
I don't like the regex I'd use \b instead, anyway I want to change as little as possible the existing code.</p>
<p>I get this error executing the script:</p>
<pre><code>UserWarning: This pattern is interpreted as a regular expression, and has match groups. To actually get ... | <python><pandas><regex> | 2023-01-21 06:37:41 | 1 | 734 | Daniele Rugginenti |
75,191,442 | 10,035,190 | How to run route from other route function flask? | <p>are routes run only after clicking submit button? I want to run routes from other route function not by clicking submit button. I am doing like this because ajaxCall route only running function not rendering template</p>
<pre><code>from flask import Flask,render_template,send_file
app = Flask(__name__)
@app.route(... | <python><python-3.x><flask><flask-wtforms> | 2023-01-21 06:01:37 | 1 | 930 | zircon |
75,191,438 | 6,758,739 | Identifying the calling python script in the called python script and print | <p>How can I print the name of the script that called the current script in python? Are there any built-in functions to identify the source script?</p>
<p>Example: if <code>x.py</code> calls <code>y.py</code> and <code>y.py</code> calls <code>z.py</code>, I want to print <code>x.py</code> in <code>z.py</code> as <code>... | <python> | 2023-01-21 05:59:07 | 0 | 992 | LearningCpp |
75,191,375 | 2,676,598 | Changing FPS in OpenCV | <p>I have an application that needs to capture only a few frames per second from a webcam. Setting videowriter in the below code to 3 frames per second results in the webcam's normal framerate of approximately 30 fps being saved.
What are the options to save only the recorded 3 frames per second, and let the other 27 o... | <python><opencv><video-processing><mjpeg> | 2023-01-21 05:43:59 | 2 | 2,174 | portsample |
75,191,261 | 17,347,824 | Multiple sets of criteria to subset python dataframe with Pandas | <p>I have a small data set that I am trying to filter out to create an even smaller dataframe. The issue I'm having is I don't know how to get the sets of criteria nested inside one another to work correctly.</p>
<p>The code below is the closest I have been able to get. It should be looking in the larger data frame wit... | <python><pandas> | 2023-01-21 05:11:15 | 1 | 409 | data_life |
75,191,187 | 1,389,057 | TypeError: unhashable type: 'Path' (Importing any package) | <p><strong>EDIT</strong>: I've narrowed this down to django rest framework, but not exactly why. About to start deep package debugging :/</p>
<p>I've got a weird one here. I've setup a mini Django project, and in the urls.py file, if I try any "from package import X", it results in an exception: TypeError: un... | <python><django> | 2023-01-21 04:46:28 | 0 | 3,133 | Trent |
75,191,021 | 13,700,055 | Overlay plot on an image inside a for loop Python | <p>I am trying to overlay a matplotlib plot on an image using the following code snippet.</p>
<pre><code>plt.imshow(image, zorder=0)
plt.plot(some_array, zorder=1)
plt.savefig('image_array.png')
</code></pre>
<p>If I now include this code inside a <code>for</code> loop to overlay a plot on a different image in each loo... | <python><matplotlib><overlay> | 2023-01-21 03:44:28 | 3 | 403 | Nanda |
75,190,914 | 11,281,877 | How to put values on a single raw from multiple columns in Pandas | <p>I have been scratching my head for days about this problem. Please, find below the structure of my input data and the output that I want.
I color-coded per ID, Plot, Survey, Trial and the 3 estimation methods.
In the output, I want to get all the scorings for each group, which are represented by color, on the same r... | <python><pandas><join><merge><functools> | 2023-01-21 03:08:02 | 1 | 519 | Amilovsky |
75,190,911 | 7,021,137 | Angle at Intersection of Two Lines | <p>This is a rather simple question, but I'm trying to track down a bug and could use a confirmation of my methods.</p>
<p>Given this example code, how would you calculate the angle at the intersection of the two lines <code>a</code> and <code>b</code>? i.e., at θ? Please only use <code>numpy</code>.</p>
<pre><code>imp... | <python><numpy><angle> | 2023-01-21 03:07:35 | 1 | 377 | NoVa |
75,190,835 | 15,843,133 | How to write a function that that generates the login for a mailbox with imap_tools? | <p>I created a helper function that logs into a mailbox.</p>
<pre><code>import imap_tools
def mailbox_login():
try:
with imap_tools.MailBoxUnencrypted(ENV["IMAP4_FQDN"]).login(
ENV["RECEIVING_EMAIL_USER"], ENV["RECEIVING_EMAIL_PASSWORD"]
) as mailbox:
... | <python><imap-tools> | 2023-01-21 02:42:56 | 2 | 353 | Trouble Bucket |
75,190,832 | 6,814,713 | How to coalesce multiple pyspark arrays? | <p>I have an arbitrary number of arrays of equal length in a PySpark DataFrame. I need to coalesce these, element by element, into a single list. The problem with coalesce is that it doesn't work by element, but rather selects the entire first non-null array. Any suggestions for how to accomplish this would be apprecia... | <python><apache-spark><pyspark><coalesce> | 2023-01-21 02:41:47 | 3 | 2,124 | Brendan |
75,190,755 | 11,478,305 | TypeError: plot() missing 1 required positional argument: 'ys' (Python) | <p>I'm doing some basic plotting with matplotlib 3.6.2 of an Artificial Neural Network for an online class for Tensorflow 2.0 that uses Colab and I'm doing it in VS Code with Tensorflow 2.3.0, it works in Jupyter Notebooks, but I'm getting this error running it in the console:</p>
<pre><code>Traceback (most recent call... | <python><artificial-intelligence> | 2023-01-21 02:10:47 | 2 | 359 | Cale McCollough |
75,190,696 | 1,019,129 | Shorten the number of logical checks | <p>Is there a way to shorten the number of checks</p>
<pre><code> def is_render(self):
if not hasattr(self, 'p') : return True
if hasattr(self, 'p') and 'render' not in self.p : return True
if hasattr(self, 'p') and 'render' in self.p and self.p['render'] != 0 : return True
return Fal... | <python><logic> | 2023-01-21 01:41:03 | 2 | 7,536 | sten |
75,190,663 | 1,204,143 | ThreadingHTTPServer eventually stops accepting sockets on macOS | <p>I'm running into a weird issue on macOS + Python (macOS 12.6.2, Python 3.10.7 from python.org) when using a ThreadingHTTPServer to serve requests, although I suspect the issue might not be limited to ThreadingHTTPServer. After around an hour or two of serving requests, the server eventually stops accepting new conne... | <python><macos><sockets> | 2023-01-21 01:27:29 | 0 | 180,592 | nneonneo |
75,190,654 | 9,934,348 | pip doesn't install the lastest vertion of a package | <p>I'm trying to install the latest version (<code>0.0.7</code>) of the package <a href="https://pypi.org/project/revolutionhtl/" rel="nofollow noreferrer">https://pypi.org/project/revolutionhtl/</a> using the command</p>
<p><code>pip install revolutionhtl</code></p>
<p>After running this command, the installed version... | <python><pip><version><pypi> | 2023-01-21 01:25:43 | 2 | 304 | Antonio Ramírez |
75,190,628 | 9,090,340 | write data using pyodbc iterate over a dictionary | <p>I have the below python snippet where I am parsing data from a dictionary, to produce into a table using pyodbc library.</p>
<pre><code>import pyodbc
data = {
"demographic": [
{
"id": 1,
"country": {
"code": "AU",
"name":... | <python> | 2023-01-21 01:18:36 | 1 | 937 | paone |
75,190,363 | 4,531,757 | Pandas - Build sequnce in the group while resetting and create new dataframe with summary | <p>I got some help in the past and was able to advance well. Now I have an additional need to create a summary dataset for the study. Please help me if you can.</p>
<p>This is my current Dataset:
import pandas as pd</p>
<pre><code>df2 = pd.DataFrame({'patient': ['one', 'one', 'one', 'three','three', 'two','two','two','... | <python><pandas><numpy> | 2023-01-21 00:04:45 | 2 | 601 | Murali |
75,190,328 | 8,816,642 | Calculate AUC by different segments in python | <p>I have a dataset which contains <strong>id, datetime, model features, ground truth labels</strong> and the <strong>predicted probability</strong>.</p>
<pre><code>id datetime feature1 feature2 feature3 ... label probability
001 2023-01-01 a1 b3 c1 ... Rejected ... | <python><pandas><machine-learning><scikit-learn><auc> | 2023-01-20 23:55:13 | 2 | 719 | Jiayu Zhang |
75,190,310 | 5,601,193 | Need help implementing this state-variable filter | <p>Pursuant to <a href="https://dsp.stackexchange.com/questions/86305/how-do-i-use-the-lazzarini-timoney-dsvf-as-a-sine-generator">this question</a>, I rewrote some simple generator code into a Python filter class and tried to get the same result out of the filter itself. It didn't work. There is a bunch of code here... | <python><signal-processing> | 2023-01-20 23:51:43 | 1 | 483 | John Moser |
75,190,302 | 807,797 | py command breaks in ps1 but not in PowerShell terminal | <p>The <code>py -3 -m venv venv</code> command works when typed manually into a Powershell terminal, but breaks when called from a ps1 script.</p>
<p>What specifically must be changed in the code below in order for the <code>setup.ps1</code> script to successfully run the <code>py -3 -m venv venv</code> command when th... | <python><powershell><python-venv><invoke-command> | 2023-01-20 23:50:06 | 0 | 9,239 | CodeMed |
75,190,290 | 7,217,960 | Is it possible to have two distinct installs of Python 3 of the same revision on a Windows system? | <p>I know it possible to have two installs of Python of different versions on a Windows system. But I cannot manage to have two installs of the same revision (in my case 3.8.10) to coexist.</p>
<p>I'm designing an application that creates a Python process. That process needs to run from a specific version of Python wit... | <python><windows> | 2023-01-20 23:48:06 | 1 | 412 | Guett31 |
75,190,227 | 2,403,819 | Why do the Pyproj and Haversine methods to calculate heading from two lat/lon points differ from what Google Earth displays? | <p>I am trying to implement a short python function to calculate the heading between two points. In other words if I am at point one, what heading relative to true north would I need to take to get to point two. I have used the following Python implementation which gives me essentially the same results.</p>
<pre><cod... | <python><geopy><pyproj> | 2023-01-20 23:29:20 | 1 | 1,829 | Jon |
75,190,098 | 19,628,700 | How to calculate mulitple rolling windows on one column in pandas quickly | <p>I am currently trying to calculate the rolling average of one column in my pandas dataframe over many rolling periods. My dataframe has one column of interest where I wish to calculate a rolling average from 2-40 periods and have the same dataframe and indexes know these values. This has proven a bit to slow as my... | <python><pandas><performance><rolling-computation> | 2023-01-20 23:05:18 | 1 | 311 | finman69 |
75,190,046 | 4,547,759 | Duplicate rows when merging dataframes with repetitions | <p>Say I have the following dataframes:</p>
<pre><code>>>> df1 = pd.DataFrame({'fruit':['apple','orange','orange'],'taste':['sweet','sweet','sour']})
>>> df1
fruit taste
0 apple sweet
1 orange sweet
2 orange sour
>>> df2 = pd.DataFrame({'fruit':['apple','orange','orange'],'price'... | <python><pandas> | 2023-01-20 22:56:17 | 2 | 363 | Akahs |
75,190,020 | 14,692,430 | Python static method return subclass instead of superclass | <p>Intuitively this seems impossible, but here goes.</p>
<p>I am importing a class from a python module, where it has a static method that returns a new instance of the class and does some stuff to that instance, let's just call this method <code>make_instance</code>. I am trying to create a custom class with some over... | <python><class><inheritance><return><static-methods> | 2023-01-20 22:52:30 | 1 | 352 | DaNubCoding |
75,190,008 | 2,396,640 | Python BoundedSemaphore Acquire and then stuck | <p>While trying to investigate this issue : <a href="https://stackoverflow.com/questions/75161513/cant-pause-python-process-using-debug">Can't pause python process using debug</a> I was trying to figure out what makes the sub process stuck so I ended up logging every line to a file and I encountered a weird situati... | <python><python-3.x><multithreading><python-multithreading><semaphore> | 2023-01-20 22:49:40 | 0 | 369 | user2396640 |
75,189,975 | 10,200,497 | Replacing values with nan based on values of another column | <p>This is my dataframe:</p>
<pre><code>df = pd.DataFrame(
{
'a': [np.nan, np.nan, np.nan, 3333, np.nan, np.nan, 10, np.nan, np.nan, np.nan, np.nan, 200, 100],
'b': [np.nan, 20, np.nan, np.nan, np.nan, np.nan, np.nan, np.nan, 100, np.nan, np.nan, np.nan, np.nan]
}
)
</code></pre>
<p>And this is... | <python><pandas><dataframe> | 2023-01-20 22:45:09 | 2 | 2,679 | AmirX |
75,189,805 | 5,734,187 | How do I implement a model that finds a correlation (not similarity) between query and target sentence? | <p>When building an NLP model (I'm going to use an attention-based one), how can we implement one for finding the <em>correlation</em>, not <em>similarity</em>, between the query and target sentences?
For instance, the two sentences "I am an environmentalist." and "We should raise the gas price, ban comb... | <python><deep-learning><nlp><attention-model><sentence-similarity> | 2023-01-20 22:14:33 | 0 | 1,132 | kemakino |
75,189,803 | 2,471,211 | Inheriting from a class that has __new__ returning another class in python | <p>If have a class like this one:</p>
<pre><code>class ExA:
def __new__(cls, obj):
if type(obj) is dict:
return ExADict(obj)
if type(obj) is list
return ExAList(obj)
</code></pre>
<p>Assuming I cannot change this class.
I want to inherit from it.</p>
<pre><code>class ExB(ExA)... | <python><inheritance> | 2023-01-20 22:14:33 | 0 | 485 | Flo |
75,189,704 | 1,473,517 | How to save a large dict with tuples as keys? | <p>I have large dict which has 3-tuples of integers as keys. I would like to save it to disk so I can read it in quickly. Sadly it seems I can't save it as a JSON file (which would let me use a fast JSON module such as <a href="https://pypi.org/project/orjson/" rel="nofollow noreferrer">orjson</a>). What are my option... | <python><dictionary><tuples> | 2023-01-20 21:59:17 | 1 | 21,513 | Simd |
75,189,699 | 1,489,422 | Pytest mocking nested object | <p>I am trying to understand how to overcome an issue with mocking a python attribute coming from an imported module within a constructor.</p>
<p>I have a simplified Tableau python class which is defined like this:</p>
<pre class="lang-py prettyprint-override"><code>import tableauserverclient as TSC
import pandas as pd... | <python><mocking><pytest> | 2023-01-20 21:58:38 | 1 | 439 | Michael K |
75,189,681 | 17,945,841 | After performing t-SNE dimentionality reduction, use k-means and check what features contribute the most in each individual cluster | <p>The following plot displays the t-SNE plot. I can show it here but unfortunately, I can't show you the labels. There are 4 different labels:</p>
<p><a href="https://i.sstatic.net/ztBgI.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ztBgI.png" alt="enter image description here" /></a></p>
<p>The plot ... | <python><r><machine-learning><k-means><dimensionality-reduction> | 2023-01-20 21:56:15 | 2 | 1,352 | Programming Noob |
75,189,529 | 3,507,584 | Remove zero from ternary plot | <p>I have the following plot and I want to remove the 0 in the origins.</p>
<pre><code>import plotly.graph_objects as go
import plotly.express as px
fig = go.Figure(go.Scatterternary({
'mode': 'markers', 'a': [0.3],'b': [0.5], 'c': [0.6],
'marker': {'color': 'AliceBlue','size': 14,'line': {'width': 2} },
... | <python><plotly><axis-labels><ternary> | 2023-01-20 21:35:01 | 1 | 3,689 | User981636 |
75,189,522 | 368,367 | QtCreator's UI is not applied to the window, it's always empty (Qt for Python) | <p>I have a fresh QtCreator installation, and I set it up to run using a fresh install of Python3.8 on which I pip-installed both pyside2 and pyside6.</p>
<p>When I create a new Qt for Python - Window (UI file) application, whatever I do to the UI file the window always shows up empty and with the default size when I r... | <python><qt><pyside> | 2023-01-20 21:33:47 | 1 | 1,002 | Mister Mystère |
75,189,505 | 15,810,170 | PyMuPDF get optimal font size given a rectangle | <p>I am making an algorithm that performs certain edits to a PDF using the fitz module of PyMuPDF, more precisely inside widgets. The font size 0 has a weird behaviour, not fitting in the widget, so I thought of calculating the distance myself.
But searching how to do so only led me to innate/library functions in other... | <python><pymupdf> | 2023-01-20 21:32:20 | 1 | 742 | Clement Genninasca |
75,189,435 | 11,380,243 | Printing matrices between text in Python | <p>I have seen a few examples over here where it was explained how to print a matrix to a .txt file. However, I haven't found a simple way to perform what I would like to do, which is to print several matrices that are written in a .txt in which additional text is also being printed. Note, this text is not meant to be ... | <python><numpy><matrix> | 2023-01-20 21:22:39 | 3 | 438 | Marc Schwambach |
75,189,391 | 9,169,546 | Why is Django check_password=True but authenticate=None | <p>I'm trying to write a unit test for a login endpoint in Django using as much of the built in functionality as possible.</p>
<p>There are existing tests that confirm that the account create endpoint is functioning properly.</p>
<p>In the login view, however, the <code>check_password()</code> function will return <cod... | <python><django><authentication> | 2023-01-20 21:14:46 | 2 | 1,601 | ang |
75,189,350 | 12,386 | How do I debug through a gdb helper script written in python? | <p>there may very well be an answer to this question, but it's really hard to google for.</p>
<p>you can add commands to gdb by writing them in python. I am interested in debugging one of those python scripts that's running in gdb session.</p>
<p>my best guess is to run gdb on gdb and execute the user added command and... | <python><gdb><gdb-python> | 2023-01-20 21:07:38 | 1 | 8,875 | stu |
75,189,298 | 9,373,756 | The variables created using jupyter (.ipynb) do not work on .py files in vscode (in the same environment in WSL). Different terminals? | <p>Context: I'm using vscode with WSL and I also use conda for environment management.</p>
<p>I'm trying to create a variable in a jupyter notebook, let's say <code>x = [10, 20]</code>, and then use that same variable in a .py file (not on jupyter notebooks). I'm already using the same environment on both, but the term... | <python><visual-studio><jupyter-notebook><environment-variables><conda> | 2023-01-20 20:59:25 | 0 | 725 | Artur |
75,189,277 | 2,601,293 | upgrade python offline - ubuntu apt | <p>I have an Ubuntu VM without internet access. It currently has Python 3.10 installed but I want to update to Python 3.11 (the latest at the time of this post).</p>
<p>On a machine with internet access, I used <code>apt</code> to download Python3.11.</p>
<pre><code>mkdir python_3.11
apt-get --download-only -o Dir::Ca... | <python><ubuntu><offline><apt> | 2023-01-20 20:57:36 | 1 | 3,876 | J'e |
75,189,220 | 425,895 | How to modify the Timeseries forecasting for weather prediction example to increase the number of predictions? | <p>(And plot them all in the same figure).</p>
<p>I've been following the "Timeseries forecasting for weather prediction" code found here:<br />
<a href="https://keras.io/examples/timeseries/timeseries_weather_forecasting/" rel="nofollow noreferrer">https://keras.io/examples/timeseries/timeseries_weather_fore... | <python><tensorflow><keras> | 2023-01-20 20:50:39 | 1 | 7,790 | skan |
75,189,205 | 17,274,113 | `TypeError: missing 1 required positional argument: 'self'` Whitebox tools | <p>I am attempting to use whitebox geospatial tools to analyze .tif files. Any whitebox tool I run however, raises the error: <code>TypeError: missing 1 required positional argument: 'self'</code>. I understand that this is a well-documented error within the stack overflow community, however, the way I understand the s... | <python><typeerror><self><positional-argument> | 2023-01-20 20:48:45 | 1 | 429 | Max Duso |
75,189,181 | 1,353,951 | Obtaining values from a foreign key Python model | <p>Let's say I have these models/classes:</p>
<pre><code>class User(models.Model):
id = models.AutoField. . .
group = models.ForeignKey(
Group,
. . .
)
. . .
class Group(models.Model):
id = models.AutoField. . .
name = models.CharField. . .
. . .
</code></pre>
<p>In a custom... | <python><django><django-models> | 2023-01-20 20:45:10 | 2 | 1,501 | Ness |
75,189,130 | 1,718,174 | Python order of execution of logic check | <p>So my boss came up with this (by accident) after a quick search and replace on the code and opening a Pull Request, where tag is always a string:</p>
<pre><code>if "team_" in tag in tag:
</code></pre>
<p>To my surprise, that actually works! Not really sure why. I was expecting to parse it from left to righ... | <python><python-3.x> | 2023-01-20 20:39:38 | 2 | 11,945 | Vini.g.fer |
75,189,084 | 5,471,957 | Flask-Socketio emitting from an external process | <p>I've been working on a project using flask, flask-socketio and redis</p>
<p>I have a server, and some modules I would like to be able to emit from outside of the server file.</p>
<p>server.py</p>
<pre><code>from flask import Flask, Response, request, json
from flask_socketio import SocketIO, join_room, leave_room, e... | <python><flask><redis><flask-socketio> | 2023-01-20 20:36:00 | 1 | 1,276 | SpeedOfRound |
75,188,930 | 19,838,445 | Poetry add same library for different Python versions | <p>I know how to add python constraint for a single library</p>
<pre class="lang-ini prettyprint-override"><code>flake8 = { version = "^6.0.0", python = ">=3.8.1" }
</code></pre>
<p>But what if I want to have same library, but different version for a different Python version? In case I add it wit... | <python><python-packaging><python-poetry><pyproject.toml> | 2023-01-20 20:12:36 | 1 | 720 | GopherM |
75,188,852 | 20,102,061 | match case in micropython - SyntaxError: invalid syntax | <p>I am using python 3.10.5 on my raspberry pi pico and I am trying to use <code>match</code> & <code>case</code> instead of <code>if</code> statements When I try to run the program it returns an error:</p>
<pre><code>Traceback (most recent call last):
File "<stdin>", line 22
SyntaxError: invalid ... | <python><python-3.x><micropython><python-3.10><raspberry-pi-pico> | 2023-01-20 20:01:47 | 1 | 402 | David |
75,188,823 | 6,687,699 | Override a template of a Django package | <p>How can I override a change_list.html template of a Django package e.g <a href="https://github.com/django-import-export/django-import-export" rel="nofollow noreferrer">Django import export</a>, in an existing Django app.</p>
<p>E.g I want to override this package <a href="https://github.com/django-import-export/dja... | <python><django><django-templates> | 2023-01-20 19:57:33 | 2 | 4,030 | Lutaaya Huzaifah Idris |
75,188,812 | 3,611,472 | Evaluating algebraic expression of the keys of a dictionary on its values | <p>I have a class <code>A</code> whose objects have a dictionary as a property. This dictionary is <code>self.data</code>. The keys of the dictionary are strings, while the values are float numbers.</p>
<p>I want to define a <code>__getitem__(self,src:str)</code> method that processes a string <code>src</code> as an al... | <python><dictionary> | 2023-01-20 19:56:40 | 1 | 443 | apt45 |
75,188,789 | 7,447,976 | How to get proper feature importance information when using categorical feature in h2O | <p>When I have categorical features in my dataset, <code>h20</code> implies one-hot encoding and start the training process. When I call <code>summary</code> method to see the feature importance tho, it treats each encoded categorical feature as a feature. My question is that how can I get the feature importance inform... | <python><regression><h2o><feature-selection> | 2023-01-20 19:52:48 | 1 | 662 | sergey_208 |
75,188,722 | 2,954,547 | Wrapping a polling-based asynchronous API as an Awaitable | <p>Consider some library with an interface like this:</p>
<ul>
<li><code>RemoteTask.start()</code></li>
<li><code>RemoteTask.cancel()</code></li>
<li><code>RemoteTask.get_id()</code></li>
<li><code>RemoteTask.get_result()</code></li>
<li><code>RemoteTask.is_done()</code></li>
</ul>
<p>For example, <code>concurrent.futu... | <python><asynchronous><python-asyncio><python-trio><python-anyio> | 2023-01-20 19:44:01 | 2 | 14,083 | shadowtalker |
75,188,661 | 2,747,181 | Running a feed forward Neural Network in PyTorch Results in an error when run layer by layer vs all at once | <p>This is my neural network:</p>
<pre><code>class NeuralNetwork(nn.Module):
def __init__(self):
super(NeuralNetwork, self).__init__()
# self.flatten = nn.Flatten()
self.cnn = nn.Sequential(
nn.Conv2d(in_channels=1, out_channels=4, kernel_size=3), # 28 x 28 --> 26 x 26 x 4
... | <python><deep-learning><pytorch><neural-network><conv-neural-network> | 2023-01-20 19:36:07 | 1 | 302 | bujian |
75,188,581 | 3,156,300 | Using imagemagick to mask one image and output transparent png | <p>I've gone nuts here. I'm simply trying to do the following with imagemagick and don't understand where im going one. I'm trying blend my colored image onto a transparent background using the illuminance of another image.</p>
<p><a href="https://i.sstatic.net/WXTjh.png" rel="nofollow noreferrer"><img src="https://i.s... | <python><imagemagick> | 2023-01-20 19:26:32 | 1 | 6,178 | JokerMartini |
75,188,563 | 5,120,843 | How do I tell SpringBoot where to find Python packages? | <p>I've installed several Python libraries, like the "ML" library called "flair" into Ubuntu server 20.04.</p>
<p>Now, although I can run the flair python program, as one example, fine <strong>from the command line</strong> in Ubuntu 20.04 server (Ubuntu knows where to look), when I run this same lo... | <python><java><spring-boot><ubuntu> | 2023-01-20 19:25:00 | 1 | 627 | Morkus |
75,188,523 | 13,455,916 | Installing requirements.txt in a venv inside VSCode | <p>Apart from typing out commands - is there a good way to install <code>requirements.txt</code> inside <code>VSCode</code>.</p>
<p>I have a workspace with 2 folders containing different Python projects added - each has it's own virtual environment. I would like to run a task to execute and install the requirements to... | <python><visual-studio-code><python-venv><requirements.txt> | 2023-01-20 19:19:59 | 1 | 347 | andrewthedev |
75,188,501 | 1,323,044 | Obtaining a pandas series by constructing its name as a string | <p>I'm looking to construct a series name as a string and get its values for a given index, or set its value for a particular index. For example:</p>
<pre><code>def getEntityValue(self, testCase, ent_order):
if ent_order == 1:
return self.testInputEnt1[testCase]
elif ent_order == 2:
return self.... | <python><pandas><series> | 2023-01-20 19:17:07 | 1 | 569 | Baykal |
75,188,488 | 12,313,380 | How to render differently a django model object field on a html page? | <p>My model object have a IntegerField but I want to be able to render it differently on my html page, like lets say the object IntegerField is <code>500000</code> I want to render it as <code>500 000$</code> on my html page. So Add a space before the <code>last 3 number</code> and add a <code>$</code> at the end.</p>
... | <python><django> | 2023-01-20 19:15:46 | 1 | 576 | tiberhockey |
75,188,401 | 9,306,620 | Python: Class Serialization: Convert class object to JSON | <p>I have a complex class object that I am trying to convert to a json array. It works, but the json is double quoted. I tried to make the class serializable using json.dumps and this function is converting it to a string.</p>
<pre><code>import datetime as dt
import json
class StatusDetails:
def __init__(self, Des... | <python><json> | 2023-01-20 19:06:15 | 2 | 1,041 | SoftwareDveloper |
75,188,362 | 523,612 | How can I diagnose common errors in JSON data? | <p>I have to deal with putative JSON from a lot of different sources, and a lot of the time it seems that there is a problem with the data itself. I suspect that it sometimes isn't intended to be JSON at all; but a lot of the time it comes from a buggy tool, or it was written by hand for a quick test and has some typo ... | <python><json><debugging><syntax> | 2023-01-20 19:02:31 | 1 | 61,352 | Karl Knechtel |
75,188,254 | 11,825,717 | PyTorch — proper way to compute loss on GPU? | <p>What is the proper way to handle loss values with <code>PyTorch</code> CUDA? For example:</p>
<ol>
<li>Should I store the loss value in GPU?</li>
<li>How do I move the loss value to GPU?</li>
<li>How do I update the loss value on GPU?</li>
</ol>
<h3>Inside __init__():</h3>
<pre><code>self.device = torch.device('cuda... | <python><pytorch> | 2023-01-20 18:50:41 | 1 | 2,343 | Jeff Bezos |
75,188,016 | 4,764,604 | 'project.Account' has no ForeignKey to 'project.Object': How to link an account model to the objects of a project? | <p>I am trying to create an announcement website (<code>All</code>) that can be visible to others (the <code>Users</code>, for which I added an <code>Account</code>). For this I wanted to modify a little the user profile to add fields like telephone, email address...</p>
<p>So I modified <code>admin.py</code>:</p>
<pre... | <python><python-3.x><django><model><one-to-many> | 2023-01-20 18:24:40 | 1 | 3,396 | Revolucion for Monica |
75,187,972 | 19,776,016 | how to divide a column of a matrix to a constant number in numpy? | <p>I try this division and get these strange zeros instead of correct numbers.</p>
<pre><code>i = 0
data_x = np.array([[3104, 5, 1, 45], [1416, 3, 2, 40], [852, 2, 1, 35]])
mu_i = np.mean(data_x[:,i])
print(mu_i)
max_num = np.max(data_x[:,i])
min_num = np.min(data_x[:,i])
d = (max_num - min_num)
print(d)
data_x[:,i] = ... | <python><numpy> | 2023-01-20 18:20:12 | 0 | 339 | Gaff |
75,187,862 | 10,576,322 | Default variables with python-dotenv | <p>I want to make a package that works out of the box with reasonable default variables, like defining some servers, ports etc. so that the code works for an average user like he expects it without further configuration.
But I want this environment variables to be overriden if a .env file exists in order to allow confi... | <python><environment-variables><python-dotenv> | 2023-01-20 18:07:29 | 3 | 426 | FordPrefect |
75,187,849 | 10,328,083 | Why does import <package> not work ,but import <package.submodule> work? | <p>I am trying to use a python package called <code>nilearn</code>, but I think this issue could occur more generally, and I'm just trying to understand WHY this happens. I'd really appreciate any further references that could help me understand what's going on at a deeper level.</p>
<p>The very first instructions in t... | <python><import><module><attributes><attributeerror> | 2023-01-20 18:05:30 | 2 | 547 | seeker_after_truth |
75,187,730 | 11,002,498 | Find emojis in messages and then react using discord.py | <p>I am trying to make a discord bot that finds emojis in messages in a channel and then reacts with these messages.</p>
<p>My code is:</p>
<pre><code>if message.channel.id == 645647298423613453:
custom_emojis = re.findall(r'<:\w*:\d*>', message.content)
custom_emojis = [e.split('<')[1].replace('&g... | <python><discord><discord.py><emoji><replit> | 2023-01-20 17:55:07 | 1 | 464 | Skapis9999 |
75,187,724 | 1,443,098 | How should I change my tkinter code to rearrange the elements on my page? | <p>I'm learning tkinter and getting stumped in one area. Here's the code:</p>
<pre><code>from tkinter import *
from tkinter.messagebox import showinfo
def button_press():
showinfo('info','pressed button')
root = Tk()
root.geometry('800x500')
f = Frame(root)
f.pack()
Label(f, text="this is a line of tex... | <python><tkinter> | 2023-01-20 17:54:14 | 1 | 7,755 | user1443098 |
75,187,644 | 8,372,455 | Adding new values to pandas df and increment timestamp | <p>I have a time series dataset of a Pandas series df that I am trying to add a new value to the bottom of the df and then increment the timestamp which is the df index.</p>
<p>For example the new value I can add to the bottom of the df like this:</p>
<pre><code>testday.loc[len(testday.index)] = testday_predict[0]
pri... | <python><pandas> | 2023-01-20 17:46:56 | 1 | 3,564 | bbartling |
75,187,339 | 8,869,570 | Printing list of class object's member variable | <p>I have a list of class objects and each object has a variable <code>val</code>.</p>
<p>e.g.,</p>
<pre><code>class my_class:
a = 3
lst = [my_class(), my_class()]
</code></pre>
<p>I would like to print all the object's <code>val</code>. How can this be done without iterating through the list?</p>
<p>I tried</p>
<pre... | <python><list> | 2023-01-20 17:19:22 | 0 | 2,328 | 24n8 |
75,187,259 | 14,500,576 | Kill a Python.exe process after opening it with PowerShell and Task Scheduler | <p>I used to run Python scripts with Task Scheduler by executing a .bat file. However, since I'm running this on a Windows VM, this approach would fail after the computer received a Windows update. So I decided to open the scripts differently, I still call the .bat file from Task Scheduler but this file now opens a Pow... | <python><powershell><windows-task-scheduler> | 2023-01-20 17:11:33 | 0 | 355 | ortunoa |
75,187,149 | 13,943,207 | matplotlib is indexing in a wrong way | <p>I'm trying to plot vertical lines on an existing (realtime) plot.<br></p>
<pre><code>def animate(ival):
df = pd.read_pickle("/Users/user/Workfiles/Python/rp/0.72.0.0/df.pkl")
ax1.clear()
mpf.plot(df, ax=ax1, type='candle', ylabel='p', warn_too_much_data=999999999999)
try:
ax1.h... | <python><matplotlib> | 2023-01-20 17:01:24 | 1 | 552 | stanvooz |
75,187,041 | 10,589,816 | How do I extract the modal peaks from a 1-d data vector? | <pre><code>values = [ 8.42, 8.87, 8.88, 8.88, 8.88, 8.58, 8.58,
8.58, 8.58, 8.58, 8.58, 8.58, 8.58, 8.58, 0. , 8.58,
17.65, 17.65, 17.65, 17.65, 17.65, 17.65, 17.65, 17.65, 17.65,
17.65, 17.65, 17.65, 17.9 , 0. , 17.9 , 17.9 , 17.68, 17.68,
17.68, 17.68, 17.68, 17.68, 17.68... | <python><kernel-density> | 2023-01-20 16:50:42 | 1 | 918 | Peter Prescott |
75,186,965 | 13,488,334 | Python - Creating installable packages from different unique project structure | <p>My goal is to establish a project structure that will limit future headache. The project I am working on has 3 different packages that need to be installable and tested, the structure looks something like this:</p>
<pre><code>my-project
- src
- __init__.py
- widely_used_module_1.py
- wide... | <python><configuration><setuptools><python-packaging><project-structure> | 2023-01-20 16:43:21 | 0 | 394 | wisenickel |
75,186,953 | 8,833,702 | Pandas/Python read file with different separators | <p>I have a .txt file as follows:</p>
<pre><code>columnA;columnB;columnC;columnD
2022040200000000000000000000011 8000702 79005889 SPECIAL_AGENCY
</code></pre>
<p>You can observe that the names of the columns are separated by a semi column <code>;</code>, however, row values, have different separators. In this exa... | <python><pandas><dataframe><text-files> | 2023-01-20 16:42:36 | 2 | 433 | robsanna |
75,186,853 | 4,332,480 | How to properly run tests based on the APITestCase in Django? | <p>When I use the <code>python manage.py test</code> command, in the console I see such a result: <code>Ran 0 tests in 0.000s</code>.</p>
<p>How to run these <code>UNIT tests</code>?</p>
<p>Also how to know the correctness of URLs which I use in the <code>reverse</code> function?</p>
<p><strong>project/urls.py:</strong... | <python><django><django-rest-framework><django-testing><django-tests> | 2023-01-20 16:33:25 | 1 | 5,276 | Nurzhan Nogerbek |
75,186,814 | 14,094,546 | Stacked barplot inside a bar plot python | <p>I have the following barplot. It is showing the distribution of the letters in my dataset (x) in percentage (y). Inside this barplot I want to add that, for example, the 10% of L is 'male' and the 60% is female,10% is neutral,10% is other and 10% missing. For all the letters, like the second attached plot; meaning: ... | <python><matplotlib><seaborn><bar-chart><visualization> | 2023-01-20 16:30:00 | 2 | 520 | Chiara |
75,186,800 | 11,974,225 | Weighted average of a dictionary - Pandas | <p>I have the following column in a data-frame (it is an example):</p>
<p>First row is: <code>'{"100":10,"50":3,"-90":2}'</code>.</p>
<p>Second row is: <code>'{"100":70,"50":3,"-90":2,"-40":3}'</code>.</p>
<p>I want to calculate a weighted average wh... | <python><pandas><numpy> | 2023-01-20 16:29:03 | 3 | 907 | qwerty |
75,186,793 | 7,531,433 | Single sourcing package dependencies with conda build, develop and pip | <p>I am writing a Python package, for which I provide packaging via setuptools as well as a recipe for conda build. This allows the package to be installed via <code>pip</code> and <code>conda</code>.
Additionally, I want to provide an easy way to setup a conda environment for development, so I provide an <code>environ... | <python><pip><conda><setuptools><conda-build> | 2023-01-20 16:28:09 | 0 | 709 | tierriminator |
75,186,701 | 16,591,513 | How to automatically create and install requirements.txt file inside the Docker Build | <p>I have a question: how can I create <code>requirements.txt</code> file inside my Docker build, so I don't have to update it manually at project's directory, while releasing new versions of the app?</p>
<p>So, what I want is basically to construct the <code>requirements.txt</code> file inside the Docker build and ins... | <python><docker> | 2023-01-20 16:20:02 | 1 | 449 | CraZyCoDer |
75,186,553 | 528,369 | Python Pandas convert month/year dataframe with one column to dataframe where each row is one year | <p>Given a Pandas dataframe of the form</p>
<pre><code>January-2021,0.294
February-2021,0.252
March-2021,0.199
...
January-2022,0.384
February-2022,0.333
March-2022,0.271
...
</code></pre>
<p>how do I transform it to a dataframe with 12 columns, one for each month, so it looks like</p>
<pre><code>year,January,Feb... | <python><pandas><dataframe><data-wrangling> | 2023-01-20 16:08:37 | 3 | 2,605 | Fortranner |
75,186,428 | 12,065,403 | How to display two progress bar with tqdm on notebook on vscode? | <p>I would like to display two progress bars on my notebook using tqdm on vscode.</p>
<p>I wrote the following code but I do not understand why it is not working:</p>
<pre><code>import asyncio
from tqdm.notebook import tqdm
print('\n------ simple p bar ------\n')
for i in tqdm(range(10), desc='simple example'):
a... | <python><visual-studio-code><jupyter-notebook><tqdm> | 2023-01-20 15:57:36 | 0 | 1,288 | Vince M |
75,186,331 | 1,970,684 | MWAA Airflow job getting SCRAM error when connecting to postgres | <p>I'm trying to query postgres from an MWAA instance of airflow. I'm not sure if there is a conflict due to airflow itself having a different version of postgres for its metadata or what, but I get this error when connecting to postgres:</p>
<pre><code> File "/usr/local/airflow/dags/transactions/transactions.py&... | <python><postgresql><amazon-web-services><airflow><mwaa> | 2023-01-20 15:48:14 | 3 | 431 | RagePwn |
75,186,241 | 6,645,564 | How can I add more than one continuous color scale in a single px.scatter plot? | <p>I currently am trying to make a bubble plot that is generated from the following code. An example of the bubble plot that is produced is also included.</p>
<pre><code>height = (df['terms'].nunique()*20)+100
fig = px.scatter(df, x='group', y='terms', size='-log10(pvalue)',
color='health_status', hei... | <python><plotly-express> | 2023-01-20 15:39:55 | 1 | 924 | Bob McBobson |
75,186,150 | 13,742,665 | Handle Request payload using HTTPX for post data and capcha key to google recapchaV2 | <p>I'm trying to send the key I got from anti captcha, an example of the key is like this</p>
<pre class="lang-json prettyprint-override"><code>{
"errorId":0,
"status":"ready",
"solution":
{
"gRecaptchaResponse":"3AHJ_VuvYIBNBW5yyv0zRYJ75VkO... | <python><web-scraping><python-requests><recaptcha><httpx> | 2023-01-20 15:32:15 | 1 | 833 | perymerdeka |
75,186,144 | 7,959,614 | Create ranking within set of rows resulting from GROUP BY | <p>I have the following table</p>
<pre><code>CREATE TABLE "results" (
"player" INTEGER,
"tournament" INTEGER,
"year" INTEGER,
"course" INTEGER,
"round" INTEGER,
"score" INTEGER,
);
</code></pre>
<p>With the following... | <python><sqlite><count><window-functions><dense-rank> | 2023-01-20 15:31:38 | 1 | 406 | HJA24 |
75,186,036 | 1,169,091 | Why does the last line in a cell generate output but preceding lines do not? | <p>Given this Jupyter notebook cell:</p>
<pre><code>x = [1,2,3,4,5]
y = {1,2,3,4,5}
x
y
</code></pre>
<p>When the cell executes, it generates this output:</p>
<pre><code>{1, 2, 3, 4, 5}
</code></pre>
<p>The last line in the cell generates output, the line above it has no effect. This works for any data type, as far as ... | <python><jupyter-notebook> | 2023-01-20 15:22:26 | 2 | 4,741 | nicomp |
75,186,020 | 6,525,082 | How can I check for unused import in a python jupyterlab notebook? | <p>suppose a jupyter file has several imports</p>
<pre><code>import sys
import pandas as pd
import p1
import p2
</code></pre>
<p>however suppose p2 is never used and I want to remove it. The answer to the question for regular python scripts is <a href="https://stackoverflow.com/questions/2540202/how-can-i-check-for-un... | <python><jupyter-notebook><jupyter-lab> | 2023-01-20 15:20:58 | 0 | 1,436 | wander95 |
75,186,010 | 9,392,446 | Create binary columns out of data nested in another dfs columns | <p>This one is weird --</p>
<p>let's say I have a <code>df</code> like this:</p>
<pre><code>user_id city state network
123 austin tx att
113 houston tx tmobile
343 miami fl att
356 seattle wa verizon
</code></pre>
<p>and I have another ... | <python><pandas> | 2023-01-20 15:20:18 | 1 | 693 | max |
75,185,927 | 6,694,814 | Python folium - conditional based class_name for DivIcon | <p>I would like to set the class_name based on some conditions in foium.</p>
<p>I tried:</p>
<pre><code> folium.Marker(location=[lat,lng],
icon = folium.DivIcon(html="<b>" + sp + "</b>",
if role == 'Contractor':
... | <python><folium> | 2023-01-20 15:14:19 | 1 | 1,556 | Geographos |
75,185,926 | 6,683,176 | Why does FastAPI's Depends() work without any parameter passed to it? | <p>I found the following FastAPI code for authenticating a user with their information gotten from a form:</p>
<pre class="lang-py prettyprint-override"><code>@app.post("/token")
async def login_for_access_token(form_data:OAuth2PasswordRequestForm = Depends(),
db: Session = D... | <python><dependency-injection><fastapi><depends> | 2023-01-20 15:14:19 | 1 | 339 | pablowilks2 |
75,185,794 | 5,287,190 | In SQLAlchemy, how can I prevent the reassignment of a child in a one-to-many relationship? | <p>How can I dynamically prevent SQLAlchemy from reassigning a <code>many(Member)</code> to a different <code>one(Group)</code> if the member already belongs to a different group?</p>
<p>The semantics of the relationship are as follows:</p>
<ul>
<li>A <code>Group</code> may have <em>zero</em> or more <code>Members</cod... | <python><sqlalchemy> | 2023-01-20 15:03:22 | 1 | 2,255 | Brian H. |
75,185,612 | 1,920,003 | Python Unittest: How to initialize selenium in a class and avoid having the browser opening twice? | <p>Consider the example below, since I'm initializing the driver in <code>setUp</code> method and using it in <code>test_login</code>, the browser will open twice, the first time during <code>setUp</code> and then it will be closed and the tests will begin.</p>
<p>If I remove the logic from <code>setUp</code> and put i... | <python><unit-testing><selenium-webdriver><selenium-chromedriver><python-unittest> | 2023-01-20 14:49:30 | 3 | 5,375 | Lynob |
75,185,545 | 5,901,870 | After converting Spark data frame to pandas data frame, pandas data frame is throwing KeyError 0 when searching for a cell | <p>I am running this in data bricks notebook.</p>
<p>I converted a spark data frame [250 rows x 2 columns] to pandas data frame using below method:</p>
<pre><code>pandasDF = spark_df.toPandas()
</code></pre>
<p>this is successful and I was able to run below lines successfully:</p>
<pre><code>print(pandasDF)
print(panda... | <python><pandas><dataframe><databricks> | 2023-01-20 14:42:47 | 0 | 400 | Mikesama |
75,185,484 | 17,561,414 | further expldoe on string datatype pyspark | <p>I have df where I have the column called data. In the data column we can expect the single values per <code>identifier_filed</code> column or list values. This is shown as <code>[ ]</code>brackets under the data column. For example <code>Allegren</code> under the <code>values</code> column can have different <code>... | <python><apache-spark><pyspark> | 2023-01-20 14:37:07 | 2 | 735 | Greencolor |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.