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
75,864,661
2,251,736
Running flask for multiple port number in a single thread
<p>In our setup we have 4 cameras, I'm creating 4 individual threads, in which I capture the raw camera frames using <code>cv2.VideoCapture(&quot;some_rtsp_stream&quot;)</code>, apply some image processing logic using opencv and produce the desired output frame.</p> <p>What I need is to create a single threaded flask m...
<python><multithreading><opencv><flask>
2023-03-28 09:45:58
0
444
Vikrant
75,864,649
8,179,672
Test FastAPI with Big Query client in backend
<p>I'm writing a REST API in FastAPI where I have to use Big Query for fetching data. I have problems with creating unit tests for positive scenarios where everything goes fine. I'm a beginner in API unit testing and I don't know how to mock Big Query Client.</p> <p>Below please find the simplified code showing the ove...
<python><testing><mocking><pytest><fastapi>
2023-03-28 09:45:16
1
739
Roberto
75,864,479
5,246,211
How to list Dataproc operations in `google-cloud-dataproc` client
<p>I am looking for a way to do something similar to CLI's <code>gcloud dataproc operations list --filter &quot;...&quot;</code>.</p> <p>The minimal code example:</p> <pre class="lang-py prettyprint-override"><code>from google.cloud import dataproc_v1 region = 'us-west1' client_options = {&quot;api_endpoint&quot;: f&...
<python><google-cloud-platform><google-cloud-dataproc>
2023-03-28 09:27:45
2
968
egordoe
75,864,326
15,011,154
Unable to add text to some PDFs with PyMuPDF
<p>I'm writing a Python (v3.11) script, using the library PyMuPDF, to write some text to PDF. The script works fine with some PDFs, but with others it doesn't write the text. It doesn't show any errors, the output file is created, but without the text added.</p> <p>Here is the script:</p> <pre class="lang-py prettyprin...
<python><python-3.x><pdf>
2023-03-28 09:09:48
1
555
Ma3x
75,864,104
221,270
Keras - get number of samples used to build the model
<p>I have a Keras model for image classification saved as an HDF5 file. Is it possible to trace back the number of samples (images) used to create the model?</p>
<python><tensorflow><keras>
2023-03-28 08:46:58
1
2,520
honeymoon
75,864,073
4,253,946
Use of UnstructuredPDFLoader unstructured package not found, please install it with `pip install unstructured
<p>I just have a newly created Environment in Anaconda (conda 22.9.0 and Python 3.10.10). Then I proceed to install langchain (<code>pip install langchain</code> if I try conda install langchain it does not work). According to the quickstart guide <a href="https://python.langchain.com/en/latest/getting_started/getting_...
<python><conda><openai-api><langchain>
2023-03-28 08:44:10
3
376
Edu
75,863,988
11,809,811
os.path.join with forward and backward slashes
<p>I want to import multiple images from a folder using os.path.join and os.walk. Here is the code so far:</p> <pre><code>path = '../images' # path to folder for _,__,image_paths in os.walk(path): for file_name in image_paths: full_path = os.path.join(path,file_name) </code></pre> <p>When I print full pat...
<python>
2023-03-28 08:35:16
1
830
Another_coder
75,863,975
5,868,293
Merge with one column and also with another if value between other values in pandas
<p>I have the following dataframes</p> <pre><code>import pandas as pd foo1 = pd.DataFrame({'id':[1,1,2,2], 'phase':['Pre','Post','Pre','Post'], 'date_start': ['2022-07-24', '2022-12-25', '2022-09-30', '2022-12-25'], 'date_end': ['2022-07-30', '2023-03-07', '2022-10-05', '2023-...
<python><pandas>
2023-03-28 08:34:14
1
4,512
quant
75,863,754
13,839,945
Dimension of target and label in Pytorch
<p>I know this is probably discussed somewhere but I couldn't find it. I always have a missmatch of shapes when using pytorch between target and label. For a batch size of 64 I would get <code>[64, 1]</code> for the target and <code>[64]</code> for the label. I always fix this using <code>label.view(-1, 1)</code> insid...
<python><pytorch>
2023-03-28 08:08:47
1
341
JD.
75,863,595
10,998,672
How to download file from sharepoint using office365-rest-python-api
<p>I was trying to use that lib to connect with my SharePoint and download the file: <a href="https://github.com/vgrem/Office365-REST-Python-Client" rel="nofollow noreferrer">https://github.com/vgrem/Office365-REST-Python-Client</a></p> <p>I tried two approaches for auth:</p> <ol> <li>UserCredential</li> <li>ClientCred...
<python><azure><sharepoint><office365>
2023-03-28 07:51:00
1
1,185
martin
75,863,518
6,057,371
pandas iterate over many dataframe and create list of occurance per key
<p>I have the few hundreds of dataframe with the same sturcture. I want to aggregate per key as follows: For the list columns - create a list of lists (where each list is the value of specific dataframe) For example in case of 2 datarames:</p> <pre><code>df1 = Key C1. C2. C3 A [1,2] 6 b B [6,1] 9 c df2 =...
<python><pandas><dataframe><aggregate><data-munging>
2023-03-28 07:39:40
1
2,050
Cranjis
75,863,494
11,167,518
Python custom module not found, but path is in PYTHONPATH
<p>I searched for a similar question, but none of the solutions I've found have solved my problem.</p> <p>I'm trying to use a local module as a python library, and I want to be able to import it everywhere when using python. I'm using a Mac OS Ventura and python 3.9.13.</p> <p>The module is in the following folder stru...
<python><macos><environment-variables><python-module>
2023-03-28 07:35:21
0
602
jcf
75,863,425
10,994,166
java.lang.OutOfMemoryError: GC overhead limit exceeded Pyspark
<p>I'm trying to join two dataframe in Pyspark, here are tables details:</p> <pre><code>df1.count(): 9989352358(2 columns) df2.count(): 64000000(1 columns) </code></pre> <p>Now every time when I join them I can in Spark UI that out of 1000 task 1 task is always failing and sometimes it's giving <code>GC overhead limit ...
<python><apache-spark><pyspark>
2023-03-28 07:27:47
1
923
Chris_007
75,863,152
5,197,270
pytest fixture vs global variable
<p>I know that when multiple tests use the same variable, it should be defined as a fixture, so that it gets initialized once, and can be re-used.</p> <p>What I don't understand, however, is what advantage it offers (apart from looking cleaner) over a simple global variable, that also gets initialized once, and is acce...
<python><pytest>
2023-03-28 06:50:45
2
411
scott_m
75,863,105
189,035
How to programmatically getting link to CSV behind javascript page?
<p>I'm using python and I'm trying to get the link from which the CSV come from when I click on the <code>DATA V CSV</code> button at the bottom of <a href="https://www.ceps.cz/en/all-data#AktualniSystemovaOdchylkaCR" rel="nofollow noreferrer">this page</a>.</p> <p>I tried <code>beautifulsoup</code>:</p> <pre><code>imp...
<python><web-scraping><beautifulsoup>
2023-03-28 06:44:38
2
5,809
user189035
75,862,874
11,901,732
String format empty string caused extra space in print
<p>I want to string format a sentence as below:</p> <pre><code>integer = 1 if integer != 1: n_val, book = integer, 'books' else: n_val, book ='', 'book' print(f'Fetch the top {n_val} children {book}.') </code></pre> <p>and I expected to see:</p> <pre><code>Fetch the top 3 children books. </code></pre> <p>or</p...
<python><string-formatting>
2023-03-28 06:15:45
1
5,315
nilsinelabore
75,862,688
3,573,626
Python Postgres - psycopg2 insert onto a table with columns that includes curly bracket
<p>I have the following function that insert dataframe into a postgres table:</p> <pre><code>def insert(conn, df, table, return_field_list): tuples = [tuple(x) for x in df.to_numpy()] cols = ','.join(list(df.columns)) query = &quot;INSERT INTO {} ({}) VALUES (%%s)&quot;.format(table, cols) ...
<python><postgresql><dataframe><escaping><special-characters>
2023-03-28 05:45:15
1
1,043
kitchenprinzessin
75,862,665
10,964,685
How to adjust cell line width for hexbin mapbox?
<p>Is it possible to adjust the cell linewidth using Plotly hexbin mapbox? I've had a look at the doco and can't find anything. If the linewidth can't be adjusted, can the color?</p> <p>If I try to pass the linewidth parameter, it returns an error.</p> <pre><code>import pandas as pd import plotly.figure_factory as ff ...
<python><plotly>
2023-03-28 05:40:28
1
392
jonboy
75,862,606
8,973,609
Calculate percentage of win attempts in pandas DataFrame
<p>I have the following pandas <code>DataFrame</code> and I am trying to solve a small lottery exercise. I would like to calculate the percentage of persons who won <code>nth</code> attempt (1st attempt, 2nd attempt, 3rd attempt, and so on...). For some reason I am getting total percentage above 100%. Not sure why... ...
<python><pandas>
2023-03-28 05:30:21
1
507
konichiwa
75,862,378
10,964,685
Plot difference between two Plotly hexbin maps
<p>I've seen posts relating to plotting the difference between two hexbin maps in matplotlib. I couldn't find anything executing the same process but for Plotly hexbin map box plots. If I have two separate hexbin subplots <code>(t, y)</code>, is it possible to produce a single plot that subtracts the difference between...
<python><plotly>
2023-03-28 04:37:20
1
392
jonboy
75,862,353
14,154,784
Django form save: Object is None, but form is valid
<p>I expect the <a href="https://stackoverflow.com/questions/15184000/django-overriden-form-save-method-returns-none">answer here</a> is related to the problem I have, but it is unfortunately not the same and I have not been able to use it to solve the problem. I also tried following the <a href="https://stackoverflow....
<python><django><django-models><django-views><django-forms>
2023-03-28 04:31:32
2
2,725
BLimitless
75,862,277
2,946,773
ATM cash withdraw algorithm to distribute notes using $20 and $50 notes only
<p>I want to begin by acknowledging that <strong>I know</strong> there are a ton of similar questions in SO and other websites, but all proposed solutions seem to have the same problem for my specific example.</p> <p>Only using <strong>$20</strong> and <strong>$50</strong> notes, I'd like to calculate the less amount o...
<python><algorithm>
2023-03-28 04:12:34
3
10,705
AndreFeijo
75,862,231
992,421
T5 multilabel classification using tf
<p>I am trying to do multilabel classification on a corpus of data which has labels too. When The data looks like this after adding the tag in the front for each row: print(texts) 0 multilabel classification: how time changes th... 1 multilabel classification: hawaii has been in ... 2 multilabel cl...
<python><tensorflow><huggingface-transformers>
2023-03-28 04:01:04
0
850
Ram
75,862,162
3,055,164
Programmatically invoking method chaining in Python
<p>I have a simple method which needs to be chained depending on the list of dictionaries. Following is the example.</p> <pre><code>e = Example() instance_copy = e.perform_action(&quot;A, &quot;Good&quot;) .perform_action(&quot;B&quot;, &quot;Very Good&quot;) .perform_action(&quot;C&qu...
<python><python-3.x><python-2.7>
2023-03-28 03:42:33
2
401
rishm.msc
75,861,803
4,259,243
How to have multiple sets of scatter markers with different colormaps in Plotly Express?
<p>I'm trying to make a plot with two (or more) sets of points that that are plotted according to different colormaps.</p> <p>There is a similar question <a href="https://stackoverflow.com/questions/60458220/two-or-three-colorbars-for-one-plot-in-plotly">here</a>, however when I try to modify the example answer that us...
<python><plotly><colormap>
2023-03-28 02:06:00
0
1,542
sh37211
75,861,767
1,039,860
Is there any way to provide additional information about member variables in python?
<p>I want to create a function that creates a dialog from different classes, providing a text (or checkbox for boolean, etc) input for each member variable. I understand how to get a list of the variables from a class and how to use hints to specify variable types, but I'd like to provide additional information (i.e. t...
<python><tags><introspection>
2023-03-28 01:59:26
0
1,116
jordanthompson
75,861,680
14,328,098
How to adjust the label position of the main scale?
<p><a href="https://i.sstatic.net/fNysR.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/fNysR.png" alt="enter image description here" /></a></p> <p>I want to draw this type of graph below based on data in excel. In this way, I don't need to download the excel file from the server every time to generate i...
<python><matplotlib>
2023-03-28 01:35:43
0
816
Gerrie
75,861,483
1,915,230
sorting/merging a binary file in-place, which translates to sorting an array that contains two parts - both of which are already sorted
<p>first and foremost, I'd like to stress out that this code would never be ran on production (I am fully aware that there are dedicated solutions called time-series database(s)). I'm just doing this to keep my brain active with solving some fun project. Here's the problem I'm trying to solve.</p> <p>Imagine I'm gather...
<python><algorithm><sorting><time-series><in-place>
2023-03-28 00:45:45
1
864
toudi
75,861,384
4,133,188
AttributeError: module 'tensorflow.compat.v2.__internal__' has no attribute 'monitoring'
<p>Recently installed <code>tensorflow</code> and <code>tensorflow_hub</code> in a <code>miniconda</code> environment and have an issue when trying to run a script. Receive the following error:</p> <pre><code>Traceback (most recent call last): File &quot;/test/models.py&quot;, line 3, in &lt;module&gt; import ten...
<python><tensorflow><anaconda><tensorflow-hub>
2023-03-28 00:19:08
1
771
BeginnersMindTruly
75,861,332
1,303,826
Build PySide2 for Apple Silicon architecture
<p>I’m trying to build my project dependencies for a native Apple Silicon support. However, I’m having issues to compile PySide2. I know… I know… it’s too old and it’s better to use PySide6. We want to upgrade that too. But my point is to know if I can do the arm64 support first.</p> <p>To build PySide2 I’m using:</p> ...
<python><qt><pyside2>
2023-03-28 00:04:19
2
558
po5i
75,861,304
1,185,242
Can you calculate the average distance between a set of shapes in shapely?
<p>For a set of N polygons. What is the fasters way to calculate the average across all shapes and their nearest neighbour. Where the nearest neighbour is shape which has a point nearest to a point on the current shape closer than any other.</p>
<python><shapely>
2023-03-27 23:56:12
1
26,004
nickponline
75,861,236
2,717,373
Python list comprehension to create list of pairs, two at a time
<p>I am trying to generate a list of pairs using a comprehension, that creates the pairs two at a time. I can create a list of lists, where each sub-list is two pairs, e.g.,:</p> <pre class="lang-py prettyprint-override"><code>mylist = [[(f'2i_{i}',2*i),(f'8i_{i}',8*i)] for i in range(1,4)] # [[('2i_1', 2), ('8i_1', 8...
<python><list><list-comprehension>
2023-03-27 23:38:10
0
1,373
guskenny83
75,861,042
303,624
Tkinter buttons disappear when window is resized
<p>This is the start of a simple text editor. Everything works, except if I make the window shorter, the buttons disappear. How can I solve this?</p> <pre><code>from tkinter import * top = Tk() def main(): frame1 = Frame(top) frame1.pack(side='top', fill=BOTH, expand=True) scrollbar = Scrollbar(fr...
<python><tkinter>
2023-03-27 22:56:07
1
1,263
David Matuszek
75,860,881
11,922,765
Python Find matching item in a list of dictionaries
<p>I have a big list of dictionaries. Each dictionary contains timeseries data of each sensor when each data point is collected. I want to know the index location of a specific sensor and date. So, I can update the sensor value. My code:</p> <pre><code>big_list = [ dict({'sensor':12,'time':'2022-02-03','value':10}), di...
<python><list><numpy><dictionary><numpy-ndarray>
2023-03-27 22:26:16
7
4,702
Mainland
75,860,805
967,621
Pass dropdown menu selection to Pyodide
<p>I am trying to pass the value selected by the user from the dropdown menu to the Python code in Pyodide. In the simplified example below, I am trying to:</p> <ul> <li>Read the user-selected input file</li> <li>Convert file contents to lowercase</li> <li>Append the user-selected value of &quot;strand&quot; (for examp...
<javascript><python><html-select><webassembly><pyodide>
2023-03-27 22:13:03
1
12,712
Timur Shtatland
75,860,721
3,103,957
Since everything in an object in Python, which is the top most object?
<p>In Python, it is said that everything is an object. Could someone please help me which is the top most object.</p> <p>Do we have any such thing Java? Java does have a parent class called &quot;Object&quot; from which all other classes are inheriting. Not everything is an object in Java.</p> <p>Is the OO principle w....
<python><java>
2023-03-27 21:59:46
2
878
user3103957
75,860,641
673,859
big_modeling.py not finding the offload_dir
<p>I'm trying to load a large model on my local machine and trying to offload some of the compute to my CPU since my GPU isn't great (Macbook Air M2). Here's my code:</p> <pre><code>from peft import PeftModel from transformers import AutoTokenizer, GPTJForCausalLM, GenerationConfig from transformers import BitsAndBytes...
<python><peft>
2023-03-27 21:47:46
1
8,651
Matthew Berman
75,860,567
17,810,039
Python Flet AttributeError: module 'flet_core.page' has no attribute 'controls'
<p>In summary, I am at the very beginning of the project.</p> <p>What I'm trying to do is use a custom 'navigation rail' for navigation between pages.Now there is a problem. When I use the custom navigation rail alone, the program works, but when I want to integrate it into my project, I get an error. error = Attribute...
<python><flet>
2023-03-27 21:35:12
1
382
Hasancan Çakıcıoğlu
75,860,309
16,305,340
socket is terminating for some reason
<p>so I am a newbie in python and I am trying to establish a server-client program in python, but I want when I send something from server or the client, the other side has to listen till the sender finish his message, so I made a function called <code>recvTillTimeOut</code> which is supposed to receive till timeout oc...
<python><sockets>
2023-03-27 20:58:00
1
1,893
abdo Salm
75,860,270
14,461,379
Why does flask redirect parse character & to HTML entity &amp; for external URLs?
<p>I want to redirect users to an external URL with parameters in a flask application that I've set up, I use <code>urlencode</code> like so:</p> <pre class="lang-py prettyprint-override"><code>parameters = {'foo': 'bar', 'baz': 'qux'} link = 'https://some.domain.com?%s' % urlencode(parameters) return redirect(link, co...
<python><flask><urlencode>
2023-03-27 20:52:47
0
331
gbrl
75,860,165
2,254,971
How should I read this python traceback/what is causing "breaks" in?
<p><strong>I know what a key error is, and why I am getting it, this question is about what is occurring to the call stack not why I am getting a key error. I am also not looking to know exactly what's happening in the pandas operation specifically, but anytime I see a callstack that appears to be &quot;divided&quot;</...
<python><stack-trace>
2023-03-27 20:37:09
0
730
Sidney
75,860,164
12,436,050
Groupby and concatenate unique values by separator in Pandas dataframa
<p>I have following pandas dataframe.</p> <pre><code> org_id org_name location_id loc_status city country 0 100023310 advance GmbH LOC-100052061 ACTIVE Planegg Germany 1 100023310 advance GmbH LOC-100032442 ACTIVE Planegg Germany 2 100023310 ...
<python><pandas><group-by><aggregate>
2023-03-27 20:37:04
3
1,495
rshar
75,859,965
21,420,742
Creating a column that that compares values from one Dataframe to another in Python
<p>I have 2 data frames one employee history and another is a hiring report. What I want is to see if a person's ID, if they are a manager, and in both data frames, and don't have open as a status then Vacant. A a new column <strong>Vacancy</strong> in the first data frame. Below is what the data frames look like:</p> ...
<python><python-3.x><pandas><dataframe><numpy>
2023-03-27 20:08:46
1
473
Coding_Nubie
75,859,915
3,726,546
Compare rows from the same dataframe and update/create new columns
<p>I am comparing values from different rows of the same dataframe and updating the <code>score</code> column with data from the afore matched row. The following code works fine for what I need, however it is not an efficient solution and takes hours to run for a 20K DF.</p> <p>What is a faster vectorised way to achiev...
<python><pandas><dataframe><group-by>
2023-03-27 20:01:40
2
409
B Jacob
75,859,799
2,256,085
return contour label positions
<p>The reproducible example below shows nearly concentric contours; it captures something I'm trying to do with matplotlib for comparing a 2D analytical solution to a numerical method solution. Because the two solution have small differences, the contours do not plot on top of one another.</p> <pre><code>import numpy i...
<python><matplotlib>
2023-03-27 19:46:05
1
469
user2256085
75,859,754
8,487,782
Python Selenium Can not solving reCaptcha
<p>2capthca not solved my targeting site. I try using python with selenium to solve this. My targeting site is: <a href="https://visa.vfsglobal.com/ind/en/ltu/login" rel="nofollow noreferrer">https://visa.vfsglobal.com/ind/en/ltu/login</a></p> <p>I got result from 2captcha api. But when I click button got error.</p> <p...
<python><selenium-webdriver><captcha>
2023-03-27 19:40:34
0
400
A S M Saief
75,859,739
5,188,353
How to bulk insert into a Presto DB using Python
<p>In my environment, I have to handle a lot of different data saved in Excel and CSV files. My python script reads all these Excel and CSV files, extracts the relevant data into a dataframe, and does some transformation.</p> <p>The final step is to load the data into a Presto DB. The current code simply loops over the...
<python><sql><insert><presto><bulkinsert>
2023-03-27 19:38:22
2
675
clex
75,859,706
3,605,534
How to calculate real accuracy in CIFAR100 Tensorflow after retrain pretrained InceptionResNetV2 model
<p>I was working with CIFAR100 dataset. I used InceptionResNetV2 to build my model. I trained for 25 epochs using data augmentation. Even though this dataset has 32x32 images, I upscaled them to 75x75. The result is as follow</p> <p><a href="https://i.sstatic.net/0hZbx.png" rel="nofollow noreferrer"><img src="https://i...
<python><tensorflow><scikit-learn>
2023-03-27 19:31:56
1
945
GSandro_Strongs
75,859,687
14,608,529
How to use variable volume control for mac via python?
<p>I found this code in python to control mac volume:</p> <pre><code>osascript.osascript(&quot;set volume output volume 35&quot;) </code></pre> <p>I want to use a variable to control this volume instead like:</p> <pre><code>volumes = [35, 35, 30, 35, 45, 45, 45, 45, 45, 40, 45, 45, 45, 45, 55, 45, 50, 45, 50, 55] for i...
<python><python-3.x><string><macos><volume>
2023-03-27 19:30:16
3
792
Ricardo Francois
75,859,649
1,457,380
Negate findall in Python re module
<p>I would like to strip every instance of a solution environment in a <code>.tex</code> file (i.e., text between <code>\begin{solution}</code> and <code>\end{solution}</code>) and save the output to a new file.</p> <p>The code snippet below grabs the solution environment: How can I negate that to strip it instead?</p>...
<python><python-3.x><regex><python-re>
2023-03-27 19:25:46
1
10,646
PatrickT
75,859,426
2,112,406
matplotlib change vertical padding only between two specific columns of subplots
<p>I'm creating a 2 by 3 array of plots with:</p> <pre><code>fig, ax = plt.subplots( nrows=2, ncols=3, figsize=( 22, 10), gridspec_kw={ 'width_ratios': [ 0.7, 0.7, 1]}) </code></pre> <p>I can adjust the vertical spacing with</p> <pre><code>plt.tight_layout(w_pad=5.0) </code></pre...
<python><matplotlib>
2023-03-27 18:58:43
1
3,203
sodiumnitrate
75,859,357
2,595,546
changes() function in python sqlite3 wrapper?
<p>Python's sqlite3 library has a total_changes property on its connection object. However, I would like to know the amount of changes made by my last query, which I would typically query using the sqlite3 changes() function.</p> <p>Is there a wrapper for that function in the sqlite3 python library?</p>
<python><database><sqlite>
2023-03-27 18:51:17
1
868
Fly
75,859,326
12,734,492
PySpark : How to merge two json columns to new column
<p>Pyspark Table:</p> <pre><code>Col1 {'table': [{'name': 'XXS', 'ranges': {'chestc': {'min': 87.88, 'max': 87.88}, 'waistc': {'min': 58.42, 'max': 58.42}}}, {'name': 'XS', 'ranges': {'chestc': {'min': 94.22, 'max': 94.22}, 'waistc': {'min': 66.04, 'max': 66.04}}}, {'name': 'S', 'ranges'...
<python><json><apache-spark><pyspark><apache-spark-sql>
2023-03-27 18:47:06
1
487
Galat
75,859,096
7,655,687
How to load a csv file into tksheet
<p>How do you save and load csv files into the Python tkinter table widget <code>tksheet</code> found here <a href="https://github.com/ragardner/tksheet" rel="nofollow noreferrer">https://github.com/ragardner/tksheet</a> using a standard tkinter window</p>
<python><python-3.x><tkinter>
2023-03-27 18:17:56
1
2,005
ragardner
75,859,074
6,695,297
Getting RateLimitError while implementing openai GPT with Python
<p>I have started to implement openai gpt model in python. I have to send a single request in which I am getting RateLimitError.</p> <p>My code looks like this</p> <pre><code>import openai key = '&lt;SECRET-KEY&gt;' openai.api_key = key model_engine = 'text-ada-001' prompt = 'Hi, How are you today?' completion = opena...
<python><python-3.x><openai-api><gpt-3>
2023-03-27 18:14:46
3
1,323
Shubham Srivastava
75,859,013
3,016,483
Python regex for matching a substring with maximum 1 space
<p>I'm trying to write a regex which will match a substring with at least one alphabet, one number, max 1 space and string length of 7.</p> <p>Here is what I have come up with until now:</p> <pre><code>r'\b(?=.*[a-zA-Z])(?=.*\d)[a-zA-Z\d\s]{7}(?!=[ ]{2,})\b' </code></pre> <p>Examples</p> <pre><code>1. &quot;abc 12 3 vh...
<python><regex>
2023-03-27 18:07:31
2
612
Illuminati0x5B
75,858,726
496,289
Configuring log4j with IDE / pyspark shell to log to console and file using properties file
<p>In my development env on my laptop (Ubuntu box), I write my &quot;pyspark code&quot; and run it through <code>pytest</code> to test. I inject the spark session that's created using <code>SparkSession.builder.getOrCreate()</code> into my tests. This &quot;pyspark code&quot; has a bunch of log statements at info level...
<python><java><logging><pyspark><log4j>
2023-03-27 17:34:04
1
17,945
Kashyap
75,858,681
9,481,731
cannot import requests in python script running on jenkins container
<p>Team, request module is not found by python script though it is installed. so is it some path I need to tell python script to look at? I am trying to run python on jenkins container ubuntu based.</p> <p>version setup from container is below</p> <pre><code>python --version Python 2.7.18 pip --version pip 20.0.2 from...
<python><python-2.7><jenkins>
2023-03-27 17:28:53
1
1,832
AhmFM
75,858,629
2,772,805
Separate vtk self intersected polydata into multiple polygons from duplicate points?
<p>From a vtk self intersected polydata, I would like to separate it into multiple polygons.</p> <p>Note that intersections in the initial polygon can be detected from duplicate points in the list of points that form the polygon.</p> <p>Get the test file from a wget <a href="https://thredds-su.ipsl.fr/thredds/fileServ...
<python><vtk><shapely><pyvista>
2023-03-27 17:23:11
1
429
PBrockmann
75,858,590
11,453,690
how set Month as string in Python datetime
<p>I found this example how to set time and covert back to readable form</p> <pre><code>import datetime x = datetime.datetime(2020, 5, 17) print(x.strftime(&quot;%Y %b %d&quot;)) </code></pre> <p>My question is how to set new date with <code>Month</code> as string ? Is it possible ? Is there some parameter/function f...
<python>
2023-03-27 17:18:00
2
619
andrew
75,858,415
14,978,092
Changing Hexa color not changing output color in Image recoloring
<p>I am using below code to change the color of intended object . I pass hexa code and object of image and its job is to recolor it. When i pass it in my code it always gives blue color after recoloring. I am changing hexa color but not effecting, What is issue in my code:</p> <p><strong>Image</strong></p> <p><a href="...
<python><opencv><matplotlib>
2023-03-27 16:57:29
1
590
Hamza
75,858,404
6,003,629
How can I mock the instantiation of a Class
<p>I can't seem to figure out how to mock the instantiation of a class, any pointers would be greatly appreciated. Here is what I am trying to do:</p> <p>I would like to test the method <code>ClassA.some_method()</code> and specifically if <code>kafka_producer.flush()</code> was called, however I don't want <code>Kafka...
<python><unit-testing><pytest><kafka-python>
2023-03-27 16:55:35
1
385
jimfawkes
75,858,396
9,418,115
Python Oracledb - Segmentation Fault Error
<p>When I use <a href="https://python-oracledb.readthedocs.io/en/latest/index.html" rel="nofollow noreferrer">oracledb</a> Python module in Thick mode, I get a <code>Segmentation fault</code> error on a huge database request with Oracle v11.2 client.</p> <p><strong>Code:</strong></p> <pre><code># main.py import oracled...
<python><oracle-database><python-oracledb>
2023-03-27 16:54:51
2
2,410
Adrien Arcuri
75,858,336
17,973,259
Is there a better way to define multiple boolean variables?
<p>I have multiple Boolean variables in my code and now they are defined like this:</p> <pre><code>self.paused, self.show_difficulty, self.resizable, self.high_score_saved, \ self.show_high_scores, self.show_game_modes = \ False, False, True, False, False, False </code></pre> <p>And I thought of refactoring the code li...
<python><boolean>
2023-03-27 16:47:50
1
878
Alex
75,858,239
10,430,394
Beautifulsoup cannot parse htm created in word?
<p>I created a .htm file (the stripped type without a data folder) in MS Word 365. I used to create those types of files all the time and load them into a .py script all the time using bs4, but now it doesn't work for some reason. That might've been caused by me writing a previous version to a new file with <code>error...
<python><html><beautifulsoup><encoding>
2023-03-27 16:36:54
1
534
J.Doe
75,858,143
10,755,782
Create a directory, only if it doesn't exist using python os.mkdir()
<p>We can create a directory, only if it does not exist using</p> <p><code> mkdir -p ./my_directory/</code></p> <p>How can we achieve the same using <code>os.mkdir()</code> in python? <code>os.mkdir(&quot;./my_directory/&quot;)</code> fails if <code>./my_directory/</code> already exists and <code>os.mkdir(&quot; -p ./m...
<python><operating-system><mkdir>
2023-03-27 16:27:09
1
660
brownser
75,858,139
8,958,754
Python kivy, enlarging an image in
<p>In python kivy, I have an FloatLayout for my self.root, later i add an Image to it with a pos_hint.</p> <pre><code>self.avatar.image = Image(source=self.avatar.current_images[0], keep_ratio=False, pos_hint={'center_x':0.5, 'center_y': 0.5}) </code></pre> <p>I then add it to root on startup.</p> <p>I want to be able ...
<python><kivy><kivy-language>
2023-03-27 16:26:54
1
855
Murchie85
75,858,068
3,387,716
Multiprocessing. How to output the computed records of a text file in the same order as they where read?
<p>I have a text file of about 300GiB in size that has a header followed by data records. Here's a dummy <code>input.txt</code>:</p> <pre class="lang-none prettyprint-override"><code># header # etc... (the number of lines in the header can vary) record #1 record #2 record #3 record #4 record #5 record #6 record #7 rec...
<python><multiprocessing>
2023-03-27 16:18:17
1
17,608
Fravadona
75,858,010
13,014,864
PySpark add rank column to large dataset
<p>I have a large dataframe and I want to compute a metric based on the rank of one of the columns. This metric really only depends on two columns from the dataframe, so I first select the two columns I care about, then compute the metric. Once the two relevant columns are selected, the dataframe looks something like t...
<python><apache-spark><sorting><pyspark><indexing>
2023-03-27 16:13:01
1
931
CopyOfA
75,857,923
283,538
get columns from numpy array in specific format given column indices
<p>I have a numpy array like this:</p> <pre><code>import numpy as np # Create a NumPy array array_data = np.array([[1, 2, 3], [4, 5, 6], [7, 8, 9]]) </code></pre> <p>and yes I can get the 2nd column like this:</p> <pre><code>column_index = 1 selected_column = array_data[:,...
<python><pandas><numpy>
2023-03-27 16:03:22
2
17,568
cs0815
75,857,827
10,192,593
Plots using for loop in Python
<p>I have a numpy array of shape (2,2,1000) representing income-groups, age-groups and a sample of 1000 observations for each group.</p> <p>I am trying to use a for-loop to plot the 4 combinations of values:</p> <pre><code> 1. &lt; 18 age, i0 income 2. &lt; 18 age, i1 income 3. &gt;= 18 age, i0 income 4. &gt;= 18 ag...
<python><for-loop><matplotlib>
2023-03-27 15:52:56
1
564
Stata_user
75,857,794
15,326,565
How does Cloudflare detect that I am a bot even though I have provided the cf_clearance cookie?
<p>How does Cloudflare even know that this request came from a script even if I provided all the data, cookies and parameters when making a normal request? What does it check for? Am I doing something wrong? For example (I have redacted some of the values):</p> <pre class="lang-py prettyprint-override"><code>import req...
<python><cookies><python-requests><session-cookies><cloudflare>
2023-03-27 15:49:49
3
857
Anm
75,857,731
1,194,864
Sort a vector in PyTorch
<p>I am performing a prediction using an input image and a pre-trained classifier on <code>ImageNet</code> using <code>PyTorch</code>. What I would like to do is to calculate the value for each for the class and returned the highest 10 values. My code looks like:</p> <pre><code>img = imread_img('image.png') input = pre...
<python><image><jupyter-notebook><pytorch>
2023-03-27 15:43:08
2
5,452
Jose Ramon
75,857,726
15,376,262
Remove group from pandas df if at least one group member consistently meets condition
<p>I have a pandas dataframe that looks like this:</p> <pre><code>import pandas as pd d = {'name': ['peter', 'peter', 'peter', 'peter', 'peter', 'peter', 'david', 'david', 'david', 'david', 'david', 'david'], 'class': ['A', 'B', 'A', 'B', 'A', 'B', 'A', 'B', 'C', 'A', 'B', 'C'], 'value': [2, 0, 3, 5, 0, 0, ...
<python><pandas><dataframe>
2023-03-27 15:42:41
3
479
sampeterson
75,857,719
11,819,955
Matplotlib axis not appearing in saved images
<p><strong>I'll submit this question only because I couldn't find any similar questions.</strong></p> <p>Today I was making plots using Python 3.10.4, matplotlib 3.5.2 I used <code>matplotlib.pyplot.savefig(f&quot;[ImageSpecificName{specifier}]&quot;.png)</code> in a loop to save a series of figures that I then sent to...
<python><matplotlib><png>
2023-03-27 15:42:13
1
437
Messypuddle
75,857,669
21,376,217
How does the IDAT block of a PNG image store pixel information?
<p>This is my Python code:</p> <pre class="lang-py prettyprint-override"><code>import struct import zlib PNG_HEADER = b'\x89\x50\x4e\x47\x0d\x0a\x1a\x0a' IHDR = b'\x00\x00\x00\x0d\x49\x48\x44\x52\x00\x00\x00\x02\x00\x00\x00\x02\x08\x02\x00\x00\x00' IHDR += struct.pack('&gt;I', zlib.crc32(IHDR[4:])) sRGB = b'\x00\x00\x...
<python><image><image-processing><png><libpng>
2023-03-27 15:36:56
1
402
S-N
75,857,623
13,494,917
Executing an sql statement into a dataframe and receiving this error ValueError: setting an array element with a sequence
<p>For some reason this line of code isn't working for me anymore on a specific table. And I'm not sure how I'd go about fixing it.</p> <pre class="lang-py prettyprint-override"><code>sql_query = pd.read_sql_query(&quot;SELECT * FROM &quot;+key+&quot;.&quot;+table+&quot;&quot;, conn, chunksize=10000) </code></pre> <p>E...
<python><pandas><sqlalchemy><azure-sql-database>
2023-03-27 15:31:54
1
687
BlakeB9
75,857,558
9,640,238
Find events in log that occur after a specific event
<p>I have a log of events to analyze that looks like this:</p> <pre><code>+----+---------------------+----------+--------+ | id | timestamp | record | event | +====+=====================+==========+========+ | 1 | 2023-03-01 13:17:05 | record03 | Edit | +----+---------------------+----------+--------+ |...
<python><pandas><time-series>
2023-03-27 15:24:30
1
2,690
mrgou
75,857,537
10,687,615
Add new column with incremental increase
<p>I have a dataframe that looks like this:</p> <pre><code> Date LOC_A 0 2022-07-01 154 1 2022-07-02 162 2 2022-07-03 170 3 2022-07-04 169 4 2022-07-05 201 </code></pre> <p>I would like to create a new column bas...
<python><pandas>
2023-03-27 15:22:23
1
859
Raven
75,857,496
6,071,697
How to Django query only latest rows
<p>I have the following Django models:</p> <pre><code>class Amount(Model): hold_fk = ForeignKey(to=Hold) creation_time = DateTimeField() class Hold(Model): group_fk = ForeignKey(to=Group) class Group(Model): pass </code></pre> <p>Each <code>Group</code> has multiple holds and each <code>Hold</code> ha...
<python><django>
2023-03-27 15:18:15
1
622
Epic
75,857,347
3,525,290
Evaluating 2 list using all function throwing error in python
<p>I am using the <code>all</code> function to compare list items to see if they are less than or equall to 10 of each other. I am testing to see if the values in l2 is 10 lower than value in l1. But I am getting a syntax error.</p> <pre><code>l1 = [10, 20, 30, 40, 50] l2 = [50, 75, 30, 20, 40] all([result for x,y in...
<python><python-3.x><list-comprehension><python-all-function>
2023-03-27 15:04:12
1
1,619
user3525290
75,857,317
2,912,859
sshtunnel is not using specified key and not using private key password
<p>I'm writing a script that needs to connect to a MySQL server via SSH. I have the following:</p> <pre><code>import mysql.connector from sshtunnel import SSHTunnelForwarder def query_mysql_server(query): with SSHTunnelForwarder( ('ssh_server_ip', 22), ssh_username='sshuser', ssh_pkey='/Us...
<python><mysql><ssh>
2023-03-27 15:00:11
3
344
equinoxe5
75,857,226
8,414,280
Parallel sorting a dictionary and returning the first k items
<p>One approach to returning the first <code>k</code> items of a sorted dictionary is shown in the code snippet below:</p> <pre class="lang-py prettyprint-override"><code>dict(sorted(dictionary.items(), key=lambda item: item[1], reverse=True)[:k]) </code></pre> <p>Therefore, is there a more efficient approach (for inst...
<python><sorting><numba>
2023-03-27 14:51:46
0
744
Celso França
75,857,007
3,971,855
How to get a list of dictionary in a single column of pandas dataframe
<p>Hi I have a dataframe in 1NF form which I wanted to change to different format where I can access those values.</p> <p>This is how my dataframe looks like</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th style="text-align: left;">Code</th> <th style="text-align: center;">ProvType</th> <th...
<python><pandas><dataframe><dictionary><group-by>
2023-03-27 14:31:52
1
309
BrownBatman
75,856,742
13,294,769
Is it possible to use SQLAlchemy create_engine and pass a certificate from an environment variable?
<p>The title pretty much sums it up. I can connect using <code>sslrootcert</code> as an argument to <code>create_engine</code>, assuming that it points to an existing certificate in my local storage. However, I would like to pass the certificate using an environment variable, or load it from a vault, etc..</p> <p>Is th...
<python><sql><python-3.x><sqlalchemy><psycopg2>
2023-03-27 14:08:06
1
1,063
doublethink13
75,856,699
5,868,293
Keep only rows for which sum is less or equal than a threshold
<p>I have the following data</p> <p>import pandas as pd</p> <pre><code>pd.DataFrame({'id': [1,1,1,1,1,2,2,2,2], 'day':[1,2,3,4,5,1,2,3,4], 'value':[5,6,7,8,9,11,12,13,14], 'day_before': [4,4,4,4,4,3,3,3,3]}) id day value day_before 0 1 1 5 4 1 1 2 6 4 2 1 3 7 4 3 ...
<python><pandas>
2023-03-27 14:03:35
1
4,512
quant
75,856,674
13,799,627
How to change the cell width of an exported jupyter notebook as html?
<p>I exported my .ipynb with jupyter notebook as html.<br /> When using the build-in export in jupyter-notebook via &quot;File&quot; -&gt; &quot;Export as&quot; -&gt; &quot;HTML&quot;, the cells become infinite wide which can look very bad when there are images included within some markdown cells.<br /> Naturally, jupy...
<python><html><jupyter-notebook><jupyter>
2023-03-27 14:01:01
0
535
Crysers
75,856,666
8,467,078
mypy doesn't understand copy.copy
<p>I'm having issues getting mypy to understand that the functions <code>copy.deepcopy</code> (and also <code>copy.copy</code>) from the <code>copy</code> standard library are callables. Even more so when these functions are assigned to a variable via a <code>x if y else z</code> expression. Below I included an example...
<python><mypy>
2023-03-27 13:59:56
0
345
VY_CMa
75,856,568
10,938,315
How to find exact substring in list of substrings?
<p>Say I have this dictionary:</p> <pre><code>lookup = {&quot;text_text&quot;: 1, &quot;text_text_num&quot;: 1} </code></pre> <p>And a list of strings:</p> <pre><code>my_strings = [&quot;text_text_part1&quot;, &quot;text_text_part2&quot;, &quot;text_text_another_part3&quot;, &quot;text_text_num_something_part3&quot;] <...
<python>
2023-03-27 13:49:13
1
881
Omega
75,856,491
4,837,637
Python SqlAlchemy Google Cloud Sql connectionevent loop error closed
<p>I'm trying to connect with my Google Cloud Sql db using google.cloud.sql.connector, and this is the code to connect:</p> <pre><code>def getconn(): with Connector() as connector: conn = connector.connect( instance_connection_name, &quot;pg8000&quot;, user = db_user, ...
<python><postgresql><google-cloud-platform><sqlalchemy><google-cloud-sql>
2023-03-27 13:42:44
2
415
dev_
75,856,326
4,262,876
pynput keyboard typing upper case letter
<p>I'm facing a weird issue here with the pynput library and maybe one of you might enlighten me.</p> <p>So this is a simple code that will help you to reproduce the behavior I'm having.</p> <p>install pynput <code>pip install pynput</code> then copy and paste the code into a .py file and run it. Then in a notepad try ...
<python><python-3.x><python-2.7><keyboard><pynput>
2023-03-27 13:26:15
0
924
1020rpz
75,856,310
14,789,957
Grouping dataframe by similar non matching values
<p>If I have a pandas dataframe with the following columns: <strong>id</strong>, <strong>num</strong>, <strong>amount</strong>.</p> <p>I want to group the dataframe such that all rows in each group have the same <strong>id</strong> and <strong>amount</strong> and where each row's value of <strong>num</strong> has a val...
<python><pandas><dataframe><grouping>
2023-03-27 13:24:46
2
785
yem
75,856,240
5,896,319
How to display celery output on the frontend?
<p>I have a celery task in my project that trigger a command from another project. Everything is working well. I'm running the celery command as</p> <pre><code>celery -A fdaconfig worker --loglevel=info </code></pre> <p>How can I display the outputs of terminal in the frontend?</p> <pre><code>@shared_task def trigger_...
<python><django><celery>
2023-03-27 13:17:31
1
680
edche
75,856,221
3,614,197
Stacked bar chart from time series data when stacked divisions are in the same column - Pandas
<p>I have a dataframe that look like the following</p> <pre><code> TrgID SenName SignalToNoise date 0 20201001000732016 a 1.645613 2020-10-01 1 20201001000732016 b 2.601088 2020-10-01 2 20201001000732016 c 1.253404 2020-10-01 ...
<python><pandas><matplotlib>
2023-03-27 13:14:45
0
636
Spooked
75,856,169
8,981,425
Pandas Datetime reduced ISO format
<p>I have to read tables where some columns may be dates. These tables are defined by the user so the format may change from one to another. For example, these would be valid formats:</p> <pre><code>'1998' '2003-10-1' '2003/5' '2004/4/5 10:40' </code></pre> <p>Pandas pd.to_datetime() handles this really well, but when ...
<python><pandas><datetime><iso8601>
2023-03-27 13:10:45
0
367
edoelas
75,855,999
3,103,767
How to broadcast using asyncio's datagram endpoint?
<p>I have tried to build on <a href="https://docs.python.org/3/library/asyncio-protocol.html#udp-echo-client" rel="nofollow noreferrer">asyncio's edp echo client example</a> for building a broadcaster (for Wake On LAN, but cut out some details below to keep the code short). The code below however always fails to send. ...
<python><udp><python-asyncio><broadcast>
2023-03-27 12:54:24
1
983
Diederick C. Niehorster
75,855,883
9,998,989
Ways of supress prints from joblib parallelization
<p>I have a script that contains parallelization. Can I suppress the parallelization prints with a simple contextlib suppressor or do I have to initialize a mute in the subprocesses with.</p> <pre><code>from joblib import Parallel, delayed import os import contextlib def start(): print('HELLO') def para(i): ...
<python><stdout>
2023-03-27 12:42:16
1
752
Noob Programmer
75,855,618
7,945,506
Selenium (python): How to access alerts?
<p>During an interaction with a website via Selenium (Python) I get this popup window: <a href="https://i.sstatic.net/hTu2i.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/hTu2i.png" alt="enter image description here" /></a></p> <p>I want to check the checkbox and then click on the left button.</p> <p>I ...
<python><selenium-webdriver><alert>
2023-03-27 12:14:54
1
613
Julian
75,855,547
10,542,284
subproccess.check_output don't recognize unix command
<pre><code>import subprocess with open(&quot;file.txt&quot;, 'r') as fl: xs = fl.readlines() for x in xs: output = subprocess.check_output(f&quot;command -L {x} -N&quot;, shell=True, stderr=subprocess.STDOUT) print(output) </code></pre> <p>Trying to run this python script in Linux but <code...
<python><subprocess>
2023-03-27 12:04:18
1
473
Jugert Mucoimaj
75,855,392
8,337,391
Convert DataFrameGroupBy object to Dict without Index column
<p>I want to do a <em>groupby</em> on my <em>dataframe</em> (like below):</p> <pre><code> VendorID ProductID Qty Expiring Date 123456 P789456 1195 True xyz 123456 P123456 1015 True xyz 987564 P168816 251 False xyz 123456 P900456 1222 T...
<python><python-3.x><pandas><dataframe>
2023-03-27 11:47:47
1
433
iPaul