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
74,906,285
444,644
yt-dl command to download audio files - in a python script
<p>I want to convert this command into a python call:</p> <pre><code>yt-dlp --continue --no-overwrites --extract-audio --audio-format mp3 -o &quot;ST_%(upload_date)s_%(title).50s.%(ext)s&quot; https://www.youtube.com/channel/UCYt3jqP4rRP2rr5Ye8fs0LQ/videos --playlist-reverse --restrict-filenames --add-metadata --post...
<python><youtube-dl><yt-dlp>
2022-12-24 07:50:20
0
3,207
vishvAs vAsuki
74,906,113
7,317,408
Keep only day 1 from multi day runners - stock market, Python
<p>I am trying to build a strategy around intraday runners in the stock market, and I need to eliminate from my dataset any date from a symbol which occurs after the first day of a multi day runner.</p> <p>However, only when that symbol runs multiple days. If it is only a day 1, then I need to keep it.</p> <p>So let's ...
<python><pandas><numpy><stock><trading>
2022-12-24 07:06:40
2
3,436
a7dc
74,905,654
8,281,509
Run MATLAB executable from Python
<p>I am trying to run a MATLAB executable (main.exe) from Python. main.exe file was generated using the .m files in my project, using the application compiler. To run the executable from Python, I tried</p> <pre><code>import subprocess cmd = r&quot;C:/Windows/System32/cmd I:/sim/main/main.exe&quot; process = subproces...
<python><matlab><subprocess><executable>
2022-12-24 04:53:36
1
1,571
Natasha
74,905,601
14,108,609
how to run a conda environment based script via rc.local
<p>I have a lengthy python scrip <code>program.py</code> sitting inside my downloads folder. I am able to run this script only after activating my specific conda environment using <code>source /home/machineX/miniconda3/bin/activate my_env</code>. I have written the below bash script <code>trigger.sh</code> to activate ...
<python><linux><raspberry-pi><conda>
2022-12-24 04:33:28
1
1,351
Janzaib M Baloch
74,905,558
1,145,760
Python type hint on default parameter explodes
<p>Without <code>: int</code> this program runs fine:</p> <pre><code>#!/usr/bin/env python3 import typing # not needed def foo(): return (1,2,3) def bar(i = foo()[0]: int): # adding ': int' breaks the Universe return i print(bar()) </code></pre>
<python><types>
2022-12-24 04:16:29
1
9,246
Vorac
74,905,253
17,981,859
Why does sphinx automodule work properly only on local but not on readthedocs?
<h2>Local Sphinx</h2> <p><a href="https://i.sstatic.net/5zVkf.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/5zVkf.png" alt="Local Sphinx" /></a></p> <h2>ReadTheDocs</h2> <p><a href="https://i.sstatic.net/BxkBd.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/BxkBd.png" alt="readthedocs" /...
<python><python-sphinx><read-the-docs>
2022-12-24 02:16:25
1
355
Stawa
74,905,175
825,227
Intersection of non-NaN entries for pivot table in Python
<p>I have a collection of SQL data output that I'm reshaping via Pandas <code>pivot_table</code> to be row-based instead of column-based. Each of the new columns will be a time-series with associated datetime index, but the resulting columns may not have coinciding timeseries history.</p> <p>What's the best way to kee...
<python><python-3.x><pandas><pivot-table>
2022-12-24 01:51:23
1
1,702
Chris
74,904,917
2,316,663
Keras model_plot generates random text in figure
<p>I am currently testing some dummy code about CNN. I created the following tranditional model</p> <pre><code>model = Sequential() model.add(Conv2D(16, (3, 3), activation = 'relu', padding='same', input_shape = (6,6,1))) model.add(MaxPooling2D((2, 2), padding='same')) model.add(Conv2D(32, (3, 3), activation = 'relu', ...
<python><keras>
2022-12-24 00:16:56
0
363
Osama El-Ghonimy
74,904,866
3,875,378
Repeated Categorical X-Axis Labels in Matplotlib
<p>I have a simple question: <strong>why are my x-axis labels repeated?</strong></p> <p><a href="https://i.sstatic.net/G9trl.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/G9trl.png" alt="MWE Plot" /></a></p> <p>Here's an MWE: <a href="https://colab.research.google.com/drive/1yJHJdqIiZkkG9yZntyLWywKJNKY...
<python><matplotlib><axis-labels>
2022-12-24 00:03:23
1
447
DarkRunner
74,904,647
1,054,322
How can I restrict this dataclass serialization to only attributes on the base class?
<p>Here's some code:</p> <pre class="lang-py prettyprint-override"><code>from dataclasses import dataclass from dataclasses_json import dataclass_json @dataclass_json @dataclass class Foo: f: str @dataclass_json @dataclass class Baz(Foo): b: str def full(self): return self.to_dict() # as ...
<python><python-dataclasses>
2022-12-23 23:08:59
1
9,389
MatrixManAtYrService
74,904,556
15,875,806
appedPlainText without new line in pyqt5
<p>I have a QPlainTextEdit box which is read-only and is used as an application console. I basically want to append a string WITHOUT a newline or <code>\r</code> to the PlainTextEdit widget using <code>appendPlainText</code>. Looking through similar quesitions, people seem to just set cursor to the end with <code>myTex...
<python><pyqt5>
2022-12-23 22:47:42
0
305
hashy
74,904,444
9,947,140
Connect to a GCP Cloud SQL Auth Proxy using SQL alchemy and a GCP service account
<p>I am using terraform to set up a simple application that has a postgres db via Cloud SQL in google cloud platform (GCP). I set up a GCP Cloud SQL Auth proxy for my postgresql db using <a href="https://github.com/GoogleCloudPlatform/cloud-sql-proxy" rel="nofollow noreferrer">this guide</a>. I set up the proxy as a si...
<python><postgresql><kubernetes><google-cloud-platform><sqlalchemy>
2022-12-23 22:26:19
1
342
randomrabbit
74,904,389
14,159,985
How to check if pyspark dataframe is empty QUICKLY
<p>I'm trying to check if my pyspark dataframe is empty and I have tried different ways to do that, like:</p> <pre><code>df.count() == 0 df.rdd.isEmpty() df.first().isEmpty() </code></pre> <p>But all this solutions are to slow, taking up to 2 minutes to run. How can I quicly check if my pyspark dataframe is empty or no...
<python><apache-spark><pyspark>
2022-12-23 22:16:42
2
338
fernando fincatti
74,904,373
9,470,078
PyTorch create combination of ranges
<p>Is there a way to nest <code>arange</code>'s easily to create all the combinations of two ranges in PyTorch? For example:</p> <pre><code>x = torch.arange(2, 4) y = torch.arange(0, 3) something(x, y) # should be [[2,0], [2,1], [2,3], [3,0], [3,1], [3,2]] </code></pre> <p>I.e., something with the same functionality a...
<python><pytorch>
2022-12-23 22:13:27
2
1,157
Monolith
74,904,322
1,285,419
Looking for an approach to break a B-spline/Cubic spline into multiple sections
<p>I am self-learning a game developing. The current topic I am learning is about path design. I get some random points and need a good math model to design a smooth path through those points (not necessary to pass all points but in best fitting). I read a book about spline (B-spline and cubic spline) and seems it is a...
<python><numpy><interpolation><bezier><spline>
2022-12-23 22:06:15
0
2,225
user1285419
74,904,304
4,541,649
How to stack summing vectors to numpy 3d array?
<p>I have a 3d <code>numpy</code> array that looks like so:</p> <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt; g array([[[ 1., 1., 1., 1., 1.], [ 0., 0., 0., 0., 0.], [ 1., 2., 3., 4., 6.]], [[ 0., 0., 0., 0., 0.], [11., 22., 33., 44., 66.], [ 0., 0...
<python><arrays><numpy><multidimensional-array><sum>
2022-12-23 22:02:40
2
1,655
Sergey Zakharov
74,904,236
15,446,076
Python: ValueError Data cardinality is ambiguous
<p>I'm trying to make an AI that can convert handwriting to plain text. But I'm encountering the following error:</p> <pre><code>ValueError: Data cardinality is ambiguous: x sizes: 8 y sizes: 1 Make sure all arrays contain the same number of samples. </code></pre> <p>I have 8 images as testing dataset, each image h...
<python><pandas><dataframe><numpy><artificial-intelligence>
2022-12-23 21:49:17
0
374
Tetie
74,904,197
12,242,085
How to find column where is punctation mark as a single value in Python Pandas?
<p>I have DataFrame like below:</p> <pre><code>COL1 | COL2 | COL3 -----|------|-------- abc | P | 123 b.bb | , | 22 1 | B | 2 ... |... | ... </code></pre> <p>And I need to find columns where is only punctation mark like !&quot;#$%&amp;'()*+,-./:;&lt;=&gt;?@[]^_`{|}~</p> <p>So as a result I need somethin...
<python><pandas><string><dataframe>
2022-12-23 21:42:19
2
2,350
dingaro
74,904,129
5,716,192
How to add concrete type annotations for np.recarray?
<p>I have the following code in a file <code>scratch.py</code>:</p> <pre><code>import numpy as np def my_array(arr: np.recarray) -&gt; None: print(arr.x) my_array(np.rec.array([(1.0, 2), (3.0, 4)], dtype=[('x', '&lt;f8'), ('y', '&lt;i8')])) </code></pre> <p>Running <code>mypy scratch.py --disallow-any-generics</...
<python><numpy><mypy>
2022-12-23 21:30:16
1
693
Victory Omole
74,904,086
8,401,294
Services on the same network cannot be seen by alias, only by ip
<p>I have the following <code>bridge</code> network locally:</p> <pre class="lang-bash prettyprint-override"><code>$ docker network ls NETWORK ID NAME DRIVER SCOPE 08e7e0710fd9 bridge bridge local </code></pre> <p>I have 3 containers linked in this netw...
<python><docker><docker-compose>
2022-12-23 21:22:41
0
365
José Victor
74,904,066
1,664,557
Python utf-8 encoding not following unicode rules
<p>Background: I've got a byte file that is encoded using unicode. However, I can't figure out the right method to get Python to decode it to a string. Sometimes is uses 1-byte ASCII text. The majority of the time it uses 2-byte &quot;plain latin&quot; text, but it can possibly contain any unicode character. So my pyth...
<python><unicode><encoding><utf-8>
2022-12-23 21:20:18
1
410
krose
74,903,930
14,336,726
Module not found error: what is Jupyter core?
<p>I think this code</p> <pre><code>jupyter nbconvert --to script weather_observations.ipynb </code></pre> <p>should convert a Jupyter script to a Python script, but I get this error</p> <pre><code>File &quot;/Library/Frameworks/Python.framework/Versions/3.8/bin/jupyter&quot;, line 6, in &lt;module&gt; from jupyter...
<python><jupyter-notebook><jupyter-lab>
2022-12-23 20:56:56
1
480
Espejito
74,903,737
3,543,200
MyPy shows "untyped decorator" error with a ContextDecorator?
<p>I have a timer that I use as both a context manager and as a decorator, i.e.</p> <pre class="lang-py prettyprint-override"><code>class Timer(ContextDecorator): &quot;&quot;&quot;Context manager which times block execution and adds results to APMContext instance&quot;&quot;&quot; def __init__(self, key: ...
<python><mypy><python-typing>
2022-12-23 20:26:23
1
997
gmoss
74,903,722
9,367,543
How to install tensorflow on MacOS
<p>In a new virtual env, python 3.9 I tried to install tensorflow using pip</p> <pre><code>pip install tensorflow </code></pre> <p>I keep getting the error</p> <blockquote> <p>ERROR: Could not find a version that satisfies the requirement tensorflow (from versions: none) ERROR: No matching distribution found for tensor...
<python><tensorflow><apple-silicon>
2022-12-23 20:23:39
1
338
welu
74,903,289
2,313,307
Plotly Python - Heatmap - Include and update additional label parameters in Hovertext when using slider
<p>I want to plot data in a heatmap in Plotly and include a slider to toggle between different categories of a certain slider column.</p> <p>I am currently able to update the text in the <code>hovertemplate</code>, but I would also like to include additional information in the box, which should also be updated whenever...
<python><plotly><plotly-dash><heatmap>
2022-12-23 19:18:20
1
1,419
finstats
74,903,173
7,462,275
Problem in Pandas : impossible to do sum of int with arbitrary precision
<p>I tried to do the sum of large integers in pandas and the answer is not as expected.</p> <p>Input file : <code>my_file_lg_int</code></p> <pre><code>my_int 111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111 22222222222222222222222222222222222222222222222222222222222...
<python><pandas>
2022-12-23 19:04:00
3
2,515
Stef1611
74,903,112
4,541,649
How to turn a 3d numpy array into a pandas dataframe of numpy 1d arrays?
<p>I have a <code>numpy</code> 3d array. I'd like to create a <code>pandas</code> dataframe off of it which would have as many rows as the array's 1st dimension's size and the number of columns would be the size of the 2nd dimension. The values of the dataframe should be the actual vectors (<code>numpy</code> arrays) w...
<python><arrays><pandas><numpy><multidimensional-array>
2022-12-23 18:54:43
1
1,655
Sergey Zakharov
74,903,025
3,788
Missing "nonce" claim with Quickbooks + Authlib
<p>When I try to implement an OAuth flow into Quickbooks Online with the <code>openid</code> scope, I receive an error <code>authlib.jose.errors.MissingClaimError: missing_claim: Missing &quot;nonce&quot; claim</code>.</p> <p>Here is the code:</p> <pre class="lang-py prettyprint-override"><code>from authlib.integration...
<python><openid><quickbooks><authlib>
2022-12-23 18:44:42
0
19,469
poundifdef
74,902,874
17,148,496
Finding if the values in one list, are found between values of another sub-list
<p>I know the title is a bit confusing, it was hard for me to put a title to this. I'll give an example to what I need I think it will be clear.</p> <p>I have a list of coefficients (contains 15 values), let's call it listA:</p> <pre><code>Coefficients: [ 0.04870086 0.57480212 0.89015539 2.3233615 4.55812396 7.1...
<python><list>
2022-12-23 18:25:27
2
375
Kev
74,902,698
9,720,696
Keeping the structure of a list in after operating a nested loop
<p>Suppose I have two lists as follow:</p> <pre><code>x = [['a','b','c'],['e','f']] y = ['w','x','y'] </code></pre> <p>I want to add each element of list <code>x</code> with each element of list <code>y</code> while keeping the structure as given in <code>x</code> the desired output should be like:</p> <pre><code>[['aw...
<python><list><nested-loops><list-manipulation>
2022-12-23 18:02:28
3
1,098
Wiliam
74,902,695
10,197,418
Multiple aggregations on multiple columns in Python polars
<p>Checking out how to implement binning with Python polars, I can easily calculate aggregates for individual columns:</p> <pre class="lang-py prettyprint-override"><code>import polars as pl import numpy as np t, v = np.arange(0, 100, 2), np.arange(0, 100, 2) df = pl.DataFrame({&quot;t&quot;: t, &quot;v0&quot;: v, &qu...
<python><dataframe><group-by><aggregate><python-polars>
2022-12-23 18:02:01
1
26,076
FObersteiner
74,902,561
12,282,349
SQLAlchemy backref and backpopulates conflicts with relationship and mapper mapped has no property
<p>In FastAPI application I am using sqlalchemy library. I have tried to establish a many to many relationship as described below:</p> <pre><code>PostCity = Table('PostCity', Base.metadata, Column('id', Integer, primary_key=True), Column('post_id', Integer, ForeignKey('post.id')), Column('city_id', Inte...
<python><sqlalchemy><fastapi>
2022-12-23 17:45:17
1
513
Tomas Am
74,902,542
19,838,445
Track invocations of methods and functions
<p>I'm looking for the library which allows to track invocation of methods and functions. Think of it as of <a href="https://docs.python.org/3/library/unittest.mock.html#unittest.mock.Mock.called" rel="nofollow noreferrer">Mock</a> providing <code>called</code> and <code>call_count</code> properties.</p> <p>Example of ...
<python><python-3.x><profiling><python-decorators><proxy-object>
2022-12-23 17:43:10
1
720
GopherM
74,902,387
1,436,222
import error attempting to import from the directory above
<p>Not a python developer and I am clearly missing something fundamental here. Using Python 3.10.7 and i am getting an error:</p> <pre><code>from ..class_one import ClassOne ImportError: attempted relative import beyond top-level package </code></pre> <p>when attempting to execute <code>python run_me.py</code> script...
<python><import><package><python-import>
2022-12-23 17:26:16
2
459
concentriq
74,902,212
12,361,700
multiprocessing Pool seems to get stuck for no apparent reason
<p>I have a python script with the following, more or less, code:</p> <pre><code>def some_function(): pass class SomeClass: def __init__(self): self.pool = mp.Pool(10) def do_smth(self): self.pool.map(some_function, range(10)) if __name__ == '__main__': cls = SomeClass() for _ in range(1000): p...
<python><multithreading><terminal>
2022-12-23 17:05:24
1
13,109
Alberto
74,902,103
3,460,864
Rolling sum between two tables with date gaps
<p><strong>Background and goal</strong>: I have two tables: counts and picks. The base table is counts and is what I want the result of all of this to be merged with. Screenshot of a reproducible example below.</p> <p><a href="https://i.sstatic.net/dxZVF.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/dx...
<python><pandas><rolling-computation>
2022-12-23 16:52:04
2
411
user137698
74,902,068
10,634,126
Accessing PyMongo UpdateOne operation properties
<p>If I am receiving a list of prepared PyMongo UpdateOne operations (e.g. below)...</p> <pre><code>print(type(to_load[0])) &gt; &lt;class 'pymongo.operations.UpdateOne'&gt; print(to_load[0]) &gt; UpdateOne({'id': XXX}, {'$set': {'name': 'YYY'}}, True, None, None, None) </code></pre> <p>...is it possible to then extra...
<python><mongodb><pymongo>
2022-12-23 16:47:50
1
909
OJT
74,901,980
10,025,767
Plotly can't display png images in subplots
<p>Is there any way to put png image instead of one of this Scatter graphs? I could only find how to use the image as logo or background image</p> <pre><code>from plotly.subplots import make_subplots import plotly.graph_objects as go fig = make_subplots(rows=1, cols=2) fig.add_trace( go.Scatter(x=[1, 2, 3], y=[4,...
<python><html><plotly>
2022-12-23 16:38:57
1
558
James Flash
74,901,976
8,070,090
How to give permission to Google Spreadsheet created by Service Account?
<p>I created a Google Service Account with this step:</p> <ol> <li>Open this link: <a href="https://console.cloud.google.com/apis/credentials?project=MyProject" rel="noreferrer">https://console.cloud.google.com/apis/credentials?project=MyProject</a></li> <li>Click on <strong>CREATE CREDENTIALS</strong> button, then sel...
<python><google-cloud-platform><google-sheets-api><service-accounts>
2022-12-23 16:38:33
1
3,109
Tri
74,901,881
4,527,628
Django - Import Models from an installed Package
<p>I have all of my Django models in another package which I install using pip in a Django app.</p> <pre><code>models_package | - models.py | - setup.py </code></pre> <p>and in <code>models.py</code> i have</p> <pre><code>from django.contrib.auth.models import AbstractUser class User(AbstractUser): .... </code...
<python><django><django-models>
2022-12-23 16:30:12
1
1,225
M.Armoun
74,901,872
6,446,053
How to average multiindex row in Pandas
<p>The objective is to average the first level of a multi index row.</p> <p>For example, the task it to average the rows (s1,s2) and (s1,s3).</p> <p>Given the following <code>df</code></p> <pre><code> a fe gg new_text (s1, s2) 4 0 3 t (s1, s3) 3 3 1 t (s2, s3) 3 2 4 t (s2,...
<python><pandas><multi-index>
2022-12-23 16:28:37
4
3,297
rpb
74,901,825
386,861
How to solve error in VS Code - exited with code=127
<p>Baffled by this. I've been using VSCode for a few weeks and have python installed.</p> <pre><code>def print menu(): print (&quot;Let's play a game of Wordle!&quot;) print (&quot;Please type in a 5-letter word&quot;) print_menu() print_menu() </code></pre> <p>So far so simple, but when I run it I get...
<python><visual-studio-code>
2022-12-23 16:23:26
6
7,882
elksie5000
74,901,804
12,282,349
Sqlalchemy engine - run a function only after a database with tables has been created
<p>On my FastApI application I am using sqlalchemy library:</p> <pre><code>from db import models from db.database import engine models.Base.metadata.create_all(engine) ... </code></pre> <p>If a db does not exist it creates one. Sometimes I delete that db and recreate, but I loose all the data. I run a function to rep...
<python><sqlalchemy><fastapi>
2022-12-23 16:19:38
1
513
Tomas Am
74,901,684
6,702,598
AWS Cognito: Receive sorted user list
<p>I'm using Python with boto3 for accessing my AWS Cognito user data information.</p> <h5>Problem</h5> <p>I'm using <a href="https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/cognito-idp.html?highlight=list_users_#CognitoIdentityProvider.Client.list_users" rel="nofollow noreferrer"><code>list_...
<python><amazon-web-services><boto3><amazon-cognito>
2022-12-23 16:07:12
0
3,673
DarkTrick
74,901,522
453,673
Can MediaPipe specify which parts of the face mesh are the lips or nose or eyes?
<p>MediaPipe is capable of providing the x,y,z points of multiple points on the face, enabling it to generate a face mesh. However, the output is just in x,y,z points. Is there any way to know which of those points are those of the lips?</p> <pre><code>import cv2 import mediapipe as mp mp_drawing = mp.solutions.drawing...
<python><python-3.x><mediapipe>
2022-12-23 15:47:19
3
20,826
Nav
74,901,511
494,134
Module attribute mysteriously appears
<pre><code>$ python Python 3.8.10 (default, Nov 14 2022, 12:59:47) [GCC 9.4.0] on linux Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information. &gt;&gt;&gt; import urllib &gt;&gt;&gt; urllib.request Traceback (most recent call last): File &quot;&lt;stdin&gt;&quo...
<python>
2022-12-23 15:46:50
0
33,765
John Gordon
74,901,508
9,422,346
How to print output of pexpect consisting '\r' in next line of the terminal?
<p>I have the follwoing code snippet from a pexpect script</p> <pre><code>import pexpect import time username=&lt;username&gt; password=&lt;password&gt; child = pexpect.spawn('ssh &lt;username&gt;@192.168.1.219',timeout=40) child.expect(['MyUbuntu','\$','\#']) child.sendline(&lt;password&gt;) child.expect(['MyUbuntu','...
<python><ubuntu><ssh><pexpect>
2022-12-23 15:46:36
1
407
mrin9san
74,901,355
5,212,614
My geopy.geocoders is throwing error: SSL: CERTIFICATE_VERIFY_FAILED. How can I resolve this?
<p>When I try to run this code.</p> <pre><code>from geopy.geocoders import Nominatim geolocator = Nominatim(user_agent=&quot;ryan_data&quot;) location = geolocator.geocode(&quot;175 5th Avenue NYC&quot;) print(location.address) </code></pre> <p>I get this error.</p> <p>GeocoderUnavailable: HTTPSConnectionPool(host='nom...
<python><python-3.x><geopy>
2022-12-23 15:29:24
0
20,492
ASH
74,901,315
15,825,321
Pandas rolling mean with offset by (not continuously available) date
<p>given the following example table</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Index</th> <th>Date</th> <th>Weekday</th> <th>Value</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>05/12/2022</td> <td>2</td> <td>10</td> </tr> <tr> <td>2</td> <td>06/12/2022</td> <td>3</td> <td>20</td> </...
<python><pandas><moving-average><rolling-computation>
2022-12-23 15:26:06
2
303
Paul1911
74,901,273
769,449
scrapy.Request does not execute callback function to process custom URL
<p>I would expect to see &quot;HIT&quot; in my Visual Studio console but the <code>process_listing</code> function is never executed. When I run <code>scrapy crawl foo -O foo.json</code> I get error:</p> <blockquote> <p>start_requests = iter(self.spider.start_requests()) TypeError: 'NoneType' object is not iterable</p>...
<python><json><scrapy>
2022-12-23 15:22:04
1
6,241
Adam
74,901,265
11,092,636
Set label font to bold without changing its size and its font
<p>I know it's possible to use another object than <code>tk.Label</code> but I would want to do it with <code>tk.Label</code> (for various reasons, I'm not allowed to do it with another object).</p> <p>What I don't understand is why do the font and the size of the label change when I just set it to bold. Here is a Mini...
<python><tkinter><fonts>
2022-12-23 15:21:31
1
720
FluidMechanics Potential Flows
74,901,114
1,611,898
Prevent Python CSV to JSON for loop iteration from overwriting previous entry
<p>I have a pretty basic Python For statement that I'm using to try to remap a CSV file into geoJSON format. My script looks like this:</p> <pre><code>def make_json(csvFilePath, jsonFilePath): # create a dictionary data = { &quot;type&quot;: &quot;FeatureCollection&quot;, &quot;features...
<python><for-loop><csvtojson>
2022-12-23 15:04:46
2
631
thefreeline
74,901,076
17,945,841
Join two lists into one list of lists
<p>I have two lists of the same length. I want to merge them into a list of lists like this example:</p> <pre><code>left_list = [-1,-3,15,3,1.7] right_list = [1.2,2,17,3.5,2] res_list = [[-1,1.2],[-3,2],[15,17],[3,3.5],[1.7,2]] </code></pre> <p>notice the <code>left_list</code> has smaller valleues so the order matter...
<python><list>
2022-12-23 15:01:13
1
1,352
Programming Noob
74,900,932
4,495,790
How to flatten grouped Pandas DF columns by ID?
<p>I have the following Pandas data frame (number of rows with the same ID are always the same):</p> <pre><code>ID VALUE --------- 1 11 1 12 2 21 2 22 3 31 3 32 </code></pre> <p>I would like to get a flattened version of it where each ID have one rows with N columns with the respective values belonging to ...
<python><pandas>
2022-12-23 14:47:03
2
459
Fredrik
74,900,861
12,323,468
How to write df.query to select all columns from a dataframe with NaN?
<p>I have the following code which returns a df with all columns having NaN values:</p> <pre><code>df.loc[:, df.isna().any()] </code></pre> <p>How would I write this code using df.query?</p>
<python>
2022-12-23 14:38:44
0
329
jack homareau
74,900,797
843,458
python error : codec can't decode byte 0xe4 in position 2857: invalid continuation byte
<p>I am reading a latex file using</p> <pre><code>with open(inputFileName, 'r', encoding=&quot;utf8&quot;) as inputFileHandle: for lineInput in inputFileHandle: </code></pre> <p>It fails with lineInput showing &quot;% Declare common style&quot; with the error</p> <pre><code>can't decode byte 0xe4 in position 2857: ...
<python><encoding>
2022-12-23 14:32:46
0
3,516
Matthias Pospiech
74,900,770
4,576,519
Fast way to calculate Hessian matrix of model parameters in PyTorch
<p>I want to calculate the Hessian matrix of a loss w.r.t. model parameters in PyTorch, but using <a href="https://pytorch.org/docs/stable/generated/torch.autograd.functional.hessian.html" rel="nofollow noreferrer"><code>torch.autograd.functional.hessian</code></a> is not an option for me since it recomputes the model ...
<python><optimization><pytorch><hessian>
2022-12-23 14:30:14
1
6,829
Thomas Wagenaar
74,900,699
7,415,412
How to append to list in python module written in rust?
<p>I am writing a python model for heavy calculations in rust using the pyo3 bindings. However, for a rust struct with a variable containing an empty list I cannot append to that variable in python.</p> <p>Does anybody know how to do this? See below for a MWE ( that I cannot get to work ):</p> <p>I have a rust file cal...
<python><rust><pyo3>
2022-12-23 14:24:06
0
599
westr
74,900,683
5,472,037
Wordnet taxonomy construction
<p>I'd like to build a minimum encompassing taxonomic tree for a given set of wordnet synsets. For a set of 2 synsets the tree would be one where they are both children nodes of their lowest common hypernym.</p> <p>For the following set:</p> <pre><code>[{'name': 'tench.n.01'}, {'name': 'goldfish.n.01'}, {'name': 'gre...
<python><nlp><nltk><wordnet>
2022-12-23 14:22:54
1
641
Iyar Lin
74,900,576
9,385,568
How to map values from one dataframe to another?
<p>I have two different dataframes as follows:</p> <pre class="lang-py prettyprint-override"><code>df.head() ext_id credit_debit_indicator index_name business_date trench_tag trench_tag_l2 0 4SL19N2YQLCU62TY C ib-prodfulltext-t24-transhist-202208 2022-07-31 XXX9999999 XXX99 1 1EXHR74Y2YXBN4AM ...
<python><pandas>
2022-12-23 14:10:38
1
873
Stanislav Jirak
74,900,505
360,362
Convert SQLAlchemy Column type to Python data type respecting variant
<p>I have added support for sqlite in some of my SQLAlchemy models, so some columns appear with variants based on the dialect</p> <pre><code>dt = Column(DateTime().with_variant(String, 'sqlite')) </code></pre> <p>I have a logic that relies on the python data type for that field, such as <code> col.type.python_type</cod...
<python><sqlalchemy>
2022-12-23 14:02:33
1
9,790
Meitham
74,900,454
16,389,095
Python TypeError: takes 4 positional arguments but 5 were given
<p>I'm trying to design a user interface in Python / Kivy MD. Starting from an <a href="https://github.com/kivymd/KivyMD/wiki/Components-DropDownItem" rel="nofollow noreferrer">example</a>, I developed an interface with a simple drop down widget, such as a combobox. When the app runs, the widget should display its elem...
<python><kivy><kivy-language><kivymd>
2022-12-23 13:58:08
1
421
eljamba
74,900,422
4,865,723
Open & write to a file-like object but avoid AttributeError about missing open()
<p>I want to have function that can write content into a file-like object. It accepts <code>pathlib.Path</code> objects or <code>io.StringIO</code>. The first one need to be <code>open()</code>'ed first, the second one not.</p> <p>Because of that it seems to me I have to explicte type check the object to know if I have...
<python><file>
2022-12-23 13:54:47
1
12,450
buhtz
74,900,305
12,845,199
Regex that captures and filters the "steps" strings that have only one sole number at the early part
<p>So I have a pandas.Series as such</p> <pre><code>s = pd.Series(['1-Onboarding + Retorno', '1.1-Onboarding escolha de bot', '2-Seleciona produto', '3-Informa localizacao e cpf', '3.1-CPF valido (V.2.0)', '3.2-Obtencao de CEP'],name = 'Steps') 0 1-Onboarding + Retorno 1 ...
<python><pandas><regex>
2022-12-23 13:42:49
2
1,628
INGl0R1AM0R1
74,899,785
14,224,895
psycopg2.errors.ActiveSqlTransaction: CREATE DATABASE cannot run inside a transaction block
<p>I am trying to create a Django app that creates a new database for every user when he/she signs up. I am going with this approach due to some reason. I have tried many ways using management commands and even Celery. But I am still getting the same error.</p> <pre><code>2022-12-23 07:16:07.410 UTC [49] STATEMENT: CR...
<python><django><postgresql><psycopg2>
2022-12-23 12:44:47
1
927
Abdullah Mujahid
74,899,706
4,718,423
bottom up method development parameter passing
<p>I develop bottom up, starting with small simple methods to go to the big full fledged implementation</p> <pre><code>class Pop(object): def welcome(self, name, new_member = False): response = &quot;&quot; if new_member: response = &quot; NOT&quot; return str(&quot;hello th...
<python>
2022-12-23 12:34:31
1
1,446
hewi
74,899,586
3,423,825
How to add permissions in Django post_save signal?
<p>I have a problem to add permissions in Django post_save signal because the m2m relationships don't persist. They are correctly displayed with <code>user_permissions.all()</code> after assignment, but as soon as I save the model again the queryset get empty. What am'I doing wrong ?</p> <p>I don't have the same proble...
<python><django>
2022-12-23 12:21:01
1
1,948
Florent
74,899,506
996,366
How to get log mel spectrogram of specific shape using librosa
<p>I have some audio files which I want to convert to log mel spectogram. I need the log mel spectogram to be in the shape of <code>(512,512)</code>. I changed the n_mels to 512, to get the first dimension 512 but I am unable to change the second dimension to 512 for all audios. I tried experimenting with hop_length va...
<python><audio><librosa><spectrogram><mel>
2022-12-23 12:13:09
1
15,212
Eka
74,899,431
19,574,336
Python C API, send a python function pointer to c and execute it
<p>I want to create a function in python, pass it's function pointer to c and execute it there.</p> <p>So my python file:</p> <pre><code>import ctypes import example def tester_print(): print(&quot;Hello&quot;) my_function_ptr = ctypes.CFUNCTYPE(None)(tester_print) example.pass_func(my_function_ptr) </code></pre> ...
<python><c><python-c-api>
2022-12-23 12:02:44
1
859
Turgut
74,899,353
10,430,394
Discord bot doesn't show up in server members, even though invitation button says it has joined
<p>I made a bot with discord.py and have already invited it to my own private server. It works on that one without issues and now I wanted to add it to another server on which I have mod permissions. So I send an invitation to the new channel to my bot and clicked the accept button. I got redirected to the chat and the...
<python><discord><discord.py>
2022-12-23 11:54:36
1
534
J.Doe
74,899,335
9,185,021
TensorFlow unable to set large precision of tensors for 12 decimals with float 64
<p>Hello i am using TensorFlow i have i try to load float 64 tensor value but when i load to i loose decimals any help?</p> <pre><code> tenosr = tf.constant([57.695030261422, 11.911734826863], dtype=tf.float64) </code></pre> <p><a href="https://i.sstatic.net/mG0Q3.png" rel="nofollow noreferrer"><img src="https://i.ssta...
<python><tensorflow><precision><floating-accuracy>
2022-12-23 11:52:31
0
339
Mixalis Navridis
74,899,302
12,242,085
How to deal with JSON and nested JSON inside a DataFrame columns into new columns in Python Pandas?
<p>I have DataFrame like below:</p> <p>data type:</p> <ul> <li>COL1 - float</li> <li>COL2 - int</li> <li>COL3 - int</li> <li>COL4 - float</li> <li>COL5 - float</li> <li>COL6 - object</li> <li>COL7 - object</li> </ul> <p>Source code:</p> <pre><code>a = pd.DataFrame() a[&quot;COL1&quot;] = [0.0, 800.0] a[&quot;COL2&quot;...
<python><json><pandas><dataframe>
2022-12-23 11:48:43
2
2,350
dingaro
74,899,260
6,346,482
Don't make a second level when aggregating in Pandas
<p>Indexes and levels in Pandas still drive me nuts when using it. My dataframe structure looks like that:</p> <pre><code>Indexstruktur Datensatz Workload Selectivity Dimensionen Anzahl Datenpunkte Operation Measure Wert </code></pre> <p>I now group by all columns except the last one (&quot;Wert&q...
<python><pandas><multi-index>
2022-12-23 11:44:18
1
804
Hemmelig
74,899,104
2,444,023
How to get a convolution of 3 or more continuous PDFs to obtain the average of the PDFs in Python and or R
<p>Say I have three random variables. I would like to do a convolution to obtain the <strong>average</strong>. How do I do this in Python and or R?</p> <h3>Edit 1</h3> <p>Also. It seems the default behavior is to have the convolution size larger than any of the inputs. I will assume that all of the inputs are the same ...
<python><r><statistics><probability><convolution>
2022-12-23 11:26:10
1
2,838
Alex
74,899,068
7,333,766
Is is considered bad code practice to put code into __init__.py?
<p>Most of the __ init__.py of a project I work on (python 3.7) are empty but some have code in it.</p> <p>I am in charge of refactoring.</p> <p>Should I move the code out of the __ init__.pys as much as possible ?</p>
<python><python-3.x>
2022-12-23 11:21:02
0
2,215
Eli O.
74,898,922
5,362,515
Exception handling in Python asyncio code
<p>I am running the following example:</p> <pre class="lang-py prettyprint-override"><code>import asyncio async def longwait(n): print('doing long wait') await asyncio.sleep(n) async def main(): long_task = asyncio.create_task(longwait(10)) try: result = await asyncio.wait_for(asyncio.shield...
<python><python-asyncio>
2022-12-23 11:04:14
1
327
mayankkaizen
74,898,806
4,290,315
Warning: MariaDB version ['8.0', '31'] is less than 10.6 which is not supported by Frappe
<p>I am trying to create a new site bench new-site library.test</p> <pre class="lang-none prettyprint-override"><code>Warning: MariaDB version ['8.0', '31'] is less than 10.6 which is not supported by Frappe Installing frappe... Updating DocTypes for frappe : [===== ] 12%Syntax...
<python><mariadb><frappe>
2022-12-23 10:51:32
1
606
ketan pradhan
74,898,775
19,155,645
pandas: plot .value_counts() of same column from two different dataframes
<p>I have two dataframes with same columns (different values, important for me not to combine the two).</p> <p>I would like to make a bar plot of the <code>.value_counts()</code> of the same column for these dataframes (e.g. column 'A' in dataframe1 will be green, and column 'A' in dataframe2 will be blue).</p> <p>of c...
<python><pandas><matplotlib>
2022-12-23 10:48:14
1
512
ArieAI
74,898,759
15,178,267
Django: how to write a conditional statement to check if a post status was changes from live to cancel in django?
<p>i want to write a condition that would show a warning message when a user try to change the status of a an object to <strong>cancel</strong> that already have a <strong>participant</strong> in the object. The conditional statement seems not to be working.</p> <pre><code> class PredictionUpdate(ProductInline, UpdateV...
<python><django>
2022-12-23 10:46:26
2
851
Destiny Franks
74,898,743
18,749,472
Django session variables not saving when back button clicked
<p>On my page i am trying to implement a recently viewed section on my home page. The problem is when I append a new item to request.session[&quot;recently-viewed&quot;], the item i just viewed gets deleted from the list when i load a new page.</p> <p>The item view is a page which displays the details about a specific ...
<python><django><session><session-variables><django-sessions>
2022-12-23 10:43:53
1
639
logan_9997
74,898,631
17,491,224
Cannot load table object with sqlalchemy asyncio
<p>I am attempting to load a table using sqlalchemy asyncio. The synchronous way I would run it is as follows:</p> <pre><code>connect_string = 'db_handle://user:password@db_address:port/database' # where db_handle is postgressql+psycopg2 engine = create_engine(connect_string) table = Table(table, metadata, autoload=Tr...
<python><asynchronous><sqlalchemy>
2022-12-23 10:31:42
1
518
Christina Stebbins
74,898,454
8,913,983
Calculating difference in multi index pandas data frame
<p>I have a <code>df</code>:</p> <pre><code>df_test = sns.load_dataset(&quot;flights&quot;) df_test['cat_2'] = np.random.choice(range(10), df_test.shape[0]) df_test.pivot_table(index='month', columns='year', values=['passengers', 'cat_2'])\ .swaple...
<python><pandas>
2022-12-23 10:11:01
1
4,870
Jonas Palačionis
74,898,227
8,070,090
Can I using Google Sheet API only with API Key or using Client ID and Client secret, but without client_secret.json?
<p>In this provided Python code in this <a href="https://developers.google.com/sheets/api/quickstart/python#configure_the_sample" rel="nofollow noreferrer">quickstart</a>, it using <strong>credentials.json</strong> such in this line:</p> <pre><code>flow = InstalledAppFlow.from_client_secrets_file('credentials.json', SC...
<python><google-api><google-oauth><google-sheets-api>
2022-12-23 09:46:19
2
3,109
Tri
74,897,874
257,299
FastAPI + uvicorn: Is it possible to accept multiple connections with a single worker?
<p>Here is some sample code to demonstrate the issue:</p> <pre class="lang-py prettyprint-override"><code>import asyncio import datetime import time import uvicorn from fastapi import FastAPI from starlette.responses import PlainTextResponse app = FastAPI() @app.get(path=&quot;/sync&quot;) def get_sync(): print...
<python><asynchronous><async-await><fastapi><uvicorn>
2022-12-23 09:01:25
1
21,609
kevinarpe
74,897,789
9,476,917
Concat List of DataFrames row-wise - throws pandas.errors.InvalidIndexError:
<p>I am trying to concatenate a list <code>df_l</code> of ~200 Dataframes, which all have the same number of columns and names.</p> <p>When I try to run:</p> <p><code>df = pd.concat(df_l, axis=0)</code></p> <p>it throws the error:</p> <blockquote> <p>pandas.errors.InvalidIndexError: Reindexing only valid with uniquely ...
<python><pandas><dataframe><concatenation>
2022-12-23 08:51:43
1
755
Maeaex1
74,897,772
3,004,472
How to match names when one group is not present in RegEx
<p>I am stuck with following regex. my intention is to match following</p> <pre><code>abc_123_v1_f1_t21 12c_1sdsd_f1_t1 Android_v1_t21 </code></pre> <p>regex i am trying is</p> <pre><code>_(v[1-9]{1,3}\d?_f[1-9]{1,3}\d?_t[1-9]{1,3}\d?)(?!\d) </code></pre> <p>I am not able to get regex match if my names doesn't con...
<python><regex>
2022-12-23 08:49:53
2
880
BigD
74,897,769
20,793,070
Display exponential values as float in Polars
<p>I have some float columns in Polars df. Some values displays like <code>9.4036e15</code>. How I can display it with normal digital view?</p>
<python><dataframe><python-polars>
2022-12-23 08:49:10
1
433
Jahspear
74,897,725
3,131,604
Tensorflow 2 graph mode - For loop in a model train_step() function?
<p>I am struggling to make a loop work in a model train_step() function in graph mode.</p> <p>=====&gt; Please jump directly to UPDATE below</p> <p>The following snippet, which works in eager mode but not in graph mode, is not my train_step() code but if someone could explain how to make it work when the decorator is ...
<python><tensorflow2.0><eager-execution>
2022-12-23 08:41:54
2
7,433
u2gilles
74,897,712
13,647,125
How to make dictionary from list
<p>I have this variables:</p> <pre><code>fab_centrum = ['A', 'B'] sales_line = ['1AA', '2BB', '3CC', '1AA', '2BB', '3CC'] keys = ['feasibility_score', 'capacity_score'] feasibility_score = [10,30,40, 10,30,40] capacity_score = [50,60,70, 50,60,70] </code></pre> <p>And I would like to make dic with this structure</p> <...
<python><loops><dictionary>
2022-12-23 08:40:20
1
755
onhalu
74,897,669
1,354,400
pytype is not recognizing int or float output type as Number
<p>I have a function that returns a number but it's not obvious what the user enters. It could accept a str, int or float. So I've type-hinted it as follows:</p> <pre class="lang-py prettyprint-override"><code>from numbers import Number def to_number(value: Union[str, Number]) -&gt; Number: if isinstance(value, N...
<python><python-typing><pytype>
2022-12-23 08:34:11
0
902
Syafiq Kamarul Azman
74,897,649
13,546,726
Mapping for entering values ​into a dataframe using a dictionary
<p>I have a dictionary that looks like this: {1:&quot;A&quot;, 2:&quot;B&quot;, 3:&quot;C&quot;}</p> <p>And dataframe:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th style="text-align: left;">col_1</th> <th style="text-align: center;">col_2</th> </tr> </thead> <tbody> <tr> <td style="text-...
<python><pandas>
2022-12-23 08:32:06
2
309
Sam324
74,897,630
12,631,415
Maya 2022 crashes while i run a python script
<p>I am trying to create a menu, a submenu and an optionBox which lets the submenu item to create and remove itself from main menu. when I continuously try to add and remove the item from the main menu maya crashes with the message</p> <blockquote> <p>Fatal Error. Attempting to save in &quot;{temp location}&quot;.ma</p...
<python><maya><pymel><maya-api>
2022-12-23 08:30:09
1
381
aNup
74,897,486
1,926,852
How to resolve Pandas Read csv not working for Mock S3?
<p>I created a mock s3 bucket with moto. I put an object into it. I am trying to read with pandas read_csv.</p> <pre><code>S3_BUCKET_NAME = 'mock_bucket' def s3_bucket(): mocks3 = mock_s3() mocks3.start() os.environ[&quot;AWS_DEFAULT_REGION&quot;] = &quot;us-east-1&quot; s3 = boto3.resource('s3') s3...
<python><pandas><unit-testing><mocking><moto>
2022-12-23 08:12:58
0
602
Luv
74,897,395
8,924,587
AsyncIO: AttributeError: Can't pickle local object
<p>I am working on code that accesses an api that's not made using asyncio along with a discord bot that uses asyncio. In my dsicord commands I created local functions with the blocking parts of the api and want to run them with <code>BaseEventLoop.run_in_executer</code> with a <code>ProcessPoolExecutor</code> object.<...
<python><multiprocessing><python-asyncio><pickle>
2022-12-23 08:00:57
1
339
Hein Gertenbach
74,897,362
11,332,693
Removing inverted commas and brackets from python dataframe column items
<p>df1</p> <pre><code> Place Actor ['new york','washington'] ['chris evans','John'] ['new york','los angeles'] ['kate','lopez'] </code></pre> <p>I want to remove brackets and inverted commas from each column items:</p> <p>Expected output:</p> <p>df1</p> <pre><code...
<python><pandas><string><text><split>
2022-12-23 07:56:23
1
417
AB14
74,897,316
11,693,768
Split dataframe into multiple dataframe where each frame contains only rows and columns where that data isn't missing
<p>I have the following dataframe called <code>v</code>.</p> <pre><code> date x1 x2 x3 x4 x5 dname 1 20200705 8119 8013 8133 8031 100806 D1 2 20200706 8031 7950 8271 8200 443809 D1 3 20200707 8200 8188 8281 8217 303151 D1 4 20...
<python><pandas><dataframe>
2022-12-23 07:50:21
1
5,234
anarchy
74,897,222
3,423,825
How to set different permissions for GET and POST methods with ListCreateAPIView?
<p>I would like to set <code>IsAuthenticated</code> permission for <code>GET</code> and <code>IsTeamLeader</code> permission for <code>POST</code> with <code>ListCreateAPIView</code> and <code>ModelSerializer</code>, but without having a unique permission that check the request method in <code>has_permission</code>, as...
<python><django><django-rest-framework>
2022-12-23 07:37:56
1
1,948
Florent
74,897,182
13,454,049
Python equality if variables can be NaN
<p>Is there a better way to compare variables if they can be NaN? Surely there must be something built-in for this, right?</p> <pre class="lang-py prettyprint-override"><code>NaN = float(&quot;NaN&quot;) def remove(obj, value_1): for key in reversed([ i for i, value_2 in enumerate(obj) if ...
<python>
2022-12-23 07:32:22
1
1,205
Nice Zombies
74,897,149
16,223,122
typing recursive function with nested type
<p>background: solving some algorithm problem</p> <h2>Problem</h2> <p>I'm trying to use a recursive function with nested type in VSCode, and it keep throwing error to me. I reduced it to this</p> <pre class="lang-py prettyprint-override"><code>from typing import Type NestedStr = list[str | Type[&quot;NestedStr&quot;]]...
<python><mypy><python-typing><pylance>
2022-12-23 07:28:30
2
1,453
Pablo LION
74,897,123
11,622,114
Get last and first n elements of a list
<p>Need an answer where numbers to leave from the start and end can easily be adjusted. Thanks.</p> <p>This is my code:</p> <pre><code>ls = [1,2,3,4,5,6] # desired output: [1,2,5,6] #Tried the following: ls[-2:2:1] ls[2:4:-1] # Both return empty list </code></pre>
<python><list>
2022-12-23 07:25:28
6
522
Sumant Agnihotri