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,461,018
3,917,668
Pysimplegui: get event source without a key
<p>I'm making a Calendar app for my workplace. I want to be able to assign shift (in manager mode) or request &amp; block shifts (in worker mode).</p> <p>In order for the latter part to be convenient, I want the Text element for each shift to be clickable, making it colored red for block for example.</p> <p>My problem ...
<python><event-handling><pysimplegui>
2023-11-10 15:14:07
1
449
Oded Sayar
77,460,982
2,854,673
OpenCV puttext curved text printing
<p>I am trying to print text in curved way instead of straight line using opencv puttext function. Can lineType supports curve option instead of cv2.LINE_AA? Any other alternatives available to print curved text on an image?</p> <pre><code>Syntax: cv2.putText(image, text, org, font, fontScale, color[, thickness[, lineT...
<python><image><opencv><text><curve>
2023-11-10 15:09:35
1
334
UserM
77,460,950
3,611,472
Optimising the computation of a (quasi) infinite series on Pandas/Numpy
<p>I have a time series stored in a pandas dataframe. The time series is the sequence {<code>X_t</code>} where <code>t</code> is the time index that in my case it is truncated, i.e. t = [0,T&gt;0].</p> <p>For each <code>t</code>, I would like to compute the following series</p> <p><a href="https://i.sstatic.net/D4O14.j...
<python><pandas><numpy><optimization>
2023-11-10 15:06:07
1
443
apt45
77,460,905
2,394,163
How can I reference multiple Google Sheets worksheets from .streamlit/secrets.toml?
<p>I want to be able to aggregate data from multiple Google sheets spreadsheets in a single <a href="https://docs.streamlit.io/" rel="nofollow noreferrer">streamlit</a> application.</p> <p>The documentation at <a href="https://docs.streamlit.io/knowledge-base/tutorials/databases/public-gsheet" rel="nofollow noreferrer"...
<python><google-sheets><streamlit>
2023-11-10 14:57:50
1
2,054
Nick
77,460,818
3,066,306
Pyinstaller ignores dll which is part of a dependency
<p>I am creating a slim Python project which is wrapping a native dll, so that other Python developers can use the functionality of this dll without bothering about C-internals. This project can be build into a wheel, it can be pip installed, and it can be successfully used within scripts. However, when bundled with py...
<python><python-3.x><pyinstaller>
2023-11-10 14:43:45
1
303
Dune
77,460,705
13,151,304
How to detect any key pressed without blocking execution in Python
<p>I have an script that checks the position of the mouse every 60 seconds. If the mouse has not moved, it moves it, makes a right click, clicks esc, and sleeps. It is pretty handy to avoid the computer going to sleep. If the mouse has moved, does nothing, goes to sleep and checks again in 60 sec.</p> <p>Now I want to ...
<python>
2023-11-10 14:26:21
1
417
El_que_no_duda
77,460,692
1,554,386
Can not install apache-airflow-providers-mysql or mysqlclient: pkg-config error on MacOS
<p>Using MacOS Ventura 13.6, when trying to install <code>apache-airflow-providers-mysql</code> or <code>mysqlclient</code> package I get the following error:</p> <pre><code>$ pip install apache-airflow-providers-mysql ... Collecting mysqlclient&gt;=1.3.6 (from apache-airflow-providers-mysql) Using cached mysqlclient...
<python><macos><airflow><libmysqlclient>
2023-11-10 14:24:08
1
27,985
Alastair McCormack
77,460,652
7,334,572
Parse text with newline and write it to file using argparse
<p>I want to pass some strings with the new lines in command into the file, but <code>argparse</code> did not deal with the <code>\n</code> as the file <code>aaa</code> showed in the following script with the command <code>python test.py -t &quot;aa\nbb\ncc\n&quot;</code>.</p> <p>The <code>test.py</code> is here:</p> <...
<python><argparse>
2023-11-10 14:17:25
1
442
cwind
77,460,540
610,569
Iterables difference and common elements
<p>Given 2 iterables/lists, the goal is to extract the common and different elements from both lists.</p> <p>For example, given:</p> <pre><code>x, y = [1,1,5,2,2,3,4,5,5], [2,3,4,5] </code></pre> <p>The goal is to achieve:</p> <pre><code>common = [2,3,4,5] x_only = [1,1,5,2,5] y_only = [] </code></pre> <p>Explanation:<...
<python><list><counter><iterable>
2023-11-10 13:59:30
1
123,325
alvas
77,460,486
12,279,326
How to get stacked bar chart rows share the same axis
<p>I have a stacked horizontal bar chart using <code>matplotlib.pyplot</code>. It produces the following output: <a href="https://i.sstatic.net/49wns.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/49wns.png" alt="enter image description here" /></a></p> <p>I wanted the x-axis width to be 100%, so colour...
<python><matplotlib><stacked-bar-chart>
2023-11-10 13:50:05
1
948
dimButTries
77,460,389
1,819,402
Run cron jobs inside of Docker container
<p>I'm trying to run my python program every minute in a Docker container. To do this I want to build image with Python and cron and then with cron expression run <code>main.py</code>.</p> <p>Can you please look at my Dockerfile and tell me why nothing is executing? Even the second cron expr (<code>echo &quot;OK&quot;<...
<python><docker><cron>
2023-11-10 13:33:10
1
3,199
MAGx2
77,460,276
159,072
What version of TensorFlow+Keras should I install for nVidia GeForce GTX 480?
<pre><code>Microsoft Windows [Version 10.0.19045.2965] (c) Microsoft Corporation. All rights reserved. C:\Users\pc&gt;nvcc -V nvcc: NVIDIA (R) Cuda compiler driver Copyright (c) 2005-2017 NVIDIA Corporation Built on Fri_Sep__1_21:08:32_Central_Daylight_Time_2017 Cuda compilation tools, release 9.0, V9.0.176 C:\User...
<python><tensorflow><gpu><nvidia>
2023-11-10 13:13:48
1
17,446
user366312
77,460,275
15,638,204
Using pyodbc&pandas to load a Table data to df
<p>I'm connecting to a DB and can get all the tables from it. No errors I wanted to find a table named &quot;ToolHistory&quot; and later some other tables and then use pandas DF and filter some rows from the table/tables. Here is what I got so far:</p> <pre><code>conn = pyodbc.connect('DRIVER={SQL Server};SERVER=SomeSe...
<python><pandas>
2023-11-10 13:13:43
1
956
avocadoLambda
77,460,117
2,791,346
Find file on SFTP server that contains string content in Python
<h2>Problem</h2> <p>In Python, my task is to find a file <code>(XML)</code> on an external <code>SFTP</code> server that contains</p> <pre><code>&lt;myTag&gt;BLA&lt;/myTag&gt; </code></pre> <p>The problem is there could be more than 5000 files on the server.</p> <p>Is there a way to do it efficiently?</p> <h2>Right now...
<python><optimization><sftp><pysftp>
2023-11-10 12:47:01
0
8,760
Marko Zadravec
77,460,101
13,146,029
werkzeug.routing.exceptions.BuildError: Could not build url for endpoint 'add_user_confirm' with values
<p>Im trying to create an invite url for a project I'm working on and I have seen a few versions on line when it comes to creating a token URL for that to work.</p> <p>I have an error when it comes to creating a URL</p> <pre><code> ^^^^^^^^^^^^^^^^^^^^ File &quot;/Users/grahammorby/Documents/GitHub/tagr-api...
<python><flask>
2023-11-10 12:44:09
1
317
Graham Morby
77,460,094
726,730
Python - PyQt5 - How to show statustip for QMenu and submenu actions
<pre class="lang-py prettyprint-override"><code># -*- coding: utf-8 -*- # Form implementation generated from reading ui file 'menu_example_statustip.ui' # # Created by: PyQt5 UI code generator 5.15.9 # # WARNING: Any manual changes made to this file will be lost when pyuic5 is # run again. Do not edit this file unles...
<python><pyqt5><qmenu><qstatusbar>
2023-11-10 12:42:08
1
2,427
Chris P
77,459,882
13,899,026
How to group by and filter within the groups pandas
<p>I am looking to add an aggregate column to a DataFrame that looks something like this:</p> <p><code>pd.DataFrame({&quot;col1&quot; : [1, 2, 3, 4, 5], &quot;col2&quot; : [&quot;b&quot;, &quot;b&quot;, &quot;b&quot;, &quot;a&quot;, &quot;b&quot;], &quot;col3&quot;: [6, 2, 11, 1, 3]})</code></p> <p>When I aggregate I w...
<python><pandas><dataframe><group-by><aggregate-functions>
2023-11-10 12:05:55
1
441
Dom McEwen
77,459,646
5,868,293
How to pivot a pandas dataframe and calculate product of combinations
<p>I have a pandas dataframe that looks like this:</p> <pre><code>import pandas as pd pd.DataFrame({ 'variable': ['gender','gender', 'age_group', 'age_group'], 'category': ['F','M', 'Young', 'Old'], 'value': [0.6, 0.4, 0.7, 0.3], }) variable category value 0 gender F 0.6 1 gender M 0.4 2 a...
<python><pandas>
2023-11-10 11:25:53
2
4,512
quant
77,459,601
4,810,328
Variable context in nested python function
<p>This is probably a stupid question but I was going through the <a href="https://github.com/karpathy/micrograd/blob/master/micrograd/engine.py" rel="nofollow noreferrer">micrograd</a> repo and I came across a nested function that seems confusing to me.</p> <pre><code>class Value: &quot;&quot;&quot; stores a singl...
<python><autograd>
2023-11-10 11:20:28
1
711
Tarique
77,459,534
2,850,913
Does Mistral 7b work with Langchain tools?
<p>I am following <a href="https://www.pinecone.io/learn/series/langchain/langchain-tools/" rel="nofollow noreferrer">this tutorial</a> which is the third search result on Google for 'langchain tools'. I am trying to get Mistral 7b Instruct to use a simple circumference calculator tool. I keep getting &quot;Could not p...
<python><python-3.x><langchain><large-language-model>
2023-11-10 11:08:33
1
750
tail_recursion
77,459,456
10,950,656
Python multiple levels Logging Configuration Issue
<p>I'm trying to set up logging in my Python script using the logging module, but I'm encountering issues with the multiple level configuration. I want to log errors, warnings, and info messages into separate files. However, the current configuration only seems to create the info log. Here's a snippet of my code:</p> <...
<python><logging>
2023-11-10 10:54:26
0
481
Maya_Cent
77,459,431
10,771,559
How can I add a contour plot to a scatterplot?
<p>I have created a scatterplot of the first principal component versus the second principal component, coloured by a categorical variable using the code below:</p> <pre><code>sns.scatterplot(x=dataframe['principal component 1'], y=dataframe['principal component 2'], hue=dataframe['categorical variable']) </code></pre>...
<python><seaborn>
2023-11-10 10:50:45
1
578
Niam45
77,459,386
15,456,681
How to implement nested for loops with branches efficiently in JAX
<p>I am wanting to reimplement a function in jax that loops over a 2d array and modifies the output array at an index that is not necessarily the same as the current iterating index based on conditions. Currently I am implementing this via repeated use of <code>jnp.where</code> for the conditions separately, but the fu...
<python><jax>
2023-11-10 10:43:37
1
3,592
Nin17
77,459,326
5,852,692
Creating an autoincrement column via sqlalchemy
<p>I am using a Postgresql database via sqlalchemy orm. The table is really basic:</p> <pre><code>import sqlalchemy as sa from sqlalchemy.orm import Mapped from sqlalchemy.orm import mapped_column class Network(Base): __tablename__ = 'networks' id: Mapped[int] = mapped_column(sa.Integer, primary_key=True) ...
<python><postgresql><sqlalchemy><auto-increment>
2023-11-10 10:35:53
1
1,588
oakca
77,459,235
11,487,973
Guix Error when trying to make sphinx documentation
<p>Good afternoon. The OS used is Guix</p> <pre><code>guix --version (GNU Guix) 938a47c86d7bea785f33f42834c5c1f3dfa594b0 guix package --list-installed make 4.3 out /gnu/store/c5kpgdinijrqwkx63q4zyqcwclkn5b2s-make-4.3 git 2.41.0 out /gnu/store/57bpibp6...
<python><documentation><python-sphinx><guix>
2023-11-10 10:20:26
0
449
uanr81
77,459,198
5,612,605
paramiko - login to a host not requiring a password
<p>How can I login to a ssh-server, if this ssh server does not demand a password.</p> <p>On the (here) powershell the following works fine:</p> <pre class="lang-bash prettyprint-override"><code>ssh root@myMachine root@myMachine$: </code></pre> <p>no password asked, just simple login and hello from the machine.</p> <p...
<python><ssh><paramiko>
2023-11-10 10:13:56
1
3,651
Cutton Eye
77,459,166
1,409,644
Multiple inserts fail with IntegrityError due to failed constraint
<p>With Python (SQLAlchemy) and MariaDB, I am trying to perform three inserts, whereby a constraint for the third insert requires the first two to have been successful. However, currently the third insert fails unless the first two inserts have been committed. I would like to perform all three inserts within one tran...
<python><sql><sqlalchemy><transactions><mariadb>
2023-11-10 10:07:41
1
469
loris
77,459,159
265,521
Remove all elements matching a predicate from a list in-place
<p>How can I remove all elements matching a predicate from a list <em><strong>IN-PLACE</strong></em>?</p> <pre class="lang-py prettyprint-override"><code>T = TypeVar(&quot;T&quot;) def remove_if(a: list[T], predicate: Callable[[T], bool]): # TODO: Fill this in. # Test: a = [1, 2, 3, 4, 5] remove_if(a, lambda x: x...
<python>
2023-11-10 10:06:48
1
98,971
Timmmm
77,459,039
15,456,681
How to use *args instead of explicit function signature in a numba overload
<p>I have many (~169) functions (with ~45 unique signatures) that I am overloading with numba. I would like to add some additional logic that is the same to all the functions so I was trying to use a decorator but it seems that the 'inner' function in the decorator has to have the same signature as the function it is d...
<python><numba>
2023-11-10 09:45:13
1
3,592
Nin17
77,458,854
4,927,847
How to determine if a row is striked in Excel sheet using OpenPyxl
<p>I'm reading an excel file using openpyxl and I face the following issue:</p> <p>Some cells appear to be striked in excel and their cell strike property is True, I succeed to deal with them using Openpyxl</p> <p>But some cells appear to be striked in excel but the format cell strike property is False. This is because...
<python><excel><openpyxl>
2023-11-10 09:12:24
1
421
Quicky
77,458,642
7,119,501
How to convert NONEs to an empty string in a pyspark dataframe when it has nested columns?
<p>I have a dataframe with nested columns like below:</p> <pre><code>df_schema = StructType([ StructField(&quot;response&quot;, StringType(), True), StructField(&quot;id&quot;, StringType(), True), StructField(&quot;data&quot;, StructType([ StructField(&quot;type&quot;, StringType(), True), Stru...
<python><apache-spark><pyspark><apache-spark-sql>
2023-11-10 08:37:31
1
2,153
Metadata
77,458,556
12,890,458
Find lists of almost equal values in list
<p>I have a 1D numpy array, and I want to find the sublists/subarrays that contain almost equal values. That means they don't differ from each other more than a tolerance. I mean there is one central point in the solution from which all other points don't differ more than tolerance. For instance if I have <code>[1.0, 2...
<python><arrays><list><numpy><cluster-analysis>
2023-11-10 08:22:25
1
460
Frank Tap
77,458,463
9,404,261
Canot slice/index unicode strings with underscores
<p>I have this Unicode string:</p> <pre><code>my_string = &quot;₁ᴀa̲a̲̲&quot; </code></pre> <p>How can index and slice it to make other Unicode strings?</p> <p>If I run</p> <pre><code>print([x for x in my_string]) ['₁', 'ᴀ', 'a', '̲', 'a', '̲', '̲'] </code></pre> <p>when I expected</p> <p>['₁', 'ᴀ', 'a̲', '̲a̲̲']</p> <...
<python><python-3.x><unicode><slice>
2023-11-10 08:01:11
2
609
tutizeri
77,458,443
2,604,247
Cleanest Way to Get a Set in Redis where Individual Elements Expire in 30 Days?
<p>I need a data structure similar to a Python set in redis, with the additional capability of individual elements automatically expiring (getting popped) from the set 30 days after insertion. Basically, these are the abstract behaviours I want out of the class.</p> <pre class="lang-py prettyprint-override"><code>from ...
<python><redis><set><hashset><aioredis>
2023-11-10 07:57:52
1
1,720
Della
77,458,331
21,346,793
How to add prefix Bearer on django-yasg swagger
<p>I am using django-yasg swagger. And i need to add prefix Bearer before my token in authorization.Header needed for django-rest-framework: Bearer I should write only token, and it makes automatically into header Authorization. My settings:</p> <pre><code>SWAGGER_SETTINGS = { 'SECURITY_DEFINITIONS': { 'Beare...
<python><django-rest-framework><drf-yasg>
2023-11-10 07:32:50
1
400
Ubuty_programmist_7
77,458,259
1,973,798
Python: webbrower and missing `GLIBCXX_3.4.29'
<p>I came across an import problem causing a runtime warning at debug time. As soon as my python script invokes the open method of the webbrowser package, VSCode prints the following: <code>/snap/core20/current/lib/x86_64-linux-gnu/libstdc++.so.6: version GLIBCXX_3.4.29' not found (required by /lib/x86_64-linux-gnu/lib...
<python><linux><python-webbrowser>
2023-11-10 07:17:59
0
1,041
Andrea Moro
77,458,196
15,222,211
pydantic and pylint conflict E1137
<p>I am using <strong>pydantic</strong> in my code along with <strong>pylint</strong> for code validation. The following code appears to be valid to me, but pylint is displaying an E1137 error message. Can you help me identify what might be wrong?</p> <p>I need update dictionary inside object.</p> <pre class="lang-py p...
<python><pydantic><pylint>
2023-11-10 07:01:55
0
814
pyjedy
77,457,709
1,226,676
gunicorn looking for deleted module; cannot run django application in GCP
<p>I have a django application that's been running fine on GCP, and I recently removed a dependency: <code>django-colorfields</code>. I didn't need this functionality, so I removed these items from my models, migrated the database and uninstalled the module.</p> <p>Now when I deploy my project to GCP, I can't get past...
<python><django><google-cloud-platform><google-app-engine>
2023-11-10 04:33:26
0
5,568
nathan lachenmyer
77,457,631
6,396,569
VScode will not recognize my launch.json arguments, how can I fix this?
<p>Using Visual Studio Code v1.84.2 on Windows 10. This is my <code>launch.json</code> contents:</p> <pre><code>{ &quot;version&quot;: &quot;0.2.0&quot;, &quot;configurations&quot;: [ { &quot;name&quot;: &quot;Python: Current File&quot;, &quot;type&quot;: &quot;python&quot;, ...
<python><visual-studio-code><debugging>
2023-11-10 03:59:18
0
2,567
the_endian
77,457,542
1,188,943
Chromedriver ERR_SSL_PROTOCOL_ERROR
<p>I'm using Selenium 4.14.0 and Python 3.11.4 to crawl a website with the following settings:</p> <pre><code>options = webdriver.ChromeOptions() options.add_argument('--lang=en') options.add_argument('--allow-insecure-localhost') options.add_argument('--ignore-certificate-errors') </code></pre> <p>but get the followin...
<python><selenium-webdriver>
2023-11-10 03:26:06
0
1,035
Mahdi
77,457,504
2,849,157
tqdm bar cannot update correctly when use pdsh
<p>I have code like this:</p> <pre><code># tq_test.py from tqdm.auto import tqdm import time if __name__ == &quot;__main__&quot;: bar = tqdm(total=5) for _ in tqdm(range(3)): time.sleep(0.5) for _ in range(5): bar.update(1) </code></pre> <p>If I run it in local matchine <code>/home/user/mi...
<python><tqdm>
2023-11-10 03:11:15
1
10,083
roger
77,457,357
5,560,837
VSCode Python heap[0] is no longer the min after modifying the heap items
<p>In VS Code, I have a Python heap variable, which is a list of three-item tuples, defined as</p> <p><code>heapq.heappush(heap, (len(candidates[(i, j)]), i, j))</code></p> <p>At the beginning of debugging, <code>heap[0]</code> is always the tuple with the shortest <code>len(candidates[i, j])</code>. However, after a f...
<python><heap><sudoku>
2023-11-10 02:20:12
1
417
Egret
77,457,342
14,540,717
Download a pandas df with images into word document using python
<p>Hi I am creating a dataframe with pandas in python that is going to include pictures with the following code (the image is already downloaded into my working directory)</p> <pre><code>#Create the df using pandas import pandas as pd from IPython.display import Image, HTML row_1 = [&quot;Bob&quot;, '&lt;img src=&quot...
<python><pandas><image>
2023-11-10 02:12:43
1
428
Jeff238
77,457,324
7,391,480
Finding the minimum value in lists inside a dataframe with TypeError: 'float' object is not iterable
<p>I've generated a Dataframe with a column of lists, but if there are no values, there's a NaN instead.</p> <pre><code>import pandas as pd df = pd.DataFrame(columns=['Lists', 'Min']) df['Lists'] = [ [1,2,3], [4,5,6], [7,8,9], float('NaN') ] print(df) Lists Min 0 [1, 2, 3] NaN 1 [4, 5, 6] NaN 2 [7, 8, 9] ...
<python><pandas><dataframe><list><nested-lists>
2023-11-10 02:08:36
3
1,364
edge-case
77,457,291
627,259
pqdm.processes 'AttributeError' object is not iterable while it works with pdqm.threads
<p>I have a newbie python issue which I do not understand.</p> <p>I have working code for parallel execution using pqdm. It works if I use <code>from pqdm.threads import pqdm</code> and fails with <code>'AttributeError' object is not iterable</code> if I switch to <code>from pqdm.processes import pqdm</code> instead.</...
<python><parallel-processing><tqdm>
2023-11-10 01:51:52
0
2,085
Samo
77,457,273
1,415,826
Flask API authorization without "login"
<p>I see a lot of examples online showing how to add authentication to a flask API using JSON Web Tokens which requires a login. For example <a href="https://www.youtube.com/watch?v=J5bIPtEbS0Q" rel="nofollow noreferrer">https://www.youtube.com/watch?v=J5bIPtEbS0Q</a></p> <p>How can I add authentication without having ...
<python><flask>
2023-11-10 01:43:18
1
945
iambdot
77,457,194
1,611,813
Issue with Dataframe manipulation on Python
<p>Have the below panda data frame. Trying to create a new column labeled <em>Category</em> with the index of sorted unique values of <em>Color</em> by its <em>Fruit</em> type.</p> <p><strong>Data:</strong></p> <p><a href="https://i.sstatic.net/qrzNg.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/qrzNg....
<python><pandas>
2023-11-10 01:12:29
1
684
Saravanan K
77,457,083
2,414,842
Android Frida ProcessNotFoundError error when trying to attach to a process
<p>I've installed frida according to the <a href="https://frida.re/docs/installation/" rel="nofollow noreferrer">official page</a> installation guide and downloaded <strong>frida-server-16.1.5-android-x86_64</strong> from their github release pages and placed in the <strong>/data/local/tmp/</strong> directory of my <st...
<python><android><frida>
2023-11-10 00:24:18
1
2,294
Fnr
77,457,081
3,558,874
Next environment variables in Flask API route
<p>I've set up a Python backend for my Next frontend according to this <a href="https://vercel.com/guides/how-to-use-python-and-javascript-in-the-same-application" rel="nofollow noreferrer">Vercel article</a>.</p> <p>How do I access environment variables in these Python API routes?</p> <p>In development, the informatio...
<python><flask><next.js><python-venv>
2023-11-10 00:23:28
1
4,327
pez
77,457,080
5,475,733
prefect orion start error: No such command 'orion'
<p>I am learning <a href="https://dezoomcamp.streamlit.app/Week_2_Workflow_Orchestration" rel="nofollow noreferrer">workflow orchestration</a> from data engineering zoomcamp and have successfully ingested the data to postgresql with prefect flow but when I try to run command <code>prefect orion start</code> to see the ...
<python><prefect>
2023-11-10 00:23:27
1
1,271
npkp
77,456,942
953,553
sqlalchemy new style with Mapped anotations causes sqlalchemy.exc.ArgumentError: Could not interpret annotation Mapped chicken-egg-issue
<p>I am following the example from sqlalchemy docs <a href="https://docs.sqlalchemy.org/en/20/orm/inheritance.html#relationships-with-joined-inheritance" rel="nofollow noreferrer">https://docs.sqlalchemy.org/en/20/orm/inheritance.html#relationships-with-joined-inheritance</a></p> <p>and I am facing this kind of chicken...
<python><flask><sqlalchemy>
2023-11-09 23:36:09
1
23,529
andilabs
77,456,832
2,981,639
How to extract a struct values to a list in polars
<p>I have a pipeline that extracts regular expression groups from a <code>polars</code> text column, and I want to display the text and matches in a <code>streamlit</code> <code>st.table</code>. Provided that the column containing the matches is a List[str] this works well with <code>streamlit</code>, but <code>polars<...
<python><dataframe><python-polars>
2023-11-09 23:02:07
2
2,963
David Waterworth
77,456,821
2,101,025
Flask-Login > 0.6.0 not working on Azure Web App Deployment
<p>I have an Azure webapp running a Flask Application. I have no extra workers, just running it on default settings.</p> <p>Since moving from Flask-Login 0.6.0 to 0.6.3 it is no longer logging out when it is expired.</p> <p>I have my init.py file</p> <pre><code>def create_app(config_env=os.getenv(&quot;ENV&quot;), regi...
<python><flask><gunicorn><flask-login>
2023-11-09 22:59:14
1
303
ghawes
77,456,817
2,383,070
Is there a way to round a Duration dtype in Polars?
<p>In Pandas, you can round a Timedelta like this...</p> <pre class="lang-py prettyprint-override"><code>import pandas as pd pd.Timedelta(&quot;1h20min&quot;).round(&quot;1h&quot;) </code></pre> <p>Can something similar be done in Polars?</p> <p>When I try rounding a duration column, the error tells me this only works ...
<python><python-polars>
2023-11-09 22:58:02
2
3,511
blaylockbk
77,456,758
2,945,498
python ray out of memory (OOM) with RAY_memory_monitor_refresh_ms set to 0
<p>I'm using <a href="https://modin.readthedocs.io/en/stable/" rel="nofollow noreferrer">Modin</a> to use pandas code that can't fit in memory. It works very well locally with dataset (30GB) and my RAM(16GB). Now I want to speed this up and decided to run a cluster on GCP with modin on <a href="https://www.ray.io/" rel...
<python><google-cloud-platform><ray>
2023-11-09 22:43:48
2
967
tsh
77,456,745
284,932
Negative values in data passed to MultinomialNB when vectorize using Word2Vec
<p>I am currently working on a project where I'm attempting to use Word2Vec in combination with Multinomial Naive Bayes (MultinomialNB) for accuracy calculations.</p> <pre><code>import pandas as pd import numpy as np, sys from sklearn.model_selection import train_test_split from gensim.models import Word2Vec from sklea...
<python><scikit-learn><gensim><word2vec><naivebayes>
2023-11-09 22:41:04
2
474
celsowm
77,456,727
2,774,885
python VSCode: suggested way to run code differently based on launch / debug state
<p>I've got some python code which iterates over a large number of files, and I've written a simple multithread pool, which speeds it up substantially. (The app is not remotely complex, there are no concurrency or locking issues as each input file is mapped 1:1 to an output file and there are no shared data structures...
<python><visual-studio-code><vscode-debugger>
2023-11-09 22:36:37
1
1,028
ljwobker
77,456,701
18,139,225
Cannot load Jupyter Lab after installing "jupyter-markdown" extension
<p>I have just installed Jupyter Lab via <code>pip install</code>. It works well until I installed &quot;jupyter-markdown&quot; extension via <code>pip install jupyter-markdown</code>.</p> <p>Now I cannot load Jupyter Lab. I get the following error:</p> <pre><code>[W 2023-11-09 22:59:30.662 ServerApp] 404 GET /lab/api/...
<python><markdown><jupyter-lab>
2023-11-09 22:30:00
3
441
ezyman
77,456,584
12,827,931
Adding alpha area (confidence interval) to sns pointplot
<p>Assume a dataframe</p> <pre><code>df = pd.DataFrame({&quot;X&quot; : [1, 1, 2, 2, 3, 3, 4, 4], &quot;Model&quot; : [&quot;A&quot;, &quot;B&quot;, &quot;A&quot;, &quot;B&quot;, &quot;A&quot;, &quot;B&quot;, &quot;A&quot;, &quot;B&quot;], &quot;Lower&quot; : [0.2, 0.3, 0.2, 0.2, ...
<python><pandas><matplotlib><seaborn><visualization>
2023-11-09 22:01:25
1
447
thesecond
77,456,537
4,913,108
How to create Pandas bar plot with values from one column but filled (stacked) with values from another?
<p>I have a Pandas dataframe like the one below:</p> <pre><code>df = pd.DataFrame({'decile': [1,1,2,2,2,3,3,3], 'conversion': [.3,.3,.5,.5,.5,.55,.55,.55], 'campaign': ['tv','online','tv','online','radio','tv','online','radio'], 'campaign_pct': [.6,.4,.5,.4,.1,.4...
<python><pandas>
2023-11-09 21:46:15
1
5,750
Gaurav Bansal
77,456,519
12,297,666
Difference between one-hot-encoded and integer output in Sklearn
<p>Consider the case of a multiclass classification problem with 12 classes (classes 0 to 11). These classes are <strong>nominal</strong> categorical variables (no ranking order).</p> <p>I have trained two models (<code>M1</code> and <code>M2</code>), as follows:</p> <p><code>M1</code>: The output vector, <code>y_train...
<python><machine-learning><scikit-learn><one-hot-encoding>
2023-11-09 21:42:23
1
679
Murilo
77,456,488
226,473
How to prepend (and append) to string if it contains a whitespace character?
<p>here is what i've tried:</p> <pre><code> df[df.path.str.contains(&quot; &quot;, na=False)] = df['^' + df.path.astype('str') + '$'] </code></pre> <p>this gives me an error though. Basically what I tried was to set the 'path' column to the same value with one character prepended (and appended). But I tried to set only...
<python><pandas>
2023-11-09 21:35:24
1
21,308
Ramy
77,456,434
7,124,155
I need to aggregate and transpose one column to rows in Pyspark (long to wide format)
<p>I need to &quot;explode&quot; one column to multiple columns - similar to pivot but I need new column names.</p> <p>Give this spark dataframe:</p> <pre><code>df = spark.createDataFrame( [(1, 6, 200), (1, 6, 300), (1, 6, 400), (1, 7, 1000), (1, 6, 5000)], &quot;id int, term int, amount int&quot;) df.show()...
<python><dataframe><apache-spark><pyspark>
2023-11-09 21:23:03
2
1,329
Chuck
77,456,285
1,432,980
can't get attribute function when running multiple processes
<p>I wanted to compare the speed when using multiprocessing and a normal linear function.</p> <p>My code looks like this</p> <pre><code>from multiprocessing import Pool, Manager import time from faker import Faker num_rows = 1000000 items = [ ['Column_1', Faker(), &quot;pyint&quot;, {}], ['Column_2', Faker(),...
<python><concurrency><multiprocessing>
2023-11-09 20:55:27
1
13,485
lapots
77,456,223
1,492,613
why in the packaging.sys_tags() the lower cp version has higher priority than the py version which has no implementation spec?
<p>from the document:</p> <blockquote> <p>The iterable is ordered so that the best-matching tag is first in the sequence. The exact preferential order to tags is interpreter-specific, but in general the tag importance is in the order of:</p> <ol> <li>Interpreter</li> <li>Platform</li> <li>ABI</li> </ol> </blockquote> <...
<python><python-packaging>
2023-11-09 20:45:19
1
8,402
Wang
77,456,185
21,370,869
Passing command line arguments to a .ps1 file from Python's subprocess.Popen() method
<p>I would like to pass command line arguments to to the file &quot;my script.ps1&quot;, as well as pass <code>NoProfile</code> to the PowerShell executable.</p> <p>The scripts (<code>c:/temp/my script.ps1</code>) content is:</p> <pre><code>param($param1, $param2, $param3) $PSBoundParameters.Keys.count $param1 $param2 ...
<python><powershell>
2023-11-09 20:36:58
1
1,757
Ralf_Reddings
77,456,088
1,738,895
Difference in record counts between my SQL editor and Python psycopg2 query
<p>I am running the exact same redshift query copied from a sql editor to python. In python I have tested counts from pandas.read_sql and direct psycopg2 cursor.execute queries. On the SQL editor side, I have tested the counts in dbeaver, beekeeper and mysqlworkbench. I have stripped out all joins to simplify the query...
<python><sql><amazon-redshift><psycopg2>
2023-11-09 20:13:44
0
1,444
vizyourdata
77,455,817
1,942,868
Get the list of certain columns wihout duplicates from a model object
<p>I have a model object such as</p> <pre><code>class MyMenu(models.Model): key= m.CharField(max_length=255,unique=True) name = m.CharField(max_length=255) </code></pre> <p>Now there is data like this,</p> <pre><code> key,name a hiro b hiro c fusa d yoshi e yoshio f fusa </code></pre> <p>Now I wo...
<python><django>
2023-11-09 19:15:13
2
12,599
whitebear
77,455,738
5,277,842
Finding the nouns in a sentence given the context in Python
<p>How to find the nouns in a sentence regarding the context? I am using the <code>nltk</code> library as follows:</p> <pre><code>text = 'I bought a vintage car.' text = nltk.word_tokenize(text) result = nltk.pos_tag(text) result = [i for i in result if i[1] == 'NN'] #result = [('vintage', 'NN'), ('car', 'NN')] </code...
<python><nlp><nltk><textblob>
2023-11-09 18:59:33
2
429
Shayan
77,455,688
2,304,735
How can I add data to the index column of a pandas dataframe?
<p>I want to output the following dataframe</p> <pre><code>Ratio A B C ROA ROE ROI </code></pre> <p>Below is the code that I am trying to run</p> <pre><code>import pandas as pd col_list = ['A', 'B', 'C'] data = pd.DataFrame([['ROA', 'ROE', 'ROI']], columns=col_list) data.index.names = ['Ratios'] ratio_rows = ['RO...
<python><pandas><dataframe>
2023-11-09 18:51:08
2
515
Mahmoud Abdel-Rahman
77,455,436
11,898,085
Holoviz Panel: how to extract the button name in a callback method?
<p>I need the button name for my Holoviz Panel callback method because the name serves also as a key to a dictionary containing sql commands to be executed on click. I’ve tried to search if the event passed to the callback could have some properties including the name but I have found nothing. There must(?) be a way of...
<python><button><callback><holoviz-panel>
2023-11-09 18:03:45
1
936
jvkloc
77,455,423
10,985,257
Run command via python with sudo and capture stdout
<p>I want to run a sudo command from within python, because my script does a lot of things, that should be handled without the right necessary for commands like <code>apt install</code>.</p> <p>Further for most of those command I need the return value for analysis.</p> <p>What I have so far:</p> <pre class="lang-py pre...
<python><subprocess><sudo>
2023-11-09 17:59:43
0
1,066
MaKaNu
77,455,386
3,821,009
How to format polars.Duration?
<p>This:</p> <pre><code>df = (polars .DataFrame(dict( j=['2023-01-02 03:04:05.111', '2023-01-08 05:04:03.789'], k=['2023-01-02 03:04:05.222', '2023-01-02 03:04:05.456'], )) .select( polars.col('j').str.to_datetime(), polars.col('k').str.to_datetime(), ) .with_columns( l=polars.col('k')...
<python><python-polars>
2023-11-09 17:53:42
1
4,641
levant pied
77,455,383
1,673,702
Reshape JSON hierarchically
<p>I have this JSON file:</p> <pre><code>{ &quot;animal&quot;: { &quot;debug&quot;: { &quot;forceQuitCell&quot;: true, &quot;surviveWithoutFood&quot;: false }, &quot;name&quot;: &quot;Tyrannosaurus_sp&quot;, &quot;defaultHuntingMode&quot;: &quot;active_hunting...
<python><json><treeview>
2023-11-09 17:53:30
0
441
kankamuso
77,455,300
11,159,734
Streamlit: How to add proper citation with source content to chat message
<p>I'm currently building a RAG (Retrieval Augmented Generation) Chatbot in Streamlit that queries my own data from a Postgres database and provides it as context for GPT 3.5 to answer questions about my own data.</p> <p>I have got the basics working already (frontend and backend). Now I also want to display the source...
<python><streamlit>
2023-11-09 17:40:15
1
1,025
Daniel
77,455,287
1,946,418
python - get access to decorator class's "self" inside the inner method
<p>Following the example shown here - <a href="https://www.geeksforgeeks.org/creating-decorator-inside-a-class-in-python/" rel="nofollow noreferrer">https://www.geeksforgeeks.org/creating-decorator-inside-a-class-in-python/</a></p> <pre class="lang-py prettyprint-override"><code># creating class A class A: self.som...
<python><python-3.x><python-decorators>
2023-11-09 17:39:08
0
1,120
scorpion35
77,455,164
7,475,193
Executing .py with bash command but how to pass variables - Airflow
<p>I have a DAG definition file where I use BashOperator to call a Python script:</p> <pre><code>with DAG(dag_id='test', default_args=default_args, schedule_interval='0 1 * * *', catchup=False) as dag: # Instantiate tasks task_1 = BashOperator( task_id='tsk1', bash_command=f'python {PATH}/updat...
<python><airflow>
2023-11-09 17:16:13
0
477
eponkratova
77,455,158
8,565,438
How do I label features in an array by their size?
<p>I have a 2D boolean numpy array, <code>mask</code>:</p> <pre><code>array([[False, False, False, True, True, False, False, False], [ True, True, True, False, True, False, False, False], [False, False, True, False, False, True, False, True], [ True, False, False, False, True, True, False...
<python><numpy><scipy>
2023-11-09 17:15:37
1
8,082
zabop
77,455,083
6,458,245
Efficiently subtract row from array n times and create a new dimension?
<p>I have a numpy array of size A = (x,y). I want to subtract 100 different rows from each row in array A. So the end size is (x,y,100). How do I do this efficiently?</p> <p>In pseudo code this would look something like:</p> <pre><code>for i in range(100): list.append([A - B[i]]) np.stack(list) </code></pre>
<python><python-3.x><numpy>
2023-11-09 17:03:49
2
2,356
JobHunter69
77,455,052
6,728,433
Spark unpersist when cache() was never called
<p>I'm reviewing someone's code and I see they're calling <code>df.unpersist()</code> on a dataframe that was never cached. This is an abbreviated version of the code:</p> <pre><code>def get_and_prepare_data(): # Read the data input_df = spark.sql('SELECT * FROM my_table') try: # Do a bunch of transf...
<python><apache-spark><pyspark>
2023-11-09 16:58:54
0
798
S.S.
77,454,939
12,978,930
Polars: Nesting `over` calls
<p><strong>Context.</strong> I have written a function that computes the mean of all elements in a column except the elements in the current group.</p> <pre><code>df = pl.DataFrame({ &quot;group&quot;: [&quot;A&quot;, &quot;A&quot;, &quot;B&quot;, &quot;B&quot;, &quot;C&quot;, &quot;C&quot;], &quot;value&quot;:...
<python><dataframe><window-functions><python-polars>
2023-11-09 16:41:11
2
12,603
Hericks
77,454,929
5,548,026
Installing google-colab with anaconda and pip throws an error in pandas setup command
<p>I need to install google-colab and I keep having various issues with the task. Current version of python is 3.11.5 on Win11, pip version 23.3, conda is 23.10.0. I get the following error on my Anaconda Prompt.</p> <pre><code>Collecting google.colab Using cached google_colab-1.0.0-py2.py3-none-any.whl Collecting go...
<python><pandas><pip><google-colaboratory>
2023-11-09 16:40:00
1
401
user159941
77,454,895
7,431,005
XGBoost warning: running on cuda while input data is on cpu
<p>I tried to train a XGBoost model using GPU acceleration. When training my model using gridsearch, I get the following warning:</p> <blockquote> <p>UserWarning: [17:29:04] WARNING: /workspace/src/common/error_msg.cc:58: Falling back to prediction using DMatrix due to mismatched devices. This might lead to higher memo...
<python><scikit-learn><xgboost>
2023-11-09 16:35:26
1
4,667
user7431005
77,454,601
9,919,423
How to load a DBF file within a zip file to a variable without extracting it in Python?
<p>I am trying to load a DBF file that is contained within a zip file into a variable without extracting the zip file. I have tried using the following code, but it is not working:</p> <pre><code>import zipfile from dbfread import DBF def load_dbf_from_zip(zip_filename): with zipfile.ZipFile(zip_filename, 'r') as ...
<python><zip><dbf><python-zipfile>
2023-11-09 15:55:22
1
412
David H. J.
77,454,581
3,336,423
Python/unitest: Is it possible to have the same function called many times and test not interrupted in case of failure?
<p>I'm testing a module with Python <code>unittest</code> library. I'd like to call a unt test methos with different arguments, but would like each call to be a separate test case:</p> <pre><code>import unittest class TestStringMethods(unittest.TestCase): def test_all(self): for x in range(10): ...
<python><python-unittest>
2023-11-09 15:52:41
2
21,904
jpo38
77,454,475
583,187
TypeError when using openai-api
<p>Using the code below and openai version 0.28.0 i get an error which i can't resolve:</p> <p>File &quot;&quot;, line 11, in TypeError: string indices must be integers, not 'str'</p> <p>Which indice is it complaining about. Seems I'm a little blind today...</p> <pre><code>import requests from bs4 import BeautifulSoup...
<python><openai-api>
2023-11-09 15:38:08
1
2,841
Lumpi
77,454,412
9,686,427
ModuleNotFoundError: No module named 'firebase_admin' after installing firebase
<p>I'm getting <code>ModuleNotFoundError: No module named 'firebase_admin' </code> after installing firebase i.e. I've performed the following steps:</p> <ol> <li><p>Open the console and install firebase via <code>pip3 install firebase-admin</code>. The requirements are already satisfied.</p> </li> <li><p>Running <code...
<python><firebase><firebase-admin>
2023-11-09 15:30:40
1
484
Sam
77,454,215
2,532,408
poetry fails to install psycopg2-binary in python 3.12 (macos)
<p>I cannot get <code>psycopg2-binary</code> package to install via poetry in python3.12.</p> <hr /> <p>pyproject.toml</p> <pre><code>[tool.poetry] name = &quot;my_project&quot; [tool.poetry.dependencies] psycopg2-binary = &quot;*&quot; [build-system] requires = [&quot;poetry-core&gt;=1.8.1&quot;] build-backend = &qu...
<python><macos><psycopg2><python-poetry>
2023-11-09 15:03:33
2
4,628
Marcel Wilson
77,454,163
11,039,749
Issue Installing TensorFlow or PyTorch
<p>I am trying to Install TensorFlow or PyTorch. I tried doing in a normal project and also a virtual project. These are the errors I get and I tried many different versions and reading documentation.</p> <pre class="lang-bash prettyprint-override"><code>pip install torch pip3 install torch --no-cache-dir pip install &...
<python><tensorflow><pytorch>
2023-11-09 14:55:50
2
529
Bigbear
77,453,929
12,689,373
How to add rows in a dataframe by a column condition python
<p>I have a dataframe like that:</p> <pre><code>df = pd.DataFrame({'year': [2022,2022,2022,2022,2022,2022,2022,2022,2022,2022,2022,2022,2022,2022,2022,2022,2022,2022,2022], 'month': [1,2,3,1,2,3,4,5,6,7,8,9,10,11,1,2,3,4,5], 'client':[1,1,1,2,2,2,2,2,2,2,2,2,2,2,3,3,3,3,3], 'total':[10,20,30,55,4,64,88,5,64,32,84,24,6...
<python><row><addition>
2023-11-09 14:23:57
2
349
Cristina Dominguez Fernandez
77,453,779
6,068,294
Invert the Laplacian of a 2D fixed grid data array
<p>I want to invert the Laplacian on a 2d fixed grid in python, and then take the gradient, the first step of which was possible to do in <code>ncl</code> using the <a href="https://www.ncl.ucar.edu/Document/Functions/Built-in/ilapsf.shtml" rel="nofollow noreferrer"><code>ilapsf</code></a> function. This is essentiall...
<python><cdo-climate><ncl>
2023-11-09 14:00:01
0
8,176
ClimateUnboxed
77,453,771
9,620,383
How do I remove a choco version constraint that I previously added?
<p>Previously, I needed a specific version of python and installed <code>choco install python --version=3.7.5</code></p> <p>I now want to upgrade, but choco still thinks I have this version dependency and gives me the error:</p> <p><code>Unable to resolve dependency 'python': Unable to resolve dependencies. 'python3 3....
<python><windows><installation><chocolatey><choco>
2023-11-09 13:58:29
1
600
WorstCoder4Ever
77,453,673
3,104,974
pyspark.pandas: Converting float64 column to TimedeltaIndex
<p>I want to convert a numeric column which is resembling a timedelta in seconds to a <code>ps.TimedeltaIndex</code> (for the purpose of later resampling the dataset)</p> <pre><code>import pyspark.pandas as ps df = ps.DataFrame({&quot;time&quot;: [2.0, 3.0, 4.0], &quot;x&quot;: [4.5, 4.0, 3.5]}) df.set_index(ps.to_tim...
<python><apache-spark><pyspark><pyspark-pandas>
2023-11-09 13:42:34
2
6,315
ascripter
77,453,659
457,290
why does numpy.trapz behave differently with booleans than with ints?
<p>Booleans in Python are implemented as ints and usually there is no difference in <code>numpy</code> and other packages when changing <code>0</code> by <code>False</code> and <code>1</code> by <code>True</code>. Why then these two computations differ?</p> <pre class="lang-py prettyprint-override"><code>&gt;&gt;&gt; i...
<python><numpy>
2023-11-09 13:40:38
1
2,019
matiasg
77,453,594
315,168
Parallelising functions using multiprocessing in Jupyter Notebook
<p>Edit: I updated the question with a trivial repeatable example for ipython, PyCharm and Visual Studio Code. They all fail in a different way.</p> <p>I am running CPU-intensive tasks in Jupyter Notebook. The task is trivial to parallelise and I am already able to do this in a notebook via threads. However, due to Pyt...
<python><jupyter-notebook><python-multiprocessing>
2023-11-09 13:30:40
3
84,872
Mikko Ohtamaa
77,453,550
31,667
Numpy array of a batch of shifted ranges
<p>I'd like to create a numpy array filled with the values from another array, but each row shifted by one (or some other constant). So for example mapping an array with elements 1,2,3,4,5.... to a 5x5 array, I would expect:</p> <pre><code>1 2 3 4 5 2 3 4 5 6 3 4 5 6 7 4 5 6 7 8 5 6 7 8 9 </code></pre> <p>Currently I'm...
<python><numpy>
2023-11-09 13:24:00
3
34,355
viraptor
77,453,529
4,025,749
SSL Error with Zeep Python Library when VPN is disconnected
<p>I am currently using the Zeep Python library for my project and I’ve encountered an issue that I hope someone can help me with.</p> <p>When I try to run my code without connecting to my company’s VPN, I get the following error:</p> <pre><code>requests.exceptions.SSLError: HTTPSConnectionPool(host='ws-gateway-cert.xx...
<python><soap><ssl-certificate><zeep>
2023-11-09 13:20:09
1
616
Omid Erfanmanesh
77,453,416
7,631,505
How to make this calculation faster?
<p>So I have an issue that I will explain: I have a set of images that come from an experiment, each pixel of these images has 3 values associated which depend on the position (in case you wonder this is a diffraction experiment). What I would need is the intensity of the pixel, but as a function of these three values....
<python><numpy><performance><optimization>
2023-11-09 13:02:19
1
316
mmonti
77,453,408
2,725,810
How to process fast 10,000 small objects stored in S3
<p><strong>The problem</strong>: Given a list of 10000 paths to objects stored in S3, I need to process the corresponding objects fast (under 1 second). Each object is 40 KB.</p> <p><strong>The background</strong>: Each object represents a document. Each document is associated with one or more users (could be a thousan...
<python><amazon-web-services><amazon-s3><aws-lambda><boto3>
2023-11-09 13:01:11
1
8,211
AlwaysLearning
77,453,363
16,056,216
Videocapture from opencv doesn't work for me. What should I do?
<p>I have dockerized my app and I have used <code>http://nvcr.io/nvidia/pytorch:23.10-py3</code> base image. I'll share my dockerfile with you. I am also using Ubuntu.</p> <p>The problem here is that <code>videocapture</code> method from <code>opencv==4.8.0.74</code> doesn't work!</p> <p>It doesn't give me an error but...
<python><docker><opencv><dockerfile><video-capture>
2023-11-09 12:53:39
0
362
Amirreza Hashemi