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
⌀
77,593,017
5,029,589
Clean and Read csv file with pandas which has unwanted texts
<p>I have large number of csv files (More than 10K) and all files have unwated texts at start and end .I want to clean the csv file first and then read it . One of the example is like below (Below is a sample data ,my csv files are similar to below . I need to clean and ignore all the texts above</p> <p>Columns for re...
<python><pandas>
2023-12-03 04:18:31
2
2,174
arpit joshi
77,592,943
10,200,497
Finding the first row that meets conditions of a mask starting from nth row
<p>This is my dataframe:</p> <pre class="lang-py prettyprint-override"><code>import pandas as pd df = pd.DataFrame({'a': [20, 21, 100, 4, 100, 20], 'b': [20, 20, 20, 20, 20, 20]}) </code></pre> <p>I want to create column <code>c</code> by using a mask. This is my desired output:</p> <pre class="lang-none prettyprint-o...
<python><pandas><indexing>
2023-12-03 03:32:37
3
2,679
AmirX
77,592,875
4,398,966
Python turtle terminator error on alternating runs
<p>I have the following code running in anaconda spyder:</p> <pre><code>from turtle import * speed(0) setup(800, 700) #Blue Background penup() goto(0, -320) pendown() color(&quot;lightskyblue&quot;) begin_fill() circle(320) end_fill() done() </code></pre> <p>on the second run and every other (run 4, run 6 ...) I get ...
<python><python-turtle>
2023-12-03 02:28:55
0
15,782
DCR
77,592,795
2,205,785
How to deploy python extensions (shared libraries) with multiple architectures?
<p>Context: one can compile C code such that it can be used as a Python module. The compiled object is a shared library with a specific naming, so Python can find and load it as a module.</p> <p>Great. I have successfully compiled and tested code such that file &quot;foo.c&quot; becomes a shared library &quot;foo.so&qu...
<python><python-c-api>
2023-12-03 01:45:51
4
4,590
pbuck
77,592,555
5,938,276
Calculating time between high state
<p>In python I want calculations of high / low states of a signal in chunks of a given size (<code>samples_to_process</code>).</p> <p>The two required calculations are number index between rising edges (<code>length_between_high_states</code>) and number of index's the signal is high for (<code>high_state_length</code>...
<python><signal-processing>
2023-12-02 23:29:08
1
2,456
Al Grant
77,592,428
2,774,885
more efficient way to capture output / maybe not .communicate() from multiple python subprocesses?
<p>I've got the following block of code. <code>cmdTable</code> is a dict where the keys are strings that describe a subprocess to open (like &quot;out_From_hi_mom&quot;) and the values are the executable command (like &quot;echo hi mom&quot;)... something like:</p> <p><code>cmdTable['himom'] : &quot;echo hi there momm...
<python><subprocess>
2023-12-02 22:29:14
1
1,028
ljwobker
77,592,409
9,231,706
How to run Stockfish on AWS Lambda
<p>I am trying to run stockfish on AWS lambda.</p> <p>Here is my lambda function</p> <pre><code> import os import json from stockfish import Stockfish # The Stockfish binary is located at the root of your deployment package stockfish_path = &quot;/var/task/stockfish-ubuntu-x86-64-avx2&quot; def lambda_handler(even...
<python><stockfish>
2023-12-02 22:23:17
0
729
James
77,592,262
5,801,127
Crontab failing shell script if statement
<p>I have a shell script which executes a python program by first checking if it is running</p> <p>However, the problem is that it seems to fail the first block of the if statement. The shell script does work manually</p> <p>This is what my shell script looks like:</p> <pre><code>PATH=/opt/conda/bin:/opt/conda/condabin...
<python><linux><cron>
2023-12-02 21:33:02
1
1,011
PutsandCalls
77,592,209
8,313,547
Visual Studio code not connecting directories/references from imported packages
<p>Usually with an IDE, when the Python interpreter is set to the anaconda python.exe file, and the environment is correct, the imported packages can be easily referenced and the IDE will acknowledge them. But, I am getting no references to packages installed. The code runs, when I run the python package, but I cannot ...
<python><visual-studio-code><ide>
2023-12-02 21:16:22
1
449
mikanim
77,592,197
891,203
IntelliJ with Python plugin and project SDK virtualenv, can't find library code for browsing
<p>Using IntelliJ 2023.1.2 on MacOS 13.3.</p> <p>Created project with a Python 3.10 virtualenv SDK at project level. Then <code>pip install openai</code>. Copied simple OpenAI tutorial script into my project. It is recognized as a Python file. The script runs successfully from the command line or from an IntelliJ R...
<python><intellij-idea><virtualenv>
2023-12-02 21:13:46
1
1,658
devdanke
77,592,144
10,152,435
I am trying to seperate my python files in diffrent folders when I try to import I get error No module named 'animal'
<p>I have this file structure</p> <pre><code>- animal //this folder contains my pthon project - mamal (Folder) - dog.py //this is my dog python file - reptile (Folder) - snake.py //this is my snake python file - main.py // Is the python file that should access the mamal.py file </code></pr...
<python>
2023-12-02 20:56:35
1
772
J.C
77,592,100
1,256,347
How to show axis labels of all subplots when the labels are strings?
<h3>Problem summary</h3> <p>Whenever I try to create a plot with <a href="https://plotly.com/python/plotly-express/" rel="nofollow noreferrer">plotly express 5.18.0</a> containing a subplot <em>and</em> axes labels that are not numbers, I only get labels for the first subplot subsequent subplots show empty axis labels....
<python><plotly><facet><plotly-express>
2023-12-02 20:40:53
1
2,595
Saaru Lindestøkke
77,591,842
162,758
namespace package does not get installed as part of pip install
<p>I am working on an open source package and have it published on pypi. I am using poetry to package and publish my project. My src tree structure is as below</p> <pre><code>- src |- novi |- client | |- __init__.py |- core | |- __init__.py |- web | |- __init__.py ...
<python><pip><python-packaging><python-poetry>
2023-12-02 19:13:46
0
2,344
VDev
77,591,245
11,057,932
Why isn't __del__ called twice?
<p>I want to use an object's <code>__del__</code> method to automatically write the object data to either an external database or a local cache (a global dict), depending on certain conditions. A context manager doesn't work for me.</p> <p>However, this means that, once <code>__del__</code> is called (because the objec...
<python><destructor>
2023-12-02 16:38:36
1
1,927
David
77,591,165
951,296
Why are there so many data loss after dask.dataframe to_csv
<p>Im a newbie to Dask distribute,now I am doing a simple test to learn it and got a very strange situation, here is my code:</p> <pre class="lang-py prettyprint-override"><code>import numpy as np import pandas as pd import dask.dataframe as dd data_vol = 2000 index = pd.date_range(&quot;2021-09-01&quot;, periods=dat...
<python><dask-distributed><dask-dataframe>
2023-12-02 16:18:51
1
998
Flybywind
77,591,051
5,962,981
SqlAlchemy How to get objects from "child" class?
<p>This is the code:</p> <pre><code>from sqlalchemy.orm import declarative_base, relationship from sqlalchemy import Column, String, Integer, ForeignKey Base = declarative_base() class Parent(Base): __tablename__ = 'parents' id = Column(Integer, primary_key=True) name = Column(String(20)) ch...
<python><sqlalchemy>
2023-12-02 15:46:07
1
923
filtertips
77,590,861
4,575,197
unexpected behavior of for after using Map and Partial method
<p>I'm using Partial method to pass 2 parameters which are not iterables, thus i shouldn't use that in the <code>Map()</code> function. I'm also using ThreadPoolExecutor for I\O bound task that i have here. the problem is that inside of the <code>get_the_text_par()</code> function, i have a for loop which should go thr...
<python><pandas><dataframe><python-multithreading>
2023-12-02 14:56:35
1
10,490
Mostafa Bouzari
77,590,844
697,964
Separating empty folders from folders which only contain other folders
<p>I have a set of files and a set of folders.</p> <p>This part seems to work:</p> <pre><code>file_folders = {p.parent for p in files} no_file_folders = folders - file_folders </code></pre> <p>But this part seems to not be correct:</p> <pre><code>no_file_folders_parents = {p.parent for p in no_file_folders} folder_fold...
<python>
2023-12-02 14:50:02
1
569
jaksco
77,590,541
1,234,434
How to split string in pandas column
<p>I am new to Pandas. I have data like this:</p> <pre><code>Category Sales Paid Table 1 table Yes Chair 3chairs Yes Cushion 8 cushions Yes Table 3Tables Yes Chair 12 Chairs No Mats 12Mats Yes </code></pre> <p>I have learnt how to apply a groupby on the <c...
<python><pandas>
2023-12-02 13:26:01
1
1,033
Dan
77,590,508
1,279,000
How do I query a Flask SQLite database with SQLAlchemy outside of the Flask app url endpoints?
<p>I'm creating a Flask REST API. It's working well as an API. I've had a growing need to connect to the app's sqlite database on the side for scheduled tasks (which <a href="https://stackoverflow.com/questions/11810461/how-to-perform-periodic-task-with-flask-in-python">this post</a> could address), yet also for other ...
<python><sqlite><flask><sqlalchemy>
2023-12-02 13:16:45
1
1,278
Christopher Stevens
77,590,201
14,923,149
Issue with triangles borders in Matplotlib
<p>I am facing an issue with drawing triangle borders using Matplotlib in Python. I want to create a specific pattern, but I'm encountering unexpected behavior. I need assistance in identifying and resolving the problem.</p> <p>this is my code</p> <pre><code>import numpy as np import matplotlib.pyplot as plt N = 5 A =...
<python><python-3.x><matplotlib>
2023-12-02 11:43:11
2
504
Umar
77,590,137
11,748,924
cloud function return 400 bad requests
<p>I have this code, basically I want to extract the zip file in GCS that triggered by HTTP Request.</p> <pre><code>import functions_framework import os import tempfile import zipfile from google.cloud import storage def extract_zip(event): &quot;&quot;&quot;Cloud Function to extract contents of a zip file uploade...
<python><google-cloud-functions><google-cloud-logging>
2023-12-02 11:21:34
0
1,252
Muhammad Ikhwan Perwira
77,589,937
10,584,570
Python Create a simple library wrapper (as a side package)
<p>I need to extend a library's functionality (let it be pandas, for example). It works if I put my code inside <code>...site-packages/pandas/__init__.py</code> 👍 (however, the code I added will be auto erased with the next pandas upgrade 👎)</p> <p>Struggle: So, I need a wrapper library around pandas that I can call ...
<python><pandas><module><wrapper>
2023-12-02 10:18:12
0
303
Anton Frolov
77,589,859
8,647,273
Mocking json.dumps() method in Python unit tests
<p>I am working on test case writing using Pytest and I need to mock a function which uses json.dumps() method.</p> <p>I tried so many ways but somehow this method cannot be mocked.</p> <p>I tried using decorator -</p> <pre><code>@mock.patch(&quot;json.dumps&quot;) </code></pre> <p>But this gives error.</p> <pre><code>...
<python><mocking><pytest><python-unittest>
2023-12-02 09:57:01
1
606
Pallavi
77,589,765
1,082,349
Prepare numpy array -- similar to broadcasting
<p>Let's say I have an m-dimensional matrix <code>M</code> and an array <code>N</code> of length <code>n</code>.</p> <p>The shape of <code>M</code> is (a,b,n,e,f), meaning that on a particular axis (here, 2) the dimensionality of <code>M</code> agrees with that of <code>N</code>.</p> <p>If I want to multiply them, in t...
<python><numpy>
2023-12-02 09:22:59
1
16,698
FooBar
77,589,744
11,801,298
In search of retrograde Mercury with pandas
<p>My object, the planet Mercury, is moving in a circle back and forth. Its coordinate lies within 360 degrees. There is no problem in detecting its reversal if it is far from the 360 degree point (0 degrees).</p> <pre><code>an easy case: 13.08.2010 166.41245 14.08.2010 167.00584 15.08.2010 167.53165 16.08.2010 167...
<python><pandas><scipy>
2023-12-02 09:13:03
1
877
Igor K.
77,589,708
22,371,917
How to use proxies with seleniumbase?
<p>I am trying to use a proxy with seleniumbase but i get: You are using an unsupported command-line flag: --ignore-certificate-errors. Stability and security will suffer.(at the starting chrome page) (after opening site)Site couldnt be reached whatismyip.com took too long to respond. but the code works fine when i don...
<python><selenium-webdriver><python-requests><proxy><seleniumbase>
2023-12-02 08:59:57
1
347
Caiden
77,589,586
3,710,481
How to share websocket context in quart
<p>i have quart app with with websocket method.</p> <pre><code>charge_points = {} @app.websocket(&quot;/ws/&lt;charge_point_id&gt;&quot;) async def on_connect(charge_point_id: str): logging.info(&quot;charge_point_id: %s&quot;, charge_point_id) try: await websocket.accept() cp = SChargePoint(char...
<python><flask><websocket><quart>
2023-12-02 08:09:25
0
8,151
patelarpan
77,589,521
14,154,197
Simple approach for running a docker image with python on ubuntu
<p>The problem is that I have a python app and want to create a docker image from it. What is a simple approach to do so?</p> <p>I am using a ubuntu desktop 22.04, running a python django rest_framework app using (venv) virtual environament.</p> <p>I have docker 24.0.7 already intsalled and need to create a Dockerfile ...
<python><bash><docker><ubuntu>
2023-12-02 07:39:30
1
401
André Luiz Myszko
77,589,457
3,416,774
Is there a way to set attribute to sub objects in a class?
<p>I would like to be able to do this:</p> <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt; obj = Example('hi', 'hello') &gt;&gt;&gt; obj.a 'hi' &gt;&gt;&gt; obj.sub_obj.b 'hello' </code></pre> <p>I try this but I get <code>AttributeError: 'dict' object has no attribute 'b'</code>:</p> <pre class="lang-py ...
<python><object><attributes><nested-object>
2023-12-02 07:14:24
2
3,394
Ooker
77,589,368
3,542,535
Jinja YAML Templating: Get Value of Optional Nested Key or Use Default Value
<p>I'm trying to create a YAML file from some inputs passed to a Jinja template. I want certain input chained keys be optional and used in the templating if present, but otherwise ignored. In the example below, <code>override.source.property</code> may or may not exist in the input file, and <code>override</code> is a ...
<python><templates><yaml><jinja2>
2023-12-02 06:31:09
1
413
alpacafondue
77,589,188
12,035,739
Sorting non-negative integers in linear time using Numba breaks
<p>I am trying to sort an array/list of non-negative integers in linear time. We also only keep the unique elements. Here is an example,</p> <pre><code>Sort: [7, 7, 0, 3, 2, 1, 9, 1] 7: 10000000 7: 10000000 0: 10000001 3: 10001001 2: 10001101 1: 10001111 9: 1010001111 1: 1010001111 1010001111: [] 101000111: [0] 10100...
<python><sorting><numba>
2023-12-02 04:49:54
1
886
scribe
77,589,004
23,002,898
Problem execute calculations in a nested loop. TypeError: 'numpy.float64' object is not iterable
<p>I'm trying to calculate the <a href="https://en.wikipedia.org/wiki/Residual_sum_of_squares" rel="nofollow noreferrer">sum of squared errors</a> and i'm using a nested loop.</p> <p><a href="https://i.sstatic.net/ZnPoZ.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ZnPoZ.png" alt="enter image descripti...
<python><python-3.x><numpy><loops><math>
2023-12-02 02:56:01
3
307
Nodigap
77,588,920
5,267,751
Is it possible to override the pretty-printing of an existing data type in SageMath?
<p>In IPython, using the method in <a href="https://stackoverflow.com/questions/14977066/how-can-i-configure-ipython-to-display-integers-in-hex-format">How can I configure ipython to display integers in hex format?</a> , it's possible to customize how objects are printed:</p> <pre><code>In [1]: import ast ...: forma...
<python><sage>
2023-12-02 02:10:06
1
4,199
user202729
77,588,878
6,421,708
Why is Visual Studio Code running Python when it should run Java on Mac
<p>I wrote a standard 'Hello World' Java program in a file called QuickTest.java in the latest Visual Studio Pro (on Mac). I have installed the standard Extension Package for Java. Which seams to have installed several required packages.</p> <pre><code>class Hello { public static void main (String[] args) { ...
<python><java><macos>
2023-12-02 01:50:20
0
5,191
Keith
77,588,790
10,574,250
ModuleNotFoundError: No module named 'financials_api_get' when trying to run folder location
<p>I have a folder directory that looks as such:</p> <pre><code>-- show_case --airflow --dags fundamental_data_pipeline.py __init__.py financials_api_get.py </code></pre> <p>I am trying to run a function <code>get_fundemental_data</code> from <code>financial_api_get.py</code> within <code>fundamental_da...
<python><pathlib>
2023-12-02 01:09:15
1
1,555
geds133
77,588,662
6,162,679
`min()` is not working properly in Python?
<p>I am new to Python and notice the following error when using <code>min()</code>.</p> <pre><code>import pandas as pd a = [1,2,3,4,5] print(min(20, pd.array(a)**2)) </code></pre> <p>The code should return[1, 4, 9, 16, 20], however, it returns [1, 4, 9, 16, 25]. It seems that <code>min()</code> is not working as expect...
<python><math><min>
2023-12-02 00:14:18
2
922
Yang Yang
77,588,577
130,948
ENABLE_ORYX_BUILD being removed during remote build and function app doesn't get the new version of code
<p>I am working on azure function with python.</p> <p>Based on the documentation we are supposed to have below two configuration values when we do remote build on linux machine. Navigate <a href="https://learn.microsoft.com/en-us/azure/azure-functions/functions-deployment-technologies?tabs=linux#remote-build" rel="nofo...
<python><azure><azure-functions>
2023-12-01 23:31:23
1
743
Ravi Khambhati
77,588,539
15,456,681
Numba very slow with default arguments depending on which arguments are provided
<p>I'm implementing a function for which some arguments are compulsory and some are set as default in numba, however depending on the values set for the default arguments, which order the different types appear in and which arguments are provided I am getting very different timings:</p> <pre class="lang-py prettyprint-...
<python><numba>
2023-12-01 23:17:00
0
3,592
Nin17
77,588,420
2,006,921
Sphinx autodoc import problems
<p>I have a python project main file that resides in <code>C:\b_tool\b.py</code>. I start it from <code>C:</code> with <code>python -m b_tool.b</code>. <code>b.py</code> imports all kinds of other modules.</p> <p>I would like to add a Sphinx folder like here <code>C:\b_tool\Docs\Sphinx</code>. How would I specify the p...
<python><python-sphinx>
2023-12-01 22:35:36
1
1,105
zeus300
77,588,263
4,822,772
How to make session_state persist after button click in streamlit
<p>I'm encountering an issue with Streamlit where I'm trying to allow the user to modify text using <code>st.text_input</code> and then display the modified text when a button is clicked. However, the modified text is not persisting as expected in the session state.</p> <p>Here's a simplified version of the code:</p> <...
<python><button><streamlit>
2023-12-01 21:49:53
1
1,718
John Smith
77,588,222
2,532,408
Why does mypy not catch error when typealias is used?
<p>Consider the following code that mypy catches the fact the wrong type is used.</p> <pre class="lang-py prettyprint-override"><code>from typing import Generic, TypeVar, TypeAlias V = TypeVar(&quot;V&quot;) class MyObj(Generic[V]): def foo(self, arg: tuple[V, V]) -&gt; None: ... mo = MyObj[int]() mo.fo...
<python><mypy><python-3.12>
2023-12-01 21:40:28
0
4,628
Marcel Wilson
77,588,203
11,391,711
effectively creating dictionary of dictionaries where the values are a list from an Excel file
<p>I am reading a big table with multiple columns using <code>parse</code> command. Then, I would like to use the first and second columns as a nested key pair along with using the rest of columns as a value stored in a list. I have written a code snippet which does what I wish. I was wondering if this operation can be...
<python><pandas><dictionary>
2023-12-01 21:36:05
2
488
whitepanda
77,588,149
4,541,045
Is there any reason to do to multiple inheritance with object?
<p>While reviewing some code, it has a structure like</p> <pre class="lang-py prettyprint-override"><code>class Bar(Foo, object): </code></pre> <p>Which seems like it could easily be written instead as</p> <pre class="lang-py prettyprint-override"><code>class Bar(Foo): </code></pre> <p>The functionally appears at least...
<python><python-3.x><multiple-inheritance>
2023-12-01 21:23:20
1
19,831
ti7
77,588,137
1,288,043
Issue in simple neural network
<p>I tried below code in tensorflow with different variations for a simple regression problem. I have synthesized data as <code>y=10.0*x</code>. One input and one outcome variable. But tensorflow is giving me a loss of ~2000 to ~200000. I am using MSE as the loss function. Also tried relu activations as well, without a...
<python><tensorflow><regression>
2023-12-01 21:21:19
1
319
user1288043
77,587,970
9,571,463
Program using Asyncio with queue ends before consumer finishes
<p>I have the following producer pattern where I obtain data from a source, place it in queue, then consume it and write it to a CSV file. However, the program seems to end early because my tasks are all marked as done before they are actually wrote.</p> <p>My hunch is because it is due to the fact I am yielding data f...
<python><queue><python-asyncio><producer-consumer>
2023-12-01 20:38:35
1
1,767
Coldchain9
77,587,931
1,859,242
Langchain - Chat History with Embedded Data not working
<p>I'm trying to embed some data to gpt-4-1106-preview and chat on it. You may think like chatPDF. But my problem is, ChatGPT answers the question but doesn't remember our chat history.</p> <p>Here is the code, probably I'm doing a mistake but I couldn't found.</p> <p>Console command</p> <pre><code>!pip install langcha...
<python><openai-api><langchain><chat-gpt-4>
2023-12-01 20:29:33
1
2,088
fobus
77,587,866
10,986,032
I want to get the anchor tag value and nested anchor tag value from single URL using multithreading
<p>I try to below code for get the anchor tag <code>href</code> and nested anchor tag value for the following URL <code>https://www.tradeindia.com/</code> but not generate the exact output. below code only get the single page URL output, can any one please suggest?</p> <pre><code>import concurrent import requests from...
<python><multithreading><request><concurrent.futures>
2023-12-01 20:16:13
1
872
Sam
77,587,845
13,968,392
Modify regex capturing group in column
<p>How can I modify the capturing group in pandas <code>df.replace()</code>? I try to add thousands separators to the numbers within the string of each cell. This should happen in a method chain. Here is the code I have so far:</p> <pre class="lang-py prettyprint-override"><code>import pandas as pd df = pd.DataFrame({...
<python><pandas><regex><replace>
2023-12-01 20:12:09
4
2,117
mouwsy
77,587,807
12,114,641
ModuleNotFoundError: No module named 'openai.openai_object'
<p>I'm getting error while running a python script on macOS</p> <blockquote> <p>from openai.openai_object import OpenAIObject</p> <p>ModuleNotFoundError: No module named 'openai.openai_object'</p> </blockquote> <p>How do I fix it?</p> <pre><code>(llama-py3.12) bash-3.2$ python3 starter.py Traceback (most recent call l...
<python><llama><llama-index>
2023-12-01 20:03:24
1
1,258
Raymond
77,587,572
7,180,705
Trim a List so the Sum is Close to a Target Value
<p>I have a list of values that add up to a number and I need to trim it so the sum is close to a target value. Is there any standard algorithm for this? I will elaborate below:</p> <p>Assume there is a class named <code>MyClass</code> and <code>obj_list</code> is a list containing instances of <code>MyClass</code>. Ea...
<python><numpy>
2023-12-01 19:15:49
1
329
Mohammadreza Khoshbin
77,587,508
1,163,094
Why is `to_thread` faster than `create_task` in python asyncio?
<p>I have a blocking function that calls an REST endpoint and returns some result. Let's simulate that as below:</p> <pre class="lang-py prettyprint-override"><code>import random, time, asyncio def test_func(x): time.sleep(2*random.random()) return x </code></pre> <p>I tried to use python <code>asyncio</code> t...
<python><python-3.x><asynchronous><async-await><python-asyncio>
2023-12-01 19:01:00
0
1,240
qkhhly
77,587,324
8,167,752
python-pptx - Adding the content box in a "Title and Content" slide
<p>I'm using the pptx module to create a PowerPoint &quot;Title and Content&quot; slide.</p> <pre><code>prs = Presentation() mySlide = prs.slides.add_slide(prs.slide_layouts[1]) </code></pre> <p>I can &quot;address&quot; the title with either &quot;title&quot; attribute or the &quot;placeholder[0]&quot; attribute.</p> ...
<python><powerpoint><python-pptx>
2023-12-01 18:22:18
1
477
BobInBaltimore
77,587,293
10,994,166
Get max value from an array column and get value with similar index from another column pyspark
<p>I have dataframe like this:</p> <pre><code>| id | label | md | +-----------+-----------+------+ |[a, b, c] | [1, 4, 2] | 3 | |[b, d] | [7, 2] | 1 | |[a, c] | [1, 2] | 8 | </code></pre> <p>I want to get max value from label column and get value from id column with similar index.</...
<python><apache-spark><pyspark><apache-spark-sql>
2023-12-01 18:15:38
1
923
Chris_007
77,587,268
3,569,246
Python 3.9 - strongly typed callbacks with known first argument type and additional args typed in the function definition
<p>I have a set of a few dozen simple callbacks with various arguments, defined as such:</p> <pre><code>def test_value(tested: Tested, value: int) -&gt; bool: return tested.value &gt;= value def test_value_and_name(tested: Tested, value: int, name: str) -&gt; bool: return tested.value &gt;= value and tested.name =...
<python><python-3.x>
2023-12-01 18:11:24
2
3,756
JoannaFalkowska
77,587,206
14,392,430
Is that possible to define "SET NULL" for only one column of composite foreign key in SQLAlchemy?
<p>Postgres supports this feature - <a href="https://git.postgresql.org/gitweb/?p=postgresql.git;a=commitdiff;h=d6f96ed94e73052f99a2e545ed17a8b2fdc1fb8a" rel="nofollow noreferrer">link</a>. Not sure how to implement it in SQLAlchemy. If I do <code>ForeignKeyConstraint(..., ondelete=&quot;set null(payment_id)&quot;)</co...
<python><postgresql><sqlalchemy>
2023-12-01 17:58:03
1
708
Alexander Farkas
77,587,151
9,334,609
ValueError: client_id must not be blank using PDF Extract API
<p>I have followed the steps in Getting Started with PDF Extract API (Python) successfully. The required libraries have been installed in the virtual environment (venv_smed). The source code has no syntax errors. However, when I run the <code>python extract.py</code> command the following error is displayed:</p> <pre><...
<python><adobe>
2023-12-01 17:45:45
1
461
Ramiro
77,586,916
2,628,868
how to make PyCharm use the pdm download package
<p>I am using the pdm <a href="https://github.com/pdm-project/pdm" rel="nofollow noreferrer">https://github.com/pdm-project/pdm</a> to manage the python project dependencies, today I found the PyCharm seems did not use the pdm downloaded packages, seems use it's own downloaded package. Is it possible to make the PyChar...
<python><pycharm><pdm>
2023-12-01 16:58:41
0
40,701
Dolphin
77,586,707
8,527,313
Numpy eig/eigh high memory usage
<p>Let me start with a disclaimer that I am not as experienced in Python as one might want to be, so it could be that this is being caused by something I had caused myself.</p> <p>Disclaimer aside, I've noticed some strange behavior in terms of the memory usage in NumPy. Specifically, when performing eigenvalue decompo...
<python><numpy><scipy>
2023-12-01 16:26:13
0
1,255
Qubit
77,586,651
15,587,184
Failing to establish an SSH tunnel in Python (without Putty)
<p>I'm attempting to automate the process of connecting to a Redshift server using Python without relying on PuTTY. Currently, I'm on a Windows machine, and I need to extract data from PostgreSQL on a Redshift server. However, to achieve this, I have to:</p> <ol> <li><p>Open the PuTTY .exe</p> </li> <li><p>Enter this c...
<python><ssh><paramiko><openssh><ssh-tunnel>
2023-12-01 16:15:49
2
809
R_Student
77,586,508
66,490
How to copy Azure blobs quickly in Python
<p>I need to copy about 1000 blobs at a time from one storage account to another. The size of each blob is roughly between 100 to 1000MB. Each blob is renamed, so I cannot copy the blobs in bulk using a common prefix.</p> <p>The approach I've taken is to use <code>BlobClient.start_copy_from_url()</code> to create an as...
<python><azure><azure-blob-storage>
2023-12-01 15:52:45
2
7,505
TrayMan
77,586,440
1,614,870
Grouping and counting time intervals by hours with a marker for overlapping days
<p>I need to count the number of hour intervals over a monthly period. I need to group it by only time and not by date. For example</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Date</th> <th>Start</th> <th>End</th> </tr> </thead> <tbody> <tr> <td>23-02-2023</td> <td>12:10:00</td> <td>12...
<python><pandas><dataframe><datetime>
2023-12-01 15:40:46
2
9,634
Abhijit Mazumder
77,586,425
967,621
Aggregate dataframe using less repetitive code than a bunch of select and merge operations
<p>I am trying to summarize/aggregate a dataframe as follows. While the code gives the correct result, it is very repetitive and I would like to avoid that. I think that I need to use something like <code>groupby</code>, <code>agg</code>, <code>apply</code>, etc. but could not find a way to do that. The goal is to comp...
<python><pandas><group-by><merge><aggregate>
2023-12-01 15:38:33
4
12,712
Timur Shtatland
77,586,339
10,252,177
Quit Tkinter application by calling class method
<p>I am trying to build a splash screen that I will be able to call from an external application using Tkinter. I'd like to define my GUI in a class, like this:</p> <pre class="lang-py prettyprint-override"><code>class Splash: def __init__(self): self.root = tk.Tk() self.root.overrideredirect(...
<python><tkinter><python-multithreading><python-class><tcltk>
2023-12-01 15:27:27
1
522
Ben Zelnick
77,586,290
709,439
How to remove a tag from an element of BeautifulSoup?
<p>I have a page like this:</p> <pre><code>... &lt;div class=&quot;myclass&quot;&gt; &lt;p&gt; text 1 to keep&lt;span&gt;text 1 to remove&lt;/span&gt;and keep this too. &lt;/p&gt; &lt;p&gt; text 2 to keep&lt;span&gt;text 2 to remove&lt;/span&gt;and keep this too. &lt;/p&gt; &lt;div&gt; </code></pre> <p>...
<python><beautifulsoup>
2023-12-01 15:17:50
2
17,761
MarcoS
77,586,285
1,534,243
How can I get a pytorch Tensor containing some other Tensor's size (or shape) without conversion to Python int?
<p>In the context of exporting pytorch code to ONNX, I get this warning:</p> <p>TracerWarning: torch.tensor results are registered as constants in the trace. You can safely ignore this warning if you use this function to create tensors out of constant variables that would be the same every time you call this function. ...
<python><pytorch><onnx>
2023-12-01 15:16:52
1
578
Dietmar
77,586,262
8,483,576
Using custom JS event handler inside Gradio
<p>I have a Gradio chatbot app exposed through the iframe. The main application component is the new <a href="https://www.gradio.app/docs/chatinterface" rel="nofollow noreferrer">Gradio ChatInterface</a>. I want to pass some sensitive data from the parent app using <a href="https://developer.mozilla.org/en-US/docs/Web/...
<javascript><python><iframe><gradio><gradio-chatinterface>
2023-12-01 15:12:16
1
404
Dušan
77,586,212
2,729,831
Google cloud function finishes with status ok even when I return 500 error code
<p>I am using python for a google cloud function. When an exception occures I catch it and reutrn error code 500 but the log shows that the funcion finishes with status &quot;OK&quot;. This is the code:</p> <pre><code>import hmac import hashlib import base64 import datetime import traceback from variables import * impo...
<python><google-cloud-functions><google-cloud-pubsub>
2023-12-01 15:04:10
1
473
blob
77,586,069
1,111,088
adjustText incorrectly positions annotations when x and y values greater than 1
<p>We're using matplotlib and adjustText to plot XY coordinates and pass a list of labels to specific points in the plot and prevent the labels from overlapping one another.</p> <p>However, I noticed that applying adjust_text to XY values that are greater than 1 causes the labels to be displayed incorrectly. Here's a s...
<python><matplotlib>
2023-12-01 14:42:58
0
2,480
rikitikitik
77,586,057
5,586,359
How do I calculate the loss when samples per batch have different shapes?
<p>I have a training function like so:</p> <pre class="lang-py prettyprint-override"><code>def training(): model.train() train_mae = [] progress = tqdm(train_dataloader, desc='Training') for batch_index, batch in enumerate(progress): x = batch['x'].to(device) x_lengths = batch[...
<python><deep-learning><pytorch><loss-function>
2023-12-01 14:40:56
1
954
Vivek Joshy
77,586,036
3,521,180
why the NULL value handling not working properly?
<p>I have written a simple code to handle null value for string type column and float type column as shown below:</p> <pre><code>def format_item(item): if item is None: if isinstance(item, (Decimal, float)): return 0.00 else: return &quot;&quot; else: if isinstanc...
<python><python-3.x>
2023-12-01 14:37:55
2
1,150
user3521180
77,585,972
8,683,461
Python nested lists search optimization
<p>I have a search and test problem : in the list of prime numbers from 2 to 100k, we're searching the first set of 5 with the following criteria :</p> <ul> <li>p1 &lt; p2 &lt; p3 &lt; p4 &lt; p5</li> <li>any combination of 2 primes from the solution (3 and 7 =&gt; 37 and 73) must also be a prime</li> <li>sum(p1..p5) i...
<python><algorithm><optimization><mathematical-optimization><primes>
2023-12-01 14:30:01
1
534
MarvinLeRouge
77,585,969
395,255
pandas read_excel returns columns is wrong order if number of columns are less than total columns in the sheet
<p>I have an xlsx file which contains 3 columns. This is how my xlsx file looks like:</p> <pre><code>Items Object Information Item1 Some Object Some Information Item2 Some Object Some Information Item3 Some Object Some Information Item4 Some Object Some Information </code></pre> <p>Wh...
<python><pandas>
2023-12-01 14:29:21
1
12,380
Asdfg
77,585,904
10,986,032
how to get urls and nested page urls using concurrent.futures?
<p>I am trying to collect the anchors tag <code>href</code> value and nested urls within a webpage and repeat the operation for each such url.</p> <p>I want to reducing the time to fetch the urls using concurrency.</p> <pre><code>import concurrent.futures from urllib.parse import urlsplit import requests from bs4 impo...
<python><io><concurrent.futures>
2023-12-01 14:17:35
1
872
Sam
77,585,792
8,236,076
What is the difference between a SubQuestionQueryEngine and a MultiStepQueryEngine?
<p>The title says it: What is the difference between a SubQuestionQueryEngine and a MultiStepQueryEngine?</p> <p>Intuitively, these things seem very similar: Breaking a question down into multiple steps is very similar to breaking a question down into multiple subquestions. Conceptually, what is the difference between ...
<python><llama-index>
2023-12-01 13:59:43
0
1,144
Willem
77,585,606
18,091,040
How to demote an Endorser from Hyperledger Indy?
<p>I am currently using the example of Hyperledger Indy of <a href="https://github.com/hyperledger/indy-sdk/blob/main/docs/how-tos/write-did-and-query-verkey/README.md" rel="nofollow noreferrer">Write a DID and Query Its Verkey</a> to dive deep into DID creation.</p> <p>After generating a DID and a verkey for a TRUST_A...
<python><hyperledger-indy>
2023-12-01 13:30:32
1
640
brenodacosta
77,585,597
6,335,363
How can I have an optional TypeVar in a Generic class in Python?
<p>I'm trying to write a simple type wrapper to represent the interface of decorator functions:</p> <pre class="lang-py prettyprint-override"><code>from typing import Protocol, TypeVar, Generic TIn = TypeVar('TIn', contravariant=True) TOut = TypeVar('TOut', covariant=True) class Decorator(Protocol, Generic[TIn, TOut]...
<python><generics><python-typing><mypy>
2023-12-01 13:27:59
1
2,081
Maddy Guthridge
77,585,519
4,451,521
Best way to run several heavy processes in python
<p>I have an indeterminate number of csv files. I want to back them up, then process them and save the result in the same file. The process is kind of heavy and it involves manipulating the values in the rows and columns, performing some search, adding values, etc. Since it is heavy I would like to do it concurrently a...
<python><multiprocessing><python-multiprocessing><python-multithreading>
2023-12-01 13:15:03
0
10,576
KansaiRobot
77,585,352
12,775,432
Change batch size using a list of Pytorch's data loader
<p>During the training of my neural network model, I used a Pytorch's data loader to accelerate the training of the model. But instead of using a fixed batch size before updating the model's parameter, I have a list of different batch sizes that I want the data loader to use.</p> <p>Example</p> <pre><code>train_dataset...
<python><pytorch><pytorch-dataloader><batchsize>
2023-12-01 12:42:22
1
640
pyaj
77,585,320
6,113,142
Point `apk` to install packages to correct `site-packages`
<p>Certain (<code>py3-pandas</code>, <code>py3-scipy</code>) packages installed through <code>apk</code> on <code>python:3.12-alpine</code> are not accessible since they are installed in <code>/usr/lib/python3.11/site-packages</code> inspite of specifying <code>$PYTHONPATH=/usr/local/lib/python3.12/site-packages</code>...
<python><dockerfile><alpine-linux><python-3.12>
2023-12-01 12:35:38
1
350
Pratik K.
77,585,278
4,124,887
PyVISA error reading from TCP/IP unless exact number of incoming bytes is specified
<p>I have some Python code for reading from a device, which returns a read error unless I specify exactly the number of bytes returned or fewer. The following code successfully returns <code>SA-14212</code>, which is exactly 8 characters and is the correct response. But we will not always know the correct length of t...
<python><tcp><labview><pyvisa>
2023-12-01 12:29:00
0
1,675
Tony
77,584,918
521,347
How can I access output of previous Ptransform in next step
<p>I have to create a Apache data beam in Python which has to do following functions-</p> <ol> <li>Read an entry from a database table matching a particular criteria</li> <li>Call 1st REST API for this record</li> <li>In the response of above API call, will get an array. Call two API for each element in this array</li>...
<python><apache-spark><google-cloud-dataflow><apache-beam>
2023-12-01 11:23:28
1
1,780
Sumit Desai
77,584,854
2,352,242
JPype and robotframework custom keywords
<p>I'm trying to use JPype with Robotframework to be able to use java-based SUTs.</p> <p>I used this (<a href="https://forum.robotframework.org/t/connecting-java-with-robot-framework/5253" rel="nofollow noreferrer">https://forum.robotframework.org/t/connecting-java-with-robot-framework/5253</a>) forum Post to implement...
<python><java><robotframework><jpype>
2023-12-01 11:12:59
0
449
szoszk
77,584,671
7,290,715
Inserting hyphen in between strings as per the given format
<p>I have a string like <code>s_t = &quot;ABCD1234&quot;</code>.</p> <p>Now I have a format <code>XXX-X-00-00</code>.</p> <p>And I want to convert the string to the above format. i.e. <code>ABC-D-12-34</code> Here <code>00</code> indicates number and <code>X</code> indicates string type.</p> <p>I am following the below...
<python>
2023-12-01 10:41:25
1
1,259
pythondumb
77,584,556
7,662,164
Selecting permutationally-unique elements of a symmetric tensor
<p>I have a code which creates a numpy array <code>A</code> of shape <code>(m, m, ..., m)</code> where there are <code>n</code> copies of <code>m</code>. By construction, this array is a symmetric tensor (in the mathematical sense), meaning that <code>A[i, j, ..., k] == A[i', j', ..., k']</code>, where <code>(i', j', ....
<python><arrays><numpy><indexing><combinatorics>
2023-12-01 10:23:37
2
335
Jingyang Wang
77,584,384
6,306,190
Axios POST causes CORS error despite enabling CORS in Flask
<p>I have spent many days on this problem and still couldn't figure out how to solve this. I'm having CORS issues and I've tried enabling CORS in Flask but it didn't work.</p> <p>Backend code (hosted on port 5000):</p> <pre class="lang-py prettyprint-override"><code>from flask import Flask, request, jsonify from flask_...
<python><typescript><flask><cors><vscode-restclient>
2023-12-01 09:57:33
1
1,830
thyu
77,584,351
2,301,782
Unable to call method from Parent Class in Google colab
<p>I am trying run a music recommendation code from following this <a href="https://github.com/JingPoo/WSDM-kkbox_music_recommendation-with-KGE/tree/master" rel="nofollow noreferrer">https://github.com/JingPoo/WSDM-kkbox_music_recommendation-with-KGE/tree/master</a>.</p> <p>I have successfully ran data_preprocess.py an...
<python><python-3.x><tensorflow><google-colaboratory>
2023-12-01 09:52:20
0
1,530
TheGraduateGuy
77,584,201
3,521,180
Why the Json module cannot serialize date object in python?
<p>I have a error coming as below</p> <pre><code>{ &quot;statusCode&quot;: 500, &quot;body&quot;: &quot;\&quot;An error occurred: Object of type date is not JSON serializable\&quot;&quot; }, </code></pre> <p>and below is the code implementation to handle the error.</p> <pre><code>def format_item(it...
<python><python-3.x>
2023-12-01 09:31:31
2
1,150
user3521180
77,584,165
14,243,731
Sphinx autosummary only adding __init__ methods for classes
<p>I am trying to use Sphinx autosummary to document all of the classes within the directory <code>mypackage/src/</code>. Sphinx is only generating proper documentation for the class constructors but none of the (public) methods inside classes. What am I doing wrong?</p> <h2>Project structure:</h2> <pre><code> - docs/ ...
<python><python-sphinx><autodoc><autosummary>
2023-12-01 09:24:08
1
328
Adventure-Knorrig
77,583,899
9,819,585
XGBoost Classification, Different AUC score for XGBClassifier vs xgb.train Even After Rounding Prediction Probabilities
<p>it seems that XGBClassifier is a wrapper over <code>xgb.train</code>. I was trying to train a binary classifier using <code>xgb.train</code> and <code>&quot;objective&quot;: &quot;binary:logistic&quot;</code>.</p> <p>It seems that using <code>xgb.train</code> followed by <code>.predict()</code> returns the predictio...
<python><machine-learning><xgboost>
2023-12-01 08:32:40
0
703
Lim Kaizhuo
77,583,736
37,758
Ignore extras during model_dump
<p>I'm looking for a way to get a dictionary representation of a nested pydantic model which does not include extra elements. <code>model_dump</code> offers a number of <code>exclude</code> flags, but unfortunately no <code>exclude_extras</code>.</p> <p>Here's an example. I want the assertion to hold. Bear in mind this...
<python><pydantic>
2023-12-01 07:54:10
2
2,982
NiklasMM
77,583,719
5,594,008
Poetry error on install - SecretStorage required
<p>I'm trying to execute <code>poetry install</code>, but I got errors</p> <pre><code>Cannot install pyasn1. RuntimeError SecretStorage required </code></pre> <p>And when I try to poetry add SecretStorage, I got the same <code>SecretStorage required</code></p> <p>What should I do to fix that?</p> <p>(Python version...
<python><python-poetry>
2023-12-01 07:49:45
1
2,352
Headmaster
77,583,685
8,968,910
Python: regex number with different cases
<p>Consider:</p> <pre><code>import re l='the number is 35.897, please check' print(re.sub(r&quot;([0-9])\.([0-9])&quot;, r&quot;\1 of&quot;, l)) i='the number is 35+897, please check' print(re.sub(r&quot;([0-9])\+([0-9])&quot;, r&quot;\1 plus&quot;, i)) j='the number is 35、897, please check' print(re.sub(r&quot;([0-9...
<python><regex>
2023-12-01 07:42:54
1
699
Lara19
77,583,506
13,793,478
manipulating pandas dataframe to add new column
<p>I have this pandas dataframe</p> <pre><code> ticker created_at entry_price exit_price direction size 0 APPL 2023-05-29 1 4 LONG 12 1 TSLA 2023-05-29 2 3 SHORT 32 </code></pre> <p>but I want to add another column at the end which would be the sum of ent...
<python><pandas>
2023-12-01 07:03:27
0
514
Mt Khalifa
77,582,815
13,046,093
How to randomly map a proportion of data value to a specific category?
<p>I have a dataset below which shows if a customer is a return customer or not. The end goal is for all returned customers, I need to map about 25% of them to 'yes 1 purchase' and 75% of them to 'yes &gt;1 purchase'. I also need to set a seed to make sure the result does not change each time I re-run the process.</p> ...
<python><random-seed><numpy-random>
2023-12-01 03:12:09
1
460
user032020
77,582,760
367,878
How to fill missing values in dataframe sequentially?
<p>I have a data frame in PySpark that looks like this:</p> <pre><code>row_id, group_id 1, 1 2, null 3, null 4, null 5, 5 6, null 7, null 8, 8 9, null 10, null 11, null 12, null </code></pre> <p>And so on: where row_id is sequential number (incremental and unique...
<python><dataframe><apache-spark><pyspark><apache-spark-sql>
2023-12-01 02:54:12
1
25,654
bensiu
77,582,620
5,231,110
Tensorflow _pywrap_tf2 ImportError: DLL load failed
<p>I got the following error with TensorFlow:</p> <pre><code>from tensorflow.python.platform import _pywrap_tf2 ImportError: DLL load failed while importing _pywrap_tf2: A dynamic link library (DLL) initialization routine failed. </code></pre> <p>There are similar questions, but not with <code>_pywrap_tf2</code> and as...
<python><tensorflow>
2023-12-01 02:01:41
3
2,936
root
77,582,477
22,437,734
What can I do about Jupyter returning error for no clear reason?
<p>I had been doing a ML course where we had to use conda + anaconda.</p> <p>In the course, they start up jupyter through the terminal, which for some reason I couldn't do. So I started using the <code>microsoft</code> extension for <code>jupyter notebooks</code>. It worked okay for some time until an error popped up u...
<python><conda><jupyter><importerror>
2023-12-01 00:53:20
0
473
Gleb
77,582,315
14,775,628
rankN type equivalent for mypy in python
<p>In Haskell we can use rankN types like so:</p> <pre class="lang-hs prettyprint-override"><code>rankN :: (forall n. Num n =&gt; n -&gt; n) -&gt; (Int, Double) rankN f = (f 1, f 1.0) </code></pre> <p>Is the same thing possible in python with mypy?</p> <p>I tried the following code in python 3.10.2 with mypy 1.7.1:</p>...
<python><haskell><types><mypy>
2023-11-30 23:52:28
2
518
petrucci4prez
77,582,299
2,718,496
Tensor (5-dim matrix) in python pandas?
<p>I have a CSV file that looks like</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>time</th> <th>Col_A</th> <th>Col_B</th> <th>Col_C</th> <th>Col_D</th> <th>Price</th> </tr> </thead> <tbody> <tr> <td>123</td> <td>A1</td> <td>B1</td> <td>C2</td> <td>D6</td> <td>23.43</td> </tr> <tr> <td>12...
<python><pandas><numpy><matrix><tensor>
2023-11-30 23:47:46
1
1,015
Orvar Korvar