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
78,470,209
8,884,239
How to explode string type column in pyspark dataframe and make individual columns in table
<p>I am getting following value as string from dataframe loaded from table in pyspark. It is List of nested dicts. I want to explode and make them as separate columns in table using pyspark.</p> <pre><code>dataframe col = [{ser={cos=hon, mgse=yyyyyyyy, bd=1994-06-11}, ap={}, ep={}}, {ser={cos=null, mgse=null, bd=null}...
<python><amazon-web-services><apache-spark><pyspark><aws-glue>
2024-05-13 05:31:14
1
301
Bab
78,470,100
4,390,618
Raspberry pi GPIO pin not turning off
<p>I bought RPi, flashed the OS. I also bought a 5V relay. I have connected the 2nd pin to VCC of the relay, 6th pin to GND of the relay, 40th pin to the 'IN' point of the relay. At present I have not connected anything to the other side of the relay (but the problem also exists if I connect a load of led). Also no oth...
<python><raspberry-pi3><gpio>
2024-05-13 04:36:04
3
439
LearneriOS
78,470,098
19,048,408
How do I configure Python "yapf" to format method calls with chained methods in args (Polars-style) like this?
<p>How do I configure <a href="https://github.com/google/yapf" rel="nofollow noreferrer">YAPF</a> to auto-format Python code like the following example? This is very useful in the domain-specific language (DSL) that Polars creates for data transformations.</p> <p>This is roughly how I want it to be formatted (note the ...
<python><python-polars><yapf>
2024-05-13 04:34:56
0
468
HumpbackWhale194
78,469,817
11,280,068
duckdb - can't insert data due to constraint, but also there is no constraint
<p>I have a table in postgres that I want to use duckdb to insert into. I have a unique constraint on the table that uses multiple columns to determine a unique row. On conflict, the duplicate rows should be ignored.</p> <p>Here is the code I use to set it up (in a class but doesn't make a difference)</p> <pre class="l...
<python><sql><postgresql><constraints><duckdb>
2024-05-13 02:14:53
1
1,194
NFeruch - FreePalestine
78,469,772
5,656,369
Import fails with certain subdirectory name
<ul> <li>I attempt to import a Python module that's in a subdirectory of my current working directory.</li> <li>If I name the subdirectory <code>foo_bar</code> or <code>one_two_three</code> or <code>python_foo</code>, the import succeeds.</li> <li>But if I name the subdirectory <code>python_utils</code>, the import fai...
<python>
2024-05-13 01:49:34
0
462
teraspora
78,469,755
108,741
Zoho CRM Python SDK 2.1 won't update record owner
<p>When I try to change the owner on a Zoho record I get a success message but the Lead Owner field doesn't change. The record is in the &quot;Potentials&quot; module (I think it's a custom module)</p> <pre><code>lead: Record = self.get_lead(int(lead_id)) user: ZCRMUser = self.get_user_by_email(owner_email) # Perform ...
<python><zoho>
2024-05-13 01:40:43
1
39,106
SpliFF
78,469,621
2,684,250
Custom MultiInput Model Field in Django
<p>I'm trying to create a custom field for volume made up of 4 parts (length, width, height and units). I'm thinking that extending the models.JSONField class makes the most sense.</p> <p>Here is what I have so far.</p> <p>inventory/models.py</p> <pre><code>from django.db import models from tpt.fields import VolumeFiel...
<python><django><django-models><django-forms>
2024-05-13 00:09:15
1
405
Stuart Clarke
78,469,592
16,717,009
How can I access the name of namedtuple attribute from inside a method if it wasn't passed as a string?
<p>This is a followup to <a href="https://stackoverflow.com/questions/78450557/how-can-i-pass-a-namedtuple-attribute-to-a-method-without-using-a-string">How can I pass a namedtuple attribute to a method without using a string?</a>. Given this solution to the above:</p> <pre><code>from typing import NamedTuple class Re...
<python><namedtuple>
2024-05-12 23:54:40
1
343
MikeP
78,469,589
2,410,605
Python program to send updates to a vendor's API works accept for processing the return response
<p>This is my first attempt at using an API. I went with Python and everything seemed to work -- I was able to send 17,500+ records to a vendor and they are showing up perfect on their website. The problem is that the vendor is using different IDs then we are. I work for a public school system and this is for our bus t...
<python><t-sql>
2024-05-12 23:53:51
1
657
JimmyG
78,469,325
7,339,624
AttributeError: module 'networkx' has no attribute 'bfs_layout'
<p>I just installed <code>networkx</code>(currently version 3.3) and I went to try their <a href="https://networkx.org/documentation/stable/reference/generated/networkx.drawing.layout.bfs_layout.html#networkx.drawing.layout.bfs_layout" rel="nofollow noreferrer">official sample code</a> for drawing a graph with bfs layo...
<python><graph><networkx>
2024-05-12 21:20:06
1
4,337
Peyman
78,469,275
12,304,000
to_numeric() adds a decimal to all numeric values
<p>I have a dataset that looks like this:</p> <pre><code>profession Australia_F Australia_M Canada_F Canada_M Kenya_F Kenya_M Author #DIV/0! 80 55 34 60 23 Librarian 10 34 89 33 89 12 Pil...
<python><pandas><dataframe><data-analysis><pandas-melt>
2024-05-12 20:55:58
1
3,522
x89
78,469,262
12,304,000
create heatmap with only 2 colors
<p>I have a dataset that looks like this:</p> <pre><code>profession Australia_F Australia_M Canada_F Canada_M Kenya_F Kenya_M Author 20 80 55 34 60 23 Librarian 10 34 89 33 89 12 Pil...
<python><pandas><matplotlib><seaborn><heatmap>
2024-05-12 20:49:21
2
3,522
x89
78,469,209
1,377,288
Unable to connect to VertexAI from Cloud Run, but it works locally
<p><strong>EDIT</strong></p> <p>In my case, this was happening because of the VPC. I'm not sure how to configure things so that VertexAI is accessible via VPC (like I said below, I added the integration), but for now, I disabled the VPC and the service is able to access the model.</p> <hr /> <p>I have a Cloud Run servi...
<python><docker><gcloud><google-cloud-run><google-cloud-vertex-ai>
2024-05-12 20:23:53
0
527
Tuma
78,469,002
3,120,501
Python packaging: including files/modules which import each other
<p>Sorry for the simple question, but I've been through some tutorials and I'm still not sure what the best way is to solve my issue.</p> <p>I'm trying to install my Python code locally to make it easier to import into other projects I'm developing (the core project is a simulator which I want to utilise in other appli...
<python><python-import><setuptools><python-packaging>
2024-05-12 19:00:48
0
528
LordCat
78,468,872
16,674,436
matplotlib ValueError: Image size of 1781907x1084 pixels is too large. It must be less than 2^16 in each direction
<p>Yet another question regarding this somewhat typical error I guess, but I neither understand nor find the correct answer.</p> <p>Here is the data frame I have:</p> <pre><code>import pandas as pd df = pd.DataFrame({ 'author': ['someguy', 'someone', 'again'], 'created_utc': ['2021-01-30 18:00:38', '2021-01-28...
<python><pandas><matplotlib><plot>
2024-05-12 18:18:37
0
341
Louis
78,468,862
10,089,194
Struggling with relative imports. Help me confirm that my understanding of "attempted relative import beyond top-level package" error is correct
<p>In my folder named <code>project</code>, this is my directory structure.</p> <pre><code>. ├── folder_1 │ ├── folder_3 │ │ ├── module_3.py │ │ └── module_4.py │ └── module_1.py ├── folder_2 │ └── module_2.py └── script.py </code></pre> <p>I am trying to do relative imports inside <code>module_3.py</code...
<python><import><package><relative-import>
2024-05-12 18:14:59
1
369
user10089194
78,468,856
2,128,014
Advancing to the next video using PyQt6
<p>I am trying to run a PyQt6 <a href="https://doc.qt.io/qtforpython-6.2/examples/example_multimedia__player.html" rel="nofollow noreferrer">example</a> , but the method to advance the video player to the next clip gets the UI stuck (unresponsive). How can I fix that?</p> <p>The code to move to the next clip is</p> <pr...
<python><pyqt6>
2024-05-12 18:14:27
0
4,191
radumanolescu
78,468,763
6,626,531
Using MultiThreading to Call and API. How to get kill slow processes?
<p>I need to kill tasks that are running long.</p> <p>I have a bunch of api calls that I need to make. I'm currenting using <code>ThreadPoolExecutor</code> to have 12 workers to run in parallel. Each worker will call the api and return a result that I then join back together.</p> <p>The problem is that the api that I'...
<python><python-3.x><python-requests><threadpoolexecutor>
2024-05-12 17:34:21
0
1,975
Micah Pearce
78,468,180
9,815,697
How to install a locally developed python wheel file as part of a native Snowflake app
<p>I am trying to install a local python wheel file as part of a Snowflake native app.</p> <p>I tried the steps in the following article: <a href="https://medium.com/snowflake/introducing-simple-workflow-for-using-python-packages-in-snowpark-928f667ff1aa" rel="nofollow noreferrer">https://medium.com/snowflake/introduci...
<python><snowflake-cloud-data-platform>
2024-05-12 14:18:27
1
1,182
Mutlu Simsek
78,468,135
5,515,287
Anaconda Navigator Backup on Mac OS is not working on Windows
<p>I have a backup from my anaconda navigator environment on mac but when I'm importing it on windows its not working and showing the error that packages not found:</p> <pre><code>name: university_web_scraping channels: - conda-forge - defaults dependencies: - anyio=4.2.0=py310hecd8cb5_0 - appnope=0.1.2=py310he...
<python><anaconda>
2024-05-12 14:01:06
1
3,123
Mustafa Poya
78,467,773
2,302,262
Use decorator for repeated overloading
<h3>TLDR</h3> <p>I'm trying to make my type checker happy by specifying overloading of my functions. There is a specific signature I have many of, and I'd like to keep things dry.</p> <h3>Example and current code</h3> <p>I have many functions that take, as their first argument, an <code>int</code> or a <code>float</cod...
<python><python-typing>
2024-05-12 12:04:53
1
2,294
ElRudi
78,467,713
2,707,955
How to use numpy polynomial expression without numpy?
<p>To follow up on a <a href="https://stackoverflow.com/questions/78455901/how-to-find-the-mathematical-function-from-list-of-plots">previous question</a>, I would like to extract the polynomial to calculate the result for certain values ​​in a python environment without numpy.</p> <p>The code :</p> <pre><code>import n...
<python><numpy>
2024-05-12 11:46:22
1
365
Aurélien
78,467,681
1,381,340
How is Numpy able to get an array size at run-time?
<p>In C++ the size of an array must be determined at the compile-time. I want to write a simple code in C++, say, to do a naive matrix multiplication with itself (for a matrix that is square in size) and I want to do it for any matrix size. However, I do not know how I can get the matrix sizes or the matrices of variou...
<python><c++><numpy><heap-memory><stack-memory>
2024-05-12 11:37:27
1
2,871
MOON
78,467,670
9,864,539
Passing pointer to C struct to ioctl in Python
<p>I am writing a Python script that needs to use the <a href="https://docs.kernel.org/filesystems/fscrypt.html#fs-ioc-add-encryption-key" rel="nofollow noreferrer"><code>FS_IOC_ADD_ENCRYPTION_KEY</code></a> ioctl.</p> <p>This ioctl expects an argument of type (pointer to) <code>fscrypt_add_key_arg</code>, which has th...
<python><c><ioctl>
2024-05-12 11:33:58
1
672
Ricky Sixx
78,467,605
1,113,579
Broken automatic parameter injection of Connexion 2.7.0 when used with OpenAPI 3.0.0
<p>I have a Flask backend which uses Connexion 2.7.0 with OpenAPI 3.0.0.</p> <p>My swagger.yaml file is defined like this:</p> <pre><code>openapi: 3.0.0 info: title: MyApp version: &quot;1.0&quot; paths: /run_recon: post: summary: run_recon operationId: services.model.run_recon requestBody: ...
<python><flask><swagger><openapi><connexion>
2024-05-12 11:09:59
0
1,276
AllSolutions
78,467,484
4,342,400
Installed requirements cannot be found in heroku
<p>Hello everyone im trying to deploy a small monorepo app with the ui and the api on the same project. I want to deploy on heroku solely through the git integration and not heroku cli or something else. I use a package.json in my root folder which is the following.</p> <pre><code>{ &quot;name&quot;: &quot;app&quot;, &...
<python><heroku><deployment><requirements.txt>
2024-05-12 10:30:22
1
336
leo_bouts
78,467,412
9,506,773
How to toggle torch cpu and gpu installation using poetry
<p>I am trying to enable the installation of cpu and gpu versions of <code>torch</code> and <code>torchvision</code>, using <code>poetry install --with cpu</code> and <code>poetry install --with gpu</code>, respectively. I have the following in my <code>pyproject.toml</code>:</p> <pre class="lang-ini prettyprint-overri...
<python><python-poetry>
2024-05-12 10:01:44
2
3,629
Mike B
78,467,030
6,032,979
Why does Cognito's admin-get-user report that a user does not exist if it is external user?
<p>There is a user, let's say, <code>user@email.com</code> whom I can see in AWS Cognito Console. But when I try to access that user using <code>admin-get-user</code>, I get <code>UserNotFoundException</code>. Here is a python code of what I was trying to do:</p> <pre class="lang-py prettyprint-override"><code>import b...
<python><amazon-web-services><amazon-cognito>
2024-05-12 07:43:25
1
584
KapilDev Neupane
78,466,922
9,072,753
What is the rationale for specifying dynamic width and precision _after_ the argument in str.format?
<p>In C programming language dynamic field width and precision is specified before the argument.</p> <pre><code>printf(&quot;%.*s&quot;, 2, &quot;ABCDEF&quot;) </code></pre> <p>Yet when <code>str.format</code> was introduced in Python3.0 in 2008 the dynamic field width and precision is specified <em>after</em> the argu...
<python><python-3.x><format><f-string>
2024-05-12 06:52:19
3
145,478
KamilCuk
78,466,852
3,286,489
In Python, how to print a date in an array concisely without extracting it?
<p>When I extract a date from a PR and printed it as below</p> <pre><code>updated = pull_request.updated_at print(f&quot;Updated At: {updated}&quot;) </code></pre> <p>It printed well</p> <pre><code>Updated At: 2024-05-09 00:45:14+00:00 </code></pre> <p>However if I put in an array (I have some other element in the arra...
<python><arrays>
2024-05-12 06:20:39
3
61,245
Elye
78,466,835
5,043,301
Create Super User issue in django
<p>My model is like below.</p> <pre><code>from django.db import models from django.contrib.auth.models import AbstractUser # Create your models here. class User(AbstractUser): GENDER_CHOICES = ( ('M', 'Male'), ('F', 'Female'), ('O', 'Other'), ) USER_TYPE = ( ('S', 'Super A...
<python><django><django-models>
2024-05-12 06:11:13
0
7,102
abu abu
78,466,772
7,021,836
Single millisecond send resolution with python-can, Vector CANalyzer
<p>python version: 3.9.13, python-can version: 4.0.0</p> <p>I am trying to send a CAN message every millisecond using python-can to access Vector's CANalyzer software. Using the code below, I would expect to see a message every millisecond:</p> <pre><code>import can import time import logging bus = can.interface.Bus(b...
<python><can-bus><python-can>
2024-05-12 05:25:04
0
1,251
ack
78,466,708
193,939
CrewAI not finding co-worker
<p>I'm new to python and its frameworks, but I'm an experienced C# developer. I'm attempting to write a test &quot;Crew&quot; for CrewAI, but I'm getting:</p> <pre><code>Error executing tool. Co-worker mentioned not found, it must to be one of the following options: - writer </code></pre> <p>A single-agent crew works a...
<python><langchain><crewai>
2024-05-12 04:33:53
1
5,952
Nathan Wheeler
78,466,674
10,474,024
No such file or directory error for entrypoint.sh file in docker
<p>I am following a course and currently stuck on <a href="https://testdriven.io/courses/tdd-django/pytest-setup/" rel="nofollow noreferrer">this part</a> of it.</p> <p>After starting up Docker container (that says it is installed correctly when running localhost) I get: <code>service &quot;movies&quot; is not running...
<python><django><docker-compose>
2024-05-12 04:06:49
1
321
ProsperousHeart
78,466,656
1,851,782
Matplotlib plot contours of a function with downhill direction?
<p>I am trying to recreate a plot style in matplotlib.</p> <p>In the plot, the ticks on each contour show the downhill direction of the function. I want to recreate this plot but for the surface <code>-x^3/3+x y^2+x</code> with tick marks showing the downhill direction like in this plot.</p> <p>How can I achieve this e...
<python><matplotlib><plot>
2024-05-12 03:49:03
0
1,724
random0620
78,466,652
5,361,994
How to exclude fields with null values using polar dataframe columns for final json output?
<p>I am trying to read and process the bigquery table using the polars. At the end I want to write the each row as a JSON in the file such that all the fields that have null values in it (no matter how nested the JSON is) is excluded.</p> <p>I am using polars to process the bigquery row. I am new to polars and could no...
<python><google-bigquery><python-polars><google-bigquery-storage-api>
2024-05-12 03:46:30
2
428
programmingtech
78,466,591
222,977
Tensorflow input of varying shapes
<p>I'm using Tensorflow 2.16.1. I have a list of Tensors I want to use as training data. They are varying shapes. It's unclear how I can make this work. Here is some example code:</p> <pre><code>import tensorflow as tf indices = [[0, 0], [1, 1]] values = [0.5, 0.5] tensor_1 = tf.sparse.SparseTensor(indices=indices, va...
<python><tensorflow><keras>
2024-05-12 02:59:41
0
583
Dan
78,465,961
3,163,618
Correctness of smaller cube function
<p>For what range is this function I came up with to find the biggest cube smaller than integer n valid?</p> <pre><code>def smaller_cube(n): k = int(n**(1/3)) return k**3 if k**3 &lt; n else (k-1)**3 </code></pre> <p><code>64**(1/3) == 3.99999...</code> but the truncation works in this case, and if it were <co...
<python><integer><precision>
2024-05-11 20:03:04
1
11,524
qwr
78,465,956
2,789,445
Are WEBSITE_RUN_FROM_PACKAGE="1" and SCM_DO_BUILD_DURING_DEPLOYMENT=true compatible options for a ZipDeploy Azure App Service Python WebApp on linux?
<p>Are <code>WEBSITE_RUN_FROM_PACKAGE=&quot;1&quot;</code> and <code>SCM_DO_BUILD_DURING_DEPLOYMENT=true</code> compatible options for a ZipDeploy Azure App Service Python WebApp on linux? Also, my webapp is using gunicorn, if that matters.</p> <p>When I deploy my python webapp as a zipfile, which includes my python fi...
<python><web-applications><azure-web-app-service><gunicorn><azure-appservice>
2024-05-11 20:01:08
2
3,401
successhawk
78,465,666
8,131,903
How to save the child set instance in the parent object in Django's Many to One (Foreign Key) relationship?
<p>I am working on a social media project where users can follow each other. Here are the models that are relevant to this problem</p> <pre class="lang-py prettyprint-override"><code>django.contrib.auth.models.User </code></pre> <pre class="lang-py prettyprint-override"><code>class UsersProfiles(ddm.Model): user = ...
<python><python-3.x><django><django-models>
2024-05-11 18:19:18
1
315
Aditya
78,465,537
3,052,438
CalledProcessError.stderr of subprocess.check_call is None despite the process outputting an error message
<p>I'm trying to capture the error message of a program called by <code>subprocess.check_call</code> but the <code>stderr</code> in the error object is always <code>None</code>.</p> <p>Here is a short script that shows this:</p> <pre class="lang-py prettyprint-override"><code>import subprocess import sys if '--fail' i...
<python><subprocess>
2024-05-11 17:34:41
1
5,159
Piotr Siupa
78,465,459
9,659,840
how to combine array of map in a single map per column in pyspark
<p>i have followed <a href="https://stackoverflow.com/questions/43723864/combine-array-of-maps-into-single-map-in-pyspark-dataframe">this</a> question but the answers there not working for me i don't want a UDF for this and map_concat doesn't work for me. is there any other way to combine maps?</p> <p>eg</p> <div class...
<python><pyspark><databricks>
2024-05-11 17:09:15
1
469
UC57
78,465,203
242,042
Internally, is asyncio run_forever() basically a while True loop?
<p><a href="https://stackoverflow.com/questions/32761095/python-asyncio-run-forever-or-while-true">python asyncio run_forever or while True</a> is similar but it is a &quot;should I do this...&quot; question.</p> <p>I am more trying to understand if the internals of python <code>asyncio</code> is basically a</p> <pre><...
<python><python-asyncio>
2024-05-11 15:39:44
1
43,097
Archimedes Trajano
78,465,177
13,438,431
Generic Factory <-> Good relationship with PEP695 (Self referential generics)
<p>How to express this kind of relationship between types with PEP695 annotations? Pylance (pyright) says that <code>Self is not valid in this context</code>, but there seems to be no other way to express it?</p> <p>The goal is to have <code>AbstractFactory</code> know what kind of goods it produces, and have <code>Abs...
<python><generics><python-typing>
2024-05-11 15:32:42
1
2,104
winwin
78,465,166
2,850,522
How to Fix Shape Mismatch in TensorFlow when attempting to create a model from a trained data set
<p>I am working with machine learning project using TensorFlow and Keras to process audio data. The project is designed to handle inputs with multiple channels, but there's an issue during the training phase where the input shape does not match the expected model input shape.</p> <p>In the github repo you can find mode...
<python><tensorflow><deep-learning><conv-neural-network>
2024-05-11 15:27:03
0
570
Nonlin
78,464,919
1,888,781
Special Characters Error While converting STRING to JSON in python
<p>I have following string coming from 3rd party api.</p> <pre><code>teststring = '{&quot;@speccialcharacterssample&quot;: &quot;/special.character.test.Sample&quot;,&quot;content&quot;: {&quot;description&quot;: &quot;Some number **451000**, Some Time **Monday, April 8th, UTC 11:00**. \n# BackSpace\nBreakline\nMore Sp...
<python><json>
2024-05-11 14:08:20
0
471
Khizar Shujaat
78,464,772
1,667,884
performance of getting a new list with an additional value
<p>To get a new list from a list with an additional value, I used to think that <code>list_b = [*list_a, value]</code> is more performant than <code>list_b = list_a + [value]</code>, as the latter generates an intermediate <code>[value]</code>.</p> <p>However, according to the benchmark (tested in Python 3.12.3 / Windo...
<python><list><performance>
2024-05-11 13:24:52
1
2,357
Danny Lin
78,464,654
3,120,501
Access values of design variables while solver is running (OpenMDAO with IPOPT)
<p>I'm trying to do trajectory optimisation in Dymos (a library built atop OpenMDAO), but I'm not getting the convergence properties I'm expecting and I'd like to inspect the intermediate solutions of the solver in order to debug.</p> <p>Is there a way, in OpenMDAO, to access the design variables as the solver is runni...
<python><optimization><openmdao><ipopt>
2024-05-11 12:44:15
1
528
LordCat
78,464,573
4,505,301
AWS Boto3 EC2 client send_command process shuts down
<p>I am using send_command() function to run local python script on about 100 ec2 instances for long periods(days).</p> <pre><code>ssm_client = boto3.client('ssm', region_name = 'eu-west-1') commands_to_execute = &quot;&quot;&quot;cd /home/ubuntu set -x exec 3&gt;&amp;1 4&gt;&amp;2 trap 'exec 2&gt;&amp;4 1&gt;&amp;3' ...
<python><amazon-web-services><bash><amazon-ec2><boto3>
2024-05-11 12:18:20
1
1,562
meliksahturker
78,464,534
7,307,824
Extracting int values from a string (in different formats) using a regex
<p>I have a string value (football score) in my Pandas dataset. I would like to extract the home goals and the away goals from this score.</p> <p>The score can be written in a couple of ways (sometimes it is won on penalties and presented with brackets.</p> <p>Standard score:</p> <p><code>&quot;4-2&quot;</code> I would...
<python><pandas><regex>
2024-05-11 12:06:59
2
568
Ewan
78,464,426
774,575
How to correctly index a dataframe with a function?
<p>Given a dataframe:</p> <pre><code> a b c u 5 0 3 v 3 7 9 w 3 5 2 </code></pre> <p>I'd like to select rows/columns in a dataframe using a function. This function gets the dataframe and returns a tuple of lists of labels, e.g. it returns <code>['v', 'u'], ['c']</code> using this lambda:</p> <pre><code>get...
<python><pandas><indexing>
2024-05-11 11:33:11
2
7,768
mins
78,464,072
10,200,497
What is the best way to merge two dataframes that one of them has overlapping ranges?
<p>My DataFrames are:</p> <pre><code>import pandas as pd df_1 = pd.DataFrame( { 'a': [10, 12, 14, 20, 25, 30, 42, 50, 80] } ) df_2 = pd.DataFrame( { 'start': [9, 19], 'end': [26, 50], 'label': ['a', 'b'] } ) </code></pre> <p>Expected output: Adding column <code>label</c...
<python><pandas><dataframe>
2024-05-11 09:26:53
3
2,679
AmirX
78,463,870
17,718,669
Lock classes and Threading in python for dict moifications
<p>I was learning and testing <code>threading</code> in python, and <code>Lock</code> class, So in here I want to add a key to <code>persons</code> but let's say it will takes some time, in another thread I want to read the key. in first thread I should lock the process but I still get an error.</p> <pre class="lang-py...
<python><multithreading><python-multiprocessing>
2024-05-11 08:17:20
2
326
parsariyahi
78,463,764
16,359,942
CCXT - load markets for exchange OneTrading
<p>I am trying to use python library <code>ccxt</code> to retrieve public data (e.g. available markets) from crypto exchange OneTrading.</p> <p>I created an API key with read-permissions.</p> <p>Somehow, ccxt retrieves an empty dict. Why is this?</p> <p>This is my example code:</p> <pre class="lang-py prettyprint-overr...
<python><python-3.x><ccxt>
2024-05-11 07:43:38
1
464
dovregubben
78,463,746
1,324,366
How to set port number in Python Package manager Anaconda Navigator
<p>Every time, I launch Anaconda-Navigator it is open in a new port. I want to set or fix the port number when I launch it.</p> <p>I have searched the documentation a bit, however, I did not find anything or I might miss.</p> <p>Does anyone know how to set the port number while launching the Anaconda-navigator?</p> <p>...
<python><anaconda><conda>
2024-05-11 07:33:48
0
4,453
Ahmad Sharif
78,463,676
1,413,856
Understanding Tkinter window, and Canvas sizes
<p>I can’t get any information on exactly how window and canvas sizes work in Tkinter.</p> <p>If I create a window, I can set its size using either the <code>.configure()</code> method or the <code>.geometry()</code> method. If I set both, the <code>.geometry()</code> method appears to override the <code>.configure()</...
<python><tkinter><tkinter-canvas>
2024-05-11 07:06:06
0
16,921
Manngo
78,463,610
9,494,140
Django rest frame-work error : django.core.exceptions.ImproperlyConfigured: Router with basename X is already registered , despite it is not
<p>In my <code>django</code> app am using <code>DRF</code> and it gives me , and it gives me this strange error when i try to run the app :</p> <pre><code>water_maps | router.register(r'breaches_edit_delete', api.BreacEditDeletehViewSet) water_maps | File &quot;/usr/local/lib/python3.10/dist-packages/rest_frame...
<python><django><django-rest-framework>
2024-05-11 06:36:49
1
4,483
Ahmed Wagdi
78,463,455
5,821,028
Manual SVD Implementation in Python failed
<p>I am trying to implement a function for Singular Value Decomposition (SVD) in Python by myself, using the eigenvalue decomposition of A^T A and AA^T, but the reconstructed matrix (B) does not always match the original matrix (A). Here is my code:</p> <pre><code>import numpy as np # Generate a random matrix A row, co...
<python><svd>
2024-05-11 05:10:46
1
1,125
Jihyun
78,463,439
13,380,708
Django products not being added to cart immediately
<p><a href="https://i.sstatic.net/kEPmcEeb.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/kEPmcEeb.png" alt="This is the add to cart button which when I click on, the product is added and the cart modal should show up with the added product" /></a></p> <p>[<img src="https://i.sstatic.net/xfKteFiI.png" a...
<javascript><python><html><django>
2024-05-11 04:59:45
1
470
Jack
78,463,386
4,387,837
Python: MultiIndex Dataframe to json-like list of dictionaries
<p>I want to store this data frame</p> <pre><code>df = pd.DataFrame({ 'id':[1,1,2,2], 'gender':[&quot;m&quot;,&quot;m&quot;,&quot;f&quot;,&quot;f&quot;], 'val1':[1,2,5,6], 'val2':[3,4,7,8] }).set_index(['id','gender']) </code></pre> <p>as a json file that contains list...
<python><pandas><dictionary>
2024-05-11 04:32:33
1
839
HOSS_JFL
78,463,166
4,367,371
Spark melt/transpose columns to values
<p>I am trying to transpose the columns of a table to rows</p> <p>I have a table that looks like this:</p> <pre><code>+-----+-----+-----+-------+ |Date |col_1|col_2|col_...| +-----+-------------------+ | 1 | 0.0| 0.6| ... | | 2 | 0.6| 0.7| ... | | 3 | 0.5| 0.9| ... | | ...| ...| ...| ... | </code...
<python><pandas><apache-spark><pyspark><azure-databricks>
2024-05-11 02:11:14
2
3,671
Mustard Tiger
78,462,902
1,815,710
Django rest framework's ModelSerializer missing user field causing KeyError
<p>My <code>ModelSerializer</code> is getting a <code>KeyError</code> when I call <code>.data</code> on the serializer and I'm not sure how to properly fix this error.</p> <p><a href="https://github.com/jazzband/django-rest-knox/blob/master/knox/models.py#L25" rel="nofollow noreferrer">Knox's AuthToken model</a> looks ...
<python><django><django-rest-framework><django-serializer><django-rest-knox>
2024-05-10 23:25:34
0
16,539
Liondancer
78,462,855
2,055,998
How to refer to configured Datasource from my code (IntelliJ + Python)
<p>I have Cassandra Datasource configured in my IntelliJ (as global).</p> <p>I can manually establish a session and run CQL queries from console.</p> <p>How do I do it from Python code without re-entering User ID and other parameters and referring to the Datasource instead?</p> <p>This must a <em>RTFM</em> case but I c...
<python><intellij-idea><datasource>
2024-05-10 23:02:24
1
13,449
PM 77-1
78,462,450
22,056,059
I am trying to Forecast a trend for the next year, using a historical data of past year (every 10 minute interval for 1 year) using SARIMAX
<pre><code>from statsmodels.tsa.statespace.sarimax import SARIMAX import pandas as pd import itertools import warnings import numpy as np import statsmodels.api as sm try: print(&quot;Starting script...&quot;) # Load your dataset print(&quot;Loading dataset...&quot;) df = pd.read_csv('C:/Users/iameh...
<python>
2024-05-10 20:38:36
0
314
Jahidul Hasan Razib
78,462,307
2,153,235
How best to avoid overwriting library source files from Spyder?
<p>I have Anaconda installed with a Python 3.9 environment under my personal user account on Windows. I use <code>runfile</code> to run a <code>*.py</code> file from the Spyder console. I normally have the Spyder editor closed and use Cygwin and Vim tabs/subwindows to do anything text related.</p> <p>When <code>runf...
<python><anaconda><spyder>
2024-05-10 19:59:26
0
1,265
user2153235
78,462,178
480,118
Routing submodule functions using FastAPI's APIRouter
<p>I have the following in my <code>main.py</code>:</p> <pre class="lang-py prettyprint-override"><code>from fastapi import FastAPI, Request from fastapi.responses import HTMLResponse from fastapi.middleware.gzip import GZipMiddleware from fastapi.templating import Jinja2Templates from fastapi.staticfiles import Static...
<python><fastapi><starlette>
2024-05-10 19:24:34
2
6,184
mike01010
78,462,165
19,299,757
How to return multiple list in a python return statement
<p>I've a python block like this. And I want to return 2 lists in the return statement.</p> <p>I currently have return trade_result_list + blotter_result_list, but this shows an error &quot;Expected type 'list[TradeResult]' (matched generic type 'list[_T]'), got 'list[BlotterResults]' instead &quot; in the line where r...
<python>
2024-05-10 19:22:29
2
433
Ram
78,461,881
2,475,195
Pandas keep every nth row with special rule
<p>For example, I want to keep every 3rd row, but I must keep numbers divisible by 3(or some special rule like that). When I see a number divisible by 3, that restarts the count, meaning I will start counting to 3 from there, unless I see anoter value divisible by 3. Example given below:</p> <pre><code>import pandas as...
<python><pandas><dataframe><subsampling>
2024-05-10 18:06:44
1
4,355
Baron Yugovich
78,461,790
2,671,688
How to split a NumPy array such that lengths of subarrays are evenly distributed?
<p>I'm new to NumPy and still figuring out what's easy to do with built-ins, vs. rolling my own.</p> <p>I'm trying to split an array, but have the unevenness in subarrays be distributed evenly throughout the result.</p> <p>To illustrate, if I run the following in numpy:</p> <pre class="lang-py prettyprint-override"><co...
<python><numpy>
2024-05-10 17:43:07
1
701
user2671688
78,461,648
13,366,967
Pylance reportArgumentType with Pydantic’s BeforeValidator
<p>I’m writing a <code>pydantic</code> type similar to <code>ImportString</code> called <code>ImportPlugin</code> which imports and optionally calls objects and returns the call result. For example:</p> <pre class="lang-py prettyprint-override"><code>from typing import Annotated, TypeVar from pydantic import BaseModel,...
<python><python-typing><pydantic><pyright>
2024-05-10 17:07:58
0
394
mohamed martini
78,461,566
869,180
Flask app running on AWS App Runner returns 502 Bad Gateway
<p>I have a Flask application running in AWS App Runner with Gunicorn. It was running fine but I added a new feature which includes an API that calls to different endpoints and takes around 2-3 minutes to return a response.</p> <p>In local it's working fine but when deployed it returns 502 Bad Gateway every time I call...
<python><amazon-web-services><flask><gunicorn><amazon-app-runner>
2024-05-10 16:51:52
1
1,068
andoni90
78,461,564
2,836,338
How to properly rotate 3D numpy array to uniformly sample sphere?
<p>I have a 3D numpy array with density values. I would like to rotate this array around the origin to uniformly sample the sphere as closely as possible. I found some answers here that allow me to get close (<a href="https://stackoverflow.com/a/44164075/2836338">Evenly distributing n points on a sphere</a>, <a href="h...
<python><numpy><scipy><rotation><ndimage>
2024-05-10 16:51:32
0
363
tomerg
78,461,523
6,431,509
Python unresolved reference with inner class
<p>I'm learning inner classe in python, pycharm tips me</p> <blockquote> <p>unresolved reference Clienta</p> </blockquote> <p>in this code</p> <blockquote> <p>model = <em><strong>Clienta</strong></em>.OverviewSchema.Overview</p> </blockquote> <pre><code>class Clienta(Document): class Overview(EmbeddedDocument): ...
<python>
2024-05-10 16:42:40
0
521
candrwow
78,461,448
1,113,579
Why is this simple Python code resulting in an empty dict?
<p>Why is this simple Python code resulting in an empty dict?</p> <pre><code>from collections import defaultdict dict1 = defaultdict(list) dict1['old_key'] = [{'name': 'A'}] dict1['old_key'].extend(dict1.pop('old_key')) print(dict1) </code></pre> <p>My understanding of how this should have worked:</p> <p>The pop metho...
<python>
2024-05-10 16:28:17
4
1,276
AllSolutions
78,460,988
1,123,336
How to shut down the resource tracker after running Python's ProcessPoolExecutor
<p>I have been using the ProcessPoolExecutor in concurrent.futures for a while, but I recently noticed that jobs with concurrent processes, which were submitted to a cluster batch queue, were never properly shut down after completion. The reason appears to be that, although the parallel processes completed succesfully,...
<python><python-multiprocessing><concurrent.futures>
2024-05-10 15:00:48
0
582
Ray Osborn
78,460,765
2,244,766
How to convert to dict for append action?
<p>Having something like this:</p> <pre><code>&gt;&gt;&gt; import argparse &gt;&gt;&gt; ap = argparse.ArgumentParser() &gt;&gt;&gt; ap.add_argument('-e', '--env', action='append', nargs=2, metavar=('NAME', 'VALUE'), dest='extra_env', help='set some env var to given value') _AppendAction(option_strings=['-e', '--env'], ...
<python><argparse>
2024-05-10 14:25:13
1
4,035
murison
78,460,746
1,209,675
How to copy Numpy arrays into C++ arrays quickly
<p>I'm trying to create an circular buffer for images in C++ that receives the images as Numpy arrays. I can correctly store the images and retrieve them, but it's crazy slow, 100's of times slower than just doing it all in Python. I'm learning C++, but I'm not sure how to speed this up. Any help would be greatly ap...
<python><c++><numpy><pybind11>
2024-05-10 14:22:07
0
335
user1209675
78,460,333
23,260,297
Create new columns in dataframe with values from other columns based on condition
<p>Let's say I have a dataframe (df) that looks like this(dots indicate more columns):</p> <pre><code>Type Price1 Price2 Price3 Price4 Price5 ... ... A nan 1 nan nan 2 A nan 3 nan nan 2 B nan nan 4 5 nan B nan nan ...
<python><pandas><dataframe>
2024-05-10 13:07:51
3
2,185
iBeMeltin
78,460,166
21,049,944
How to effectively iterate through categories
<p>I have a large dataframe -&gt; lazyframe that was cut by the <a href="https://docs.pola.rs/py-polars/html/reference/expressions/api/polars.Expr.cut.html" rel="nofollow noreferrer">Expr.cut</a> function. Now I would like to iterate through these categories, but I failed to find an effective way. When I use group_by, ...
<python><group-by><python-polars><lazyframe>
2024-05-10 12:39:04
1
388
Galedon
78,459,786
2,475,195
Pandas every nth row from each group
<p>Assume groups will have more than <code>n</code> memebers, I want to take every <code>n</code>th row from each group. I looked at <a href="https://pandas.pydata.org/pandas-docs/version/0.17.0/generated/pandas.core.groupby.GroupBy.nth.html" rel="nofollow noreferrer">https://pandas.pydata.org/pandas-docs/version/0.17....
<python><pandas><dataframe><group-by>
2024-05-10 11:23:11
1
4,355
Baron Yugovich
78,459,479
1,028,024
Odoo onchange event for invoice_status of sale.order not firing
<p>Does anyone know why the onchange event as coded below is not fired as expected? It fires only once, when making a new Sale Order (before saving). The invoice_status <em>is actually changing</em> (as is confirmable in the tree view). Expected behavior is that the event is fired on every change.</p> <pre><code>import...
<python><odoo><odoo-17>
2024-05-10 10:21:33
1
655
Berdus
78,459,338
6,386,056
Scipy.optimize.least_square sensitive to order of inputs
<p>The following code generate different results depending on the order of the inputs I pass on. Why is that? I'd expect least square optimization to reach same result no matter what order the inputs are passed to the error generating function. What is it exactly that create this discrepancy?</p> <pre><code>import nump...
<python><scipy><scipy-optimize><least-squares>
2024-05-10 09:59:29
1
667
Mth Clv
78,459,217
10,425,150
Keep columns and rows that contains "FAIL" in pandas dataframe
<p>I would like to keep columns that contains word &quot;FAIL&quot;.</p> <p><strong>Input data:</strong></p> <div class="s-table-container"><table class="s-table"> <thead> <tr> <th style="text-align: right;">Values1</th> <th style="text-align: right;">Values2</th> <th style="text-align: right;">Values3</th> <th style="...
<python><pandas><dataframe>
2024-05-10 09:37:11
2
1,051
Gооd_Mаn
78,459,119
9,494,140
How to fix the ImportError: cannot import name 'formatargspec' from 'inspect' (/usr/lib/python3.12/inspect.py). Did you mean: 'formatargvalues'?
<p>I'm trying to run <code>django</code> app usind <code>docker</code> .. it gives me this error when i try to <code>docker-compose up --build</code> :</p> <pre><code>water_maps | File &quot;&lt;frozen importlib._bootstrap&gt;&quot;, line 1387, in _gcd_import water_maps | File &quot;&lt;frozen importlib._bootstra...
<python><docker>
2024-05-10 09:15:16
1
4,483
Ahmed Wagdi
78,458,998
18,949,720
Matplotlib interactive figures with streamlit
<p>I am trying to display matplotlib interactive figures in Streamlit generated pages i.e. to display the pan/zoom and mouse-location tools.</p> <p>I know there are other ways to make figures interactive that are commonly used with streamlit, but I need to stick to matplotlib because they provide widgets that I use (re...
<python><matplotlib><streamlit><matplotlib-widget>
2024-05-10 08:51:04
1
358
Droidux
78,458,994
3,373,967
Plotly generated pie chart text exceed page boundary
<p>I am using plotly to generate a pie chart, with textinfo set in outside of the sector. However, when number of sectors increase to a large amount, the textinfo will not shown in the figure frame</p> <p>A MWE is as the following</p> <pre class="lang-py prettyprint-override"><code>import plotly.express as px from rand...
<python><plotly><bar-chart><image-size>
2024-05-10 08:49:22
1
973
Eric Sun
78,458,753
2,151,275
How to receive file send from flask with curl?
<p>Here the server side code with python &amp; flask:</p> <pre><code>from flask import Flask, request, send_file import io import zipfile import bitstring app = Flask(__name__) @app.route('/s/', methods=['POST']) def return_files_tut(): try: f = io.BytesIO() f.write(&quot;abcd&quot;.encode()) ...
<python><web-services><flask><curl>
2024-05-10 07:56:55
1
1,864
heLomaN
78,458,709
480,118
FastAPI how to refer to a base/extend jina2 template
<p>In my old flask app i have the following:</p> <pre><code>{% extends &quot;base.html&quot; %} {% block title %}Home{% endblock %} </code></pre> <p>Im converting my app to FastAPI.<br /> The folders 'static' and 'templates' are subfolders from where main.py resides.</p> <p>main.py:</p> <pre><code>app = FastAPI() app....
<python><jinja2><fastapi>
2024-05-10 07:45:31
0
6,184
mike01010
78,458,665
3,099,733
How to report `redefined-argument-from-local` as error in ruff?
<p>In order to avoid making another bug due to override the function arguments in a for-loop, I find that there is a lint rule <a href="https://docs.astral.sh/ruff/rules/redefined-argument-from-local/" rel="nofollow noreferrer">redefined-argument-from-local</a> can detect this error. I try to enable this rule by add it...
<python><pylint><ruff>
2024-05-10 07:34:40
0
1,959
link89
78,458,502
2,192,824
Is there a simple way in python to read and write a file from two separate threads?
<p>Not familiar with the file operation and multi-threading in python, so I'm asking here. So I want to do something like this: one writing thread will write some data to a file, and another reading thread to read the data from the top of the file, but if the file is empty the reading thread would just wait until the f...
<python><python-3.x><multithreading><file>
2024-05-10 06:58:48
1
417
Ames ISU
78,458,418
2,641,038
How to get all attributes of an Python object `pxr.Usd.Prim` bound by an C++ object
<p>I am using the Python package <a href="https://pypi.org/project/usd-core/" rel="nofollow noreferrer">pxr</a> to read a <a href="https://en.wikipedia.org/wiki/Universal_Scene_Description" rel="nofollow noreferrer">USD</a> file. The problem is that I cannot find enough information to fully understand how to work with ...
<python><c++><usdz><usd><omniverse>
2024-05-10 06:38:56
0
2,025
Der Fänger im Roggen
78,458,284
7,700,802
How to fix line bleeding in fpdf
<p>I have these functions</p> <pre><code>def investment_summary(pdf, text): pdf.set_font(&quot;Arial&quot;, size=8) pdf.write(5, text) for point in text.splitlines(): if point.startswith(&quot;-&quot;): pdf.set_x(15) pdf.write(5, point) def create_report(county_and_state, llm_text, analytics_loca...
<python><pyfpdf>
2024-05-10 06:02:21
1
480
Wolfy
78,458,074
913,494
Query dynamoDB with datetime filter expression - Incorrect operand
<p>I am try to query my Dynamodb to get items older than 5 min.</p> <p>My item is stored as:</p> <pre><code>{ &quot;main_event_code&quot;: { &quot;S&quot;: &quot;1160&quot; }, &quot;event_code&quot;: { &quot;S&quot;: &quot;9999&quot; }, &quot;last_upload&quot;: { &quot;S&quot;: &quot;2024-05-10T04...
<python><amazon-dynamodb><boto3>
2024-05-10 05:01:29
1
535
Matt Winer
78,457,889
10,485,253
How can I find if another DAG is currently running and what configs were passed to it
<p>I'm using airflow 1.10.12</p> <p>I have DAG A and DAG B. DAG A runs every 12 hours and DAG B is only triggered manually with a configuration JSON.</p> <p>I know how to access the configuration JSON in DAG B, but is there a way to tell from DAG A if DAG B is running and it's configuration JSON?</p>
<python><airflow>
2024-05-10 03:42:18
1
887
TreeWater
78,457,753
19,123,103
Importing GuardrailsOutputParser from langchain.output_parsers is deprecated
<p>I'm using langchain 0.1.17. I get this warning:</p> <pre class="lang-none prettyprint-override"><code>\venv\Lib\site-packages\langchain\_api\module_import.py:87: LangChainDeprecationWarning: Importing GuardrailsOutputParser from langchain.output_parsers is deprecated. Please replace the import with the following:...
<python><warnings><langchain>
2024-05-10 02:36:31
1
25,331
cottontail
78,457,650
3,788,767
Python Numba is not performing as expected
<p>I have the following code in python3 and I am comparing the <a href="https://numba.pydata.org/" rel="nofollow noreferrer">Numba JIT</a> compiler performance with a regular code.</p> <p>My OS is Ubuntu 22.04, <code>pip3 install virtualenv</code> and <code>pip3 install numba numpy</code></p> <p>benchmark.py</p> <pre><...
<python><python-3.x><numba>
2024-05-10 01:49:51
1
5,580
IgorAlves
78,457,389
8,271,180
Auto inherite a parent class with decorator
<p>I have a class decorator <code>p()</code> that can be used only on classes that inherite from some abstract class <code>P</code>.</p> <p>So anytime someone uses <code>p</code> it should be written as follows:</p> <pre><code>@p() class Child(P): ... </code></pre> <p>Is there any way to automatically inherite P us...
<python><class><inheritance><python-decorators>
2024-05-09 23:43:10
1
1,356
Tomer Wolberg
78,457,374
2,057,516
Circular imports from classes whose attributes reference one another
<p>I know there are a lot of questions that talk about circular imports. I've looked at a lot of them, but I can't seem to be able to figure out how to apply them to this scenario.</p> <p>I have a pair of data loading classes for importing data from an excel document with multiple sheets. The sheets are each configur...
<python><python-import><circular-reference>
2024-05-09 23:31:39
1
1,225
hepcat72
78,457,370
4,526,441
How to create a tensor based on another one - Studying PyTorch in practice?
<p>I'm studying IA using PyTorch and implementing some toy examples. First, I created a one-dimensional tensor (X) and a second tensor (y), derived from the first one:</p> <pre class="lang-py prettyprint-override"><code>X = torch.arange(0, 100, 1.0).unsqueeze(dim=1) y = X * 2 </code></pre> <p>So I have something like</...
<python><numpy><machine-learning><pytorch><artificial-intelligence>
2024-05-09 23:28:50
1
313
Victor Vidigal Ribeiro
78,457,216
9,983,652
how to add a new column with different length into a existing dataframe
<p>I am trying to go over a loop to add columns into a empty dataframe. each column might have a different length. Look like the final number of rows are defined by lenght of first column added. The columns with a Longer length will be cut values.</p> <p>How to always keep all the values of each column when column leng...
<python><pandas>
2024-05-09 22:22:54
1
4,338
roudan