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,923,269
10,866,873
Tkinter multi-parent class not initialising
<p>I am working on overhauling Tkinter to do a few extra things. To facilitate this I have created a bunch of classes for each of the widgets along with a base class for global methods.</p> <p>The issue I am having is the global class not being initialised when using the super() method in one of the widgets due to the ...
<python><python-3.x><tkinter>
2023-04-03 19:48:50
0
426
Scott Paterson
75,922,887
21,420,742
Counting how many IDs Report to a manager in Python
<p>I have a dataset that uses python and numpy in it, what I have is a dataset that looks at Employees and their managers. What I want is to count how many reports one manager has.</p> <p>Here is the sample dataset:</p> <pre><code>ID Date Job Dept. Manager ID 1 Oct 2022 Sales Rep ...
<python><python-3.x><pandas><dataframe><numpy>
2023-04-03 18:57:29
4
473
Coding_Nubie
75,922,876
4,454,635
Python - overwrite constant from imported file and use in imported functions
<p>I have a module where some constants are defined and also used in several functions. How can I over-ride their values from my main file ?</p> <p>Say this is the module, <code>test_import.py</code></p> <pre><code>MY_CONST = 1 def my_func(var = MY_CONST): print(var) </code></pre> <p>And this is my <code>main.py</...
<python><python-import>
2023-04-03 18:56:10
1
3,186
horace_vr
75,922,599
5,212,614
Is Spyder pointed to the wrong folder or is my setup totally wrong?
<p>I was using Spyder just fine until a few hours ago. Now, I realize, there are two ways to access Spyder, as seen in the image below.</p> <p><a href="https://i.sstatic.net/wUi5S.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/wUi5S.png" alt="enter image description here" /></a></p> <p>I guess something...
<python><python-3.x><anaconda><spyder>
2023-04-03 18:21:25
1
20,492
ASH
75,922,563
14,024,882
xticklabels not disappearing even after setting them to null
<p>I am trying to plot things from 0.01 to 0.1 on a log scale. I am using the following piece of code:</p> <pre><code> fig = plt.figure ( figsize=(4/1.6,3/1.6), constrained_layout=True ) ax = plt.axes()` plt.rcParams[&quot;axes.labelweight&quot;] = &quot;bold&quot; ax.tick_params(direction='in', botto...
<python><matplotlib>
2023-04-03 18:17:21
1
365
megamence
75,922,456
14,236,252
Is session auth possible in Django Rest Framework with a mobile client?
<p>I want my application to have a mobile client (non native, built using Quasar). As I understand token auth will work, so I have chosen and implemented JWT for the web app though I havent tested the mobile client yet. I was wondering is it possible/recommended to use session auth in this context?</p>
<python><django><django-rest-framework><quasar>
2023-04-03 18:02:48
2
514
bendowlingtech
75,922,425
7,009,988
pyplot second subplot won't show
<p>I'm trying to plot 2 scatterplots next to each other using pyplot, but I can't get it to work.</p> <pre><code>x1 = list(stablepdfs.keys()) y1 = list(stablepdfs.values()) plt.scatter(x1,y1) plt.title('Size of Succeeded vs Failed Pdfs') plt.xlabel('Pdf Size in MB') plt.ylabel('# of Pdfs') plt.subplot(211) #---------...
<python><matplotlib>
2023-04-03 17:57:47
0
1,643
wheeeee
75,922,371
10,620,003
Change the a parameter or name of the function all over the .py files
<p>I have the different .py files (~10). For example, here is two function in two different .py files. So, I want to change the parameter b to c, and the name of function sum to new_name and I want to change them all over the other .py files. Do we have any option in python for that:</p> <p>f1.py:</p> <pre><code>def su...
<python>
2023-04-03 17:50:25
1
730
Sadcow
75,922,153
21,420,742
How to get count of Employee activity by Manager in Python
<p>I have a dataset that uses numpy and pandas and looks at employees by ID # and all activity like promotion, termination, job switch, and etc. What I want to do is know how to count the number of changes and group them to the manager.</p> <p>Here is a sample of the data. For Reference: 1 = Yes 0 = No</p> <pre><code>I...
<python><python-3.x><pandas><dataframe><numpy>
2023-04-03 17:21:44
1
473
Coding_Nubie
75,921,970
726,730
PyQt5 QGroupBox with checkbox - disable checkbox only not the child widgets
<p>in pyqt5 if i have a checkable QGroupBox. Is there any easy way to disable only the checkbox (True - False) but not the child widgets of QGroupBox?</p>
<python><pyqt5><qgroupbox>
2023-04-03 16:59:19
0
2,427
Chris P
75,921,952
6,928,292
Create N tasks in step function. One for each lambda function that exists in list
<p>I'm just trying to create a simple step function where each task runs sequentially: <code>task1 -&gt; task2 -&gt; task3</code></p> <p>One task for every lambda in <code>lambda_handler_paths</code> = <code>['/Users/aaronwest/Code/ce-engineering-test-live/tests/tf-senior-engineer/validators/my-other-function/lambda.zi...
<python><python-3.x><aws-cdk><aws-step-functions>
2023-04-03 16:57:51
1
1,815
aphexlog
75,921,938
13,004,915
Bootstrap a function with multiple arguments using scipy.stats.bootstrap
<p>I am trying to compute the Standard Error of an estimate using <code>scipy.stats.bootstrap</code>. The function I am using takes two arguments. E.g. I have two lists like:</p> <pre class="lang-py prettyprint-override"><code>x = [12, 14, 82, 55, 63, 56] w = [0.61, 1.01, 1.8, 2.6, 0.93, 1.13] </code></pre> <p>An I wou...
<python><scipy>
2023-04-03 16:55:42
1
759
Josep Espasa
75,921,890
504,717
How to force sqlalchemy to use big int for specific and clause
<p>I have this code</p> <pre><code>my_query = query.filter( sa.and_(Content.target_type == 'a_name', Content.target_ids.overlap(a_name_ids)) ) </code></pre> <p><code>a_name_ids</code> is a value which get fed into system from another api. It just so happened that the api has changed the value and it now contains bi...
<python><postgresql><sqlalchemy><python-3.8>
2023-04-03 16:49:32
0
8,834
Em Ae
75,921,584
10,271,487
Pyplot creating chart as 1 continuous line instead of multiple individual lines
<p>Plotting a dataframe results in 1 line instead of 1 line per iteration of a dataframe of values.</p> <p>Instead on multiple individual lines that trace positioning from a dataframe, I get 1 line which connects the end of one iteration to the start of the next and I'm not sure why.</p> <pre><code>fig = plt.figure(fig...
<python><matplotlib>
2023-04-03 16:14:28
1
309
evan
75,921,577
488,917
Murmur3 Hash Compatibility Between Go and Python
<p>We have two different libraries, one in Python and one in Go that need to compute murmur3 hashes identically. Unfortunately no matter how hard we try, we cannot get the libraries to produce the same result. It appears from <a href="https://stackoverflow.com/questions/29932956/murmur3-hash-different-result-between-py...
<python><go><hash><murmurhash>
2023-04-03 16:14:02
1
5,432
bbengfort
75,921,438
6,224,557
Replace column value in panda dataframe based on another colum value
<p>I have the following panda dataframe:</p> <pre><code> Material Min_lot Reorder 0 E01 1 0 1 E02 1 -1 2 E03 1 10 3 E04 1 1 4 E05 5 0 5 E06 5 -1 6 E07 5...
<python><pandas>
2023-04-03 15:57:40
5
305
Rolando Azevedo
75,921,409
8,862,235
Group by with applying a custom function
<p>I want to get a list of points after performing an aggregation. Suppose that I have the following dataset:</p> <pre><code>AC_ID,AC_PERIOD,ROU_ROUTE_ID,SEQUENCE_NR,SEG_POINT_FROM_ID,SEG_POINT_TO_ID 502,S,A1,1,BRY,LUREN 502,S,A1,2,LUREN,DJL 502,S,A1,3,DJL,LISMO 502,S,A1,4,LISMO,SIROD 502,S,A100,1,KL,*ROS1 502,S,A100,2...
<python><pandas><dataframe><group-by>
2023-04-03 15:54:41
3
323
Filip
75,921,348
4,044,696
Read CSV wit specific columns and rest into last column
<p>I have set of columnar data, separated by spaces</p> <pre><code>Lorem ipsum dolor sit amet, consectetur adipiscing elit </code></pre> <p>What is needed is to read it as CSV, separated by white spaces, but only 5 first columns to be in, rest of the text should be single column, something like this</p> <pre><code>|Lor...
<python><pandas><csv>
2023-04-03 15:47:21
3
20,330
Severin Pappadeux
75,921,330
2,009,409
Django and Time Zone for regions that no longer observe the Daylight Save Time (DST)
<p>I have a Django project, time zone is enabled for multiple purposes, my <code>TIME_ZONE = 'America/Mexico_City'</code>, however, since this year 2023, in this time zone it's no longer observed the DST, I use the <code>localtime</code> to get the right date/time in some cases, but it detects the DST</p> <pre><code>&g...
<python><django><timezone><dst>
2023-04-03 15:44:23
1
333
Alejandro Franco
75,921,214
13,039,962
How to give a 3d shape (to the bars) to 2d grouped bars plot
<p>I have this df:</p> <pre><code> YEAR CODE ANOM% 0 1964 152101 -85.294118 1 1965 152101 -62.352941 2 1965 152111 -85.862069 3 1966 152101 -81.352941 4 1966 152111 -77.873563 .. ... ... ... 108 2020 152101 -38.823529 109 2021 152101 -5...
<python><pandas><matplotlib>
2023-04-03 15:33:12
0
523
Javier
75,921,094
9,363,181
Unable to mock the return value of the private method in python unittest
<p>I have the core logic as below:</p> <pre><code>class DBTProjectUploader: def __init__(self, file_manager: FileManager, s3_client): self.file_manager = file_manager self.s3_client = s3_client def copy(self, dbt_attr: DbtAttr): old_bucket, old_bucket_name, old_prefix, new_bucket, new_p...
<python><unit-testing><python-unittest>
2023-04-03 15:19:35
1
645
RushHour
75,921,024
2,233,608
Automatically modernize python syntax
<p>I'm looking for a tool that will automatically modernize my python code. Something that will take a python version as configuration, and automatically modernize the code for that version.</p> <p>For example, with python 3.9+ we can convert all</p> <pre><code>from typing import List my_list:List[str] = [] </code></p...
<python><mypy><flake8><python-black>
2023-04-03 15:12:49
1
1,178
niltz
75,920,984
21,351,146
How do you indicate in Python that a class method will return a class instance?
<p>I am trying to emulate the idea of ok and err variants from rust in python, here is a result class</p> <pre><code>from typing import Any, Union class Result: def __init__(self, value: Any, status: bool = True) -&gt; None: self.value = value self.status = status @classmethod def Ok(cls, ...
<python><python-typing>
2023-04-03 15:08:14
0
301
userh897
75,920,773
9,403,794
How to change columns type in numpy ndarray
<p>Because I do not understand numpy dtypes, I have to create Pandas and then I can change type of columns. But that is wrong way because of memory consumption. If I have pandas columns like that:</p> <pre><code>df[0 ] = df[0 ].astype(np.int64) df[1 ] = df[1 ].astype(np.int8) df[2 ] = df[2 ].astype(np.int8) df[3 ] = ...
<python><pandas><numpy><numpy-ndarray>
2023-04-03 14:49:05
0
309
luki
75,920,755
19,198,552
Why does the parameter "disabledwidth" of a tkinter canvas rectangle not work?
<p>I want the outline of a rectangle in a canvas to get a bigger width, when the rectangle is in state &quot;disabled&quot;. Therefore I use the parameter &quot;disabledwidth=4&quot;. But when the rectangle is in state &quot;disabled&quot;, the outline has still a width of 1 instead of 4.</p> <p>This is my code, which ...
<python><tkinter><canvas>
2023-04-03 14:47:15
2
729
Matthias Schweikart
75,920,640
16,436,095
What is the fundamental difference between flags and kwargs with bool values in Python?
<p>e. g. <a href="https://docs.python.org/3/library/re.html#flags" rel="nofollow noreferrer">flags are used in module <code>re</code></a>.</p> <p>When do I need to use flags when writing my own module, and when do I need keywords with bool values? Is it just a matter of convenience or not?</p> <pre class="lang-py prett...
<python>
2023-04-03 14:33:39
1
370
maskalev
75,920,592
19,674,402
Replace only first row for each user
<p>I have a table that has users, food, and which one is their favorite.</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th style="text-align: left;">user</th> <th style="text-align: center;">food</th> <th style="text-align: right;">is_favorite</th> </tr> </thead> <tbody> <tr> <td style="text-...
<python><pandas><dataframe><group-by>
2023-04-03 14:28:55
1
496
PythonForEver
75,920,451
11,501,976
How to modify numpy array with arbitrary indices in vectorized way?
<h1>Simplified story</h1> <p>Suppose I have an array <code>arr</code> and indices <code>idx</code>. For each <code>i</code> occuring in <code>idx</code>, I want to increase <code>arr[i]</code> by one.</p> <p>A non-vectorized approch will be like this:</p> <pre class="lang-py prettyprint-override"><code>import numpy as ...
<python><numpy>
2023-04-03 14:16:25
2
378
JS S
75,920,227
21,787,377
How to use choice field in flask
<p>I'm from django, in django models, when we want to use <code>choices</code> in our field, we defined it like this:</p> <pre><code>class ListAlbum(models.Model): LIST_OF_ALBUM = ( ('Shakira', 'shakira'), ('Don Jazy', 'Don Jazy'), ('Psquare', 'Psquare') ) name = models.Charfield(max...
<python><flask>
2023-04-03 13:51:56
0
305
Adamu Abdulkarim Dee
75,920,179
12,990,915
Why does torch.cuda.is_available() return True in terminal but False in Jupyter notebook?
<p>As you can see from the image below, <code>torch.cuda.is_available()</code> returns <code>True</code> in terminal but <code>False</code> in Jupyter notebook. It seems that I am using the same Python.</p> <p><strong>In Jupyter notebook:</strong></p> <pre><code>import torch </code></pre> <pre><code>!which python </cod...
<python><jupyter-notebook><pytorch>
2023-04-03 13:46:34
1
383
user572780
75,920,123
2,744,242
How to import the 'PyPDF4' library in Pyodide?
<p>&quot;I'm trying to import the 'PyPDF4' library in Pyodide using micropip but it's giving me an error:</p> <pre><code>ValueError: Can't find a pure Python 3 wheel for 'pypdf4'. </code></pre> <p>Would anyone know what I'm doing wrong?&quot;</p> <pre><code>async function main() { let pyodide = await loadPyodide();...
<python><pyodide>
2023-04-03 13:39:57
1
13,406
rafaelcb21
75,919,967
1,586,860
How to benchmark a single function call in Python?
<p>How to interactively (micro)benchmark a code expression in Python (i.e. the equivalent of <code>@btime</code>/<code>@benchmark</code> in Julia) ?</p> <p>I would like to benchmark interactively an expression (a function call), where the number of times this expression should be evaluated depends on its computational...
<python><benchmarking><microbenchmark>
2023-04-03 13:23:57
1
6,503
Antonello
75,919,928
12,248,220
where can I find the numpy.matmul() source code?
<p>I do not obtain the same results when I use <code>np.matmul(A, b)</code> in Python and when I use <code>xtensor-blas</code>'s <code>xt::linalg::dot(A, b)</code> in C++.</p> <p>I am investigating the reasons, as when saved and read from disk, <code>A</code> and <code>b</code> are identical when doing <code>np.allclo...
<python><arrays><numpy><optimization><blas>
2023-04-03 13:18:40
1
576
velenos14
75,919,862
10,844,937
Is it possible to print different in a decorator in Python?
<p>I need to call the function <code>notice</code> <strong>twice</strong>. And here <code>notice</code> function calls a decorator.</p> <pre><code>def decorator(func): def wrapper(*args, **kwargs): # print 'first' or 'second' here. return func(*args, **kwargs) return wrapper @decorator def not...
<python><python-3.x>
2023-04-03 13:12:21
0
783
haojie
75,919,809
21,420,742
How to get Multiple Results without using if elif statement in Python
<p>I am trying to conditionally make a statement without using if elif statement in python to get multiple results. I am using Numpy and pandas at the current moment and I have found a way to use I just forgot the correct steps and don't know the name of this conditional statement.</p> <pre><code>grade = [] condition =...
<python><python-3.x><pandas><dataframe><numpy>
2023-04-03 13:06:05
2
473
Coding_Nubie
75,919,792
6,645,564
What is the most efficient way to read from a template text file and then write interpolated values from different variables from a script?
<p>I have a Python script that I want to output with a README.txt files for users. In the README.txt, there are going to be some description of what was run in the script, including the values. The values of these variables change depending on the project. Since the README.txt file is kind of long, and copying and past...
<python><string-interpolation>
2023-04-03 13:03:47
1
924
Bob McBobson
75,919,742
6,057,371
pandas apply groupby and agg, and update orig columns
<p>I have a dataframe <code>df</code>:</p> <pre><code> Group1. Group2 Val 0 1 Q 2 1 1 Q 3 2 2 R 8 3 4 Y 9 </code></pre> <p>I want to update df with list of values per group, so new df will be</p> <pre><code> Group Group2 Val new 0 1 Q ...
<python><pandas><dataframe><group-by>
2023-04-03 12:58:04
2
2,050
Cranjis
75,919,738
4,940,741
how can i add numeric scales to x and y axis of scanpy umap?
<p><a href="https://i.sstatic.net/DLb84.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/DLb84.png" alt="enter image description here" /></a>I am using the code below to make two population on my umap</p> <pre><code>adata_all.obs[&quot;cell_type_lvl0&quot;] = adata_all.X[:, adata_all.var[&quot;marker&quot...
<python><matplotlib><visualization><scanpy>
2023-04-03 12:57:53
1
575
minoo
75,919,642
4,100,282
Combine three markers in a single matplotlib legend item
<p>I would like to plot square markers of two colors, with some of the markers of each color having an extra dot in the middle:</p> <pre class="lang-py prettyprint-override"><code>import numpy as np from matplotlib import pyplot as ppl x = np.array([1,2,3,4]) y = np.array([1,2,3,4]) kw = dict(mew = 1, mec = 'k', ms =...
<python><matplotlib><legend>
2023-04-03 12:46:22
2
305
Mathieu
75,919,241
14,131,782
Pandas.ExcelWriter() file corruption unless use .save() function
<p>I am trying to use Pandas to write a dataframe to Excel. The data is just some price data from a public Crypto API:</p> <p><a href="https://i.sstatic.net/QlPeX.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/QlPeX.png" alt="first few rows of data in Excel" /></a></p> <p>My code is as follows:</p> <pre...
<python><pandas><dataframe><pandas.excelwriter>
2023-04-03 11:59:03
1
1,078
user14131782
75,919,230
4,125,774
azure information protection remove label in linux
<p>I am in a situation that requires (decrypting/removeLabel) in Linux eg. Debian or rasbian ? I have looked into azure products and they clearly stated that there is no &quot;official&quot; support for Linux..... but my question here is .... is there any workaround to achieve this in Linux?</p> <p>One silly way I coul...
<python><linux><azure>
2023-04-03 11:58:01
1
307
KapaA
75,919,215
6,546,835
win32serviceutil issue with starting a custom service
<p>I'm trying to create a windows service by using the code below. The global variables are defined, and the imports are properly imported. The main bulk of the code is:</p> <pre><code>class MyHandler(FileSystemEventHandler): def __init__(self): self.changed_files = {} def on_any_event(self, event)...
<python><automation><service><windows-services><win32serviceutil>
2023-04-03 11:56:26
1
636
Yafim Simanovsky
75,919,008
10,216,028
How to pass "-c" argument correctly to pytest.main?
<p>I already checked <a href="https://stackoverflow.com/questions/55933832/pytest-define-custom-path-for-tests-collection">this question</a> but couldn't fix the error.</p> <p>I am designing a testing framework based on using <code>pytest</code>.</p> <p><code>pytest</code> will be called in a python script and not from...
<python><python-3.x><pytest>
2023-04-03 11:33:24
1
455
Coder
75,918,895
4,373,805
is there a way to implement pandas wide_to_long in Polars?
<p>I use Pandas wide to long to stack survey data and it works beautifully with regex and stub names, is this possible to do in Polars ?</p> <p>e.g. in Pandas -</p> <pre><code>import pandas as pd df = pd.DataFrame({ 'famid': [1, 1, 1, 2, 2, 2, 3, 3, 3], 'birth': [1, 2, 3, 1, 2, 3, 1, 2, 3], 'ht_one': [2.8, 2.9, 2.2, 2,...
<python><python-polars>
2023-04-03 11:18:02
1
468
Ezio
75,918,753
12,284,585
What is the equivalent of this Python code in Hasekell?
<p>I try to make the below Haskell code equal to the Python code, but it doesn't work and i can't spot the error? Can somebody spot the error? The Python output is what i want</p> <pre><code>def balanceList(lst): length = len(lst) if length&lt;3: return lst else: middle=length//2 ret...
<python><haskell>
2023-04-03 11:03:24
1
1,333
tturbo
75,918,731
4,847,250
why predict with a tensorflow model don't give the same answer for each signal separatly and all signal at once?
<p>Have created a tenforflow model that is taking 512 input samples (1 * N * 512) and I would like to make a prediction with new input.</p> <p>I have an s variable that has 19*512 signal if i predict the output of my model with one signal at a time</p> <pre><code>[DLmodel( s[i,:][np.newaxis,np.newaxis,:] ).numpy()[0,:,...
<python><tensorflow><predict>
2023-04-03 11:00:42
1
5,207
ymmx
75,918,462
7,386,830
How to save each iterating Statsmodel as a file to be used later?
<p>I have the following table generated:</p> <pre><code>import pandas as pd import numpy as np from matplotlib import pyplot as plt # Generate 'random' data np.random.seed(0) X = 2.5 * np.random.randn(10) + 1.5 res = 0.5 * np.random.randn(10) y = 2 + 0.3 * X + res Name = ['A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', '...
<python><pandas><matplotlib><regression><statsmodels>
2023-04-03 10:28:54
2
754
Dinesh
75,918,378
9,356,904
Python script for retrieving Reddit posts works but returns blank results
<p>I've written a python script which is intended to :</p> <ul> <li>Call the Reddit API</li> <li>Retrieve posts and comments of the subreddit 'r/booksuggestions'</li> <li>Save the results into a CSV for further analysis</li> </ul> <p>The CSV successfully creates but the content is blank. I've confirmed the credentials ...
<python><reddit><praw>
2023-04-03 10:18:31
1
559
nc14
75,918,366
10,428,677
Groupby and generate a column saying how many values are imputed
<p>I have a dataframe that looks like this:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Region</th> <th>Country</th> <th>Imputed</th> <th>Year</th> <th>Price</th> </tr> </thead> <tbody> <tr> <td>Africa</td> <td>South Africa</td> <td>No</td> <td>2016</td> <td>500</td> </tr> <tr> <td>Afri...
<python><pandas><dataframe>
2023-04-03 10:17:39
2
590
A.N.
75,918,361
2,405,663
How to set date format in DatePicker bokeh
<p>I m building a page with some chart using Bokeh and Python. I m using DatePicker to show a field to select a Date.</p> <p>This is the code:</p> <pre><code>date_pickerStart = DatePicker(title='', value=dateStart, width=100) </code></pre> <p>now this field is displayed in the page and the user can select the date usin...
<python><datepicker><bokeh>
2023-04-03 10:16:53
2
2,177
bircastri
75,918,140
1,587,118
Getting RuntimeError: expected scalar type Half but found Float in AWS P3 instances in opt6.7B fine tune
<p>I have a simple code which takes a opt6.7B model and fine tunes it. When I run this code in Google colab(Tesla T4, 16GB) it runs without any problem. But when I try to run the the same code in AWS p3-2xlarge environment (Tesla V100 GPU, 16GB) it gives the error.</p> <pre><code>RuntimeError: expected scalar type Half...
<python><pytorch><huggingface-transformers><huggingface>
2023-04-03 09:53:31
4
2,271
SRC
75,918,043
6,064,623
How to avoid extra digit being added in the addition of decimals in Python
<p><code>print(37.4&lt;(32.0+5.0+0.2+0.2))</code> This statement gives a True result but I need it should give me a False as the addition of the numbers (32.0+5.0+0.2+0.2) is precisely the same as 37.4 but here it gives the following result 37.400000000000006 for this equation (32.0+5.0+0.2+0.2). Hence, I am getting a ...
<python>
2023-04-03 09:44:05
3
1,607
amol
75,917,994
3,614,197
Web scraping to obtain pdf reports with beautiful soup Python
<p>I am trying to write some web scraping code to search the net for feasability studies of mining companies. As a starting point I would like reports that are PDF. what I have so far is below but I get an error with the last line</p> <pre><code>import requests from bs4 import BeautifulSoup import pandas as pd # Set ...
<python><web-scraping><beautifulsoup>
2023-04-03 09:37:17
1
636
Spooked
75,917,956
8,040,369
modbus controller: Trying to get data from Modbus controller using IP address in Python
<p>I am trying to get data from Modbus controller using IP address.</p> <pre><code>from pymodbus.client.sync import ModbusTcpClient as ModbusClient client = ModbusClient(&quot;10.98.237.80&quot;, port=502, auto_open=True) client.connect() rr = client.read_holding_registers(60, 2, unit=1) print (rr.registers) </code>...
<python><modbus><modbus-tcp><pymodbus>
2023-04-03 09:32:23
1
787
SM079
75,917,940
7,132,596
Django post_save is not executed on CI/CD
<p>I recently increased the default permissions for all my Django Views. In order for the users to have some default permissions I add new users to a default Group that has mainly viewing permissions. This is done via a <code>post_save</code> signal.</p> <pre class="lang-py prettyprint-override"><code>MODELS_VIEW = [ ...
<python><django><continuous-integration><pytest><pytest-django>
2023-04-03 09:30:42
2
956
Hans Bambel
75,917,750
9,143,046
Very slow aggregate on Pandas 2.0 dataframe with pyarrow as dtype_backend
<p>Let's say I have the following dataframe:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Code</th> <th>Price</th> </tr> </thead> <tbody> <tr> <td>AA1</td> <td>10</td> </tr> <tr> <td>AA1</td> <td>20</td> </tr> <tr> <td>BB2</td> <td>30</td> </tr> </tbody> </table> </div> <p>And I want to ...
<python><pandas><group-by><pyarrow><apache-arrow>
2023-04-03 09:06:55
1
331
ADEL NAMANI
75,917,657
630,971
Translate list of labels into array of labels per ID in python
<p>I have a data frame with texts and labels. Each text has multiple rows with on label.</p> <pre><code>dummy_df = pd.DataFrame([['Text1','label1'], ['Text1', 'label2']], columns=[&quot;TEXT&quot;, &quot;LABELS&quot;]) </code></pre> <p>I would like to have the following to apply MultiLabelBinarizer() function.</p> <pre...
<python><pandas><dataframe>
2023-04-03 08:54:48
1
472
sveer
75,917,449
4,837,637
Python sql alchemy cursor not select statement
<p>i have developed this Database class to create more function to reuse in other file:</p> <pre><code>import threading import sqlite3 from queue import Queue import sqlalchemy class Database(threading.Thread): def __init__(self, db, logger = None): super(Database, self).__init__() self.db=db ...
<python><sqlalchemy><cursor>
2023-04-03 08:31:14
0
415
dev_
75,917,443
14,269,252
Plotly - how all the data point in x and y axis and adjust the size of chart depends on number of data points
<p>I wrote the code as follows to plot the scatter plot using Plotly and I just want to use this library.</p> <ul> <li><p>how can I get rid of this messy x and y axis when I want to show all data?</p> </li> <li><p>how can I adjust the size of chart depends on number of data points that is showing ? because the chart is...
<python><plot><charts><plotly><streamlit>
2023-04-03 08:30:44
0
450
user14269252
75,917,238
9,850,681
Error "Auto offset commit failed: [Error 25] UnknownMemberIdError:" after days of use
<p>This problem always occurs after a few days that microservices communicate with kafka, I have 3 nodes, and for each microservice I use a group id on a specific topic. The error is as follows.</p> <pre><code>Unable connect to node with id 1: Failed fetch messages from 1: NodeNotReadyError: Attempt to send a request t...
<python><apache-kafka><aiokafka>
2023-04-03 08:04:01
0
460
Plaoo
75,917,020
3,650,477
Doxygen for Python produces bad formatting since an update
<p>I'm using doxygen for a while to document my project. However in a new computer with a newer version of doxygen (1.9.1) it produces bad formatting for function docstrings.</p> <p>I attach an image that summarises very well the issue.</p> <p><a href="https://i.sstatic.net/j9CO6.png" rel="nofollow noreferrer"><img src...
<python><doxygen><docstring>
2023-04-03 07:36:58
1
2,729
Pythonist
75,916,896
5,025,009
Trying to understand the order of the legend labels when using pandas and matplotlib.pyplot
<p>I am trying to understand why the order of the labels behave like that in the following case.</p> <p>I first plot the pandas dataframe and then I plot a horizontal line. I then change the legend labels and create them in the order (pandas column names, line label i.e. <code>['case0', 'case1', 'case2'] + ['line label...
<python><pandas><matplotlib>
2023-04-03 07:21:14
1
33,417
seralouk
75,916,837
869,402
Poetry include additional data files in wheel
<p>I have a simple python package, let's call it <code>my_package</code>.</p> <p>Its files are located in <code>src/python/my_package</code>. In addition, there is a <code>data</code> folder in the repository root, which should be included in the resulting python wheel within the <code>my_package</code>.</p> <pre><code...
<python><python-poetry><python-wheel>
2023-04-03 07:10:54
1
6,896
Stefan Profanter
75,916,672
2,291,357
rails deployment fails on asset precompilation due to npm/pyton issue
<p>In the process of deploying to a Ubuntu 20.04 server</p> <pre><code> 01 $HOME/.rbenv/bin/rbenv exec bundle exec rake assets:precompile 01 yarn install v1.22.19 01 [1/4] Resolving packages... 01 [2/4] Fetching packages... 01 [3/4] Linking dependencies... 01 warning &quot; &gt; webpa...
<python><ruby-on-rails><npm><webpacker>
2023-04-03 06:47:14
1
6,329
Jerome
75,916,653
6,765,276
Convert MATLAB use of Probability Density Function (PDF) to Python
<p>I'm working to convert below MATLAB code to Python:</p> <p><strong>MATLAB:</strong></p> <pre><code>data = [ 44374 44034 44150 44142 44332 43986 44423 44346 44199 44129 44173 43981 44152 43797 44167 43944 44069 44327 44083 44473 44530 44361 44067 44154 44212 44537 44158 44428 43911 44397]; RMS ...
<python><numpy><matlab>
2023-04-03 06:44:20
0
569
DavidDr90
75,916,373
3,810,748
Do I need to manually disconnect my Google Drive credentials from Google Colab?
<p>I am new to using Google Colab and I am currently mounting data from Google Drive like this:</p> <pre><code>from google.colab import drive drive.mount('/content/drive') </code></pre> <p>Do I need to be worried about potential security issues? Do I need to manually clear out sessions?</p> <p>Or does Google Colab aut...
<python><security><google-colaboratory>
2023-04-03 05:54:53
1
6,155
AlanSTACK
75,916,309
10,621,921
Using tf.data.Dataset prefetch makes model performance overfit?
<p>I'm trying to train a simple LRCN model with some sequential image dataset in Tensorflow 2.5.0. Training performance was fine like increasing to 0.9x training &amp; validation accuracy both in first 5 epochs and train &amp; validation loss kept decreasing during the training.</p> <p>Then, I've tried to optimize data...
<python><tensorflow><machine-learning><deep-learning><prefetch>
2023-04-03 05:37:43
1
513
Young.J
75,916,234
3,810,748
Is there anything else I need to do besides calling model.to(device) for HuggingFace GPU?
<p>I am new to using HuggingFace and the PyTorch ML ecosystem. I am trying to use a GPU device instead of the default CPU.</p> <p>Can someone tell me if the following script is correct? The only thing I am calling is <code>lmhead_model.to(device)</code>.</p> <p>I am not sure whether or not I need to move the <code>toke...
<python><pytorch><huggingface>
2023-04-03 05:22:10
1
6,155
AlanSTACK
75,916,129
11,774,808
Why am I unable to create Boto3 S3 client instance in Airflow 2.5 (task gets stuck without error)? How to debug it?
<p>When I try to create a Boto3 client instance (e.g., <code>s3 = boto3.client('s3')</code>), the Airflow task gets stuck. It doesn't end or get timed out or even throw any error.</p> <p>Questions:</p> <ol> <li>How do I debug this?</li> <li>Which environment variables / files should I ensure exist?</li> </ol> <p>More i...
<python><macos><airflow><boto3>
2023-04-03 04:53:09
1
1,142
m01010011
75,915,991
17,698,538
Mock a library method response using pytest
<p>I am new to pytest, i want to create a test for a method called inside a library. So following is my sample usecase.</p> <p>I have a python library called <strong>core</strong>:</p> <ul> <li>Inside <strong>core</strong> there is a folder called <strong>p_core</strong>.</li> <li>Inside <strong>p_core</strong> there i...
<python><python-3.x><pytest><pytest-mock>
2023-04-03 04:12:58
1
367
randomDev
75,915,813
13,431,295
Upload KML data from Google Earth to django Models
<p>I have a model</p> <pre class="lang-py prettyprint-override"><code>class Area(models.Model): name = models.CharField(max_length = 255) point = postgis.PointField(null = True, blank = True) area = postgis.MultiPolygonField(null = True, blank = True) </code></pre> <p>I have a kml file which consist of diff...
<python><django><kml><geodjango>
2023-04-03 03:18:01
2
965
Shaheem PP
75,915,809
7,421,447
Accuracy value more than 1 with nn.BCEWithLogitsLoss() loss function pytorch in Binary Classifier
<p>I am trying to use <code>nn.BCEWithLogitsLoss()</code> for model which <a href="https://pytorch.org/tutorials/beginner/transfer_learning_tutorial.html" rel="nofollow noreferrer">initially</a> used <code>nn.CrossEntropyLoss()</code>. However, after doing some changes to the training function to accommodate the <code>...
<python><machine-learning><pytorch><loss-function><transfer-learning>
2023-04-03 03:17:04
1
713
Alain Michael Janith Schroter
75,915,644
4,928,920
Call decorator only once in a nested class function
<p>My class has the &quot;public&quot; functions attached with a decorator. In one of the functions, I call another class function that also has the same decorator. But given the decorator was already invoked, I'd like to skip this decorator call. Is there a way to achieve this?</p> <p>Background: I have some virtual &...
<python><python-3.x><python-decorators>
2023-04-03 02:23:28
3
1,228
rookie
75,915,537
13,854,064
Using BeautifulSoup in a BeeWare app gives `ModuleNotFoundError: No module named 'bs4'
<p>I am trying to import <code>beautifulsoup4</code>in a BeeWare app (with its own virtual environment) using the command:</p> <pre><code>from bs4 import BeautifulSoup </code></pre> <p>But I get a <code>ModuleNotFoundError: No module named 'bs4'</code> even though I have installed <code>beautifulsoup4</code> in my virt...
<python><beautifulsoup><python-import><python-venv><beeware>
2023-04-03 01:45:20
1
434
gimi
75,915,513
2,392,151
parquet time stamp overflow with fastparquet/pyarrow
<p>I have a parquet file I am reading from s3 using fastparquet/pandas , the parquet file has a column with date 2022-10-06 00:00:00 , and I see it is wrapping it as 1970-01-20 06:30:14.400, Please see code and error and screen shot of parquet file below .I am not sure why this is happening ? 2022-09-01 00:00:00 se...
<python><pandas><parquet><pyarrow><fastparquet>
2023-04-03 01:36:57
1
363
Bill
75,915,279
9,354,344
How to substract raster1 and raster2 in rasterio
<p>I have tried to subtract the <code>raster1.tif</code> and <code>raster2.tif</code> using rasterio in python. The <code>raster1.tif</code> file is larger and completely overlaps the <code>raster2.tif</code>.</p> <p>I need to subtract <code>raster1.tif - raster2.tif</code> in such a way so that the output raster exten...
<python><rasterio>
2023-04-03 00:14:51
1
2,397
Tek Kshetri
75,915,102
2,247,459
Does Python 'any' function requires evaluating all boolean values?
<p>Consider the following python instruction</p> <pre><code>any([condition(element) for element in some_list]) </code></pre> <p>Is it optimised to stop once <code>condition(element)</code> is <code>True</code>, or <code>any</code> is applied after the whole list of boolean values is built?</p> <p>If case the the whole...
<python><any>
2023-04-02 23:19:56
1
3,984
cyanide
75,915,020
7,327,257
Fill array with multiple arrays and multiple masks
<p>I'm working with classifier's prediction, with a dataframe where I removed NaN values before feeding the algorithm. After the prediction, I want to create a new array where, if there was a valid point in the original dataframe, it will take the prediction, in other case the thing gets complicated: if there was a NaN...
<python><arrays><numpy>
2023-04-02 22:57:11
1
357
M. Merida-Floriano
75,915,006
2,817,520
Updating a WSGI application without rebooting the server
<p>Is is possible to update a WSGI application without the need to reboot the server? I mean you can do that with WordPress. In WordPress you can install plugins, update them or even update the whole WordPress. How? Is it because it is written in PHP?</p>
<python><wsgi>
2023-04-02 22:53:24
1
860
Dante
75,914,894
20,276,285
How to convert a hexstring to shellcode format?
<p>I have a bytes key define as:</p> <blockquote> <p>KEY = b'\xb5\x89\xd5\x03\x03\x96`\x9dq\xa7\x81\xed\xb2gYR'</p> </blockquote> <p>I want this to be formatted like shellcode, i.e two hexa characters like: \x41\x42\x43...</p> <p>So I tried to do it like this:</p> <pre><code>KEY = b'\xb5\x89\xd5\x03\x03\x96`\x9dq\xa7\x...
<python><shellcode>
2023-04-02 22:20:47
1
308
IRP_HANDLER
75,914,807
7,386,830
Loop through each row and build regression model & plot (n-1 row step through)
<p>I have a simple linear regression model below, that has been fit to a 10 row data.</p> <pre><code>import pandas as pd import numpy as np from matplotlib import pyplot as plt # Generate 'random' data np.random.seed(0) X = 2.5 * np.random.randn(10) + 1.5 res = 0.5 * np.random.randn(10) y = 2 + 0.3 * X + res...
<python><pandas><regression><statsmodels>
2023-04-02 21:57:57
2
754
Dinesh
75,914,786
13,960,043
How to ensure a clean exit with a script hosted on the cloud?
<p>I built a web scraper that would scrape multiple websites for data, problem is that the data is very large and takes like 8 hours to scrape(with the use of sleep don't want to bother their servers too much).</p> <p>Well, the cloud service I want to host it on will only run it for 6 hours before killing the script so...
<python><web-scraping><cloud><remote-server>
2023-04-02 21:52:12
1
317
Nandril
75,914,757
272,023
How to integrate Kerberos into FastApi?
<p>Is there an existing way of integrating Kerberos authentication into <a href="https://fastapi.tiangolo.com/" rel="nofollow noreferrer">FastApi</a>?</p> <p>I can see in this <a href="https://stackoverflow.com/questions/64146591/custom-authentication-for-fastapi">SO question</a> details of creating a custom authentica...
<python><fastapi><kerberos>
2023-04-02 21:43:30
1
12,131
John
75,914,570
9,840,684
Creating labels based on partial string matches in Python
<p>I have an index column that's leading 2 or 3 characters indicating a category I'd like to create labels for. Consider the following data:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Index</th> </tr> </thead> <tbody> <tr> <td>NDP2207342</td> </tr> <tr> <td>OC22178098</td> </tr> <tr> <...
<python><pandas><function>
2023-04-02 20:56:15
2
373
JLuu
75,914,464
14,883,879
RuntimeError: The size of tensor a (61) must match the size of tensor b (64) at non-singleton dimension 3
<p>Has anyone a clue what the error here could be? I already looked at other StackOverflow threads or PyTorch forum threads, but I didn't find anything 😕</p> <p>My Dataset is from <a href="https://github.com/skyatmoon/CHoiCe-Dataset" rel="nofollow noreferrer">https://github.com/skyatmoon/CHoiCe-Dataset</a>. For Labels...
<python><tensorflow><deep-learning><pytorch><neural-network>
2023-04-02 20:31:29
1
445
basti394
75,914,405
4,913,254
How to filter values in a column with common values in another common and apply two conditions in the filtering
<p>I have a data frame like this</p> <pre><code>df = pd.DataFrame({'patient': ['patient1', 'patient1', 'patient1','patient2', 'patient2', 'patient3','patient3','patient4'], 'gene':['TYR','TYR','TYR','TYR','TYR','TYR','TYR','TYR'], 'variant': ['buu', 'luu', 'stm','lol', 'bla', 'buu...
<python><pandas>
2023-04-02 20:17:11
3
1,393
Manolo Dominguez Becerra
75,914,306
5,081,918
Unable to set correct Email Template for Mailchimp Campaign via Python API
<p>I'm unable to set correct Email template for Mailchimp Campign.</p> <p>I'm picking the <code>Template_ID</code> from the browser URL like: <a href="https://xxx.admin.mailchimp.com/email/templates/editor?id=%60Template_ID%60" rel="nofollow noreferrer">https://xxx.admin.mailchimp.com/email/templates/editor?id=`Templat...
<python><mailchimp><mailchimp-api-v3.0>
2023-04-02 19:55:28
0
1,054
nishit chittora
75,914,293
1,053,961
Nested async-to-sync generator stops at first iteration when executing each iteration individually with asyncio.run
<p>I’m working on a async library that intends to provide a sync support. For that I use <code>asgiref</code> but for demonstration purpose i’ll run <code>asyncio</code> that has the same issue.</p> <p>I want to wrap an async function that returns an async generator into a decorator that will transform this result into...
<python><python-asyncio>
2023-04-02 19:53:03
1
440
Guibod
75,914,181
8,372,455
pandas creating M-F time series dummies
<p>Is it possible to create a Boolean point one hot style in time series data for when the data frame hour is between 7AM and 5PM Monday through Friday? This errors out below when I add in the additional <code>and df.index.weekday &lt;= 4</code> to the lambda function:</p> <pre><code>hours = pd.get_dummies(df.index.hou...
<python><pandas>
2023-04-02 19:28:04
1
3,564
bbartling
75,914,039
11,021,252
How to calculate the distance between shapely Linestring and Point (3D)
<p>As shown in the figure, I have a 3D shapely Linestring (<code>line</code>) and a Point (<code>point</code>). I am trying to calculate the distance between them using the command <code>line.distance(point)</code>. But I am getting <code>0.0</code> as the output. It is not supposed to be zero, as shown in the figure.<...
<python><gis><geopandas><shapely>
2023-04-02 18:59:57
1
507
VGB
75,913,917
565,200
Tkinter Progress bar without progress
<p>I'm having a problem when plotting a progress bar and using Object oriented. The following code creates a main window with the progress bar and three buttons but also another one. Why does the code create this second window?</p> <p>In addition, the progress bar doesn't show a real progress. The buttons are configure...
<python><python-3.x><user-interface><tkinter>
2023-04-02 18:32:09
1
7,570
Jorge Vega Sánchez
75,913,916
2,272,824
How to create a useful Polars Dataframe from a numpy structured array?
<p>I'm converting an application from Pandas to Polars in search of better scalability and performance. My app reads data from an hdf5 compound dataset (using h5py) into a numpy structured array from which I create the Pandas dataframe directly as follows,</p> <pre><code># dset is the hdf5 compound Dataset np_struct_ar...
<python><dataframe><numpy><hdf5><python-polars>
2023-04-02 18:32:02
1
391
scotsman60
75,913,847
11,611,246
Run and break loop with progress bar in tkinter
<p>I want to create a small GUI in <code>tkinter</code> to download a list of files stored as URLs in a <code>*.csv</code> table.</p> <p>However, I could not find a method to combine a progress bar plus an option to interrupt the process at any time. If I run the download loop within the main thread, it will block anyt...
<python><tkinter><python-multithreading><progress>
2023-04-02 18:20:28
1
1,215
Manuel Popp
75,913,796
2,288,287
What is the correct use of "key" in the min() function?
<p>I have a question about the min() function in Python. I am confused about the use of the &quot;key&quot; option in min(). Could someone explain how key works in min(), especially in relation to a lambda function?</p> <p>For example:</p> <pre><code>lst = [10, -5, 20, 1] min(lst, key=lambda x: x &gt; 0) </code></pre> ...
<python><min>
2023-04-02 18:10:21
1
328
Jose Angel
75,913,733
668,445
python: how close to the recursion limit?
<p>Is there a way I can measure how close I am to python's recursion limit? I know about <code>sys.getrecursionlimit</code> and <code>sys.setrecursionlimit</code>. I'd like to know how close I am to the limit, without actually reaching it: either by measuring the remaining gap, or by measuring how deep I am already and...
<python><recursion>
2023-04-02 18:00:54
0
3,878
Bill Evans at Mariposa
75,913,609
5,640,517
Install mod-wsgi in a poetry virtual environment
<p>I have a django app.</p> <p>I've created a poetry virtual environment to manage dependencies.</p> <p>This app runs on python 3.10.</p> <p>My <code>pyproject.toml</code> looks like this:</p> <pre class="lang-ini prettyprint-override"><code>[tool.poetry] name = &quot;django_manager&quot; version = &quot;0.1.0&quot; de...
<python><django><apache><mod-wsgi>
2023-04-02 17:33:50
1
1,601
Daviid
75,913,504
103,969
How can I reference a specific rect in a Bokeh plot?
<p>I'm working on a plot with ornamentations that draw rectangles over the plot to highlight some sections.</p> <p>I'd like to find a reference for a rect that is plotted on top so that i can move it, unrelated to the data plotted. I can't seem to figure out how to do that. If there were multiple glyphs how would I b...
<python><bokeh>
2023-04-02 17:12:53
1
1,779
shigeta
75,913,334
926,319
Get Rust struct for parent or subclass from an attribute of a PyAny object
<p>I have the following class structure defined in a Rust PyO3 Extension:</p> <pre class="lang-rust prettyprint-override"><code>#[pyclass(subclass)] struct Parent { foo: i32 } #[pyclass(extends=Parent)] struct Child { bar: i32 } </code></pre> <p>Then in Python, a pure python class contains an attribute which c...
<python><rust><pyo3>
2023-04-02 16:43:30
1
2,054
Darren
75,913,320
20,726,966
List all files and folders in a specific subdirectory from Firebase Cloud Storage through Python
<p>I would like to list all the files and folders in a specific directory inside firebase cloud storage. I have tried using <code>files = storage.list_files()</code> from other stack overflow answers. This lists all the files and folders. I have tried using <code>files = storage.list_files(prefix='images/')</code> but ...
<python><firebase><cloud-storage><pyrebase>
2023-04-02 16:39:55
2
318
Homit Dalia
75,913,208
12,129,443
Why Pandas .divide() method adding the divisor as a column with NAN values?
<p>I am trying to divide a Pandas timeseries data frame with another data frame with exact matching datetime index, using pandas' <code>.divide()</code> method. When I do so instead of the expected element wise division, the divisor column is getting as a column the data frame being divided with NAN values. Why is that...
<python><pandas><dataframe>
2023-04-02 16:18:25
1
668
Srinivas