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,965,506
19,214,678
How to specify url in sqlalchemy?
<p>I am trying to link a database table to a python class using <code>sqlalchemy</code>, and when creating the engine I am getting an error on the URL:</p> <pre><code># Creating the declarative base class Base = declarative_base() class State(Base): &quot;&quot;&quot;Class that links to the states table of the hbt...
<python><sql><sqlalchemy>
2022-12-30 20:18:47
1
349
Leuel Asfaw
74,965,445
4,796,942
Conditionally format cell to end with one of 2 strings using pygsheets
<p>I am using pygsheets and have a column that I'd like to conditionally format so that its either a string ending in &quot;@gmail.com&quot; or a string ending in &quot;@yahoo.com&quot;.</p> <p>It seems to work for one but I am not sure how to extend this to 2 conditions.</p> <p>I went through these resources and could...
<python><google-sheets><google-sheets-api><conditional-formatting><pygsheets>
2022-12-30 20:07:42
1
1,587
user4933
74,965,372
8,025,793
Pyspark map function behaving unexpectedly with given method
<p>I have written a class to add values from a 2D list based on an ID column.</p> <p>The class works just fine when called normally, and the merge function works as intended. However, when handed to the map function of an Pyspark rdd pipline the result errors whenever I call collect or try and apply the reduce function...
<python><dictionary><pyspark><mapreduce>
2022-12-30 19:58:16
0
388
Parzavil
74,965,310
209,920
What are best practices for adding initial configuration data to a Python Django instance?
<p>I have a Django application that has a <code>Setting</code> model. I've manually added the configuration data to the database through the Django Admin UI/Django Console but I want to package up this data and have it automatically created when an individual creates/upgrades an instance of this app. What are some of t...
<python><json><django><migration><data-migration>
2022-12-30 19:50:53
3
4,452
Dave Mackey
74,965,265
17,975,829
How to create a Gunicorn custom application with Click commands?
<p>I am trying to build a custom application using <code>gunicorn</code> server with <code>flask</code> framework utilizing <code>click</code> commands. I used the class <code>App</code> to create an application that has the command <code>say_hello</code> which outputs <code>Hello</code> to the terminal:</p> <pre><code...
<python><gunicorn><python-click>
2022-12-30 19:43:25
1
360
loaded_dypper
74,965,228
12,323,468
Calculate all possible combinations of column totals using pyspark.pandas
<p>I have the following code which takes columns in my pandas df and calculates all combination of totals minus duplicates:</p> <pre><code>import itertools as it import pandas as pd df = pd.DataFrame({'a': [3,4,5,6,3], 'b': [5,7,1,0,5], 'c':[3,4,2,1,3], 'd':[2,0,1,5,9]}) orig_cols = df.columns for r in range(2, df.sha...
<python><pandas><pyspark>
2022-12-30 19:37:06
1
329
jack homareau
74,964,957
12,860,924
How to use SVM classifier with keras CNN model?
<p>I am working on predicting seizure epilepsy using CNN. I have 2 classes in my dataset. I want to use CNN model as a feature extractor, then I want to use SVM as a classifier. I don't know how to do this with my model.</p> <p>I am using <code>mode.fit_generator</code> in my model and I don't have x and y because I us...
<python><tensorflow><machine-learning><keras><svm>
2022-12-30 19:01:17
0
685
Eda
74,964,902
6,843,153
how to make python argparse to accept not declared argument
<p>I have a script that receives online arguments using <code>argparse</code>, like this:</p> <pre><code>parser = argparse.ArgumentParser() parser.add_argument( &quot;--local&quot;, action=&quot;store_true&quot;, help=(&quot;Write outputs to local disk.&quot;) ) parser.add_argument( &quot;--swe&quot;, action=&...
<python><argparse>
2022-12-30 18:53:42
0
5,505
HuLu ViCa
74,964,835
2,084,503
Can I see library versions for a google cloud function?
<p>I've got a cloud function I deployed a while ago. It's running fine, but some of its dependent libraries were updated, and I didn't specify <code>==</code> in the <code>requirements.txt</code>, so now when I try to deploy again <code>pip</code> can't resolve dependencies. I'd like to know which specific versions my ...
<python><google-cloud-platform><google-cloud-functions>
2022-12-30 18:43:56
2
1,266
Pavel Komarov
74,964,779
1,547,004
How do I read extended annotations from Annotated?
<p><a href="https://peps.python.org/pep-0593/" rel="nofollow noreferrer">PEP 593</a> added extended annotations via <code>Annotated</code>.</p> <p>But neither the PEP nor the documentation for <code>Annotated</code> describes how we're supposed to access the underlying annotations. How are we supposed to read the extra...
<python><python-typing>
2022-12-30 18:37:29
1
37,968
Brendan Abel
74,964,769
10,128,864
How to Capture The OAuth Redirect to POST A Response
<p>So my colleague and I have an application whereby we need to capture the OAuth Redirect from Google's OAuth Server Response, the reason being is we need to send a payload to capture to renew our pickle token, and we need to do it without human intervention. The code looks like this:</p> <pre class="lang-py prettypri...
<python><python-3.x><google-oauth><gmail-api><google-api-python-client>
2022-12-30 18:36:20
1
869
R. Barrett
74,964,740
7,446,564
List of lists: how to delete all lists that contain certain values?
<p>There's a list of lists (or it could be tuple of tuples). For example:</p> <pre class="lang-py prettyprint-override"><code>my_list = [ ['A', 7462], ['B', 8361], ['C', 3713], ] </code></pre> <p>What would be the most efficient way to filter out all lists that have a value <code>'B'</code> in them, considering t...
<python><list>
2022-12-30 18:32:41
2
447
Lev Slinsen
74,964,724
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-30 18:30:14
2
7,882
elksie5000
74,964,698
21,115
Print SQL generated by SQLObject
<pre class="lang-py prettyprint-override"><code>from sqlobject import * class Data(SQLObject): ts = TimeCol() val = FloatCol() Data.select().count() </code></pre> <p>Fails with:</p> <pre><code>AttributeError: No connection has been defined for this thread or process </code></pre> <p>How do I get the SQL which...
<python><sqlobject>
2022-12-30 18:25:33
1
18,140
davetapley
74,964,655
773,389
pandas performance warning that can't get rid of
<p>I have a panda dataframe df with a column name 'C'. I am creating 280 duplicate columns added to the same dataframe with names of 1 ... 280 as follows:</p> <pre><code>for l in range(1,281): df[str[l]] = df['C'] </code></pre> <p>I haven't figured out how to do this operation more efficiently, however, this operat...
<python><pandas><dataframe>
2022-12-30 18:20:22
1
1,843
afshin
74,964,649
8,372,455
print time every n seconds using datetime and % operator
<p>How do I print the time every 10 seconds based off of using the % operator and the datetime package? This only prints once...</p> <pre><code>from datetime import datetime, timezone, timedelta import time now_utc = datetime.now(timezone.utc) while True: if (now_utc - datetime.now(timezone.utc)).total_seconds() ...
<python><datetime>
2022-12-30 18:19:34
1
3,564
bbartling
74,964,490
16,009,435
display byte format jpeg in img
<p>I have a byte format jpeg that I get from python that looks like this <code>b'\xff\xd8\xff\xe0\x00\x10JFIF\x00\x01\x01\...'</code>. How can I display that inside an HTML <code>img</code> tag? Any help is appreciated. Thanks in advance.</p>
<python><html>
2022-12-30 18:01:22
2
1,387
seriously
74,964,423
2,653,179
Python: Method in subclasses that has different assignments
<p>I have a method <code>run()</code> in subclasses, which has an API POST request in each subclass, gets data from the POST request, and assigns an ID from this data to <code>self._id</code>. Now I would like to get a description too. However, description is returned only in the API request <code>self._api_obj.trigger...
<python>
2022-12-30 17:53:24
1
423
user2653179
74,964,404
7,028,973
Is it possible to mock a module and all it's submodules in pytest at once?
<p>I am trying to mock a module in pytest and have a lot of functions from that module imported like so:</p> <pre><code>from common.util import funct1, funct2, funct3 from common.shared.utils import some_funct from common.public.utils import some_other_funct </code></pre> <p>So far I have been using</p> <pre><code>sys....
<python><mocking><pytest>
2022-12-30 17:51:05
0
334
Jayleen
74,964,388
7,317,408
groupby and mean returning NaN
<p>I am trying to use groupby to group by symbol and return the average of prior high volume days using pandas.</p> <p>I create my data:</p> <pre><code>import pandas as pd import numpy as np df = pd.DataFrame({ &quot;date&quot;: ['2022-01-01', '2022-01-02', '2022-01-03', '2022-01-04', '2022-01-05', '2022-01-06'], ...
<python><pandas><numpy>
2022-12-30 17:48:33
3
3,436
a7dc
74,964,361
7,984,318
pandas df.to_sql if column value exits replace or update row
<p>I'm using pandas df.to_sql to inserting rows to postgresql database.</p> <pre><code>df.to_sql('example_table', engine, if_exists='replace',index=False) </code></pre> <p>example_table has 3 columns :'id' ,'name' ,'datetime'</p> <p>I want to add a checking logic before inserting ,that if the datetime is already exits ...
<python><pandas><postgresql><pandas-to-sql>
2022-12-30 17:44:58
2
4,094
William
74,964,334
8,534,089
Google Analytics API authentication failure using JWT
<p>I want to connect to Google Analytics Reporting API to fetch data, For which I have been provided with details of the service account in JSON format which contains details like (type, project_id, client_email, client_id, private_key,client_x509_cert_url, auth_provider_x509_cert_url)</p> <p>Using this JSON file I am ...
<python><oauth><jwt><google-analytics-api><service-accounts>
2022-12-30 17:40:32
0
907
Vikas J
74,963,990
18,694,400
different behavior for dict and list in match/case (check if it is empty or not)
<p>I know there are other ways to check if <code>dict</code> is empty or not using <code>match/case</code> (for example, <code>dict(data) if len(data) == 0</code>), but I can't understand why python give different answers for <code>list</code> and <code>dict</code> types while we check for emptiness</p> <pre><code>data...
<python><pattern-matching>
2022-12-30 16:59:42
2
2,404
MoRe
74,963,987
6,552,666
How to add inputs to a redirect after form?
<p>I have a form that, upon submitting, I want to process, and then redirect the user to a validation page.</p> <pre><code>if request.method == 'POST': form_validation_list = [] for key in request.form: processed_field = process_somehow(request, key) form_validation_list.append(processed_field) ...
<python><flask><jinja2>
2022-12-30 16:58:55
1
673
Frank Harris
74,963,767
14,901,271
how to automated my selenium web scrapper?
<p>I was able to write a script to scrape using selenium, right now I'm trying to automate it so it can work periodically on a server so I don't bother myself by running it from my local, I did a lot of googling but I got no clue of how I can do that, can anyone simplify things for me ..</p>
<python><selenium><automation>
2022-12-30 16:33:44
3
322
Omar Hossam
74,963,750
5,568,409
Seaborn pairplot warning not understandable
<p>I give a small example to make the question clearer:</p> <pre><code>import pandas as pd import seaborn as sns df = pd.DataFrame( [ [28, 72, 12], [28, 17, 25], [54, 15, 45], [30, 57, 28] ], columns = [&quot;x&quot;, &quot;y&quot;, &quot;z...
<python><seaborn><warnings><pairplot>
2022-12-30 16:31:53
1
1,216
Andrew
74,963,650
205,147
Christofides TSP; let start and end node be those that are the farthest apart
<p>I'm using Christofides algorithm to calculate a solution for a Traveling Salesman Problem. The implementation is the one integrated in <code>networkx</code> library for Python.</p> <p>The algorithm accepts an undirected networkx graph and returns a list of nodes in the order of the TSP solution. I'm not sure if I un...
<python><networkx><traveling-salesman>
2022-12-30 16:20:04
1
2,229
Hendrik Wiese
74,963,539
8,372,455
Modbus client script read a sensor value
<p>I have a Modbus server setup on a LAN with IP address 192.168.0.111 and Modbus map is this snip below where I am trying read the sensor highlighted yellow:</p> <p><a href="https://i.sstatic.net/8Axqh.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/8Axqh.png" alt="enter image description here" /></a></...
<python><modbus><pymodbus>
2022-12-30 16:06:20
1
3,564
bbartling
74,963,435
8,885,812
Draw a grid of cells using Matplotlib
<p>I'm trying to draw a grid of cells using Matplotlib where each border (top, right, bottom, left) of a cell can have a different width (random number between 1 and 5). I should note also that the width and height of the inner area of a cell (white part) can vary between 15 and 20.</p> <p><a href="https://i.sstatic.ne...
<python><matplotlib>
2022-12-30 15:54:55
1
353
mrkasri
74,963,326
3,247,006
How to retry when exception occurs in Django Admin?
<p>I want to retry if exception occurs in <strong>Django Admin</strong>:</p> <ol> <li>When trying to add data:</li> </ol> <p><a href="https://i.sstatic.net/rh12e.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/rh12e.png" alt="enter image description here" /></a></p> <ol start="2"> <li>When trying to chan...
<python><django><exception><django-admin><django-admin-actions>
2022-12-30 15:43:50
1
42,516
Super Kai - Kazuya Ito
74,963,246
13,100,938
Using serial ports over bluetooth with micro bit
<p>I have correctly got a microbit working with serial communication via COM port USB.</p> <p>My aim is to use COM over bluetooth to do the same.</p> <p><strong>Steps I have taken:</strong></p> <ol> <li><em>(on windows 10)</em> bluetooth settings -&gt; more bluetooth settings -&gt; COM ports -&gt; add -&gt; incoming</l...
<python><bluetooth><serial-port><bbc-microbit><spp>
2022-12-30 15:34:28
2
2,023
Joe Moore
74,963,218
4,495,790
Create Pandas date column from fix starting date and offset days as integer colum
<p>I have the following one-column Pandas data frame:</p> <pre><code>num_days -------- 9236 9601 9636 10454 </code></pre> <p>Here the integers are number of days counted from a constant predefined date:</p> <pre><code>START_DATE = pd.to_datetime('1980-01-01') </code></pre> <p>Now I want to have a column with dates (cal...
<python><pandas><datetime>
2022-12-30 15:31:20
1
459
Fredrik
74,963,200
1,625,545
Add a legend that covers the lines of the twinx axis
<p>I have this python code.</p> <ol> <li>it twinx the axis <code>ax</code> and plots some function on both axis</li> <li>I plot the legend on <code>ax1</code></li> </ol> <p>The problem is that the legend is not covering the curves of <code>ax2</code></p> <p>It is possible to <strong>automatically positioning</strong> t...
<python><matplotlib><legend><twinx>
2022-12-30 15:29:47
3
720
Giggi
74,963,146
9,064,356
PySpark `monotonically_increasing_id()` returns 0 for each row
<p>This code</p> <pre><code>def foobar(df): return ( df.withColumn(&quot;id&quot;, monotonically_increasing_id()) .withColumn(&quot;foo&quot;, lit(&quot;bar&quot;)) .withColumn(&quot;bar&quot;, lit(&quot;foo&quot;)) ) somedf = foobar(somedf) somedf.show() # &lt;-- each `id` has value 0 ...
<python><amazon-web-services><apache-spark><pyspark><amazon-emr>
2022-12-30 15:24:48
1
961
hdw3
74,963,097
9,138,097
How to get the key/value from python dict into requests for get method
<p>I'm trying to get the specific values from dict and use in the requests module to make the get requests.</p> <pre><code>clusters = { 'cluster_1':'https://cluster_1.something.com/api', 'cluster_2':'https://cluster_2.something.com/api' } </code></pre> <p>Code:</p> <pre><code>def getCsv(): for i in clusters...
<python><python-3.x><pandas><csv><request>
2022-12-30 15:19:41
1
811
Aziz Zoaib
74,962,935
1,112,283
Menu font too large in PySide6 app on Windows
<p>The font size of menus and menu entries in a PySide6 app on Windows is way too large when scaling is greater than 100%. I have it set to 150% (on a 4K monitor) and it looks like this:</p> <p><a href="https://i.sstatic.net/sMpp4.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/sMpp4.png" alt="enter imag...
<python><windows><qt><pyside6>
2022-12-30 15:04:17
1
1,821
cbrnr
74,962,856
859,227
Join data frames and reset a column
<p>For the data frames like</p> <pre><code> ID Name Time 0 0 A 100 1 1 B 70 ID Name Time 0 0 C 40 1 1 D 90 </code></pre> <p>I want to join them by rows and reset the <code>ID</code> numbers. So the final data frame should be</p> <pre><code> ID Name Time 0 0 A 100 1 1 ...
<python><pandas><dataframe>
2022-12-30 14:55:59
4
25,175
mahmood
74,962,733
17,795,398
Python: tkinter doubles tkinter.Entry.insert
<p>I have this 'simple' code</p> <pre><code>import tkinter as tk from tkinter import ttk import datetime class Page(tk.Frame): def __init__(self, root): # Set up super().__init__(root) # Labels self.labels = {} # Buttons self.buttons = {} # Entries...
<python><tkinter>
2022-12-30 14:42:38
1
472
Abel Gutiérrez
74,962,688
2,482,149
Python - Reset BytesIO So Next File Isn't Appended
<p>I'm having a problem with <code>BytesIO</code> library in Python. I want to convert a pdf file that I have retrieved from an S3 bucket, and convert it into a dataframe using a custom function <code>convert_bytes_to_df</code>. The first pdf file is fine to convert to a csv, however subsequent csvs look like they have...
<python><amazon-s3><boto3><bytesio><pdfplumber>
2022-12-30 14:38:18
1
1,226
clattenburg cake
74,962,306
12,275,675
Removing index which is not common between 2 dataframes
<p>I have the following code:</p> <pre><code>import pandas.util.testing as testing df = testing.makeDataFrame() df </code></pre> <p>This this I have created 2 dataframes with one dataframe have 2 less lines than the original one.</p> <p>This is <code>df</code> - Original</p> <pre><code>A B C D OdhGFPa5Kw -0.6863...
<python><python-3.x><pandas><dataframe>
2022-12-30 13:54:15
1
1,220
Slartibartfast
74,962,204
5,134,203
Print text of regex'd/replaced element
<p>I am using beautifulsoup and python and I am trying to get the text of a traversed td like below:</p> <pre><code>&lt;tr&gt; &lt;td class=&quot;labelplain&quot;&gt;&amp;nbsp;Long Title&lt;/td&gt; &lt;td&gt;&lt;table width=&quot;100%&quot; border=&quot;0&quot; cellspacing=&quot;2&q...
<python><beautifulsoup>
2022-12-30 13:42:47
1
435
schnydszch
74,961,896
4,752,223
Python Jupyter/Notebook: How to display a variable as text on a cell without copy/paste
<p>It happens to me that when reading/reviewing the code, I becomes easier if I can see the 'look' of the variable a function is processing.</p> <p>For that, I'd like to display a 'static' version of an instance of that variable (as a visual aid).</p> <p>That variable may not be there on another run of the notebook, th...
<python><jupyter-notebook><jupyter><jupyter-lab>
2022-12-30 13:07:28
1
2,928
Rub
74,961,882
648,138
Multithreading in place of multiprocessing with celery
<p>I am a little frustrated with <a href="https://docs.celeryq.dev/en/stable/index.html" rel="nofollow noreferrer">celery documentation</a>. I understand that the command</p> <pre><code>celery -A my-module worker -l INFO -n w1 </code></pre> <p>starts a worker instance named <code>w1</code>. This means that the worker i...
<python><multithreading><multiprocessing><celery><distributed-computing>
2022-12-30 13:04:59
0
23,414
Suhail Gupta
74,961,814
4,418,481
Create multilevel Dask dataframe from multiple parquet files
<p>I have a folder with around 500 CSV files. Each parquet file was created by saving a test result that looks as follows (time series of multiple variables where each file might contain around 50,000 rows).</p> <p><a href="https://i.sstatic.net/dlZHC.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/dlZHC...
<python><pandas><dask>
2022-12-30 12:57:41
0
1,859
Ben
74,961,706
3,578,468
Label Studio: Access file specified in task record
<p>I am trying to implement a pre-labeler for Label Studio. The documentation (e.g. <a href="https://labelstud.io/guide/ml_create.html#Example-inference-call" rel="nofollow noreferrer">https://labelstud.io/guide/ml_create.html#Example-inference-call</a>) is not very helpful here. I have imported images locally and need...
<python><machine-learning><data-annotations><label-studio>
2022-12-30 12:44:03
2
3,954
lo tolmencre
74,961,668
11,558,143
How to monitor subprocess's stdout in real time
<p>I have a subprocess that generate images. A main programe will consume images.</p> <p>My plan is to launch subprocess, monitor it. Once there are several images available <em>(i.e. subprocess printed '2' or '3')</em>, I will start main programe.</p> <p>However, I fail to get 'real-time' output from subprocess. Every...
<python><subprocess><stdout>
2022-12-30 12:40:53
1
1,462
zheyuanWang
74,961,598
3,991,164
Why is VSCode Python debugger slowing down execution by a factor of 5
<p>I run a Python 3.10 script that analyzes some 350 SQL files using the <code>sqlparse</code> module. When I run this via &quot;Run Python File&quot; in VSCode 1.73.1 it takes about 4 seconds. When I run it via &quot;Debug Python File&quot;, it takes roughly 5 times as long.</p> <p>The final analysis will run on a set...
<python><python-3.x><visual-studio-code><vscode-debugger>
2022-12-30 12:34:03
0
4,235
flaschbier
74,961,567
20,646,427
How to get username and user email in my form Django
<p>I have &quot;creating order form&quot; which is need email and username to purchase. I want to push request username and user email into this form (if user is authorized)</p> <p>forms.py</p> <pre><code>class OrderCreateForm(forms.ModelForm): username = forms.CharField(label='Имя пользователя', widget=forms.TextI...
<python><django>
2022-12-30 12:29:59
1
524
Zesshi
74,961,555
12,368,148
How to recieve and parse data coming from a Python socket server in dart?
<p>I have a socket server running in Python that sends a byte stream through the socket in which, the first 8 bytes contain the size of the remaining message body. The code looks something like this:</p> <pre><code> data_to_send = struct.pack(&quot;Q&quot;, len(pickle_dump))+pickle_dump client_socket.sendal...
<python><flutter><dart><sockets><bytestream>
2022-12-30 12:28:55
1
532
Broteen Das
74,961,435
1,127,683
Python3 idiomatic way to dispatch method call on abstract base classes
<p>I'm using <code>Python 3.10.5</code>.</p> <p>I've got the following class which is designed to:</p> <ul> <li>receive an object</li> <li>lookup which class should handle the request</li> <li>invoke a method on that class that has been looked up</li> </ul> <p>What I have so far:</p> <pre class="lang-py prettyprint-ove...
<python>
2022-12-30 12:16:04
1
3,662
GreenyMcDuff
74,961,262
11,648,332
How can I scale an image with PIL without ruining its appearence?
<p>I noticed that simply multiplying and dividing an array even for coefficents equivalent to 1, will deform the image.</p> <p>I need to rescale the image pixels because I need to feed them to a ML model, but I noticed there seems to be a huge loss of information in the process.</p> <p>This is the original image (an ex...
<python><python-imaging-library>
2022-12-30 11:58:03
1
447
9879ypxkj
74,961,235
2,425,753
How to use StartingToken with DynamoDB pagination scan
<p>I have a DynamoDB table and I want to output items from it to a client using pagination. I thought I'd use <a href="https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/dynamodb.html#DynamoDB.Paginator.Scan" rel="nofollow noreferrer">DynamoDB.Paginator.Scan</a> and supply <code>StartingToken</c...
<python><amazon-web-services><pagination><amazon-dynamodb><boto3>
2022-12-30 11:54:56
1
1,636
rfg
74,961,155
7,209,826
AttributeError: 'Spider' object has no attribute 'crawler' in scarpy spider
<p>In order to access settings from <code>_init_</code> i had to add <code>from_crawler @classmethod</code>. Now it appears that some functionality of scrapy framework was lost. i am getting <code>AttributeError: 'Code1Spider' object has no attribute 'crawler'</code> when url fails and spider tries to retry request. ...
<python><scrapy>
2022-12-30 11:46:58
1
1,119
JBJ
74,961,061
9,267,178
Fibonacci Sequence based question slightly changed
<p>I was recently given this question in one of my interview which I ofcourse, failed.</p> <p><a href="https://i.sstatic.net/gRUx6.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/gRUx6.png" alt="Question" /></a></p> <p>I just want to know how this will be solved. <strong>The code I tried to use was this:...
<python><python-3.x><math><fibonacci>
2022-12-30 11:34:14
2
420
Avi Thour
74,961,041
353,337
Strip tox path from pytest-cov output
<p>When using pytest and <a href="https://pypi.org/project/pytest-cov/" rel="nofollow noreferrer">pytest-cov</a> with <a href="https://tox.wiki/en/latest/" rel="nofollow noreferrer">tox</a>. My <code>tox.ini</code> is</p> <pre class="lang-ini prettyprint-override"><code>[tox] envlist = py3 [testenv] deps = pytest ...
<python><pytest><tox><pytest-cov>
2022-12-30 11:30:59
1
59,565
Nico Schlömer
74,960,844
9,138,097
How to merge the duplicates rows in pandas dataframe with python3
<p>I'm trying to merge the duplicates in the resulting .csv but unable to get the desired result.</p> <p>My below code works just fine.</p> <pre><code>def inputCsv(): r = requests.get(endpoint, headers=headers, params=params) with open(&quot;input.csv&quot;, &quot;w&quot;) as f: f.writelines(r.text.spli...
<python><python-3.x><pandas><dataframe><lambda>
2022-12-30 11:08:50
3
811
Aziz Zoaib
74,960,828
6,689,249
how to compare field value with previous one in pydantic validator?
<p>What I tried so far:</p> <pre class="lang-py prettyprint-override"><code>from pydantic import BaseModel, validator class Foo(BaseModel): a: int b: int c: int class Config: validate_assignment = True @validator(&quot;b&quot;, always=True) def validate_b(cls, v, values, field): ...
<python><pydantic>
2022-12-30 11:07:04
1
4,362
aiven
74,960,725
6,025,866
Unable to install tensorflow-text and unable to import keras_nlp
<p>I am trying out the Keras-NLP library by using one of the examples provided on the Keras website. I have installed Keras-NLP using the command <code>pip install keras-nlp</code> and Tensorflow(version = 2.9.2).</p> <p>When I run the following,</p> <pre><code>import keras_nlp import tensorflow as tf from tensorflow i...
<python><tensorflow><keras><deep-learning><nlp>
2022-12-30 10:53:59
0
441
adhok
74,960,707
11,358,740
Poetry stuck in infinite install/update
<p>My issue is that when I execute <code>poetry install</code>, <code>poetry update</code> or <code>poetry lock</code> the process keeps running indefinitely.</p> <p>I tried using the <code>-vvv</code> flag to get output of what's happening and it looks like it gets stuck forever in the first install.</p> <p>My connect...
<python><infinite><python-poetry>
2022-12-30 10:52:15
6
824
A-fandino
74,960,656
1,473,517
How to make tqdm work with a simple while loop
<p>I have this simple code (do <code>pip install primesieve</code> first):</p> <pre><code>def prob(n): it = primesieve.Iterator() p = 1 prime = it.next_prime() while prime &lt;= n: p = p * (1-1/prime) prime = it.next_prime() return p </code></pre> <p>How can I use tqdm to get a progress bar for the wh...
<python><tqdm>
2022-12-30 10:46:58
2
21,513
Simd
74,960,653
979,974
Python AttributeError: 'numpy.ndarray' object has no attribute 'append'
<p>I am trying to parse a folder with contains csv file (These csv files are pixel images position) and store them into a numpy array. When I try to perform this action, I have an error: <code>AttributeError: 'numpy.ndarray' object has no attribute 'append'</code>. I understand that NumPy arrays do not have an <code>ap...
<python><image><numpy><image-resizing>
2022-12-30 10:46:42
3
953
user979974
74,959,824
12,242,625
How to remove white borders on left/right side?
<p>I have plots, containing technical measurements which are looking like this:</p> <p><a href="https://i.sstatic.net/AkoDy.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/AkoDy.png" alt="enter image description here" /></a></p> <p>Now I want to remove everything but the content and I managed to get to t...
<python><matplotlib><seaborn>
2022-12-30 09:03:50
1
3,304
Marco_CH
74,959,760
1,826,912
Can I use the Scipy simulated annealing library to solve the traveling salesman problem?
<p>To solve the traveling salesman problem with simulated annealing, we need to start with an initial solution, a random permutation of the cities. This is the order in which the salesman is supposed to visit them. Then, we switch to a &quot;neighboring solution&quot; by swapping two cities. And then there are details ...
<python><optimization><scipy>
2022-12-30 08:56:03
0
2,711
Rohit Pandey
74,959,601
3,381,215
pip install from private repo but requirements from PyPi only installs private package
<p>Unlike <a href="https://stackoverflow.com/questions/62282049/pip-install-from-private-repo-but-requirements-from-pypi">pip install from private repo but requirements from PyPi</a> I am able to intall my package (daisy) from our private artifactory instance with:</p> <pre class="lang-bash prettyprint-override"><code>...
<python><pip><python-poetry>
2022-12-30 08:33:28
1
1,199
Freek
74,959,578
2,998,077
Python to count number of occurrence of each line, in huge text file
<p>A big text file has millions of lines, that I want to count the number of occurrence of each line (how many times the line appear in the file).</p> <p><a href="https://i.sstatic.net/7OJe9.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/7OJe9.png" alt="enter image description here" /></a></p> <p>Curren...
<python><count>
2022-12-30 08:30:51
3
9,496
Mark K
74,959,446
2,651,073
Pandas: Select top n groups
<p>Suppose I have a dataframe like</p> <pre><code>a b i1 t1 i1 t2 i2 t3 i2 t1 i2 t3 i3 t2 </code></pre> <p>I want to group df by &quot;a&quot; and then select 2 top largest group. I specifically want the number of resulting rows</p> <pre><code>a b i2 t3 i2 t1 i2 t3 i1 t1 i1 t2 </code></pre> <p>I tried:</...
<python><pandas>
2022-12-30 08:11:32
1
9,816
Ahmad
74,959,372
1,611,067
How to concatenate Boto3 filter expression?
<p>I would like to dynamically create Boto3 filter expression. My goal is to make tool to fetch easily data from DynamoDb with most used filters. I'm trying to store filter expressions in list and then combine them to one expression.</p> <p>So, if I have this list:</p> <pre><code>list_of_expressions = [ Attr(&quot;...
<python><boto3>
2022-12-30 08:01:22
2
359
RamiR
74,959,245
9,915,864
python beautifulsoup - parsing an HTML table row
<p>I'm using BeautifulSoup to parse a bunch of combined tables' rows, row by row, column by column in order to import it into Pandas. I can't use <code>to_html()</code> because one of the columns has a list of tag links in each cell. The data structure is the same in all the tables.</p> <p>I can't figure out the correc...
<python><beautifulsoup>
2022-12-30 07:43:45
1
341
Meghan M.
74,958,898
643,208
Google authentication issue: Authorized user info was not in the expected format, missing fields refresh_token
<p>I am trying to use the Python Google API, and encounter an issue when using Google's quickstart example from <a href="https://developers.google.com/people/quickstart/python#configure_the_sample" rel="nofollow noreferrer">https://developers.google.com/people/quickstart/python#configure_the_sample</a>, as-is. When I r...
<python><google-oauth>
2022-12-30 06:54:03
2
5,986
Thomas Petazzoni
74,958,699
5,132,860
How to create multilingual web pages with fastapi-babel?
<p>I'm thinking of creating a multilingual web page with <a href="https://github.com/Anbarryprojects/fastapi-babel" rel="nofollow noreferrer">fastapi-babel</a>.</p> <p>I have configured according to the <a href="https://github.com/Anbarryprojects/fastapi-babel" rel="nofollow noreferrer">documentation</a>. The translati...
<python><fastapi><gettext>
2022-12-30 06:18:22
1
3,104
Nori
74,958,587
19,475,994
Copyable scrolling text in tkinter
<p>I wanted to create a scrollable, copyable text in tkinter. This text should be immutable <em>to the user</em>, but I can change it.</p> <p>Although this seems simple, there are some ways to approach it, but there are unsatisfactory things about each approach.*</p> <ol> <li>Use a <code>state=disabled</code> <code>Tex...
<python><python-3.x><tkinter><scroll><tkinter-canvas>
2022-12-30 05:55:05
3
303
00001H
74,958,256
17,696,880
How do I put a parameter to a function whose return is inside a re.sub()?
<pre class="lang-py prettyprint-override"><code>import re def one_day_or_another_day_relative_to_a_date_func(m, type_of_date_unit_used): input_text = m.group() print(repr(input_text)) if (type_of_date_unit_used == &quot;year&quot;): a = &quot;YYYY-mm-dd&quot; elif (type_of_date_unit_used == &quot;mon...
<python><python-3.x><regex><parameters><regex-group>
2022-12-30 04:57:27
1
875
Matt095
74,958,225
9,510,800
how to apply shift to a group when there is a change in value pandas?
<p>I am currently having a dataset as below:</p> <pre><code>id name date_and_hour 1 SS 1/1/2019 00:12 1 SS 1/1/2019 00:13 1 SS 1/1/2019 00:14 1 SB 1/1/2019 00:15 1 SS 1/1/2019 00:16 2 SE 1/1/2019 01:15 2 SR 1/1/2019 01:16 2 SS 1/1/2019 01:17 2 SS 1/1/2019 01:18 </code></pre> <p>I wa...
<python><pandas><numpy>
2022-12-30 04:50:13
3
874
python_interest
74,958,039
1,769,197
Pandas: astype datetime minutes failing
<p>I am using pandas 1.5.2.</p> <p>I have a column of timestamp stored in a pandas dataframe.</p> <p><code>df['Timestamp'].astype('datetime64[Y]')</code></p> <pre><code>0 2017-07-11 09:33:14.819 1 2017-07-11 09:33:14.819 2 2017-07-11 09:33:14.819 3 2017-07-11 09:33:14.819 4 2017-07-11 09:33:14.820 ...
<python><pandas><datetime>
2022-12-30 04:09:47
1
2,253
user1769197
74,957,780
2,882,380
Sum of values from related rows in Python dataframe
<p>I have a data frame where some rows have one ID and one related ID. In the example below, <code>a1</code> and <code>a2</code> are related (say to the same person) while <code>b</code> and <code>c</code> don't have any related rows.</p> <pre><code>import pandas as pd test = pd.DataFrame( [['a1', 1, 'a2'], [...
<python><pandas><dataframe>
2022-12-30 03:00:39
1
1,231
LaTeXFan
74,957,756
6,498,757
Jupyter notebook code cell to code block convert
<p>I have a notebook that has executable code cells and I want to batch convert them into markdown version code blocks. How to do that with <code>.ipynb</code>?</p> <p>I think it need to write some complexed regex to do the conversion.</p> <p>Suppose I know the code cell has type <code>scheme</code></p> <p>Before:</p> ...
<python><json><jupyter-notebook>
2022-12-30 02:54:22
1
351
Yiffany
74,957,673
5,032,387
Extract site id and value from dropdown on webpage
<p>I'm trying to get the names that appear in the dropdown and the associated value (as it appears in the html code).</p> <p>Here's what I have so far. The result is empty so I know I'm not searching for the section properly.</p> <pre><code>from bs4 import BeautifulSoup from requests import get url = 'http://clima.ed...
<python><beautifulsoup>
2022-12-30 02:31:01
1
3,080
matsuo_basho
74,957,524
2,474,581
Tkinter: 2 buttons next to each other resize in width with window. How to?
<p>The 2 buttons should take each of the half of the window, one on the left, one on the right. The height is fixed all time. With <code>.grid()</code> nor <code>.place()</code> I can come to that result. The red bar is the color of the frame where the buttons are placed on. The buttons resize in width with the window...
<python><tkinter><tkinter-button>
2022-12-30 01:57:19
3
1,346
Kustekjé Meklootn
74,957,429
3,277,133
How to chunk dataframe into list by sum of value in column not exceeding X?
<p>I have a df that looks like this with many rows:</p> <pre><code>col1 count a 80 b 100 c 20 </code></pre> <p>I need to chunk this dataframe by sum of the count column not exceeding 100 in sum. So the chunk code create chunks of the df in the list should be like so, where each chunk is determined by th...
<python><pandas>
2022-12-30 01:32:05
1
3,707
RustyShackleford
74,957,360
8,528,141
Is current time zone detected by default if `USE_TZ=True` in Django?
<p>It is mentioned in docs that the current time zone should be activated.</p> <blockquote> <p>You should set the current time zone to the end user’s actual time zone with <code>activate()</code>. Otherwise, the default time zone is used</p> </blockquote> <p>However, I see that the values are parsed in my local timezon...
<python><django><timezone><utc><django-timezone>
2022-12-30 01:11:19
1
1,480
Yasser Mohsen
74,957,311
1,229,531
conda error on install for RAPIDS fails due to incompatible glib
<p>OS: Linux 4.18.0-193.28.1.el8_2.x86_64 anaconda: anaconda3/2022.10</p> <p>Trying to install RAPIDS, I get:</p> <pre><code>$ conda install -c rapidsai rapids Collecting package metadata (current_repodata.json): done Solving environment: failed with initial frozen solve. Retrying with flexible solve. Solving env...
<python><conda><rapids>
2022-12-30 01:00:09
2
599
Mark Bower
74,957,250
3,591,044
Extracting part of string according to tags
<p>I have a big string and would like to extract parts of the string. You can see an example below. I would extract the text corresponding to the <code>text</code> tags. So we have three text tags, namely <code>&quot;text&quot;: &quot;{{{VAR_2}}}&quot;</code>, <code>&quot;text&quot;: &quot;Tell me. How old are you?&quo...
<python><python-3.x><string><split>
2022-12-30 00:46:49
2
891
BlackHawk
74,957,244
7,475,303
Boto3 S3 Paginator not returning filtered results
<p>I'm trying to list the items in my S3 bucket from the last few months. I'm able to get results from the normal paginator (<code>page_iterator</code>), but the <code>filtered_iterator</code> isn't yielding anything when I iterate over it.</p> <p>I've been referencing the documentation <a href="https://boto3.amazonaws...
<python><amazon-web-services><amazon-s3><boto3>
2022-12-30 00:45:27
0
453
Logan Waite
74,957,143
3,520,363
Bad output with python html parsing
<p>I have an html file in C:\temp. I want to extract this text</p> <pre><code>Death - Individual Thought Patterns (1993), Progressive Death Metal http://xxxxxxx.bb/1196198 http://yyyyyyyyyyyy.com/files/153576607/d-xxx_xxx_xxx-xxxxx-xxxxx.rar Alfadog (1994), Black Metal </code></pre> <p>from this block of code</p> <pre>...
<python>
2022-12-30 00:20:15
1
380
user3520363
74,957,083
8,272,788
Outgoing messages are being dropped for client x
<p>I have a client (ESP32) running umqtt.simple, and a broker (Pi) running Paho.MQTT. The Broker sends messages to the client. The client simply subscribes - and calls some functions as part of <code>client.call_back()</code>.</p> <p>I am am using client.ping() to keep the client connection alive.</p> <p>The client wor...
<python><mqtt><paho>
2022-12-30 00:05:32
0
1,261
MorrisseyJ
74,957,025
866,082
Can I sort the items in an Apache beam PCollection using python?
<p>Can I sort the items in an Apache beam PCollection using python?</p> <p>I need to perform an operation (transformation) that relies on the items to be sorted. But so far, I cannot find any trace of a &quot;sorting&quot; mechanism for the Apache beam.</p> <p>My use case is not for live streams. I understand that it i...
<python><sorting><apache-beam>
2022-12-29 23:51:47
1
17,161
Mehran
74,957,022
7,776,559
How to install Python 3.11 in Jupyter Notebook?
<p>I've installed Jupyter Notebook from <a href="https://www.anaconda.com/products/distribution" rel="nofollow noreferrer">https://www.anaconda.com/products/distribution</a></p> <p>Unfortunately, it's default version of python 3.9, but the latest version is 3.11.</p> <p>How can I install the latest version or other ver...
<python><installation><jupyter-notebook><anaconda><version>
2022-12-29 23:50:26
2
906
MichaelRSF
74,957,011
5,032,387
Correctly refer to a button to scrape aspx webpage using requests
<p>I'm trying to extract data from an aspx site. Trying to find the name of the submit button to include in the post request, but it doesn't appear when I inspect the page.</p> <pre><code>import csv import requests form_data = { 'CalendarioDesde': '01/11/2022', 'CalendarioHasta': '28/12/2022', 'IdEstacion...
<python><web-scraping><beautifulsoup><python-requests>
2022-12-29 23:48:49
1
3,080
matsuo_basho
74,956,916
6,248,559
Sequentially cascading radiobutton forms with tkinter
<p>I'm working on creating a simple GUI for one of my codes, so that I can enter parameters without looking for the files or the lines they're defined. However, the definition is a sequential one. Up to now, I have this:</p> <pre><code>import tkinter as tk def initiation(): analysis_type = radiobutton_initial.get()...
<python><tkinter>
2022-12-29 23:27:48
1
301
A Doe
74,956,877
1,358,829
Hydra config: using another config as an input to multiple keys within a config
<p>Suppose I have the following directory structure for my hydra configs:</p> <pre><code>config |_config.yml operations |_subconfig.yml </code></pre> <p><code>subconfig.yml</code> is</p> <pre class="lang-yaml prettyprint-override"><code>param_1: foo param_2: bar </code></pre> <p>and <code>config.yml</co...
<python><config><fb-hydra>
2022-12-29 23:20:27
1
1,232
Alb
74,956,866
2,882,380
Value not updated in for loop Python
<p>I am testing the following simple example (see comments in the coding below for background). I have two questions. Thanks.</p> <ul> <li>How come <code>b</code> in <code>bottle</code> is not updated even though the for loop did calculate the right value?</li> <li>Is there an easier way to do this without using for lo...
<python><pandas><dataframe>
2022-12-29 23:17:51
2
1,231
LaTeXFan
74,956,805
2,365,595
Spotify API curl example
<p>as I'm following some tutorials, I dont see curl examples (in Authorization guide for example), I think because spotify api guide changed? Isn't possibile to find the old guide?</p> <p>Thank you</p>
<python><python-requests><spotify><webapi><spotipy>
2022-12-29 23:08:00
1
575
Aidoru
74,956,684
3,572,505
regex python single step, match in a text only brackets that contains more than two separated numbers
<p>This is to get combo references (e.g. [23,24,28-30], this bracket contain four numbers) in sci papers with vancouver notation format. I need to match brackets with more than two numbers (don't confuse with digits). Min.repr.example:</p> <p>Input raw text</p> <pre><code>blabla [23,24] bleble [23,24,28-30] blibli [40,...
<python><regex><brackets>
2022-12-29 22:44:00
1
903
José Crespo Barrios
74,956,660
5,462,551
pytest-xdist - running parametrized fixtures for parametrized tests once without blocking
<p>Consider the following example (which is a simple template of my real issue, of course):</p> <pre class="lang-py prettyprint-override"><code>import time import pytest @pytest.fixture(scope=&quot;session&quot;, params=[1, 2, 3, 4, 5]) def heavy_computation(request): print(f&quot;heavy_computation - param is {r...
<python><testing><pytest><pytest-xdist>
2022-12-29 22:40:25
1
4,161
noamgot
74,956,616
14,403,635
Python Selenium: How to select dropdown menu
<p><a href="https://i.sstatic.net/tiPH4.jpg" rel="nofollow noreferrer"><img src="https://i.sstatic.net/tiPH4.jpg" alt="enter image description here" /></a>I need to select the item - &quot;Property owner statement&quot; in dropdown menu. In the screenshot, it shows there has no unique name I can select on the ul class ...
<python><selenium><selenium-webdriver><xpath><webdriverwait>
2022-12-29 22:33:03
2
333
janicewww
74,956,538
3,277,133
How to write pandas df to snowflake from Azure databricks?
<p>I am having a hard time writing to snowflake from Azure databricks.</p> <p>I have the following code that I am trying to use to write a pandas df to a snowflake table but I keep getting that my username or password is incorrect.</p> <p>I have tried the username and password to login in on my browser and it works no ...
<python><pandas><snowflake-cloud-data-platform><azure-databricks>
2022-12-29 22:22:13
1
3,707
RustyShackleford
74,956,404
18,840,965
How to stop a PostgreSQL query if it runs longer than the some time limit with psycopg?
<p>In Python is library <code>psycopg</code> and with that I can do queries.</p> <p>I have an array with texts and I just iterate over them and run query to find this text in postgres. But some time the query takes so much time to execute and in that moment I want to stop/terminate this query and go to the next. For ex...
<python><postgresql><psycopg3>
2022-12-29 21:58:31
2
397
Dmiich
74,956,320
3,247,006
How to remove the default "Successfully deleted ..." message for "Delete Selected" in Django Admin Action?
<p>In the overridden <a href="https://docs.djangoproject.com/en/4.1/ref/contrib/admin/#django.contrib.admin.ModelAdmin.delete_queryset" rel="nofollow noreferrer">delete_queryset()</a>, I deleted loaded messages and added <strong>the new message &quot;Deleted successfully!!&quot;</strong> as shown below:</p> <pre class=...
<python><django><django-admin><django-messages><django-admin-actions>
2022-12-29 21:45:48
0
42,516
Super Kai - Kazuya Ito
74,956,140
13,067,435
How to import a python class/module in a jupyter notebook?
<p>example contrived for this question. apologize for basic question. I have following code/directory structure</p> <pre><code>src - main.py my_notebook.ipynb </code></pre> <p>main.py</p> <pre><code>class DoSomething(): pass </code></pre> <p>I have seen various questions in stackoverflow, which suggest this should...
<python><jupyter-notebook>
2022-12-29 21:19:02
1
841
arve
74,956,132
4,119,822
Using pypa's build on a python project leads to a generic "none-any.whl" wheel, but the package has OS-specific binaries (cython)
<p>I am trying to build a package for distribution which has cython code that I would like to compile into binaries before uploading to PyPI. To do this I am using pypa's <code>build</code>,</p> <p><code>python -m build</code></p> <p>in the project's root directory. This cythonizes the code and generates the binaries f...
<python><cython><setuptools><pypi><python-packaging>
2022-12-29 21:17:13
1
329
Oniow