Category "python"

Iterating through XMLs, making dataframes from nodes and merging them with a master dataframe. How should I optimize this code?

I'm trying to iterate through a lot of xml files that have ~1000 individual nodes that I want to iterate through to extract specific attributes (each node has 1

cv2.VideoCapture inconsistent behavior between cap.set and loop read

I was trying to read the 600th frame of a video using cv2.VideoCapture. However, I found that the following two methods both successfully read an image but the

Split second level multindex column to create three level column in Pandas

Given a multiindex df X E1_ex0 E1_ex2 E2_ex0 E4_ex0 0 3 4 1 1 1 4 3 2 0 I would like to s

Python: Creating nested dictionaries, using keys stored in a list

EDIT: I forgot to mention that there are other dictionaries and lists, and the solutions suggested so far work very well for my example, but not if I want to ad

how to click on pop up elements using undetected chromedriver

i am trying to make 5-star bot i have already done half work for getting login with gmail only place i am stuck is when it come to clicking on pop up window ask

How to solve CompileError: command 'gcc' failed with exit status 1 while compiling?

I am trying to run "python build.py" by terminal on Ubuntu in a conda virtual env. But I got some below errors, you can see in the code! for your information: T

Django Framework : Problems with views settings

im learning Django framework and having some issues that i dont get it. Actually i have apps like Polls/ Blog/ and my homepage/ installed and working as i want

Dynamic TaskGroup in Airflow 2

I have a function run_step that produces a dynamic number of emr tasks within a task group. I want to keep this function in a separate file named helpers.py so

Finding the best linear section of data

I have some scientific data and wish to find the best region to fit a straight line in. Theoretically, the data should have a constant gradient but other influe

OpenCV - Correcting Image for Mis Alignment

I discovered the other day that my camera lens or perhaps tilted sensor is causing an object centered in front of the camera to appear off center in the capture

pytorch_lightning.utilities.exceptions.MisconfigurationException when training in pytorch lightning

I am training a sample model with dummy data then i got this error. I have gave everything properly but still i am getting this error: No `configure_optimizers(

Discord.py bot doesn't respond to commands but does on mentions

I have a problem with my discord.py bot. Here's a part of the code: import os, discord from discord.ext import commands from flask import Flask from threading i

How to add a comma after every three digits? [duplicate]

Add a character in between a string How can I add a comma after every three characters in a string? For example, i have a string number = "200

Python | Give list [1,2,3,4] -> return 1*2+2*3+3*4

So as i said in the title, i want to multipy each two neigbors in the list and sum them all - with a single code line. I'm looking for the most elegant and effi

How do you populate package variables when testing a class's method in Pytest?

I'm writing a test suite for a class that needs variables from a util package I have defined: # util/__init__.py codes = None def load_codes(): """Populat

Hello everyone. I would like to solve an optimal control problem by minimizing an integral but I get solution not found. here is the code [closed]

I would like to solve an optimal control problem by minimizing an integral, but I get solution not found. Here is the code. J(u)=\int{0}^{500}

Trying to load data for ml project in jupyter notebook but having issues with dtype

I'm trying to load images into my jupyter notebook but I'm getting this error TypeError Traceback (most recent call last) TypeE

Load new values from another Python script

I have a device which I am controlling in a for loop. I would like to check every iteration if a .txt file has changed. If it has I want to read values and send

How to make fixed ticks for graph using matplotlib [duplicate]

I am trying to make a graph with fixed ticks, regardless to the points values. For example, I want the ticks to be 0-6, and the points values

os.path.isdir() returns false

I'm trying to check if a folder exists by path = r"This PC\Bassel's Note\Internal storage\Audiobooks" print(os.path.isdir(path)) It always returns false even t