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,600,751
4,847,250
Does LSTM need all steptime shift for parameter identification of a model?
<p>I use LSTM deep learning to identify parameters of a mathematical model which generate a univariate time series. According to the parameters I choose for the model, the time series will change in it's oscillation frequency or shape (type of oscillation).</p> <p>For now, I made a Deep learning LSTM that's taking 1 se...
<python><keras><lstm>
2023-03-01 07:40:10
1
5,207
ymmx
75,600,734
3,751,931
launch.json breaks debugging in VSCode
<p>I wanted to set <code>justMyCode</code> to false for a python project in VSCode. So I created a <code>launch.json</code> file in a <code>.vscode</code> folder under the project root folder with the following content:</p> <pre class="lang-json prettyprint-override"><code>{ &quot;configurations&quot;: [ { ...
<python><visual-studio-code><visual-studio-debugging>
2023-03-01 07:37:39
1
2,391
shamalaia
75,600,684
10,715,700
AssertionError: SparkContext._active_spark_context is not None
<p>I create an object which when running the <code>__init__</code> function creates a map from a dictionary. This is done outside of any function or classes. So it runs when the module gets loaded during imports.</p> <p>It works fine when I run it, but when I run it using SparkStreaming, I get an assertion error shown ...
<python><apache-spark><pyspark>
2023-03-01 07:32:11
2
430
BBloggsbott
75,600,462
2,186,785
Rotating secret key but keeping other database credentials?
<p>I am currently using AWS Lambda for rotating the secret key. I followed the guide on the AWS website which uses the SecretsManagerRotationTemplate. This works well to rotate the current secret key with a new secret key.</p> <p>The problem is that I have also stored the username and database name as credentials. The ...
<python><database><amazon-web-services><aws-lambda><rotation>
2023-03-01 07:02:27
1
1,179
JavaForAndroid
75,600,460
3,745,149
Calculate vertex distances of a mesh
<p>I am using Numpy arrays to express a triangular mesh.</p> <p>I have two matrices: <code>coordinates</code> is a 3 x n matrix, and <code>connectivity</code> is an n x n matrix that uses 0s and 1s to store vertex connectivity.</p> <p>Now I want to calculate a n x n matrix named <code>distances</code> that stores verte...
<python><numpy><mesh>
2023-03-01 07:02:11
2
770
landings
75,600,328
14,445,883
I want to broadcast an pytorcc tensor of dimension (a,b,c) onto an array of dimension (b,c) to get an output of dimension (a,c) how do I do this?
<p>I have two pytorch tensors,</p> <pre><code>A.shape = [416, 20, 3] B.shape = [416,20] </code></pre> <p>I want to produce</p> <pre><code>C = matmul(A,B) C.shape = [416,3] </code></pre> <p>Ie for each of the 416 20x3 arrays in A, find the corresponding 20X1 array in B and compute <code>torch.matmul(A_i,B)</code>. Set...
<python><arrays><numpy><pytorch><array-broadcasting>
2023-03-01 06:44:12
1
783
alois
75,600,322
11,725,056
How to use stopwords and filters properly in Elasticsearch (python client)
<p>I'm learning Elasticsearch using Python client and have managed to build an index and query function.</p> <p><strong>Problem:</strong> Even if I have used <code>stemmer</code> and <code>stop words</code> in the below settings, when I query a text with all the stop words to test the working, it returns some result wh...
<python><elasticsearch><full-text-search><querying>
2023-03-01 06:43:39
0
4,292
Deshwal
75,600,244
8,229,534
How to perform dynamic filtering across multiple columns using st.session_state() or on_change()?
<p>I am trying to create a streamlit app where based on 1 filter selection criteria, I want to populate other filter selections. Then, once the submit button is hit, then I want to proceed ahead with processing the data.</p> <pre><code>import streamline as st import pandas as pd my_df = pd.DataFrame({ 'Name': ['A'...
<python><pandas><streamlit>
2023-03-01 06:31:14
2
1,973
Regressor
75,600,223
562,930
How should I wait for a queue or an event?
<p>In Python, I would like to know how to wait for the first of either <code>queue.get()</code> or <code>event.wait()</code>.</p> <p>At the moment, I am using <a href="https://docs.python.org/3/library/asyncio-task.html#asyncio.wait" rel="nofollow noreferrer"><code>asyncio.wait()</code></a> to achieve this, but this is...
<python><concurrency><python-asyncio>
2023-03-01 06:28:04
1
2,795
Matthew Walker
75,600,219
8,176,763
getting many warnings for particular dags in airflow
<p>I just recently installed airflow and whenever I execute a task, I get warning about different dags:</p> <pre><code>[2023-03-01 06:25:35,691] {taskmixin.py:205} WARNING - Dependency &lt;Task(BashOperator): create_entry_group&gt;, delete_entry_group already registered for DAG: example_complex [2023-03-01 06:25:35,691...
<python><airflow>
2023-03-01 06:27:22
1
2,459
moth
75,599,864
14,477,706
input excel file from UI in fastapi
<p>Hi I'm trying the following for api input</p> <pre><code>def upload_excel_parser(file: UploadFile = File(...)): s_filename = file.filename unique_id = str(uuid4()) project_id = s_filename + unique_id df = pd.read_excel(file) return &quot;success&quot; </code></pre> <p>also tried</p> <pre><code>df = pd.re...
<python><fastapi>
2023-03-01 05:23:37
1
327
devb
75,599,861
17,778,275
Pandas split corresponding rows based on separator in two columns duplicating everything else
<p>I have an excel sheet</p> <pre><code>Col1 Col2 Col3 Col4 John English\nMaths 34\n33 Pass Sam Science 40 Pass Jack English\nHistory\nGeography 89\n07\n98 Pass </code></pre> <p>Need to convert it to</p> <...
<python><pandas><dataframe><split>
2023-03-01 05:23:28
2
354
spd
75,599,831
13,684,789
How to properly replicate a web site's GET request to an API?
<p>I am trying to scrape data from this <a href="https://www.jewelosco.com/shop/search-results.html?q=rice" rel="nofollow noreferrer">page</a>, specifically all the information about the products.</p> <p>Using my browser's Inspect tool, I found that all of the products' data come from a JSON file; it is a response to a...
<python><web-scraping><python-requests><xmlhttprequest>
2023-03-01 05:18:40
1
330
Übermensch
75,599,811
3,821,009
Set value based on previous value in previous group if it exists
<p>Say I have this:</p> <pre><code>df = pandas.DataFrame( [ dict(a=75, b=numpy.nan, d='2023-01-01 00:00') , dict(a=82, b=numpy.nan, d='2023-01-01 10:00') , dict(a=39, b=numpy.nan, d='2023-01-01 20:00') , dict(a=10, b=82 , d='2023-01-05 00:00') , dict(a=90, b=82 , d='2023-01-05 20:00') , dict(a=6...
<python><pandas><dataframe>
2023-03-01 05:12:53
0
4,641
levant pied
75,599,785
7,394,787
how to make variable visibility in block statement in Python?
<p>How to achieve an effect like :</p> <pre><code>#there is no variable named `i` for i in range(1): pass print(i) #why </code></pre> <p>I don't want to make <code>i</code> visitable after the <code>for</code> statement finished.</p> <p>But I don't want to use <code>del i</code> manually.</p>
<python>
2023-03-01 05:08:35
1
305
Z.Lun
75,599,689
9,782,619
python can't import module when running a file, but can import the module in interactive shell
<p>I got a strange problem.</p> <p><code>filegetter</code> is a module developed by someone else and installed with <code>python setup.py install</code>.</p> <p>Here is a test file.</p> <pre><code>#instance.py import filegetter </code></pre> <p>when I run</p> <pre><code>/home/ynx/miniconda3/bin/python /home/ynx/noteboo...
<python>
2023-03-01 04:52:48
2
635
YNX
75,599,667
1,905,276
How to replace a element in a nested List in Python
<p>I can locate any listed content. In the example I locate 'q'. I manually mapped its index as <code>[1][0][1][1]</code>. Then I replaced it with 'z' and it works. My question is what is the magic to get the index(q) or Object Address(q) when the if() condition get set to True?</p> <pre><code> import ctypes l...
<python>
2023-03-01 04:47:30
2
411
Santhosh Kumar
75,599,648
5,091,964
Pyinstaller comes with errors when importing backtesting.py module
<p>I am using Windows 11 for Python code development. I have a large Python program that uses the backteting.py module. The program works fine when running it using Visual Studio Code or executing it in the console. However, when I create an EXE file using the Pyinstaller, the EXE file does not work. I managed to reduc...
<python><python-3.x><pyinstaller><back-testing>
2023-03-01 04:43:10
1
307
Menachem
75,599,626
4,451,521
Path ordering based on particular criteria
<p>I have four files (or any number of files for that matter) named</p> <pre><code>file_V2023.2.2_0.txt file_V2023.2.2_1.txt file_V2023.2.3_0.txt file_V2023.2.3_1.txt </code></pre> <p>If I do</p> <pre><code>from pathlib import Path output_path = Path(&quot;./&quot;) for video_path in sorted(output_path.glob(&quot;*.txt...
<python><glob><pathlib>
2023-03-01 04:38:39
2
10,576
KansaiRobot
75,599,488
5,659,969
How can I prevent cached modules/variables when using runpy in pytest tests?
<p>(Preface: This is a toy example to illustrate an issue that involves much larger scripts that use a ton of modules/libraries that I don't have control over)</p> <p>Given these files:</p> <pre class="lang-py prettyprint-override"><code># bar.py barvar = [] def barfun(): barvar.append(1) # foo.py import bar fo...
<python><unit-testing><testing><pytest><runpy>
2023-03-01 04:07:36
2
479
omasoud
75,599,358
10,215,301
Fail to install FlexGen: ImportError: cannot import name 'define' from 'attr'
<p>I am trying to install <a href="https://github.com/FMInference/FlexGen#install" rel="nofollow noreferrer">FlexGen</a> on Ubuntu running under Windows Subsystem for Linux (WSL; but not WSL2). I have already installed a required PyTorch &gt;= 1.12 and run <code>python3 -m flexgen.flex_opt --model facebook/opt-1.3b</co...
<python><python-3.x><windows-subsystem-for-linux><chatbot>
2023-03-01 03:36:53
1
3,723
Carlos Luis Rivera
75,599,357
2,848,049
paypal rest api and flask/django/python integration 2023, update user credits immediately after payment
<p>In my flask web application, I am trying to update user's credits immediately after user has made payment through paypal. To make it secure, I want to make sure that user doesn't modify the amount of payment. I also want to ensure that I credits to the correct user who made the payment.</p> <p>Because when paypal re...
<python><flask><paypal>
2023-03-01 03:36:15
2
574
wildcolor
75,599,257
2,998,077
Python to add data label on linechart from Matplotlib and Pandas GroupBy
<p>I am hoping to add data labels to a line chart produced by Matplotlib from Pandas GroupBy.</p> <pre><code>import matplotlib.pyplot as plt import pandas as pd from io import StringIO csvfile = StringIO( &quot;&quot;&quot; Name Year - Month Score Mike 2022-09 192 Mike 2022-08 708 Mike 2022-07 140 Mike ...
<python><pandas><matplotlib><plot>
2023-03-01 03:13:12
2
9,496
Mark K
75,599,247
7,267,480
pyswarms toy example - help to understand simple things
<p>trying to understand Particle Swarm Optimization using Python pyswarms package.</p> <p><a href="https://pyswarms.readthedocs.io/en/latest/intro.html" rel="nofollow noreferrer">https://pyswarms.readthedocs.io/en/latest/intro.html</a></p> <p>Need to optimize a function of multiple variables, given as:</p> <pre><code>#...
<python><optimization><particle-swarm>
2023-03-01 03:09:00
1
496
twistfire
75,599,218
20,240,835
Target rules may not contain wildcards. Please specify concrete files or a rule without wildcards error
<p>I have a snakemake srcipt like</p> <pre><code># minimal example configfile: &quot;../snakemake/config.yaml&quot; import os rule generateInclude: input: archaic_inc=config['input']['archaic_include'], modern_inc=config['input']['modern_include'] output: all_include='include_{ref...
<python><bioinformatics><snakemake>
2023-03-01 03:03:36
1
689
zhang
75,599,188
6,335,363
How can I split a for statement over multiple lines with Flake8?
<p>I am currently trying to write a for statement that is over 80 characters long.</p> <pre class="lang-py prettyprint-override"><code>for i, (expected, actual) in enumerate(zip_longest(self.__lines, lines)): ... # Note that the line above is 73 characters long. It becomes 81 # characters long once you put it in a...
<python><flake8>
2023-03-01 02:56:04
1
2,081
Maddy Guthridge
75,599,179
13,258,121
Tkinter dynamic tooltip that moves with the cursor and updates
<p>I would like to implement a <code>tooltip</code> beside the cursor in my <code>tkinter</code> GUI - specifically one that would display the x value of a <code>matplot</code> plot in a <code>tk.Canvas</code> that moves with and updates dynamically as the mouse moves.</p> <p>There are some good examples (<a href="http...
<python><matplotlib><tkinter>
2023-03-01 02:54:20
1
370
Lachlan
75,598,980
4,508,962
How to return a anonymous NamedTuple in python defined only in the return type hint
<p>I come from Typescript, new to Python. When I have 2 things to return from a function and I only use these 2 keys for that function return type and nowhere else in the code, I don't create a complete class but I instead use typescript convinient syntax:</p> <pre><code>fn(): { 'return_key_1': number, 'return_...
<python><typescript><type-hinting>
2023-03-01 02:12:14
1
1,207
Jerem Lachkar
75,598,774
4,451,521
Adding a column to a dataframe based on another dataframe
<p>I have a dataframe like this</p> <pre><code>some_info THIS_info abd set_1 def set_1 www set_1 qqq set_2 wws set_2 2222 set_3 </code></pre> <p>and another dataframe like this</p> <pre><code>THIS_info this_algo set_1 algo_1 set_2 algo_2 set_3 ...
<python><pandas>
2023-03-01 01:16:39
2
10,576
KansaiRobot
75,598,670
5,342,009
Stripe Subscription using stripe.Subscription.create function does not provide client_secret with Django
<p>As suggested <a href="https://stripe.com/docs/billing/subscriptions/build-subscriptions?ui=elements" rel="nofollow noreferrer">here</a> , I am using stripe.Subscription.create function to create a subscription for the users in my Django DRM and expect to have a client secret that is associated with the subscription ...
<python><django><django-models><stripe-payments>
2023-03-01 00:49:34
1
1,312
london_utku
75,598,463
19,299,757
Pytest ordering of test suites
<p>I've a set of test files (.py files) for different UI tests. I want to run these test files using pytest in a specific order. I used the below command</p> <pre><code>python -m pytest -vv -s --capture=tee-sys --html=report.html --self-contained-html ./Tests/test_transTypes.py ./Tests/test_agentBank.py ./Tests/test_ba...
<python><pytest>
2023-03-01 00:06:54
3
433
Ram
75,598,419
4,451,521
Pandas string extract from a dataframe with strings resembling dictionaries
<p>I am looking to use the Pandas string extract feature.</p> <p>I have a dataframe like this:</p> <pre><code>lista=[ &quot;{'FIRST_id': 'awe', 'THIS_id': 'awec_20230222_1626_i0ov0w', 'NOTTHIS_id': 'awep_20230222_1628_p8f5hd52u3oknc24'}&quot;,&quot;{'FIRST_id': 'awe', 'THIS_id': 'awec_20230222_1626_i0ov0w', 'NOTTHIS_id...
<python><pandas>
2023-02-28 23:57:56
1
10,576
KansaiRobot
75,598,344
10,266,106
Properly Fitting a Gamma Cumulative Distribution Function
<p>I have two Numpy arrays (both 210 entries in total) of rainfall values, one observed and the other forecast. My goal is to create a best-fit gamma CDF (my first time diving into gamma CDFs) to both of these arrays and determine the relevant percentile that values then provided would fall into. The image below provid...
<python><numpy><scipy><cdf><gamma-distribution>
2023-02-28 23:40:13
1
431
TornadoEric
75,598,306
12,734,492
Pyspark: How to write table to AWS S3 file
<p>I try to write a simple file to S3 :</p> <pre><code>from pyspark.sql import SparkSession from pyspark import SparkConf import os from dotenv import load_dotenv from pyspark.sql.functions import * # Load environment variables from the .env file load_dotenv() os.environ['PYSPARK_PYTHON'] = sys.executable os.environ[...
<python><apache-spark><amazon-s3><pyspark>
2023-02-28 23:33:36
1
487
Galat
75,598,240
5,452,378
Dynamically index into Python dictionary based on function parameters
<p>I'm building a function that indexes into a Python dictionary nested inside a list. The user knows what the dictionary looks like in advance. This is what it looks like so far:</p> <pre><code>def dict_idx(arr: list, subkey: str) -&gt; list: for i in arr: i[subkey] = i[subkey].replace(&quot;_&quot;, &quot...
<python><dictionary><nested>
2023-02-28 23:20:47
2
409
snark17
75,598,016
12,860,924
How to Calculate ROC, Sensitivity and Specificity using DenseNet121 model
<p>I am working on image classification of breast cancer using DenseNet121. I used <code>confusion_matrix</code> and <code>classification_report</code> and <code>accuracy_score</code> but it didn't calculate the requirement metrics as I want to calculate ROC and sensitivity. I tried in many ways but it didn't work.</p>...
<python><tensorflow><deep-learning><performance-testing><roc>
2023-02-28 22:43:40
0
685
Eda
75,597,960
7,839,887
can you save an object array using zarr?
<p>Following zarr's <a href="https://zarr.readthedocs.io/en/stable/tutorial.html#object-arrays" rel="nofollow noreferrer">tutorial</a>, I'm trying to save a list of list of ints to a persistent zarr:</p> <ul> <li><p><strong>Failed method 1:</strong></p> <pre><code>import numcodecs, zarr zarr.save(&quot;path/to/zarr&quo...
<python><zarr>
2023-02-28 22:34:53
1
786
David Taub
75,597,931
7,631,183
seq2seq inference outputs wrong results despite high accuracy
<p>I am training a seq2seq model following Keras tutorial <a href="https://keras.io/examples/nlp/lstm_seq2seq/" rel="nofollow noreferrer">https://keras.io/examples/nlp/lstm_seq2seq/</a>, the same code but a different dataset. Here is the main model code for reference:</p> <p>Code snippet for data preparation:</p> <pre>...
<python><tensorflow><keras><nlp><seq2seq>
2023-02-28 22:28:30
1
1,207
Wanderer
75,597,909
1,857,373
TypeError: unsupported operand type for 'str', cast variables with nan.inf, nan.NaN, float64 evidence, but 'str' type error
<p><strong>Problem Defined, Data Casting</strong></p> <p>Tying simple cast, conversion to change variable with nan.inf and nan.NaN into a safe numeric .astype(&quot;float64&quot;) to handle integers and real number fractions.</p> <p>TypeError: unsupported operand type(s) for -: 'str' and 'str'</p> <p>Perform read, then...
<python><python-3.x><pandas><dataframe><casting>
2023-02-28 22:25:05
1
449
Data Science Analytics Manager
75,597,851
5,198,162
embedding local html page with streamlit componets
<p>I am building a simple streamlit app with several pages. In one of the pages i want to display an embeded html and I am using iframe html.</p> <pre><code>import streamlit as st import streamlit.components.v1 as components components.iframe(&quot;mypage.html&quot;) </code></pre> <p>I get the following error message ...
<python><streamlit>
2023-02-28 22:18:32
1
369
Atanas Atanasov
75,597,837
1,317,018
No python detected by vscode jupyter notebook
<p>My vscode shows version <code>3.9.13 64bit</code> of python:</p> <p><a href="https://i.sstatic.net/GKEJ6.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/GKEJ6.png" alt="enter image description here" /></a></p> <p>However there are many versions of python installed on my machine (dont know how!)</p> <p...
<python><visual-studio-code><jupyter-notebook><pip><jupyter>
2023-02-28 22:16:53
2
25,281
Mahesha999
75,597,782
11,512,576
How to Interpolate One Segment of One Column in a Pandas Dataframe
<p>I have a dataframe in python as below.</p> <p><a href="https://i.sstatic.net/Hfev0.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Hfev0.png" alt="enter image description here" /></a></p> <p>Say I change the value of second and forth rows as below.</p> <p><a href="https://i.sstatic.net/CQzsy.png" rel=...
<python><pandas><interpolation>
2023-02-28 22:08:23
1
491
Harry
75,597,668
6,296,919
appending new rows to a Pandas groupby result object
<p>I am new to python and I am trying to insert record into group by result object.</p> <p>I have below dataframe where ID 1 &amp; 2 has SECTION_GROUP as GROUP 1 and 3 &amp; 4 has GROUP 2 but 5 doesn't have any SECTION_GROUP.</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th style="text-align...
<python><python-3.x><pandas><dataframe><group-by>
2023-02-28 21:52:32
3
847
tt0206
75,597,639
11,725,460
What is the simplest way for generating all possible connected and non-connected undirected graphs containing N edges using NetworkX?
<p>What is the simplest way for generating all possible connected and non-connected undirected graphs containing N edges using NetworkX?</p> <p>I need to generate all possible connected and non-connected undirected graphs containing 6 edges using NetworkX. So I was hoping to write a function that works for other number...
<python><graph><networkx>
2023-02-28 21:48:45
1
842
avgJoe
75,597,598
9,536,233
How to efficiently remove duplicates from list of lists (nested) containing dictionaries and integers?
<p>I have a list of lists, where each list contains a dictionary and integer. Sometimes duplicate lists occur, and I wish to remove these from the parent list directly. Currently, I am creating a new list and iterating over the old list to ensure only unique values are appended, but I feel this is bad practice. Can thi...
<python><list><dictionary><for-loop><list-comprehension>
2023-02-28 21:43:46
3
799
Rivered
75,597,554
10,500,424
Python NetworkX: Confining force-directed layout within circular boundary
<p>Python NetworkX has a method <code>spring_layout</code> that simulates a force-directed representation of a NetworkX instance; however, this leads to an adjusted network with nodes that are not confined within a particular boundary shape (e.g., a circle). Below is an example of this (notice how the overall graph sha...
<python><python-3.x><graph><networkx><springlayout>
2023-02-28 21:37:51
1
1,856
irahorecka
75,597,545
2,908,017
How can I make a control invisible with code in a Python FMX GUI App?
<p>I made the following GUI in <a href="https://github.com/Embarcadero/DelphiFMX4Python" rel="nofollow noreferrer">DelphiFMX for Python</a> that contains two buttons and a rectangle. I simply want to hide and show the rectangle with the button clicks:</p> <p><a href="https://i.sstatic.net/tjgR4.png" rel="nofollow noref...
<python><user-interface><firemonkey><visibility>
2023-02-28 21:37:03
1
4,263
Shaun Roselt
75,597,538
354,979
Is there a way to determine if cells are out of order in a jupyter notebook? (e.g., using a variable in one cell that is only declared in a later one)
<p>I am hoping to find for example a nbextension that can determine whether jupyter cells would crash if run. I understand this can't be achieved in the general case (halting problem) but I suppose likely culprits, such as out-of-order code, could be found fairly easily. Does such a tool exist?</p>
<python><jupyter-notebook>
2023-02-28 21:36:23
0
7,942
rhombidodecahedron
75,597,519
7,648
Subtracting a constant value from one column when condition on another column holds
<p>I have a Pandas data frame that has the following columns: <em>foo</em> and <em>bar</em>. <em>foo</em> values are integers and <em>bar</em> values are strings. For each row, if the value of <em>bar</em> is some particular value, say, 'ABC', then I want to set the value of the <em>foo</em> column (for that row) to ...
<python><pandas>
2023-02-28 21:33:30
3
7,944
Paul Reiners
75,597,419
2,908,017
How can I create a dropdown combobox from a list in a Python FMX GUI App?
<p>I'm creating a GUI using <a href="https://github.com/Embarcadero/DelphiFMX4Python" rel="nofollow noreferrer">DelphiFMX GUI library for Python</a> that has a <code>ComboBox</code> on it and I also have a list (array) of strings that I want to put into the ComboBox. Here's my current code:</p> <pre><code>from delphifm...
<python><arrays><user-interface><combobox><firemonkey>
2023-02-28 21:20:32
1
4,263
Shaun Roselt
75,597,285
2,908,017
How do I create a date picker in a Python FMX GUI App?
<p>Is there any standard component for selecting a date in the <a href="https://github.com/Embarcadero/DelphiFMX4Python" rel="nofollow noreferrer">DelphiFMX GUI library for Python</a>?</p> <p>I'm looking for some kind of Date Picker component. Currently what I'm doing is making a couple of <code>SpinBox</code> componen...
<python><user-interface><datepicker><firemonkey>
2023-02-28 21:04:30
1
4,263
Shaun Roselt
75,597,228
5,212,614
Trying to merge specific columns, including dynamic last row, from several Excel files, into one dataframe
<p>I am trying to merge data from 14 Excel files into one dataframe and save the dataframe as a CSV file. I am looping through the Excel files, but nothing is being merged into a single dataframe. I think the problem is with the code dynamically finding the last row in each Excel file. All the data I want to merge is i...
<python><python-3.x><excel><dataframe><openpyxl>
2023-02-28 20:58:28
2
20,492
ASH
75,597,182
5,308,851
Variable in generator function shadows name from outer scope
<p>I recently started to teach myself Python and currently work on generator functions. Here, I encountered a &quot;scoping&quot; issue with variable names inside of the generator shadowing names in outer scope. I did some research on this but could not come up with an explanation.</p> <p>Given this minimal example:</p...
<python><scope><generator>
2023-02-28 20:52:04
1
345
Markus Moll
75,597,098
12,983,543
Cannot read local files to docker compose
<p>I am trying to add SSL to my Django app in the backend.</p> <p>On my VPS, I created the certificate files, that are in the path:</p> <pre><code>'/etc/letsencrypt/live/domain.it/fullchain.pem' '/etc/letsencrypt/live/domain.it/privkey.pem' </code></pre> <p>And to let them be read I wrote that in the docker compose fil...
<python><docker><ssl><gunicorn>
2023-02-28 20:42:26
0
614
Matteo Possamai
75,597,030
305,883
Correctly understanding amplitude of waveforms - in librosa or other libraries
<p>I lack a background in acoustics, but need to work on a data-science project in acoustics.</p> <p>Please help me understand how to correctly interpret what amplitude of waveform represent, correctly set the metrics, and possibly set correct sampling rate when doing analysis.</p> <p>Consider this example.</p> <p>I ha...
<python><librosa><waveform><wave><acoustics>
2023-02-28 20:33:59
2
1,739
user305883
75,596,919
15,476,955
Check if an integer from a tuple is between the values of another tuple
<pre><code>def are_values_crossed(tuple_1, tuple_2): if tuple_2[0] &lt;= tuple_1[0] &lt;= tuple_2[1]: return True if tuple_2[0] &lt;= tuple_1[1] &lt;= tuple_2[1]: return True if tuple_1[0] &lt;= tuple_2[0] &lt;= tuple_1[1]: return True if tuple_1[0] &lt;= tuple_2[1] &lt;= tuple_1[1]: return True ret...
<python><logic>
2023-02-28 20:20:31
2
1,168
Utopion
75,596,871
10,976,654
pygount skip folders that start with _X recrusive
<p>I read through the documentation (<a href="https://pypi.org/project/pygount/1.2.0/" rel="nofollow noreferrer">https://pypi.org/project/pygount/1.2.0/</a>), but I am still confused. When running pygount in my root directory, how to I skip all folders that start with &quot;_X&quot; (recursive, so skip any nested folde...
<python>
2023-02-28 20:15:13
1
3,476
a11
75,596,823
19,694,624
Error "AttributeError: 'Service' object has no attribute 'process'" while running on Ubuntu 22.04 VPS
<p>I'm trying to run my selenium script on Ubuntu 22.04. VPS and get the error &quot;AttributeError: 'Service' object has no attribute 'process'&quot;. However, if I run this script on my Ubuntu machine, it works fine as it should. What should I do?</p> <p>Code:</p> <pre><code>from selenium import webdriver from seleni...
<python><ubuntu><selenium-webdriver><selenium-chromedriver><vps>
2023-02-28 20:09:15
1
303
syrok
75,596,693
2,205,916
AWS: Run a Python script to create a file in S3. No output in S3, but works locally
<p>I want to run the following <code>.py</code> script as a job in AWS Glue Studio. This script was just a test to see if I could get something to work. Basically, I want this <code>.py</code> script to run and create a file called <code>myfile.txt</code> in my desired <code>s3</code> directory. I was able to get this ...
<python><amazon-web-services><amazon-s3><aws-glue>
2023-02-28 19:53:21
1
3,476
user2205916
75,596,534
1,219,317
In Pyvis I get UnicodeEncodeError: 'charmap' codec can't encode characters in position 263607-263621: character maps to <undefined>
<p>In pyvis, Why I get this error when I am trying to visualise a simple graph (3 lines of codes only)?</p> <pre><code>net=Network(notebook=True, cdn_resources='in_line') net.from_nx(nx.davis_southern_women_graph()) net.show('example.html') </code></pre> <p>This leads to the error:</p> <pre><code>Traceback (most recent...
<python><unicode><encoding><networkx><pyvis>
2023-02-28 19:36:13
1
2,281
Travelling Salesman
75,596,481
214,526
Python typing forward declaration
<p>I'm trying to write some code with generic types like this:</p> <pre><code>from typing import Sequence, TypeVar, Hashable, Protocol, NoReturn class _SortHashable(Protocol, Hashable): def __lt__(self, other) -&gt; bool: ... def __eq__(self, other) -&gt; bool: ... SortHashableT = TypeVar(&...
<python><python-typing>
2023-02-28 19:28:11
1
911
soumeng78
75,596,475
3,357,935
How do I match a character before or after a capturing group in regex?
<p>I have a Python script with a regex pattern that searches for the word <code>employee_id</code> if there is an equals sign immediately before or after.</p> <pre><code>import re pattern = r&quot;(=employee_id|employee_id=)&quot; print(re.search(pattern, &quot;=employee_id&quot;).group(1)) # =employee_id print(re.s...
<python><regex><python-re><capture-group>
2023-02-28 19:26:54
3
27,724
Stevoisiak
75,596,451
8,068,825
Combine module and list of torch.nn.Parameters in one optimizer
<p>I have the following code:</p> <pre><code>optimizer = torch.optim.Adam([self.model.parameters()] + [self.latent_params_class.latent_params], lr=lr) </code></pre> <p>self.model is a BoTorch SingleTaskGP model (<a href="https://botorch.org/tutorials/fit_model_with_torch_optimizer" rel="nofollow noreferrer">https://bot...
<python><pytorch>
2023-02-28 19:23:45
1
733
Gooby
75,596,428
18,445,352
ModuleNotFoundError while using GitHub codespace editor
<p>Recently I started using GitHub codespace for the first time. I created a new codespace from one of my repositories. Assuming the folder structure as below:</p> <pre><code>my-codespace |--- utils |------ my_script.py |--- config.py </code></pre> <p>I get the following error when I import <code>config.py</code> insid...
<python><visual-studio-code><codespaces><github-codespaces>
2023-02-28 19:20:21
2
346
Babak
75,596,387
9,922,171
Render Icons using Font-Awesome-Kit into Streamlit Application
<p>I'm attempting to add icons using font-awesome-kit into a streamlit application and have tried several different approaches with no success.</p> <p><strong>Attempt 1</strong></p> <p>Tried importing a JS tag for the component</p> <pre><code>st.write('&lt;script src=&quot;https://kit.fontawesome.com/xyz.js&quot; cross...
<python><font-awesome><streamlit>
2023-02-28 19:15:15
1
542
Doracahl
75,596,360
5,084,560
how to avoid high memory consumption of numpy where method
<p>I have a python script which does some calculation on data. data has ~50 million rows. when the execution comes to line which have numpy where method, memory is gone wild. I tried to split dataframe but it doesn't help.</p> <p>code snippet:</p> <pre><code>##Percentage Range data_percnt = data.copy(deep=True) b = [0...
<python><pandas><numpy><machine-learning>
2023-02-28 19:12:03
0
305
Atacan
75,596,273
2,908,017
Getting CheckBox checked state in a Python FMX GUI app
<p>I've created a small app in the <a href="https://github.com/Embarcadero/DelphiFMX4Python" rel="nofollow noreferrer">DelphiFMX GUI library for Python</a> that has a <code>Checkbox</code>, <code>Button</code>, and <code>Label</code> on it:</p> <p><a href="https://i.sstatic.net/Zq0Rc.png" rel="nofollow noreferrer"><img...
<python><user-interface><checkbox><firemonkey>
2023-02-28 19:01:32
1
4,263
Shaun Roselt
75,596,269
974,555
Smallest dtype that will fit all values in an array
<p>How can I find the smallest dtype that will hold all values of an array?</p> <p>For a scalar, I can use <code>np.min_scalar_type</code> to get the smallest dtype that will fit:</p> <pre class="lang-py prettyprint-override"><code>In [32]: min_scalar_type(0) Out[32]: dtype('uint8') In [33]: min_scalar_type(0.1) Out[3...
<python><numpy><types>
2023-02-28 19:01:11
0
26,981
gerrit
75,596,215
9,183,839
Can't test Post request with FastAPI & Pytest
<p>I'm trying to test my <code>/login</code> API with FastAPI's Testclient.</p> <p>But when I pass data to the post api. It shows, <code>422 error</code> with content <code>username</code> and <code>password</code> fields are required.</p> <h3>API:</h3> <pre class="lang-py prettyprint-override"><code> @router.post('/t...
<python><pytest><fastapi><httpx>
2023-02-28 18:56:07
1
439
Fahad Md Kamal
75,596,102
8,845,766
Object of type User is not JSON serialiable
<p>I'm trying to create a sign up method for users. This is what the user model looks like:</p> <pre><code>class User(AbstractBaseUser): name = models.CharField(max_length=128, blank=False) created_at = models.DateTimeField(auto_now_add=True) is_admin = models.BooleanField(blank=True,default=False, verbose_name=&...
<python><django><django-rest-framework>
2023-02-28 18:42:41
2
794
U. Watt
75,596,053
2,211,268
Spacy similarity score for sweet M&M fails
<p>python 3 spacy seems to have a problem with sweets such as M&amp;Ms.</p> <pre><code>import spacy nlp = spacy.load(&quot;en_core_web_lg&quot; ) query = nlp( &quot;M&amp;M&quot; ) query2 = nlp(&quot;M&amp;M chocolate pouch&quot;) print( &quot;Score of M&amp;M versus the full name in shop:&quot;, query2.similarity(qu...
<python><nlp><spacy><similarity>
2023-02-28 18:36:42
1
2,092
Eamonn Kenny
75,596,029
3,510,043
timezone management in polars group_by_dynamic
<p><strong>Update:</strong> This was a bug which has since been fixed. <a href="https://github.com/pola-rs/polars/issues/7274" rel="nofollow noreferrer">https://github.com/pola-rs/polars/issues/7274</a></p> <hr /> <p>I am exploring <code>polars</code> and encountered an unexpected behavior (at least to me) as shown bel...
<python><datetime><timezone><python-polars>
2023-02-28 18:33:37
0
820
Flavien Lambert
75,596,027
1,779,091
How to write a basic if statement to compare 3 variables and return the largest?
<p>I need a basic if statement that looks at 3 variables and returns the largest.</p> <pre><code>a=10 b=20 c=30 if a&gt;=b and a&gt;=c: return a elif b&gt;=a and b&gt;=c: return b elif c&gt;=a and c&gt;=b: return c </code></pre> <ol> <li>Is this correct way to write this simple logic using IF statements? For exa...
<python>
2023-02-28 18:33:29
5
9,866
variable
75,596,024
11,922,765
Python Raspberry Pi 4: How to install erlang?
<p>There was a similar <a href="https://stackoverflow.com/questions/22828509/how-to-install-erlang">question almost a decade ago</a> and I don't think the solution applies to me. I am trying to install a new software, and it needs <code>erlang</code> software as a support package.</p> <p>Step1: I downloaded the package...
<python><raspberry-pi><erlang><raspberry-pi4><erlang-otp>
2023-02-28 18:33:07
1
4,702
Mainland
75,595,957
6,077,239
How to flatten/split a tuple of arrays and calculate column means in Polars dataframe?
<p>I have a dataframe as follows:</p> <pre><code>df = pl.DataFrame( {&quot;a&quot;: [([1, 2, 3], [2, 3, 4], [6, 7, 8]), ([1, 2, 3], [3, 4, 5], [5, 7, 9])]} ) </code></pre> <p>Basically, each cell of <code>a</code> is a tuple of three arrays of the same length. I want to fully split them to separate columns (one sca...
<python><python-polars>
2023-02-28 18:26:35
3
1,153
lebesgue
75,595,939
12,302,691
How to print dictionary with array value without any brackets or quotes?
<p>I have a dictionary that has <em>character</em> keys and <em>list</em> values.</p> <pre class="lang-py prettyprint-override"><code>my_dict = { 'A': [1, 1, 0, 0], 'B': [0, 0, 1, 1], 'C': [1, 1, 1, 0], 'D': [1, 0, 0, 0] } </code></pre> <p>When I simply print it using <code>print(my_dict)</code>, I g...
<python>
2023-02-28 18:24:51
1
429
Anushka Chauhan
75,595,854
9,743,695
create tuple from ranges in python
<p>Is there a way in python to create a tuple of months and years (as: <code>[(2020, 1),(2020,2)...]</code> ) by using the <code>tuple()</code> function?</p> <p>My code:</p> <pre><code>monthyears = [] for y in range(2020,2017,-1): if y == 2018: m_end = 6 else: m_end = 0 for m in range(12,m_e...
<python><tuples><range>
2023-02-28 18:15:55
3
332
bearcub
75,595,748
5,431,132
Logic inside Django serializer
<p>I have a Django serializer implementation that has a field which contains a list as part of a JWT authentication process. For example:</p> <pre><code>class MySerializer(serializers.ModelSerializer): class Meta: field = ['a', 'b', 'c'] </code></pre> <p>I then have some logic in my user model</p> <pre><cod...
<python><django><serialization>
2023-02-28 18:04:26
1
582
AngusTheMan
75,595,635
14,471,688
Remove strings that contain another existing string in a list of strings
<p>I want to remove the strings that contain another existing string in a list of strings. Suppose that I have a list as below:</p> <pre><code>ex_list = ['transport truck', 'truck', 'plastic boat', 'boat', 'transport', 'ferry', 'truck parking', 'pickup truck', 'pickup'] </code></pre> <p>I want to remove some specific s...
<python><list><substring>
2023-02-28 17:51:16
5
381
Erwin
75,595,538
3,493,829
How to stop websocket.WebSocketApp logs being generated
<p>I am using the <code>websocket.WebSocketApp</code> to send and receive messages on <code>websocket</code>. I am able to run the application and can send and receive messages.</p> <p>but wherever I received or send any message many logs are getting generated as shown below.</p> <pre><code>++Sent raw: b'\x82\xfe\x05X\...
<python><python-3.x><websocket>
2023-02-28 17:40:11
1
3,806
SSK
75,595,427
1,295,678
How can I properly type a subclass of class which sub-types a Generic base class?
<p>I have two classes inheriting from <code>dict</code>, like this:</p> <pre><code>class A(dict): class B(A): </code></pre> <p>This all works fine - the two classes use the inherited <code>dict</code> functionality and do other required stuff. However, I also want to use type-hinting. The first should reduce the ran...
<python><type-hinting><mypy>
2023-02-28 17:30:02
1
3,577
strubbly
75,595,323
6,165,671
Stanza based auto-py-to-exe GUI app throws exception (Windows 10)
<p>I am building a Window based .exe for a python script using auto-py-to-exe. It uses Stanza. I am able to build and run the Console based version of the app (the GUI + Console). But the GUI only .exe (Console hidden) based on same auto-py-to-exe settings (except the GUI option) does not even load for the first time (...
<python><pyinstaller><stanford-nlp>
2023-02-28 17:20:01
2
355
Shakir
75,595,167
18,758,062
Get all processes in simpy Environment
<p>If I have a <code>simpy.Process</code> that creates nested processes, is there a way to get a list of all the active/alive processes from it's <code>simpy.Environment</code>?</p> <p>Basically I've created a tree of simpy processes and at some point I want to interrupt all of the active processes. Having every proces...
<python><simpy>
2023-02-28 17:03:48
3
1,623
gameveloster
75,595,083
11,826,017
How to fix "ValueError: This tokenizer cannot be instantiated. Please make sure you have `sentencepiece` installed in order to use this tokenizer."
<p>I'm trying to run a Hugging Face model using the following code in Google Colab:</p> <pre><code>!pip install transformers from transformers import AutoTokenizer tokenizer = AutoTokenizer.from_pretrained(&quot;Helsinki-NLP/opus-mt-en-es&quot;) inputs = tokenizer(text, return_tensors=&quot;pt&quot;).input_ids </code...
<python><google-colaboratory><huggingface-transformers><valueerror>
2023-02-28 16:55:24
2
779
arnle
75,595,068
10,490,683
Standardising pydantic models for similar APIs
<p>I'm consuming a set of similar APIs, that all return a broadly standard structures.</p> <p>The code below sets up the pydantic model for <code>Api1</code></p> <p>I now need to do the model for <code>Api2</code>. The structure is the same but only the field names are different. Is it possible to create reusable code ...
<python><pydantic>
2023-02-28 16:54:18
1
8,894
Belly Buster
75,595,027
10,714,156
PyTorch: Dataloader creates a new dimension when creating batches
<p>I am seeing that when looping over the my <code>Dataloader()</code> obect using <code>enumerate()</code> I am getting a new dimension that is being coerced in order to create the batches of my data.</p> <p>I have 4 Tensors that I am slicing at a macro level (I am panel data so I slice the data in blocks of individua...
<python><pandas><pytorch><dataloader>
2023-02-28 16:50:27
1
1,966
Álvaro A. Gutiérrez-Vargas
75,594,987
800,053
How can super() instantiate a class inside it's own __new__ method?
<p>I recently had a use case for a singleton class and ended up using this definition:</p> <pre><code>class SubClient(BaseClient): def __new__(cls): if not hasattr(cls, 'instance'): cls.instance = super(SubClient, cls).__new__(cls) return cls.instance </code></pre> <p>After testing that...
<python><python-3.x>
2023-02-28 16:47:11
1
9,597
jhnclvr
75,594,828
4,865,723
Read SSH stdout via Paramiko behave different between REPL and script
<p>When I'm in the Python shell (REPL?) I'm able to create a connection read from stdout of the SSH server. But when I run the same code as a script (via <code>python3 -i script.py</code>) it is not working.</p> <p>On the server side is a text-based MUD running. After loggin in via SSH it is asking for a MUD based logi...
<python><paramiko>
2023-02-28 16:33:15
1
12,450
buhtz
75,594,692
6,761,328
How to deal with micro- or nanoseconds in datetime64?
<p>I imported <code>.xls</code> files which appear now as</p> <pre><code>0 2022-09-27 11:56:22.733740 1 2022-09-27 11:56:22.733940 2 2022-09-27 11:56:22.734140 3 2022-09-27 11:56:22.734340 4 2022-09-27 11:56:22.734540 4995 2022-09-27 11:56:23.732740 4996 2022-09-27 11:56:23.7329...
<python><datetime>
2023-02-28 16:20:40
1
1,562
Ben
75,594,687
16,813,096
How to apply transparent background in tkinter window of linux (not alpha)?
<p>I want to make some portion of a tkinter window transparent. I have successfully achieved it in windows and mac os using the following methods:</p> <p><strong>In windows:</strong></p> <pre class="lang-py prettyprint-override"><code>root.attributes(&quot;-transparentcolor&quot;, '#000001') root.config(bg=&quot;#00000...
<python><python-3.x><tkinter><tkinter-canvas><tkinter-layout>
2023-02-28 16:20:03
0
582
Akascape
75,594,594
7,575,552
Saving feature attributes to a CSV file using Python
<p>I am using the pyfeats library to extract radiomic features using the images and their respective ROI masks. I am extracting the shape features and GLRLM features. The shape features are extracted using shape_parameters function, which provides SHAPE_XcoordMax, SHAPE_YcoordMax, SHAPE_area, SHAPE_perimeter, and SHAPE...
<python><image><opencv><image-processing>
2023-02-28 16:11:14
1
1,189
shiva
75,594,556
1,307,905
Trying to deepdiff throws an error on datetime
<p>I am trying to compare two very similar data structures using <code>deepdiff</code>. The data is loaded from two msgpack files and consists of dicts and lists containing floats, integers, strings, datetime.datetime and datetime.date instances (I have some special routines to pack/unpack datetime.date instances in ms...
<python><python-deepdiff>
2023-02-28 16:08:15
1
78,248
Anthon
75,594,351
226,473
Scrapy does not find module 'attrs'
<p>I'm trying to scrape a website. I'm using scrapy with the following commands:</p> <p><code>pip install scrapy</code></p> <p><code>scrapy startproject test &amp;&amp; cd test</code></p> <p><code>scrapy genspider test_spider www.webdomain.com</code></p> <p><code>scrapy crawl test_spider</code></p> <p>this results in</...
<python><scrapy>
2023-02-28 15:51:47
1
21,308
Ramy
75,594,317
1,942,868
How to open and edit the pdf file uploaded by form
<p>I have <code>ModelViewSet</code> class which accepts the uploaded file. using pymupdf( pdf handling library)</p> <pre><code>import fitz class DrawingViewSet(viewsets.ModelViewSet): queryset = m.Drawing.objects.all() serializer_class = s.DrawingSerializer def list(self, request): serializer = s.D...
<python><django>
2023-02-28 15:48:40
0
12,599
whitebear
75,594,288
1,501,260
Absolute imports of common code with multiple entrypoints in subdirectories
<p><strong>Given</strong></p> <p>Let's say I have a code repository &quot;my_tools&quot; with some common code and some scripts (here e.g. fooscript) residing in subdirectories.</p> <p><em>utils.py</em></p> <pre><code>def my_util(): print(&quot;baz&quot;) </code></pre> <p><em>fooscript.py</em></p> <pre><code>import...
<python><aws-lambda><python-import>
2023-02-28 15:46:04
0
5,735
Michel Müller
75,594,234
9,274,940
pandas resample with global minimum and maximum specifying the filling method
<p>I want to resample a dataset, the minimum date of each series should be the same for each series, therefore, the minimum date of each series should be the minimum value for the <em>date</em> column. Same for the maximum date (Instead of resampling at series level, I want to resample taking the global maximum value)....
<python><pandas><resampling>
2023-02-28 15:41:23
1
551
Tonino Fernandez
75,594,229
11,010,254
Only the top part of div is clickable - why?
<p>I am making a website in Streamlit. With HTML and CSS, I’m trying to put a clickable logo on the top left corner, and text dead center on the same line, regardless of the logo placement. I have managed to make the logo clickable when it is not located on the same line of the logo with base64 encoding. However, when ...
<python><html><css><streamlit>
2023-02-28 15:40:42
1
428
Vladimir Vilimaitis
75,594,202
7,613,669
Fastest way to loop over Polars DataFrame columns to apply transformations?
<p>Is there a preferred way to loop and apply functions to Polars columns?</p> <p>Here is a pandas example of what I am trying to do:</p> <pre class="lang-py prettyprint-override"><code>import polars as pl df1 = pl.DataFrame( { &quot;A&quot;: np.random.rand(10), &quot;B&quot;: np.random.rand(10), ...
<python><dataframe><python-polars>
2023-02-28 15:38:28
1
348
Sharma
75,594,166
5,195,209
Why would a POST request using curl work, but not when using Python's requests library
<p>I can send a curl request to upload a release asset file on Github and it works fine:</p> <pre class="lang-bash prettyprint-override"><code>$ curl -v -X POST -H &quot;Accept: application/vnd.github+json&quot; -H &quot;Authorization: Bearer &lt;token&gt;&quot; -H &quot;X-GitHub-Api-Version: 2022-11-28&quot; -H &quot;...
<python><http><github><curl><post>
2023-02-28 15:34:55
0
587
Pux
75,594,111
14,729,820
How to convert txt file to jsoinl lines file for Hungarian char.?
<p>I have <strong><code>txt</code></strong> file that contians two columns (<code>filename</code> and <code>text</code>) the spreater during generating txt file is tab <code> </code> example of input file below :</p> <p><code>text.txt</code></p> <pre><code>23.jpg még 24.jpg több </code></pre> <p>the expacted <...
<python><pandas><dataframe><nlp><jsonlines>
2023-02-28 15:31:02
2
366
Mohammed