Quantcast
Channel: Active questions tagged python - Stack Overflow
Browsing all 13891 articles
Browse latest View live
↧

Optimize multiple SQLAlchemy queries to one query

I am trying to write a function for a given user to return a count of all online users and offline users for each chatroom the given user is a part of.The methods listed below achieve what I want but...

View Article


Replacing values on a dataframe row using a specific value as reference

I have a dataframe like this: solution_id 0 1 2 30 26688 NaN NaN NaN NaN1 26689 NaN NaN NaN NaN2 26690 NaN NaN NaN NaN3 26691 NaN NaN NaN NaN4 26692 NaN NaN NaN NaN... ... .. .. .. ..10398 37086 NaN...

View Article


How do I access packages installed by `pip --user`?

I realized I had an outdated numpy version:$ pythonPython 2.7.10 (default, Oct 23 2015, 18:05:06)[GCC 4.2.1 Compatible Apple LLVM 7.0.0 (clang-700.0.59.5)] on darwinType "help", "copyright", "credits"...

View Article

Image may be NSFW.
Clik here to view.

Why do python type hints sometimes worsen IDE recommendations?

I'm going through an exercise of adding type hints through a large codebase, but I'm sometimes seeing that less-than-optimal type hint worsens IDE recommendations:before, the IDE is able to figure out...

View Article

Reading a structured binary file with numpy: fromfile vs. read & frombuffer

I’m reading a binary file using numpy and wondering whether I should use repeated calls to numpy.fromfile or reading from the file manually and calling numpy.frombuffer:# Alternative 1: fromfilewith...

View Article


Python Beginner: Conveting an HTML document scraped from a website to a...

I am trying to scrape football players' data from the website FBRef, I got the data from the website as a bs4.element.ResultSet object.Code:import requestsfrom bs4 import BeautifulSoupimport pandas as...

View Article

A python Path.rglob pattern to match all package.json files in a directory...

I'm working with a massive monorepo, and I'm trying to write a script that will need to grab some information from all of the monorepo's package.json files, but not and package.json files that are...

View Article

How can I stop the 'input()' function after a certain amount of time?...

I'm trying to figure out how to make python stop accepting input after a certain amount of time.What I've got so far works, but won't stop the program until the user presses Enter. If it matters, I'm...

View Article


How do i automatically upload pictures from a folder onto canva using python?

I have an excel sheet that has a 100 numbers in a column, each of these numbers corresponds to the name given to a picture in a folder on the desktop. I need to upload these pictures from this folder...

View Article


Pytorch how to use num_worker>0 for Dataloader when using multiple gpus

I am using differential_evolution from scipy to do optimization. likehood is vectorized to calculate all the populations at once. I have 36 parameters and popsize=35. draws is also a large matrix...

View Article

How to rework rolling sum using Numpy.strides?

I have this code that works. I was wondering how to implement usingnp.lib.stride_tricks.as_strided or avoid loops.import yfinance as yfimport pandas as pdimport numpy as np# Fetch Apple stock...

View Article

Sanitizing user-provided SQL with Python?

I'm working on a small app which will help browse the data generated by vim-logging, and I'd like to allow people to run arbitrary SQL queries against the datasets.How can I do that safely?For example,...

View Article

Harvesters (genicam) trigger issue at high line rate | Camera: Teledyne dalsa

I use a Teledyne Dalsa line scan camera. Sometimes when I increase the line rate of my Teledyne Dalsa line scan camera to 13000 or higher and trigger it with an Arduino at 3V3, the images are not...

View Article


why does the default round function in python fix double rounding errors?

There's something wrong with my understanding of either the round function in python or how doubles are represented in python. I find a very perplexing behavior when rounding numbers that have a double...

View Article

How to create random graph where each node has at least 1 edge using Networkx

I've managed to create a random undirected weighted graph for testing with Dijkstra's algorithm, but how can I make it so each node has at least one edge that connects them to the graph?I'm using...

View Article


Trouble with prompting the user for input until it is correct in a while loop

if num < 0: input('Only nonnegative intergervalues allowed, try again: ')elif num == 0: print('The factorial of 0 = 1')while num > 1: factor = factor * num num = num -1else: num = int(input('Only...

View Article

Why can't Python find this shared object I'm trying to relative import...

I have a file __init__.py with the following import:from ._nms import lib as _lib, ffi as _ffiwhere _nms.so is a shared object in the same directory as this Python file.Relevant file structure is as...

View Article


recognize_google fails with WinError 10060

I'm encountering a TimeoutError: [WinError 10060] while attempting to establish a connection in my Python program. This error arises when the connected party does not respond properly within a specific...

View Article

Low efficiency when plotting a large amount of contours on a single axis in...

The objective of my code is to plot soil pressure from data extracted from another software. The output of this other software gives me the value of this pressure for each of the joints of a shell that...

View Article

Variable in Python going up by more than 1 at a time

I am currently making a project for my school for fun, and I came across a problem. The project is a paddle and ball game, and every time the ball hits the paddle the score SHOULD go up by one, but...

View Article
Browsing all 13891 articles
Browse latest View live