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,483,294
5,371,582
python type annotation when default argument is None
<p>Maybe related:</p> <ul> <li><a href="https://stackoverflow.com/questions/19202633/python-3-type-hinting-for-none">Python 3 type hinting for None?</a></li> <li><a href="https://stackoverflow.com/questions/71431701/in-python-how-can-i-type-hint-a-list-with-an-empty-default-value">In Python, how can I type hint a list ...
<python><python-typing><default-value>
2023-02-17 10:49:19
0
705
Laurent Claessens
75,483,258
990,639
Python saxonpy returns I/O error when transforming XML
<p>I am trying to perform XSLT transform using <a href="https://pypi.org/project/saxonpy/" rel="nofollow noreferrer">saxonpy</a> with Python code as attached:</p> <pre><code>from saxonpy import PySaxonProcessor import os class XMLProcessor: proc = PySaxonProcessor(license = False) def processXSLT2(self, sour...
<python><xml><saxon>
2023-02-17 10:45:57
1
1,147
Eugene
75,483,237
3,922,727
Python how to return an excel file without converting to bytes using HttpResponse
<p>We want to return an excel file from python to the front-end. The way were are doing it now is as follows in an azure http trigger function.</p> <pre><code>return func.HttpResponse( customizedFile, headers={&quot;Content-Disposition&quot;: 'attachment; filename=&quot;{customizedFileName}&quot...
<python><excel><azure-functions><httpresponse><azure-http-trigger>
2023-02-17 10:44:07
1
5,012
alim1990
75,483,222
18,949,720
Finding contour around a cluster of pixels
<p>I have a set of images that look like this:</p> <p><a href="https://i.sstatic.net/YmZd2.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/YmZd2.png" alt="enter image description here" /></a></p> <p>Using python need a way to find a contour around the yellow shape that ignores the isolated points and is ...
<python><image-processing><contour>
2023-02-17 10:42:53
1
358
Droidux
75,483,205
5,722,359
How to change the dynamic appearance (i.e. color) of tkinter ttk.Scrollbar?
<p>I have found questions and answers on changing the static colour of a <code>ttk.Scrollbar</code>. However, I have not yet found one on changing its dynamic appearance, which is my question.</p> <p>My <a href="https://stackoverflow.com/a/48933106/5722359">scripts</a> have exposed the elements of a <code>Vertical.TScr...
<python><tkinter><tcl><ttk>
2023-02-17 10:42:07
1
8,499
Sun Bear
75,482,636
1,389,394
Pandas merge and join not picking up correct values
<p>The join is not working. Sample data and code as follows.</p> <p>Look up file:</p> <pre><code> helper time Loc FUEL Rep KM 0.1|A100|A 0.1 A100 100.00% -3.93 659 0.1|A200|A 0.1 A200 100.00% -4.49 628 0.22|A100|B 0.22 A100 90.00% -1.49 511 ... </code><...
<python><pandas><dataframe><left-join>
2023-02-17 09:51:23
1
14,411
bonCodigo
75,482,616
215,929
How do I get clipboard image data with Python?
<p>In Win 10 you can Win+Shift+S to take a screenshot of a given section of screen, and can then Ctrl+V into something like Discord and immediately send that screenshot to people.</p> <p>I'm trying to get that data (presumably a bmp / png format file) from the clipboard using Python and the win32clipboard module, but i...
<python><python-3.x><windows><winapi><clipboarddata>
2023-02-17 09:48:54
0
2,827
Enrico Tuvera Jr
75,482,432
13,921,399
Find connected components recursively in a data frame
<p>Consider the following data frame:</p> <pre class="lang-py prettyprint-override"><code>import numpy as np import pandas as pd df = pd.DataFrame( { &quot;main&quot;: [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10], &quot;component&quot;: [ [1, 2], [np.nan], [3, 8], ...
<python><pandas><network-programming><networkx><connected-components>
2023-02-17 09:32:05
1
1,811
ko3
75,482,382
139,150
Compare each string with all other strings in a dataframe
<p>I have this dataframe:</p> <pre><code>mylist = [ &quot;₹67.00 to Rupam Sweets using Bank Account XXXXXXXX5343&lt;br&gt;11 Feb 2023, 20:42:25&quot;, &quot;₹66.00 to Rupam Sweets using Bank Account XXXXXXXX5343&lt;br&gt;10 Feb 2023, 21:09:23&quot;, &quot;₹32.00 to Nagori Sajjad Mohammed Sayyed using Bank A...
<python><numpy><nlp><vectorization><similarity>
2023-02-17 09:26:36
2
32,554
shantanuo
75,481,879
10,626,495
Multiple pytest sessions during tests run
<p>I am writing tests using <code>pytest</code> and <code>pytest-xdist</code> and I want to run <code>pytest_sessionstart</code> before all workers start running and <code>pytest_sessionfinish</code> when they are done.</p> <p>I found this solution: <a href="https://github.com/pytest-dev/pytest-xdist/issues/271#issueco...
<python><pytest><pytest-xdist>
2023-02-17 08:32:59
1
8,586
maciek97x
75,481,861
2,604,247
How to Get the Node IDs of an OPCUA Server from UA Expert?
<p>I am a noob in dealing with OPCUA and trying the python library to interface with a server. I have already established a connection with the OPCUA Expert application, and this is what a screenshot looks like.</p> <p><a href="https://i.sstatic.net/7StnF.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/7...
<python><opc-ua><opc><node-opcua>
2023-02-17 08:31:29
1
1,720
Della
75,481,729
188,331
pandas.DataFrame.groupby loses index and messes up the data
<p>I have a <code>pandas.DataFrame</code> (named <code>df</code>) with the following data:</p> <pre><code> labels texts 0 labelA Some Text 12345678 1 labelA Some Text 12345678 2 labelA Some Text 12345678 3 labelA Some Text 12345678 4 labelB Some Text 1...
<python><pandas>
2023-02-17 08:18:02
1
54,395
Raptor
75,481,684
6,953,017
Django: Deleting multiple objects with a view that requires a object pk?
<p>Hey I got this Code to remove my keys:</p> <pre class="lang-py prettyprint-override"><code>class AKeysRemove(DeleteView, ProgramContextMixin): model = AKeys template_name = 'administration/keys/remove.html' def dispatch(self, request, *args, **kwargs): return super(AKeysRemove, self).dispatch(re...
<python><django>
2023-02-17 08:13:42
1
930
NakedPython
75,481,619
8,169,680
Unusual import of a class in Python
<p>There is a file <code>exceptions.py</code> present in <code>kubernetes.client</code> folder where <code>ApiException</code> class is defined. So I can write the following line in my own file say <code>myfile.py</code> and use the <code>ApiException</code> for raising exception.</p> <p><strong>some_folder.myfile.py c...
<python><python-3.x>
2023-02-17 08:06:28
1
764
Surya
75,481,527
4,847,250
How make tensorflow use GPU?
<p>I'm working with python and I would like to use tensorflow with my GTX2080TI but tensorflow is using only the CPU.</p> <p>when I ask for device on my computer, it always return an empty list:</p> <pre><code>In [3]: tf.config.list_physical_devices('GPU') Out[3]: [] </code></pre> <p>I try this post: <a href="https://s...
<python><tensorflow><gpu>
2023-02-17 07:56:10
1
5,207
ymmx
75,481,508
14,020,570
Python Dataframe column is list of dicts and how parse it
<p>I have dataframe:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>id</th> <th>name</th> <th>describe</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>some</td> <td>[{'id':20, 'name':'thisIwantAsNameColumn','value':'thisIwantasValueinRow'},{'id':22, 'name':'thisIwantAsNameColumn2','value':...
<python><json><list><dataframe><dictionary>
2023-02-17 07:53:30
1
314
Cesc
75,481,316
5,132,860
How to avoid converting model to Traced-model every time in YOLOv7?
<p>I am using <a href="https://github.com/WongKinYiu/yolov7" rel="nofollow noreferrer">YOLOv7</a> for object detection. When I run the following command, object detection works fine:</p> <pre><code>python detect.py --weights yolov7.pt --conf 0.25 --img-size 640 --source inference/images/horses.jpg </code></pre> <p>Howe...
<python><yolov7>
2023-02-17 07:31:14
1
3,104
Nori
75,481,254
8,771,201
Python directory structure problem moving one directory up in the structure gives "no module named" error
<p>This is my project structure in Visual Studio Code:</p> <pre><code>| database |- __init__.py |- database.py | sales |- __init__.py |- shop.py main.py </code></pre> <p>Insert database.py I have a function:</p> <pre><code>def insertArticle() </code></pre> <p>Now I want to use this function in shop.py so I do this:...
<python>
2023-02-17 07:24:39
0
1,191
hacking_mike
75,480,945
16,626,322
How can I show the progress of a script running in Gradio?
<p>I have successfully implemented a button in Gardio that runs a script.</p> <pre><code>def generate_output(input_path,output_path): cmd = f&quot;python parse.py \&quot;{input_path}\&quot; \&quot;{output_path}\&quot;&quot; subprocess.call(cmd, shell=True) with gr.Row(): btn_run = gr.Button...
<python><gradio>
2023-02-17 06:38:47
2
539
sooyeon
75,480,817
1,942,868
Password shown twice for django register form
<p>I am making django register form, but it shows the password twice. (three times including password conformation)</p> <p><a href="https://i.sstatic.net/WGAYz.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/WGAYz.png" alt="enter image description here" /></a></p> <p>Does anyone figure out the reason&gt;...
<python><django>
2023-02-17 06:16:34
1
12,599
whitebear
75,480,778
2,954,547
Matplotlib shrink figure to size of axes, or otherwise match its aspect ratio
<p>I have been using Cartopy to plot data using <code>'equal'</code> aspect, resulting in all manner of non-square Axes sizes. These usually look OK in Jupyter notebooks, but when saving the images (or when doing more complicated operations like adding colorbars), the resulting Figures are often huge, with a lot of bla...
<python><matplotlib>
2023-02-17 06:08:31
0
14,083
shadowtalker
75,480,557
11,402,025
Receiving Error not all arguments converted during string formatting
<p>I am new to working on Python. I m not able to understand how can I send the correct input t0 the query.</p> <pre><code> list_of_names = [] for country in country_name_list.keys(): list_of_names.append(getValueMethod(country)) sql_query = f&quot;&quot;&quot;SELECT * FROM table1 ...
<python><sqlalchemy>
2023-02-17 05:28:01
2
1,712
Tanu
75,480,282
2,333,234
Python:how to use regex search in dict
<p>how to do regex on dic key? getting expected string or bytes-like object, got 'dict' with below code.</p> <p>Thanks</p> <pre><code>with open('fbg3.csv','r') as file: csvreader=csv.DictReader(file) regex=r&quot;^REP\W+BGR30$&quot; for row in csvreader: if re.match(regex,row): print(row...
<python><regex><dictionary>
2023-02-17 04:34:03
1
553
user2333234
75,480,268
19,425,874
Python script not returning any results while web scraping
<p>I am looking to scrape a list of URLs -- I want to visit each one &amp; then return all IMG links contained within each HREF on the page (in essence, visit each link and return the image address of the player headshot on each player profile).</p> <p>I have a successful script for one set of URLs below - this is what...
<python><beautifulsoup><python-requests><python-requests-html>
2023-02-17 04:30:08
1
393
Anthony Madle
75,480,225
3,198,568
Using if-else in "with" statement in Python
<p>I want to open a file that may be gzipped or not. To open the file, I use either</p> <pre><code>with open(myfile, 'r') as f: some_func(f) # arbitrary function </code></pre> <p>or</p> <pre><code>import gzip with gzip.open(myfile, 'r') as f: some_func(f) </code></pre> <p>I want to check if <code>myfile</code> ...
<python>
2023-02-17 04:22:43
4
2,253
irene
75,480,219
17,347,824
Reading csv data into a table in postgresql via INSERT INTO with Python
<p>I have a postgresql table created in python that I need to then populate with data from a csv file. The csv file has 4 columns and a header row. When I use a for loop with <code>INSERT INTO</code> it's not working correctly.</p> <p>It is giving me an error telling me that a certain column doesn't exist, but the colu...
<python><postgresql>
2023-02-17 04:21:28
1
409
data_life
75,480,174
10,097,229
Aggregate time series data on weekly basis
<p>I have a dataframe that consists of 3 years of data and two columns <code>remaining useful life</code> and <code>predicted remaining useful life</code>.</p> <p>I am aggregating <code>rul</code> and <code>pred_rul</code> of 3 years data for each machineID for the maximum date they have. The original dataframe looks ...
<python><pandas><datetime><time-series>
2023-02-17 04:12:30
1
1,137
PeakyBlinder
75,480,149
8,942,319
poetry --help (or any other command) results in Library not loaded: '/usr/local/Cellar/python@3.10/3.10.8/Frameworks/.../3.10/Python'
<p>I had a poetry project working fine. I re-opened it today for the first time in a while, made some changes (mostly in the app code itself) and ran <code>poetry install</code> to update the dependencies.</p> <p>Any <code>poetry</code> command results in</p> <pre><code>Library not loaded: '/usr/local/Cellar/python@3.1...
<python><python-3.x><virtualenv><python-poetry>
2023-02-17 04:02:42
0
913
sam
75,480,122
13,176,726
How to pass change_password.html to replace Django Admin Password Reset
<p>Currently in my urls.py I have the following links for user to reset their password</p> <pre><code>app_name = 'users' urlpatterns = [ path('password/', user_views.change_password, name='change_password'), path('password-reset/', auth_views.PasswordResetView.as_view(template_name='users/password_reset.html',...
<python><django><django-templates><django-urls><django-authentication>
2023-02-17 03:54:57
1
982
A_K
75,480,056
6,108,107
Remove less than character '<' and return half the numeric component styled to show changes
<p>I need to clean up some data. For items in a dataframe that are of the format '&lt;x' I want to return 'x/2' so if the cell contents is '&lt;10' it should be replaced with '5', if the cell contents is '&lt;0.006' it should be replace with 0.003 etc. I want changed cells to be formatted red and bold. I have the foll...
<python><pandas>
2023-02-17 03:40:02
2
578
flashliquid
75,480,002
3,884,713
In PyTorch, how can I avoid an expensive broadcast when adding two tensors then immediately collapsing?
<p>I have two 2-d tensors, which align via broadcasting, so if I add/subtract them, I incur a huge 3-d tensor. I don't really need that though, since I'll be performing a <code>mean</code> on one dimension. In this demo, I unsqueeze the tensors to show how they align, but they are 2-d otherwise.</p> <pre><code>x = torc...
<python><pytorch><cosine-similarity><array-broadcasting><numpy-einsum>
2023-02-17 03:27:51
1
3,806
Josh.F
75,479,827
288,609
how to fix the corrupted base environment
<p>I accidentally install a lot of packages using <code>pip install -r requirements.txt</code> under base environment. Then I tried to <code>pip uninstall</code>, but it seems that the uninstalling process is unsuccessful.</p> <p>I am using the miniconda on Windows. How can I recover the base environment to clean state...
<python><pip><conda><miniconda>
2023-02-17 02:47:01
1
13,215
user288609
75,479,771
9,386,819
Why does instantiating a set with braces preserve a string within it while instantiating with the set function splits the string?
<p>Just the question above.</p> <p>Why is</p> <pre><code>&gt;&gt;&gt; x = {'foo'} &gt;&gt;&gt; print(x) {'foo'} </code></pre> <p>But</p> <pre><code>&gt;&gt;&gt; x = set('foo') &gt;&gt;&gt; print(x) {'o', 'f'} </code></pre>
<python><set>
2023-02-17 02:36:09
1
414
NaiveBae
75,479,701
8,954,291
pandas categorical doesn't sort multiindex
<p>I've pulled some data from SQL as a CSV:</p> <pre><code>Year,Decision,Residency,Class,Count 2019,Applied,Resident,Freshmen,1143 2019,Applied,Resident,Transfer,404 2019,Applied,&quot; &quot;,Grad/Postbacc,418 2019,Applied,Non-Resident,Freshmen,1371 2019,Applied,Non-Resident,Transfer,371 2019,Admitted,Resident,Freshme...
<python><pandas><pivot-table>
2023-02-17 02:22:19
1
1,351
Jakob Lovern
75,479,577
5,235,665
Calculating bottom quartile performers with Pandas DataFrames
<p>Brand new to Pandas (Python) here and am cutting my teeth with some lightweight analytics, but am having some difficulty getting started.</p> <p>I have a spreadsheet with the following data in it:</p> <pre><code>Fruit,HarvestCount,HarvestDate Apple,100,08/03/2022 Banana,2500,04/15/2022 Apple,4000,10/11/2022 Pineappl...
<python><pandas>
2023-02-17 01:54:18
1
845
hotmeatballsoup
75,479,462
2,599,709
How do I extract the weights of my quantized model for use on hardware?
<p>EDIT: attaching some code to help generate similar results (appended at end)</p> <p>I have a really small model with architecture <code>[2, 3, 6]</code> where the hidden layer uses ReLU and it's a softmax activation for multiclass classification. Trained offline and statically quantized later to qint8. What I would ...
<python><tensorflow><deep-learning><pytorch><quantization>
2023-02-17 01:28:49
3
4,338
Chrispresso
75,479,376
728,286
Flask application fails to read data from SQLite database on server using pd.read_sql
<p>In my flask application, I have a model class called <code>Well</code>, which includes a function called <code>getProdDF</code>, which pulls production data from a model class called <code>ProductionData</code> and turns it into a pandas dataframe using <code>pd.read_sql</code>. On my local machine it works fine lik...
<python><pandas><sqlalchemy>
2023-02-17 01:09:02
1
4,914
Alex S
75,479,364
4,281,353
TensorFlow/Keras where are 'loss', 'mean_absolute_error', 'val_loss', 'val_mean_absolute_error' defined?
<p>TensorFlow/Keras has multiple metrics to monitor but where are they defined? Please point to the documentation or github code where those strings have been defined.</p> <pre><code>tf.keras.callbacks.EarlyStopping( monitor=&quot;val_loss&quot;, # &lt;----- min_delta=0, patience=0, verbose=0, m...
<python><tensorflow><keras>
2023-02-17 01:05:25
1
22,964
mon
75,479,363
17,696,880
Replace a string by another if it is found after a pattern and before another
<pre class="lang-py prettyprint-override"><code>import re input_text = &quot;Creo que ((PERS)los viejos gabinetes) estan en desuso, hay que hacer algo con ellos. ellos quedaron en el deposito de afuera, lloviznó temprano por lo que ((PERS)los viejos gabinetes) fueron llevados a la sala principal.&quot; pattern_01 = r...
<python><python-3.x><regex><replace><regex-group>
2023-02-17 01:05:15
1
875
Matt095
75,479,360
1,816,135
After updating chromium from 108 to 110: WebDriverException: Message: unknown error: unable to discover open pages
<p>I am using Selenium to access a service that require login. I login one time then the login in data saved into user data, a dir that I specify as following:</p> <pre><code> chrome_options.add_argument(&quot;--user-data-dir=%s&quot; % self.user_dir) </code></pre> <p>Everything was okay until I updated the system (...
<python><linux><ubuntu><selenium-webdriver><selenium-chromedriver>
2023-02-17 01:03:59
2
1,002
AKMalkadi
75,479,350
13,430,381
How to drop elements from a series by using a Pandas for loop index as the index parameter for the drop function?
<p>I am attempting to run a loop that filters certain elements based on a condition and removes those that match, as shown below:</p> <pre><code>for index, value in enumerate(some_dataset.iloc): if min(some_dataset.iloc[index]) &gt;= some_dataset.iloc[0].values[index]: dataset_filtered = some_dataset.drop(index=ind...
<python><pandas><dataframe>
2023-02-17 01:01:39
1
526
ttoshiro
75,479,260
1,232,087
pyspark - creating Row instance inside createDataFrame() method
<p>Following code is supposed to create a dataframe <code>df2</code> with two columns - first column storing the name of each column of <code>df</code> and the second column storing the max length of each column of <code>df</code>. But I'm getting the error shown below:</p> <p><strong>Question</strong>: What I may be d...
<python><python-3.x><apache-spark><pyspark>
2023-02-17 00:38:41
1
24,239
nam
75,479,237
5,085,934
Dynamic pattern matching with MATCH failing
<p>I'm creating a dashboard with Dash on which I want a variable number of graphs with associated dropdowns underneath each other. The dropdowns control an aspect of the graph (how it's sorted, but this is unimportant). Here is the code:</p> <pre><code>from dash import html, dcc from dash.dependencies import Output, In...
<python><plotly-dash><dashboard>
2023-02-17 00:33:08
0
486
Joshua Schroijen
75,479,194
11,098,908
Why did sns.scatterplot produce a different output compared to plt.scatter on the same dataset
<p>I tried to visualise the PCA transformed data of the MNIST Digit dataset using <code>sns.scatterplot</code> and plt.scatter approaches as below</p> <pre><code>from keras.datasets import mnist import matplotlib.pyplot as plt import numpy as np import seaborn as sns import pandas as pd from sklearn.preprocessing impor...
<python><matplotlib><seaborn><scatter-plot><pca>
2023-02-17 00:22:43
0
1,306
Nemo
75,479,151
2,225,373
How to get the IP address of incoming connection in custom PAM module
<p>I am using PAM authentication to authenticate with my linux server. I have created a view on my website through Apache2 where I can use python to manually validate each login through a web shell with facial recognition and two factor authentication. This is working, but I can't seem to recover the IP address of the ...
<python><django><bash><ssh><pam>
2023-02-17 00:13:14
1
509
Charlotte Harper
75,479,119
21,113,865
How do I run multiple configuration commands in Dell EMC OS10 with Paramiko?
<p>I am trying to run a series of commands to configure a vlan on a Dell EMC OS10 server using Paramiko. However I am running into a rather frustrating problem.</p> <p>I want to run the following</p> <pre><code># configure terminal (config)# interface vlan 3 (conf-if-vl-3)# description VLAN-TEST (conf-if-vl-3)# end </c...
<python><ssh><paramiko><switching><vlan>
2023-02-17 00:03:30
1
319
user21113865
75,479,115
1,394,353
redirecting rich.inspect to file?
<p>I am trying to troubleshoot why program receiving one set of parameters works (call it <strong>v1</strong>), while another call with <em>almost the same parameters</em> fails (call that <strong>v2</strong>).</p> <p>So I want to diff some complex nested data structures. Trying a yaml dump resulted in errors (there a...
<python><rich>
2023-02-17 00:02:09
1
12,224
JL Peyret
75,479,097
3,431,407
Scrape multiple pages with the same url using Python Selenium
<p>I have the following code that scrapes some information I need from a website. However, there are <strong>61</strong> pages I need to go through and scrape the same data that requires me to click on the 'Next' button to go to the next page with the <code>url</code> remaining the same.</p> <p>I know it is possible to...
<python><selenium-webdriver><web-scraping><webdriver>
2023-02-16 23:58:53
1
661
Funkeh-Monkeh
75,479,046
6,645,564
How can I combine a scatter plot with a density heatmap?
<p>I have a series of scatterplots (one example below), but I want to modify it so that the colors of the points in the plot become more red (or &quot;hot&quot;) when they are clustered more closely with other points, while points that are spread out further are colored more blue (or &quot;cold&quot;). Is it possible t...
<python><plotly><plotly-express>
2023-02-16 23:48:08
1
924
Bob McBobson
75,478,784
1,462,718
Clang Dump AST of Python headers
<p>I am using: <code>clang -Xclang -ast-dump -fsyntax-only /usr/local/Cellar/python@3.11/3.11.2/Frameworks/Python.framework/Versions/3.11/include/python3.11/boolobject.h</code></p> <p>on the header to try to get all function declarations in a header</p> <p><code>boolobject.h</code>:</p> <pre><code>/* Boolean object int...
<python><c++><clang>
2023-02-16 23:05:49
0
23,565
Brandon
75,478,738
19,121,443
Turtle Python Package Could Not Be Installed On Ubuntu
<p>As you can see below, The turtle package could not be install on the machine and raised errors and even note that i've install python-tk package on ubuntu, how could i solve the problem? <a href="https://i.sstatic.net/3VYsd.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/3VYsd.png" alt="Turtle Python ...
<python><pip><pypi><python-turtle>
2023-02-16 22:58:26
1
361
Soroush Mirzaei
75,478,608
3,723,031
GitPython find most recent tag in the current branch only
<p>I am using this code snippet with <a href="https://gitpython.readthedocs.io/en/stable/index.html" rel="nofollow noreferrer">GitPython</a> to capture the current branch, most recent commit, and most recent tag. This information will be inserted into a version string.</p> <pre><code>repo = git.Repo(search_parent_dire...
<python><git><gitpython>
2023-02-16 22:38:57
1
1,322
Steve
75,478,574
854,183
Using dictionary comprehension to create a dictionary from list of dictionaries
<p>This is my original code, it works as I need:</p> <pre><code>import collections import json import yaml file_list = [ {'path': '/path/to/file1', 'size': 100, 'time': '2022-02-15'}, {'path': '/path/to/file2', 'size': 200, 'time': '2022-02-13'}, {'path': '/path/to/file3', 'size': 300, 'time': '2022-02-12'}, {...
<python><dictionary-comprehension>
2023-02-16 22:32:32
3
2,613
quantum231
75,478,472
7,658,985
Pytesseract issue detecting dot
<p>I do have the following photo:</p> <p><a href="https://i.sstatic.net/KCgZb.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/KCgZb.png" alt="enter image description here" /></a></p> <p>I'm trying to extract the text from it but am facing an issue to detect the <code>dot</code> within email!</p> <pre><co...
<python><python-tesseract>
2023-02-16 22:19:06
1
11,557
αԋɱҽԃ αмєяιcαη
75,478,397
15,445,589
Python Package with Sub-Packages for Microservice purpose
<p>Im currently refactoring my monolith into microserivces. To make them communicate each service has as client module with client in it that call per request the other services. I want to manage the different packages as easy as possible so I created a repository which is my package. Then each folder/module is the ser...
<python><pip><microservices>
2023-02-16 22:08:43
1
641
Kevin Rump
75,478,394
13,978,463
Unexpected behavior when I duplicate rows in data frame with a new structure
<p>I have a data frame like this (test file, the real one is bigger):</p> <pre><code>og cogs consensus p_function category gene_1 gene_2 t dnds dn ds OG0000190 COG0593 99 / 99 Chromosomal replication initiation ATPase DnaA (DnaA) L apS2gMQ_00001 GAWBhUD_01925 0.0194 0.126 0.0021 0.0163 O...
<python><pandas>
2023-02-16 22:08:11
1
425
Someone_1313
75,478,284
2,662,728
TypeError ... not JSON serializable in Django with no reference to my code in the traceback
<p>Notice that my code is not listed. It is all libraries.</p> <pre><code>Traceback (most recent call last): File &quot;/root/env/lib/python3.9/site-packages/django/core/handlers/exception.py&quot;, line 55, in inner response = get_response(request) File &quot;/root/env/lib/python3.9/site-packages/django/utils/...
<python><json><django><session-variables>
2023-02-16 21:52:43
2
535
Anthony Petrillo
75,478,267
9,328,846
How to use Pandas groupby in a for loop (FutureWarning)
<p>I have the following pandas dataframe:</p> <pre><code>d2 = {'col1': [0, 0, 1, 1, 2], 'col2': [10, 11, 12, 13, 14]} df2 = pd.DataFrame(data=d2) df2 </code></pre> <p>Output:</p> <pre><code> col1 col2 0 0 10 1 0 11 2 1 12 3 1 13 4 2 14 </code></pre> <p>And I need to run the...
<python><pandas><dataframe><group-by>
2023-02-16 21:50:18
1
2,201
edn
75,478,168
2,175,534
Python Request to C#
<p>I'm attempting to utilize an API call that I found in some Python code and translate it into C# so that I can integrate it into a Unity application I'm developing. The Python code is:</p> <pre><code>response = requests.request( method=method, url=url.as_uri(), verify=settings.CACERT_FILE, **kwargs, )...
<python><c#>
2023-02-16 21:35:01
1
1,406
Bob
75,478,106
7,346,976
EarlyStopping custom callback to stop training if validation metric goes up/down after certain number of training steps
<p>I want to stop the model using a custom callback if the <code>val_accuracy</code> is reducing after a certain number of <em>steps (steps here mean training_examples/batch_size)</em>.</p> <p>Here's my first attempt which works but doesn't actually stop the model training:</p> <pre><code>class CustomEarlyStopping(tf.k...
<python><tensorflow><keras><early-stopping>
2023-02-16 21:27:11
0
924
mank
75,478,099
12,242,085
How to extract performance metrics from confusion matrix for multiclass classification model with 5 classes in Python?
<p>I built multiclass classification model (with 5 classes in target) in Python and I have confusion matrix like below:</p> <pre><code>confusion_matrix(y_test, model.predict(X_test)) [[2006 114 80 312 257] [567 197 87 102 155] [256 84 316 39 380] [565 30 67 592 546] [363 71 186 301 1402]] </code></pre> <p>H...
<python><function><machine-learning><confusion-matrix><multiclass-classification>
2023-02-16 21:26:29
1
2,350
dingaro
75,478,003
4,199,229
Is there a Python datetime library function that does the same thing as Oracle's NEXT_DAY function?
<p>Oracle has a very useful function for finding the date of the next weekday. This function is called <code>NEXT_DAY</code>. It takes a start date, say <code>15-OCT-2009</code>, and the weekday we're expecting, say <code>TUESDAY</code>. The result of <code>NEXT_DAY('15-OCT-2009', 'TUESDAY')</code> is <code>20-OCT-2009...
<python><datetime>
2023-02-16 21:15:55
2
358
UpTide
75,477,897
12,297,666
Dropping all rows of dataframe where discontinuous data happens
<p>Consider the following part of a Pandas dataframe:</p> <pre><code> 0 1 2 12288 1000 45047 0.403 12289 1000 45048 0.334 12290 1000 45101 0.246 12291 1000 45102 0.096 12292 1000 45103 0.096 12293 1000 45104 0.024 12294 1000 45105 0.023 12295 1000 45106 0.023 12296 1000 4510...
<python><pandas>
2023-02-16 21:03:06
3
679
Murilo
75,477,823
12,284,585
Mosquitto MQTT: setting the `"ca_certs" to "/etc/ssl/certs/" leads to `IsADirectoryError: [Errno 21] Is a directory`
<p>Im looking for the corresponding code for</p> <pre class="lang-bash prettyprint-override"><code># this works fine! mosquitto_sub --capath /etc/ssl/certs/ -u user -P xyz -h hostname.com -p 8883 -t '#' </code></pre> <p>This is my code, which should do the same...</p> <pre class="lang-py prettyprint-override"><code>imp...
<python><ssl><mqtt><mosquitto>
2023-02-16 20:55:07
1
1,333
tturbo
75,477,749
10,807,390
How can I add text to the same position in multiple matplotlib plots with different axis scales?
<p>I have ~20 plots with different axes, ranging from scales of 0-1 to 0-300. I want to use <code>plt.text(x,y)</code> to add text to the top left corner in my automated plotting function, but the changing axis size does not allow for this to be automated and completely consistent.</p> <p>Here are two example plots:</p...
<python><matplotlib><plot-annotations>
2023-02-16 20:45:51
2
427
Tom
75,477,740
4,889,914
How to run Python or C# as alternative to VBScript as automation engine
<p>For many years we have been developing an application with Visual C++ and MFC. The application itself has no technical flow logic, but functions as a com-server. After initialisation, the programme starts the Windows VBScript engine, which in turn controls the flow of the programme through VBScript code. To start VB...
<python><c#><visual-c++><automation><iactivescript>
2023-02-16 20:44:59
0
341
suriel
75,477,603
1,045,909
Is there a way to prevent specific `enum.Flag` combinations?
<p>If I have an enum class like so:</p> <pre class="lang-py prettyprint-override"><code>class TestFlag(enum.Flag): A = enum.auto() B = enum.auto() C = enum.auto() D = A | B # valid </code></pre> <p>Is it possible to specify a certain combination, such as, say <code>TestFlag.C | TestFlag.B</code> as inva...
<python><enums><enum-flags>
2023-02-16 20:29:34
2
460
tkott
75,477,433
5,730,203
SQLALCHEMY - SQLITE: (sqlite3.InterfaceError) Error binding parameter 1 - probably unsupported type
<p>For the schema below:</p> <pre><code>CREATE TABLE BatchData ( pk INTEGER PRIMARY KEY AUTOINCREMENT, batchid TEXT NOT NULL, status TEXT NOT NULL, strategyname TEXt NOT NULL, createdon DATETIME ); </code></pre> <p>I have been trying to update a column value based on list of batchids.</p> <p>Snapsho...
<python><database><sqlite><sqlalchemy><query-string>
2023-02-16 20:11:55
1
1,432
Asif Ali
75,477,402
2,280,178
How can I read csv form kaggle
<p>I want to read a csv-File from kaggle:</p> <pre><code>import os import pandas as pd df = pd.read_csv('/kaggle/input/ibm-hr-analytics-attrition-dataset/WA_Fn-UseC_-HR-Employee-Attrition.csv') print(&quot;Shape of dataframe is: {}&quot;.format(df.shape)) </code></pre> <p>But I get this error:</p> <pre><code>FileNotFou...
<python><csv><kaggle>
2023-02-16 20:08:55
1
517
SebastianS
75,477,373
6,046,626
Sqlalchemy is slow when doing query the first time
<p>I'm using Sqlalchemy(2.0.3) with python3.10 and after fresh container boot it takes ~2.2s to execute specific query, all consecutive calls of the same query take ~70ms to execute. I'm using PostgreSQL and it takes 40-70ms to execute raw query in DataGrip. Here is the code:</p> <pre class="lang-py prettyprint-overrid...
<python><postgresql><sqlalchemy><asyncpg>
2023-02-16 20:05:50
2
458
JuicyKitty
75,477,365
3,647,167
Staged_predict from a Pipeline object
<p>I am having the same issue which was outlined years ago here: <a href="https://github.com/scikit-learn/scikit-learn/issues/10197" rel="nofollow noreferrer">https://github.com/scikit-learn/scikit-learn/issues/10197</a></p> <p>It seems to not have been resolved so I am looking for a work around. The example given ther...
<python><pandas><machine-learning><scikit-learn><pipeline>
2023-02-16 20:05:17
1
4,950
Keith
75,477,316
13,636,121
How can I get rid of or recolour the background of ipywidgets frames in a Jupyter Notebook in VS Code?
<p>I have a Jupyter Notebook running in VS Code with an <code>ipywidgets</code> button. The button gets displayed in a layout frame with a white background. I'd like to get rid of that frame, or make its background transparent. I've tried putting it inside a <code>Layout</code> object such as an <code>HBox</code>, but ...
<python><visual-studio-code><jupyter-notebook>
2023-02-16 19:59:00
1
873
Carmen DiMichele
75,477,177
8,907,384
Why can't I access a specific variable inside of a threaded class
<p>I'm new to Python so this could be a simple fix.</p> <p>I am using Flask and sockets for this Python project. I am starting the socket on another thread so I can actively listen for new messages. I have an array variable called 'SocketConnections' that is within my UdpComms class. The variable gets a new 'Connection...
<python><multithreading><sockets><flask>
2023-02-16 19:43:28
1
497
Haley Mueller
75,477,157
6,552,836
Apply an equation to a dataframe using coefficients from another dataframe
<p>I have to 2 dataframes:</p> <p><code>input_df</code></p> <pre><code>Apples Pears Peaches Grapes 12 23 0 4 10 0 0 4 12 16 12 5 6 0 0 11 </code></pre> <p><code>coefficients_df</code></p> <pre><code>Fruit n w1 w2 ...
<python><pandas><dataframe><numpy><data-wrangling>
2023-02-16 19:40:45
3
439
star_it8293
75,477,133
1,078,232
Is there some syntax to unpack a tuple but have an alternate value if one of the values is falsy?
<p>Example I might have:</p> <pre><code>x = None y = x or 0 </code></pre> <p>In a tuple, am I able to somehow unpack the tuple but give some default value if a falsy value is found? Example:</p> <pre><code>values = (1, None) one or 0, two or 0 = values </code></pre> <p>I know that my solution doesn't work but I was wo...
<python><tuples>
2023-02-16 19:38:02
1
2,861
Pittfall
75,477,006
4,061,422
(FLASK, APScheduler)Error: _mysql_connector.MySQLInterfaceError: Commands out of sync; you can't run this command now
<p>I am facing this problem multiple times.</p> <p>Deploy SQL File into Remote database.</p> <p><strong>scheduler.py</strong></p> <pre><code>from execute_sql import execute_file # sql executor on remote db from flask_apscheduler import APScheduler # scheduler scheduler = APScheduler() scheduler.init_app(app) fi...
<python><mysql><flask><mysql-connector>
2023-02-16 19:23:08
1
2,510
vipin
75,476,971
2,011,513
Introspecting Django queryset field lookups
<p>I'm building a querybuilder in Django for something similar to an issues dashboard, which allows users to query and save dashboards for custom subsets of the issues in our database (e.g., all issues assigned to team A, created by client X, and created or updated in the current quarter). The frontend would allow the ...
<python><django><postgresql><django-models><django-rest-framework>
2023-02-16 19:20:10
1
3,332
Ashwin Balamohan
75,476,866
2,100,039
Python Print List Elements with Defined Range
<p>I have a list that is a column of numbers in a df called &quot;doylist&quot; for day of year list. I need to figure out how to print a range of user-defined rows in ascending order from the doylist df. For example, let's say I need to print the last daysback=60 days in the list from today's day of year to daysforwar...
<python><list><range>
2023-02-16 19:07:12
3
1,366
user2100039
75,476,855
7,376,511
Class variable type depending on another class variable's type
<pre><code>class A: var_a: bool = False var_b: int | str # str if var_a is True, else int a = A() a.var_a = True a.var_b # should be str </code></pre> <p>How can I type this so that mypy knows var_b should be a string if var_a is True? Is this possible? Maybe with some clever usage of <code>Literal[True]</co...
<python><type-hinting><mypy>
2023-02-16 19:06:24
2
797
Some Guy
75,476,769
10,260,806
Is there a way to write to a dataframe based on data in another data frame?
<p>I have 2 data frames (df_text and df_excel) and I am trying to load the write a script that takes the latest date (in this example it would be 2023-02-12) from the 'end' column in df_text, match it to the dates column in (df_excel) then write the 'status' from df_text to df_excel for the correponsing name column.</p...
<python><pandas><dataframe>
2023-02-16 18:57:39
1
982
RedRum
75,476,664
5,931,362
Force Google Colab to use R kernel for existing notebook
<p>I have several existing Jupyter notebooks that use R instead of python.</p> <p>When I open these notebooks in Colab, sometimes it will automatically use the R kernel (ir), and other times it will use Jupyter3 (which results in all the code being broken). I can't figure out why it uses the R kernel for one notebook b...
<python><r><jupyter-notebook><google-colaboratory>
2023-02-16 18:46:53
2
355
jfrench
75,476,429
16,350,154
Pandas Read Continuously Growing CSV File
<p>I have a continuously growing CSV File, that I want to periodically read. I am also only interested in new values.</p> <p>I was hoping to do something like:</p> <pre><code>file_chunks = pd.read_csv('file.csv', chunksize=1) while True: do_something(next(file_chunks)) time.sleep(0.1) </code></pre> <p>in a freq...
<python><pandas><csv>
2023-02-16 18:21:03
2
406
PlzBePython
75,476,288
11,015,558
Difference between 2 Polars dataframes
<p>What is the best way to find the differences between 2 Polars dataframes? The <code>equals</code> method tells me if there is a difference, I want to find where is the difference.</p> <p>Example:</p> <pre><code>import polars as pl df1 = pl.DataFrame([ {'id': 1,'col1': ['a',None],'col2': ['x']}, {'id': 2,'co...
<python><python-polars>
2023-02-16 18:05:50
2
1,994
Luca
75,476,282
3,542,535
ThreadPoolExecutor multiprocessing with while loop and breadth first search?
<p>I'm trying to speed up some API calls by using <code>ThreadPoolExecutor</code>. I have a class that accepts a string list of <a href="https://wolf-h3-viewer.glitch.me/" rel="nofollow noreferrer">h3 cells</a> like <code>cell1,cell2</code>. h3 uses hexagons at different resolutions to get finer detail in mapping. The ...
<python><asynchronous><multiprocessing><breadth-first-search><concurrent.futures>
2023-02-16 18:05:35
1
413
alpacafondue
75,476,211
3,082,461
Imputation after one hot encoding in scikit-learn
<p>I have a dataset where I have categorical and numerical data. I want to -</p> <ol> <li>Apply OneHot encoding for all categorical columns</li> <li>Use the numerical data + one-hot encoded categorical data to do <code>Multiple Imputation</code> using IterativeImputer.</li> <li>Integrate it to a pipeline where I have a...
<python><machine-learning><data-science><data-preprocessing>
2023-02-16 17:57:09
2
440
rhn89
75,476,062
5,091,720
Pandas what is the row of error and enter substitution value on dtype error
<p>I am reading in a large tab separated file with Pandas. I am trying to declare the dtypes prior to reading the data. I am getting errors with some data records. The file is so large that I don't know what row the error data is and what value (or maybe null) is causing the error. The column that is causing the error ...
<python><pandas>
2023-02-16 17:43:03
1
2,363
Shane S
75,476,008
2,348,290
Python execute code in parent shell upon exit
<p>I have a search program that helps users find files on their system. I would like to have it perform tasks, such as opening the file within editor or changing the parent shell directory to the parent folder of the file exiting my python program.</p> <p>Right now I achieve this by running a bash wrapper that execute...
<python><posix>
2023-02-16 17:38:22
1
2,924
jeffpkamp
75,475,985
13,324,721
Does block_collapse() in sympy fail on inverse-transpose of a block matrix?
<p>I'm trying to perform some routine linear algebra on symbolic block matrices using <code>sympy</code>. When I call <code>block_collapse()</code> on a matrix that has been inversed and then transposed (in that order), <code>block_collapse()</code> outputs <code>1</code> instead of the correct matrix. See the last exa...
<python><sympy><symbolic-math>
2023-02-16 17:36:12
0
710
David L Thiessen
75,475,933
10,687,615
Weighted Average Multiple Columns: TypeError: unhashable type: 'list'
<p>I have a table that looks like this:</p> <pre><code>charge (0.0, 1.0) (0.0, 2.0) (0.0, 3.0) 84 116 1 10 147 226 9 842 342 343 2 278 503 10 939 </code></pre>...
<python><pandas>
2023-02-16 17:31:18
1
859
Raven
75,475,769
1,812,711
Simple list of branch for a Node Python AnyTree
<p>Given a simple tree in AnyTree, when I look at a node it tells me its path to the root, but I cannot find anything that will simply give me that path as a list of the node names, or as a string which I can simply turn into a list of the names.</p> <p>Typical example</p> <pre><code>from anytree import Node, RenderTre...
<python><tree><anytree>
2023-02-16 17:16:28
1
595
RossGK
75,475,737
7,760,910
unable to mock all the private methods using python unittest
<p>I have a core class where I am trying to read the zip file, unzip, get a specific file, and get the contents of that file. This works fine but now I am trying to mock all the things I used along the way.</p> <pre><code>class ZipService: def __init__(self, path: str): self.path = path def get_manifest...
<python><python-3.x><amazon-web-services><unit-testing><amazon-s3>
2023-02-16 17:13:43
1
2,177
whatsinthename
75,475,706
3,624,000
Find the count of unique values in dataframe pandas ie) value occured only once in a column
<p>Can someone help me how I can find a count of values that have occurred only once in a column in a pandas dataframe? I know we can use n number of functions like <code>nunique</code> or <code>unique().size</code> and so on but they give us only the count of distinct values whereas I am trying to find values that hva...
<python><pandas><dataframe>
2023-02-16 17:11:41
3
311
user3624000
75,475,692
3,740,839
Passing a number to a python script
<p>I am working in Linux using Ansible. I am trying to run a script from a playbook, but I need to pass the script a few arguments: a string and 2 numbers. The first number is the number of times I need to retry to run the script, the second number variable is the retry attempt (which comes from a implement retry count...
<python><ansible><ansible-inventory>
2023-02-16 17:10:50
3
887
fr0zt
75,475,640
288,609
perform math operation between scalar and pandas dataframe
<p>In an existing code, I used the following code to perform operation against a dataframe column.</p> <pre><code>df.loc[:, ['test1']] = m/(df.loc[:, ['rh']]*d1) </code></pre> <p>Here, both <code>m</code> and <code>d1</code> are scalar. 'test1' and 'rh' are the column names.</p> <p>Is this the right way or the best pra...
<python><python-3.x><pandas><dataframe>
2023-02-16 17:06:13
1
13,215
user288609
75,475,466
11,249,098
Correct use of pytest fixtures of objects with Django
<p>I am relatively new to pytest, so I understand the simple use of fixtures that looks like that:</p> <pre class="lang-py prettyprint-override"><code>@pytest.fixture def example_data(): return &quot;abc&quot; </code></pre> <p>and then using it in a way like this:</p> <pre class="lang-py prettyprint-override"><code...
<python><django><pytest><pytest-django><pytest-fixtures>
2023-02-16 16:49:36
1
489
Flora Biletsiou
75,475,460
10,200,497
getting the first row of two masks that meets conditions and creating a new column
<p>This is my dataframe:</p> <pre><code>df = pd.DataFrame({'a': [20, 21, 333, 444, 1, 666], 'b': [20, 20, 20, 20, 20, 20], 'c': [222, 211, 2, 1, 100, 200]}) </code></pre> <p>I want to use two masks. The first one finds the second row that <code>a</code> is greater than <code>b</code>. and creates column <code>d</code>....
<python><pandas>
2023-02-16 16:48:57
2
2,679
AmirX
75,475,373
9,479,925
How to check if any of column value is updated/deleted in pandas dataframe?
<p>I have a pandas data frame as.</p> <pre><code>_d = {'first_name':['Joe','Sha','Ram','Wes','David'], 'last_name':['Doe','Jhu','Krishna','County','John'], 'middle_name':['R.','M.','Q.','S.','I.'] } df_A = pd.DataFrame(_d) </code></pre> <p><a href="https://i.sstatic.net/jEezF.png" rel="nofollow norefer...
<python><pandas>
2023-02-16 16:41:13
2
1,518
myamulla_ciencia
75,475,229
14,720,380
How can I migrate my Cython code from Shapely 1.8 to Shapely 2.0?
<p>I have some custom Cython code to detect if linestrings cross a prepared geometry.</p> <p>In the migration from shapely 1.8 to 2.0, the following line segfaults:</p> <pre><code>result[i] = &lt;np.uint8_t&gt; GEOSPreparedIntersects_r(geos_handle, geom1, geom2) </code></pre> <p>The full Cython code is:</p> <pre class=...
<python><segmentation-fault><cython><shapely>
2023-02-16 16:29:07
1
6,623
Tom McLean
75,475,219
3,397,563
How to build an extracter spacy pipeline
<p>I am currently trying to extract some texts from sentences with spacy, did some courses about it but it is still a bit blur to me.</p> <p>I have the following sentence: ZZZ LLC is a limited liability company formed in the UK. XYZ LLC is a limited liability company formed in the UK. XYZ LLC owns a commercial property...
<python><artificial-intelligence><spacy>
2023-02-16 16:28:22
1
1,778
oktapodia
75,475,193
12,596,824
Randomly Sample in Python with certain distirbution
<p>I want to create a dataframe with two columns an id column which repeats the ids 1-100 3 times and then 'age' where I randomly sample the ages 0-14 17% of the time, ages 15-64 65% of the time, ages 65-100 18% of the time.</p> <p><strong>Example DF:</strong></p> <pre><code>id age 1 21 1 21 1 21 2 45 2 45 ...
<python><pandas>
2023-02-16 16:26:21
3
1,937
Eisen