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,288,965
10,859,114
How to get unlimited multiple options from typer.Option with custom devider
<p>I want to divide unlimited values with a custom divider in <code>typer.Option</code>. below is an example of what I need:</p> <pre class="lang-bash prettyprint-override"><code>$ python main.py add -C &quot;first one&quot;,&quot;second one&quot;,&quot;third&quot; </code></pre> <p>and output should be:</p> <pre class=...
<python><command-line-interface><typer>
2023-01-30 19:01:30
1
470
Alirezaarabi
75,288,946
6,027,879
python iterate yaml with lookup
<p>I have this sample yaml,</p> <pre><code>data: - name: data1 sourceType: aws sourceSpecifier: acme/data123.zip - name: data2 sourceType: aws sourceSpecifier: acme/data234.zip - name: data3 sourceType: webdav sourceSpecifier: acme/data334.zip sources: - type: aws baseUrl: example.s3...
<python><yaml>
2023-01-30 18:59:13
1
406
hare krshn
75,288,863
10,796,158
What is the default behavior of index_col in Pandas' read_csv?
<p>In the pandas <a href="https://pandas.pydata.org/docs/user_guide/io.html#column-and-index-locations-and-names" rel="nofollow noreferrer">docs</a>, for the function <code>read_csv</code>, I'm trying to understand what the following explanation about the behavior of the function is when <code>index_col</code> is set t...
<python><pandas>
2023-01-30 18:51:06
1
1,682
An Ignorant Wanderer
75,288,775
683,233
How to solve this Error while installing libraries in Python?
<p>While executing this code <code>pip install simpletransformers datasets tqdm pandas</code></p> <p>I'm getting errors. I'm attaching the logs.</p> <pre><code>Collecting simpletransformers Using cached simpletransformers-0.63.9-py3-none-any.whl (250 kB) Collecting datasets Using cached datasets-2.9.0-py3-none-any....
<python><windows><jupyter-notebook>
2023-01-30 18:42:13
2
17,588
Sourav
75,288,528
1,715,579
Specify DC cover with espresso_exprs
<p>I'm just getting started learning pyeda, and fairly new to python in general. I have a very complex partially-defined Boolean expression (80~140 variables, 10K terms) that's too big to express as a truth table, but I can express it pretty easily as two DNF's (1 DNF that describes defined ON and OFF sets, and 1 DNF t...
<python><boolean-logic><minimization><truthtable><pyeda>
2023-01-30 18:16:07
0
149,556
p.s.w.g
75,288,451
15,500,727
Change column value with arithmetic sequences using df.loc in pandas
<p>Suppose I have the following dataframe :</p> <pre><code>data = {&quot;age&quot;:[2,3,2,5,9,12,20,43,55,60],'alpha' : [0,0,0,0,0,0,0,0,0,0]} df = pd.DataFrame(data) </code></pre> <p>I want to change value of column <code>alpha</code> based on column <code>age</code> using <code>df.loc</code> and an arithmetic sequenc...
<python><pandas>
2023-01-30 18:09:27
3
485
mehmo
75,288,401
14,353,779
Split a string column based on a logic into two new columns in pandas
<p>I have a dataframe <code>df</code> :-</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Type</th> </tr> </thead> <tbody> <tr> <td>9F,5F/6F,3T,1T</td> </tr> <tr> <td>18F/19F,2F,9T,4T</td> </tr> <tr> <td>17F/12F</td> </tr> <tr> <td>3T</td> </tr> <tr> <td>3T,2F/3F</td> </tr> <tr> <td>No Types...
<python><pandas>
2023-01-30 18:04:00
1
789
Scope
75,288,377
9,262,339
Celery: 'function' object has no attribute 'apply_async'
<p>I get an error <code>'function' object has no attribute 'apply_async'</code> when trying to run a celery task</p> <p><strong>db_sinc.py</strong></p> <pre><code>def create_or_update_google_creative(): ...logic </code></pre> <p><strong>tasks.py</strong></p> <pre><code>@shared_task def run_create_or_update_google_c...
<python><celery>
2023-01-30 18:01:38
1
3,322
Jekson
75,288,354
9,983,652
how to slice a string dynamically?
<p>I'd like keep the first few characters of a string using a[:-3] etc. But I'd like to keep this -3 as a variable, so it could be a[:-1] so I will use a variable to dynamically slice the string using a[:-b], However, to use this format, how to keep all the characters like using a[:]? I don't want to use a[:len(a)] be...
<python>
2023-01-30 17:59:25
2
4,338
roudan
75,288,232
14,640,064
How to detect horizontal line (stagnation) in data?
<p>How can I detect horizontal lines in my data in python?</p> <p>I have used function <code>scipy.signal.find_peaks()</code> to find local minima and maxima. I can use that to separate ascending and descending parts. But I need to isolate the peaks from the flat line (marked with red circes in image).</p> <p>What meth...
<python><math><scipy><data-science>
2023-01-30 17:48:12
1
705
herdek550
75,287,824
5,539,674
Split concatenated functions keeping the delimiters
<p>I am trying to split strings containing python functions, so that the resulting output keeps separate functions as list elements.<br /> <code>s='hello()there()'</code> should be split into <code>['hello()', 'there()']</code><br /> To do so I use a regex lookahead to split on the closing parenthesis, but not at the e...
<python><regex><string><split><python-re>
2023-01-30 17:10:18
2
315
O René
75,287,819
3,755,861
'list' object has no attribute 'add_subplot' in matplotlib
<p>I have followed the suggestions from another threat, but this code still gives me the list object has no no attribute error - what is the correction?</p> <pre><code>import numpy as np import seaborn as sns import matplotlib.pyplot as plt #create data x = np.array([4.1,7.1,5.2,7.1,0.3, 8.3, 9.7, 8.2]) y = np.array...
<python><matplotlib>
2023-01-30 17:10:00
1
452
Pugl
75,287,817
8,012,206
Psycopg2 - Error during insert due to double quotes
<p>I am using Python + Psycopg2 to insert an array of texts. <code>elems</code> column is of type <code>text[]</code>.</p> <pre><code>a = [&quot;A ''B'' C&quot;] cursor.execute(f&quot;&quot;&quot;\ INSERT INTO table(elems) \ VALUES (ARRAY{a}::text[]) \ &quot;&quot;&quot;) </code></pre> <p>Error:</p> <pre><code>col...
<python><postgresql><psycopg2>
2023-01-30 17:09:52
1
12,242
Joseph D.
75,287,773
9,720,696
Getting binary labels on from a dataframe and a list of labels
<p>Suppose I have the following list of labels,</p> <pre><code>labs = ['G1','G2','G3','G4','G5','G6','G7'] </code></pre> <p>and also suppose that I have the following df:</p> <pre><code> group entity_label 0 0 G1 1 0 G2 3 1 G5 4 1 G1 5 2 G1 6 ...
<python><pandas>
2023-01-30 17:06:31
1
1,098
Wiliam
75,287,621
9,074,190
TensorFlow random forest get label as prediction output
<p>I'm using TensorFlow decision forest to predict the suitable crop based on few parameters. How do i get the predict() method to return the label ?</p> <p>Im using <a href="https://www.kaggle.com/datasets/atharvaingle/crop-recommendation-dataset" rel="nofollow noreferrer">this</a> dataset for training</p> <p>My code<...
<python><tensorflow><tensorflow-decision-forests>
2023-01-30 16:54:10
1
1,745
Nishuthan S
75,287,501
5,695,336
Seems like a bug in Pylance type checking
<p>I got this weird error that <code>list[dict[str, str | int]]</code> cannot be assigned to <code>Sequence[dict[str, str | float | int] | None]</code>.</p> <pre><code>Argument of type &quot;list[dict[str, str | int]]&quot; cannot be assigned to parameter &quot;params&quot; of type &quot;Sequence[dict[str, str | float ...
<python><python-typing><pyright>
2023-01-30 16:43:24
1
2,017
Jeffrey Chen
75,287,357
11,197,301
python apply a function with two arguments to alla element of a matrix
<p>let's say that I have the following function</p> <pre><code>def my_func(a,b): res = a[0] + a[1]*b return res </code></pre> <p>I know how to apply it to one element of a matrix:</p> <pre><code>import numpy as np mydata = np.matrix([[1, 2], [3, 4]]) my_par = np.array([1, 2]) res = my_func(my_par,myd...
<python><numpy><function><matrix><vectorization>
2023-01-30 16:33:47
2
623
diedro
75,287,178
10,967,961
Comparison of two long lists for every combination
<p>I have two lists of 170000 elements each say list1 and list2 containing strings. The elements of the 2 are the same. I would like to confront the elements of list1 with all the elements of list2 and get a score of their similarity.</p> <p>What I am trying to do at the moment is:</p> <pre><code>%%time from fuzzywuzzy...
<python><string><list><similarity>
2023-01-30 16:18:01
0
653
Lusian
75,287,112
6,494,707
How to have an ordered list of files with digits?
<p>I have a folder of files and want to read the files one by one because it is frames of a video.</p> <p>However, when I am trying to have an ordered list of files, it is ordered as follows:</p> <pre><code>data_dir = './data/' filenames =listdir(data_dir) N=len(filenames) filenames.sort() filenames ['Image1.jpg', ...
<python><glob><listdir>
2023-01-30 16:11:18
2
2,236
S.EB
75,287,066
1,818,120
splprep and splrep returning different results for the same data in scipy
<p>I am trying to fit a spline through some data point and I am getting a different spline if I use <code>splprep</code> or <code>splrep</code> with the same conditions and data. <code>splrep</code> results are much easier to use, but <code>splprep</code> return the result I think is better for my data. I can't tell wh...
<python><scipy><spline>
2023-01-30 16:07:26
1
2,027
Yoav Schwartz
75,287,041
10,671,274
How to optimally set active/inactive flag based on a date and store id in a dataframe?
<p>I have a dataframe with the following structure (showing the relevant columns):</p> <pre><code>store_price_date: date store_id: string </code></pre> <p>For every store, I have to set <code>isActive</code> column to a value of <code>X</code> if the store was open. For example, I have a start and end date (e.g. 2022-0...
<python><pyspark>
2023-01-30 16:06:13
1
601
ms12
75,286,846
7,342,782
uwsgi only sending stdout logs to GCP in Kubernetes Engine
<p>I have a django application for which I want to send logs to GCP.</p> <p>Locally, everything works fine using django dev server and Cloud Logging for Python. I see the logs on my GCP dashboard with the right level, I can also see the json structured logs when I use them. It also works well when I'm using gunicorn in...
<python><django><google-cloud-platform><logging><uwsgi>
2023-01-30 15:50:03
0
476
RogerFromSpace
75,286,784
4,909,923
How do I gracefully close (terminate) Gradio from within gradio.Blocks()?
<p>I am new to using Gradio. I am attempting to modify Google Colaboratory Notebook (i.e. a Jupyter Notebook) for my own purposes.</p> <p>I would like to terminate Gradio from within a <code>gradio.Column()</code> that performs my function <code>myfunc()</code>, once the function has been executed.</p> <p>How can I end...
<python><jupyter-notebook><google-colaboratory><gradio>
2023-01-30 15:45:20
3
5,942
P A N
75,286,641
11,770,286
Add x-axis including tickmarks at 0 with matplotlib
<p>I have a chart with data going below and above 0, and I want to have my x-axis with tick marks at y==0, while tick labels are still below the chart. Note that using <code>axhline</code> is not sufficient as I need tick marks. Also, there are workarounds on SO that use <code>spines</code> to put the top spine at 0, w...
<python><matplotlib>
2023-01-30 15:35:05
1
3,271
Wouter
75,286,549
4,753,897
TypeError: col should be Column with apache spark
<p>I have this method where I am gathering positive values</p> <pre><code>def pos_values(df, metrics): num_pos_values = df.where(df.ttu &gt; 1).count() df.withColumn(&quot;loader_ttu_pos_value&quot;, num_pos_values) df.write.json(metrics) </code></pre> <p>However I get <code>TypeError: col should be Colum...
<python><python-3.x><apache-spark><pyspark>
2023-01-30 15:29:01
1
12,145
Mike3355
75,286,526
4,872,291
Getting 'RuntimeError: Working outside of application context.' when trying to import function from another Blueprint
<p><em><strong>Initial Notes:</strong> The project uses Blueprints and below are the file structure and extracts of the code used...</em></p> <h2><strong>File Structure:</strong></h2> <pre><code>/app ├── flaskapp/ │ ├── posts/ │ │ ├── __init__.py │ │ ├── forms.py │ │ ├── routes.py │ │ ├── utils.py │ ...
<python><python-3.x><function><flask><flask-sqlalchemy>
2023-01-30 15:27:36
2
378
Eric
75,286,299
498,504
detectAllFaces() method can not recognize any faces in face-api.js
<p>I'm using <a href="https://github.com/justadudewhohacks/face-api.js" rel="nofollow noreferrer">face-api.js</a> Javascript API to develop a web app that user uploads her/his picture and we want to detect faces in the picture.</p> <p>this is my HTML codes:</p> <pre><code>&lt;input type=&quot;file&quot; id=&quot;user_p...
<javascript><python><keras><face-detection><face-api>
2023-01-30 15:09:15
1
6,614
Ahmad Badpey
75,286,292
2,163,392
Get maximum of spectrum from audio file with python (audacity-like)
<p>I am brand new to Digital Signal Processing and I am trying to find the peak of an audio file spectrum, I usually open an audio file with Audacity and plot the spectrum.</p> <p><a href="https://i.sstatic.net/bCz4m.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/bCz4m.png" alt="enter image description ...
<python><plot><audio><signal-processing><fft>
2023-01-30 15:08:38
2
2,799
mad
75,286,009
2,129,263
python hard-coded multi-char delimiter vs passed multi-char delimiter
<p>I have a python script which is using csv DictReader to read a csv with unicode delimiter '\x1f'.</p> <p>I am running the script by calling a bash shell script which is passing the delimiter as follows:</p> <pre><code>python python_script.py '\x1f' import.csv </code></pre> <p>however, I am getting following error: <...
<python><csv>
2023-01-30 14:45:40
1
499
Zeeshan Arif
75,285,909
7,739,375
How to get a C object and pass it in argument of a function in cython
<p>I am trying to use a C library &quot;myClib&quot; from python.</p> <p>This library has a function &quot;myCfunction&quot; that return a pointer struct &quot;myCStruct&quot; and then had other functions that take a pointer of this struct in argument.</p> <p>I don't have the definition of this struct I only get this i...
<python><c><cython>
2023-01-30 14:36:59
1
630
bloub
75,285,772
244,297
Using bisect functions with a key
<p>While using <a href="https://docs.python.org/3/library/bisect.html#bisect.bisect_left" rel="nofollow noreferrer"><code>bisect_left</code></a> with a <code>key</code> parameter I've noticed that the key function is not applied to the searched value. For example, I want to find the first range in a sorted list of rang...
<python><binary-search><key-function>
2023-01-30 14:24:29
2
151,764
Eugene Yarmash
75,285,751
7,714,681
What is the most time efficient way to calculate the distance between tuples in a list?
<p>I have a list with tuples:</p> <p><code>tuple_list = [(1,3),(4,7),(8,1),(5,4),(9,3),(7,2),(2,7),(3,1),(8,9),(5,2)]</code></p> <p>From this list, I want to return the minimum distance of two numbers in a tuple.</p> <p>In the naive approach, I would do the following:</p> <pre><code>distance = 10 for tup in tuple_list:...
<python><list><loops><distance>
2023-01-30 14:22:19
2
1,752
Emil
75,285,712
4,478,466
How to add additional arguments to existing decorator with custom decorator
<p>I know my question sounds a bit silly, but there is an existing decorator from a library that can either take a kwarg or not. I would like to pass this parameter in when a certain condition is achieved. So my initial thought was to write a decorator which will wrap up this function. But I have no idea if this is pos...
<python><python-decorators>
2023-01-30 14:18:32
1
658
Denis Vitez
75,285,711
13,962,514
Difference between collections.abc.Sequence and typing.Sequence
<p>I was reading an article and about collection.abc and typing class in the python standard library and discover both classes have the same features.</p> <p>I tried both options using the code below and got the same results</p> <pre><code>from collections.abc import Sequence def average(sequence: Sequence): retur...
<python><python-typing><generic-collections>
2023-01-30 14:18:27
2
311
Oluwasube
75,285,604
12,845,199
Optimization of map, in grouped by object
<p>I have the following dataframe</p> <pre><code>test_df = pd.DataFrame({'Category': {0: 'product-availability address-confirmation input', 1: 'registration register-data-confirmation options', 2: 'onboarding return-start input', 3: 'registration register-data-confirmation input', 4: 'decision-tree first-intera...
<python><pandas>
2023-01-30 14:08:45
2
1,628
INGl0R1AM0R1
75,285,427
1,848,244
Custom Aggregation Across Parallel Hierarchy Levels in a Multi-Index
<p>I have a dataframe that is organised hierarchically. Consider this:</p> <pre><code> baseval indexlevel0 indexlevel1 indexlevel2 L0-0 L1-0 L2-0 1 L2-1 1 L2-2 20 ...
<python><pandas><multi-index>
2023-01-30 13:56:16
2
437
user1848244
75,285,362
6,748,145
How does Python know to use the same object in memory?
<p>If I use the below:</p> <pre><code>a = 1000 print(id(a)) myList = [a,2000,3000,4000] print(id(myList[0])) # prints the same IDs </code></pre> <p>I get the same id. This makes sense to me. I can understand how the memory manager could assign the same object to these variables, because I am directly referencing <cod...
<python><memory-management><cpython>
2023-01-30 13:51:04
1
2,270
SuperHanz98
75,285,357
14,808,637
Graph Edges intialization between nodes using numpy?
<p>Let's say I have to initialise the bi-directional edges for the following graph between the nodes:</p> <p><a href="https://i.sstatic.net/J59zH.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/J59zH.png" alt="enter image description here" /></a></p> <p>I can easily do this using the following code:</p> ...
<python><numpy><graph><edges>
2023-01-30 13:50:18
1
774
Ahmad
75,285,242
911,971
Strange pylint errors
<p>I want to add linter to my github repository, and during tests on dummy code I got strange results.</p> <p>Code:</p> <pre class="lang-py prettyprint-override"><code>&quot;&quot;&quot; Dummy module for pylint tests &quot;&quot;&quot; def is_prime(num): &quot;&quot;&quot; Checking if a number is prime &quot;&quot...
<python><pylint>
2023-01-30 13:39:28
1
506
parasit
75,285,147
159,072
Unable to render Flask web-page
<p>I am using Ubuntu 16.04. It had builtin Python 3.5. I was unable to download Flask in that version. So, I changed it to Anaconda Python3.8.</p> <p>However, I am unable to render any Flask page.</p> <p>The following command output shows that, when I run <code>app.py</code> of my <code>Flask</code> application, the we...
<python><flask><ubuntu-16.04><python-3.8>
2023-01-30 13:32:04
1
17,446
user366312
75,285,136
12,845,199
After certain string is found mark every after string as true,pandas
<pre><code>s = pd.Series({0: 'registration address-complement-insert-confirmation input', 1: 'decision-tree first-interaction-validation options', 2: 'decision-tree invalid-format-validation options', 3: 'decision-tree first-interaction-validation options', 4: 'registration address-complement-request view', 5: 'on...
<python><pandas>
2023-01-30 13:31:15
1
1,628
INGl0R1AM0R1
75,284,890
14,667,788
how to cut image according to two points in opencv?
<p>I have this input image (feel free to download it and try your solution, please):</p> <p><a href="https://i.sstatic.net/GIy6j.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/GIy6j.png" alt="enter image description here" /></a></p> <p>I need to find points A and B that are closest to the left down and ...
<python><opencv>
2023-01-30 13:11:02
2
1,265
vojtam
75,284,768
14,163,533
"ModuleNotFoundError" after installing a python package
<h1>Problem summary</h1> <p>I am very new to python package development. I developed a package and <a href="https://test.pypi.org/project/spark-map/" rel="noreferrer">published it at TestPyPI</a>. I install this package trough <code>pip</code> with no errors. However, python is giving me a &quot;ModuleNotFoundError&quo...
<python><pip><package>
2023-01-30 13:00:33
4
889
Pedro Faria
75,284,417
14,037,055
AttributeError: module 'networkx' has no attribute 'from_numpy_matrix'
<p>A is co occurrence dataframe. Why it shown AttributeError: module 'networkx' has no attribute 'from_numpy_matrix'</p> <pre><code>import numpy as np import networkx as nx import matplotlib A=np.matrix(coocc) G=nx.from_numpy_matrix(A) </code></pre>
<python><python-3.x><graph><networkx>
2023-01-30 12:32:36
3
469
Pranab
75,284,350
9,720,696
operate over values of a dictionary when values are lists
<p>Suppose I have the following dictionary:</p> <pre><code>data = {'ACCOUNT_CLOSURE': ['account closure', 'close account', 'close bank', 'terminate account', 'account deletion', 'cancel account', 'account cancellation'], 'ACCOUNT_CHANGE': ['change my account', 'switch my account', 'change from private ...
<python><dictionary><nltk>
2023-01-30 12:25:53
1
1,098
Wiliam
75,284,301
20,051,041
How to remove all digits after the last string
<p>I would like to remove all the digits from the end of: &quot;Car 7 5 8 7 4&quot;. How can I achieve it using regex or other approaches? I tried following but it only deletes 1 digit:</p> <pre><code>re.sub(r'\s*\d+$', '', text) </code></pre> <p>Thanks</p>
<python><regex><substitution>
2023-01-30 12:20:30
2
580
Mr.Slow
75,284,240
13,440,165
Pass from filter's frequency response to time-domain [b, a] representation
<p>FIR and IIR filters are usually defined by [b, a] coefficients in time-domain regression formula:</p> <pre><code>y[n] = b_0 * x[n] + b_1 * x[n-1] + ... + b_N * x[n - N] - a_1 * y[n-1] - ... - a_M * y[n-M] </code></pre> <p>One can extract the frequency response <code>h</code> from <code>[b,a]</code> using Fourier Tra...
<python><scipy><filtering><signal-processing>
2023-01-30 12:14:10
0
883
Triceratops
75,284,222
15,112,773
Find the most similar number from list of lists in a dictionary python
<p>I have a dictionary where the values are a list of lists:</p> <pre><code>dict1 = {&quot;['x1', 'y1']&quot;: [['r1', 'r2'], [78, 125]], &quot;['x1', 'y1']&quot;: [['r1', 'r2'], [77, 112]], &quot;['x1', 'y1']&quot;: [['r1', 'r2'], [73, 110]], &quot;['x2', 'y2']&quot;: [['r2', 'r3'], [71, 103]]} </code></pr...
<python><list>
2023-01-30 12:12:32
1
383
Rory
75,284,207
15,414,616
Encrypting java JWEObject with RSA in python
<p>I asked a while ago how to do something similar: <a href="https://stackoverflow.com/questions/71928580/decrypting-and-encrypting-java-jweobject-with-algorithm-rsa-oaep-256-on-python">Decrypting and encrypting java JWEObject with algorithm RSA-OAEP-256 on python</a> Now I have a different encryption key and that code...
<python><java><encryption><rsa><jwe>
2023-01-30 12:11:04
1
437
Ema Il
75,284,167
14,311,263
Why does DataFrame.cumsum work with lists/strings, but GroupBy.cumsum doesn't?
<p>With the following dataframe example</p> <pre class="lang-py prettyprint-override"><code>import pandas as pd df = pd.DataFrame({ &quot;group&quot;: [1, 1, 2, 2, 2], &quot;list&quot;: [[1], [2], [1], [2], [3]], &quot;string&quot;: [&quot;a&quot;, &quot;b&quot;, &quot;a&quot;, &quot;b&quot;, &quot;c&quot;...
<python><pandas><group-by><cumsum>
2023-01-30 12:06:50
0
11,434
Timus
75,284,052
420,892
Dataframe timestamp interpolation for multiple variables
<p>I have a dataframe with three columns: <code>timestamp</code>, <code>variable_name</code> and <code>value</code>. There is a total of 10 variables whose names are in the <code>variable_name</code> column.</p> <p>I would like to have a single dataframe, indexed by timestamp, with one column per variable. Ideally, the...
<python><pandas><dataframe><apache-spark><pyspark>
2023-01-30 11:55:32
1
8,316
Cedric H.
75,283,937
10,656,093
Capture real time `stdout` and `stderr` when run a function in a process python
<p>I have a python function and want to run it as a separate process with <code>multiprocessing</code> package.</p> <pre><code>def run(ctx: Context): print(&quot;hello world!&quot;) return ctx </code></pre> <p>afterward running it as a separate process with the following script:</p> <pre><code>import multiproce...
<python><multiprocessing><subprocess><stdout>
2023-01-30 11:43:56
1
730
Maryam
75,283,556
14,343,465
Access to fetch at 'http://localhost:8000/api/v1' from origin 'http://0.0.0.0:8000' has been blocked by CORS policy
<p>This issue is well documented but my attempts have been unsuccessful... any suggestions are welcome!</p> <ul> <li>cookiecutter project on Github: <a href="https://github.com/Buuntu/fastapi-react" rel="nofollow noreferrer">Buuntu/fastapi-react</a></li> </ul> <h2>Recreating Error</h2> <pre class="lang-bash prettyprint...
<python><reactjs><docker-compose><cors><fastapi>
2023-01-30 11:08:15
1
3,191
willwrighteng
75,283,435
12,858,691
Tf keras tuning Adamax optimizer: InvalidArgumentError: lr is not a scalar : [1]
<p>I want to tune my LSTM Model. Playing around with different optimizers, I stumbled on an issue with the Adamax optimizer. My code:</p> <pre><code>import tensorflow as tf from keras.models import Sequential from keras.layers import Dense, SimpleRNN, LSTM, Dropout import keras_tuner from tensorflow.keras.callbacks imp...
<python><tensorflow><keras><hyperparameters>
2023-01-30 10:57:20
1
611
Viktor
75,283,426
4,028,662
python serial readline() vs C# serial ReadLine()
<p>I'm trying to read serial input from my device, and have gotten it to work in Python using pyserial, e.g.</p> <pre><code>import serial port = serial.Serial(port='COM1', baudrate=19200, bytesize=8, parity='N', stopbits=1, timeout=None, xonxoff=False, rtscts=False, dsrdtr=False) while 1: N = port.in_waiting ...
<python><c#><serial-port><pyserial>
2023-01-30 10:56:41
1
362
wenhoo
75,283,405
7,415,134
how to declare cursor in flask_mysqldb for only once
<p>I have this code(not complete)</p> <pre><code>@app.route('/', methods = ['GET','POST']) def home(): &quot;&quot;&quot; the main function for routing home &quot;&quot;&quot; if request.method == 'POST': try: if not cursor: cursor = mysql.connection.cursor() ...
<python><mysql><flask><mysql-python>
2023-01-30 10:54:28
1
379
Sid
75,283,203
10,889,650
How to simulate number of occurences over a time period
<p>I have an event which happens on average once every x seconds. In Python, I wish to &quot;simulate&quot; a specific time interval of t seconds, and obtain a reasonable randomly sampled integer n which denotes the number of times the event happened in that time period.</p> <p>How can I achieve this?</p> <p>(And no, ...
<python><statistics><poisson>
2023-01-30 10:37:42
1
1,176
Omroth
75,283,167
5,680,504
How to replace the variable in Json format string in Python?
<p>I have the following json format string as below.</p> <pre><code>json_data_string = &quot;{\&quot;size\&quot;:0,\&quot;query\&quot;:{\&quot;bool\&quot;:{\&quot;must\&quot;:[{\&quot;range\&quot;:{\&quot;@timestamp\&quot;:{\&quot;time_zone\&quot;:\&quot;+09:00\&quot;,\&quot;gte\&quot;:\&quot;2023-01-24T00:00:00.000Z\&...
<python>
2023-01-30 10:34:37
2
1,329
sclee1
75,283,069
19,369,310
New column based to boost entries who have raced with other entries in this race in the past
<p>I have the following large dataset recording the result of a math competition among students in descending order of date: So for example, student 1 comes third in Race 1 while student 3 won Race 2, etc.</p> <pre><code>Race_ID Date Student_ID Rank 1 1/1/2023 1 3 1 ...
<python><python-3.x><pandas><dataframe>
2023-01-30 10:26:28
1
449
Apook
75,282,891
6,856,520
How to merge predicted values to original pandas test data frame where X_test has been converted using CountVectorizer before splitting
<p>I want to merge my predicted results of my test data to my X_test. I was able to merge it with y_test but since my X_test is a corpus I'm not sure how I can identify the indexes to merge. My codes are as below</p> <pre><code>def lr_model(df): from sklearn.feature_extraction.text import CountVectorizer from ...
<python><pandas><scikit-learn><nlp>
2023-01-30 10:12:09
1
313
Jessie
75,282,840
4,584,863
use trial.suggest_int to pick values from given list in optuna, just like trial.suggest_categorical does
<p>I'm working with optuna for hyperparameter tuning of ML models in Python. While defining the objective function for tuning a Deep Learning model I tried to define a list of choices from which the <code>trail.suggest_int</code> can pick up values from. <strong>For example</strong> -</p> <pre><code>'batch_size': trial...
<python><machine-learning><hyperparameters><optuna>
2023-01-30 10:06:22
3
510
Bhanu Chander
75,282,809
6,883,721
Python module not found when calling from another
<p>I have this project structure:</p> <pre><code>/project_name main.py ----- __init__.py ------ /modules -------- __init__.py -------- module1.py -------- module2.py </code></pre> <p>I've edited to add more information. After working and testing a lot of recomendations to solve the problem, noth...
<python>
2023-01-30 10:03:24
5
567
Vince
75,282,782
2,491,592
Choosing the earliest date per record when equal dates are present
<p>I have a table with multiple dates per record. Example of the table:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>identifier</th> <th>date</th> <th>value</th> </tr> </thead> <tbody> <tr> <td>a</td> <td>1985-01-01</td> <td>ex1</td> </tr> <tr> <td>a</td> <td>1985-01-01</td> <td>ex2</td>...
<python><pandas><dataframe>
2023-01-30 10:01:44
2
315
K3it4r0
75,282,758
9,606,828
Django Model Formset from ManyToMany not accepting queryset
<p>I have my model called Game that has a ManyToMany field.</p> <pre><code>consoles = models.ManyToManyField('Console', through='GameConsole') </code></pre> <p>That ManyToMany has some additional attributes</p> <pre><code>class GameConsole(models.Model): game = models.ForeignKey(Game, on_delete=models.CA...
<python><django><django-views><django-forms><django-queryset>
2023-01-30 09:59:24
1
303
Pedro Silva
75,282,670
1,805,275
Plotly animation speed : Faster than duration 0
<p>I have a plot with only one line of 6500 points Above this line I have a marker that is animated following the line, like we can see in this example : <a href="https://plotly.com/python/animations/#moving-point-on-a-curve" rel="nofollow noreferrer">Intro to animations in Python</a></p> <p>Everything is working great...
<python><plotly>
2023-01-30 09:51:55
0
3,322
SJU
75,282,588
7,095,530
Try next view in Django URL dispatcher
<p>We have the following URL configuration in Django.</p> <p>Django will try to match the URL with the rules down below. Once it finds a match, it will use the appropriate view and lookup the object in the model.</p> <p>The thing is, once it finds a match in the URL pattern, it will match the view. But once the object ...
<python><django>
2023-01-30 09:44:02
2
315
Kevin D.
75,282,560
8,541,953
pip.conf file does not exist
<p>I am looking for the <code>pip.conf</code> file to add an URL from which install some packages. When running <code>python3 -m pip config debug</code> I get:</p> <pre><code>&gt; env_var: env: global: /Library/Application Support/pip/pip.conf, &gt; exists: False site: /Users/myuser/miniconda3/pip.conf, exists: Fal...
<python><pip>
2023-01-30 09:42:06
1
1,103
GCGM
75,282,511
13,568,193
df to table throw error TypeError: __init__() got multiple values for argument 'schema'
<p>I have dataframe in pandas :- purchase_df. I want to convert it to sql table so I can perform sql query in pandas. I tried this method</p> <pre><code>purchase_df.to_sql('purchase_df', con=engine, if_exists='replace', index=False) </code></pre> <p>It throw an error</p> <pre><code>TypeError: __init__() got multiple va...
<python><pandas><dataframe><sqlalchemy><azure-databricks>
2023-01-30 09:37:33
3
383
Arpan Ghimire
75,282,464
826,983
Alembic creates tables despite errors in migration upgrade()
<p>I've a simple migration script which is supposed to create a few tables.</p> <p>For brevity, this is basically the content:</p> <pre class="lang-py prettyprint-override"><code>op.create_table( 'a', sa.Column('id', sa.BIGINT, primary_key=True), ) op.create_table( 'b', sa.Column('id', sa.BIGINT, prima...
<python><sqlalchemy><alembic>
2023-01-30 09:33:14
0
25,793
Stefan Falk
75,281,731
18,330,370
pre-commit fails to install isort 5.10.1 with error "RuntimeError: The Poetry configuration is invalid"
<pre><code>[INFO] Installing environment for https://github.com/pycqa/isort. [INFO] Once installed this environment will be reused. [INFO] This may take a few minutes... An unexpected error has occurred: CalledProcessError: command: ('/builds/.../.cache/pre-commit/repo0_h0f938/py_env-python3.8/bin/python', '-mpip', 'in...
<python><pre-commit-hook><pre-commit><pre-commit.com><isort>
2023-01-30 08:19:34
2
331
LOTEAT
75,281,725
291,557
My Azure Function in Python v2 doesn't show any signs of running, but it probably is
<p>I have a simple function app in Python v2. The plan is to process millions of images, but right I just want to make the scaffolding right, i.e. no image processing, just dummy data. So I have two functions:</p> <ul> <li><code>process</code> with an HTTP trigger <code>@app.route</code>, this inserts 3 random image UR...
<python><azure><azure-functions>
2023-01-30 08:18:39
1
18,906
duality_
75,281,579
13,568,193
Check three column condtion and delete based on condition
<p>I have following dataframe df in pandas</p> <pre><code> item purchase_date purchase_qty purchase_price other_adjustments sold 0 0040030 2022-01 0 0.00 0 0.0 1 0050064 2022-01 0 0.00 -5 854.0 2 0050066 2022-01 0 0...
<python><pandas>
2023-01-30 08:02:35
5
383
Arpan Ghimire
75,281,452
11,311,729
read json file nested dictionary
<p>consider this example</p> <pre><code>{ &quot;items&quot;: { &quot;PYGXGE&quot;: { &quot;id&quot;: &quot;a&quot;, &quot;number&quot;: &quot;1&quot; }, &quot;sbe7oa&quot;: { &quot;id&quot;: &quot;b&quot;, &quot;number&quot;: &quot;2&quot; }, &quot;sbe7o...
<python><json><dictionary>
2023-01-30 07:47:21
3
407
vdotup
75,281,339
420,827
Grouping Python dictionary by 2nd item in key tuple
<p>I have a dictionary:</p> <pre><code>{(bob, CA): 90, (tom, NJ): 80, (sarah, CA): 90, (jon, TX): 90} </code></pre> <p>I would like to group by the 2nd item in the key tuple:</p> <pre><code>{CA: {bob: 90, sarah: 90}, NJ: {tom: 80}, TX: {jon: 90}} </code></pre> <p>I could formulate this by iterating through the original...
<python><dictionary><tuples>
2023-01-30 07:34:41
2
551
Manas
75,281,277
16,568,780
Suggest faster way to check if a proccess is active or not
<p>I am developing a solution that is a voice chatbot using a Raspberry pi 4 and aws lex due to having many if condition and many stuff to check It takes a little bit of time to reach the recording part that will capture the user's voice</p> <p>which is sometimes not convenient since the user will speak but it didn't...
<python><multithreading><raspberry-pi><amazon-lex>
2023-01-30 07:27:03
1
345
Ali Redha
75,281,172
16,220,410
scrape fiba stats box score
<p>i am barely a beginner at python and i would like to have a data set of my favorite local basketball team, that's why i search for a code scraping fiba stats box score , i found one here on stackoverflow and i tried to edit the headers but it just generates an empty csv file, wondering if anyone could help my edit t...
<python><dataframe><web-scraping><beautifulsoup><python-requests>
2023-01-30 07:12:07
2
1,277
k1dr0ck
75,280,913
20,508,530
How to access request object of django in react?
<p>I have multiple apps in my Django project but for One app I would like to use react, so I have create two apps one for apis and other for frontend. I used webpack to merge django and react. Now I want to access <code>request.user</code> and <code>user.is_authenticated</code> in my components. How can I access those ...
<javascript><python><reactjs><django><babeljs>
2023-01-30 06:33:03
1
325
Anonymous
75,280,818
11,922,765
Pandas Dataframe: Slice a part of read_html table into a dataframe
<p>I want to import a portion of html table into a dataframe.</p> <p>Here is the table: In the below, I want to import only &quot;Total Electric Industry&quot; <a href="https://i.sstatic.net/urU9J.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/urU9J.png" alt="enter image description here" /></a></p> <p>...
<python><html><pandas><dataframe>
2023-01-30 06:18:20
1
4,702
Mainland
75,280,665
14,353,779
Get Date in specified format in python
<p>I am looking to get today's <code>date</code> and <code>n</code> - today's <code>date</code> in the format below : -</p> <pre><code>tod = datetime.datetime.now() d = datetime.timedelta(days = 365) x = tod - d </code></pre> <p>I want <code>x</code> and <code>tod</code> in YYYYMMDD format for eg : 20230130 How do I ge...
<python><python-3.x>
2023-01-30 05:51:20
3
789
Scope
75,280,572
427,494
PyQt5: Moving QTableView rows up and down - segmentation fault error on down but works on up?
<p>I have a simple GUI in PyQt5 that uses a QTableView to display a list of incidents. I am trying to change the order of these incidents by clicking the up and down buttons. I want the selected row to either move up one or down one row from where it is when the respective button is pressed.</p> <p>However, I am having...
<python><pyqt5>
2023-01-30 05:34:52
0
17,190
ab217
75,280,472
1,316,668
Updating Image in a python canvas not working (Updated)
<p>Edit: I've narrowed down the problem to the fact that the code inside the function is not correctly referencing the main canvas widget, but because the function is called via a bind event, I'm not quite sure how to reference the main canvas...(more detail at the bottom)</p> <p>I am have the following code that displ...
<python><tkinter-canvas>
2023-01-30 05:12:25
0
767
Greg Steiner
75,280,345
4,281,353
In detail explanation on how to use DeepSort
<p><a href="https://github.com/nwojke/deep_sort" rel="nofollow noreferrer">Deep SORT</a> Github does not give much information on how to use it e.g.</p> <ul> <li>what inputs it expects in what format</li> <li>which function in which code file handles the input</li> <li>What are the outputs</li> </ul> <p>The github list...
<python><object-tracking>
2023-01-30 04:45:33
1
22,964
mon
75,280,182
2,666,270
Topic Modelling Coherence Score:
<p>I'm trying to calculate the coherence score after using BERTopic modelling to discover topics from an input text. I'm facing this error though <code>&quot;unable to interpret topic as either a list of tokens or a list of ids&quot;</code>, and I'm not sure why.</p> <p>This is how I get the tokens and topics words:</p...
<python><gensim><topic-modeling>
2023-01-30 04:09:43
1
9,924
pceccon
75,280,115
1,358,829
python mpire: modifying internal state of object within multiprocessing
<p>I have a class with a method which modifies its internal state, for instance:</p> <pre class="lang-py prettyprint-override"><code>class Example(): def __init__(self, value): self.param = value def example_method(self, m): self.param = self.param * m # By convention, these ...
<python><parallel-processing>
2023-01-30 03:53:36
1
1,232
Alb
75,280,083
14,251,610
Resampling timeseries Data Frame for different customized seasons and finding aggregates
<p>I am working on a huge timeseries dataset of following format:</p> <pre><code>import pandas as pd import numpy as np import random import seaborn as sns df = pd.DataFrame({'date':pd.date_range('1990',end = '1994',freq='3H'), 'A': np.random.randint(low = 0,high=100,size=11689), 'B...
<python><pandas><dataframe><datetime><time-series>
2023-01-30 03:45:09
1
303
Peshal1067
75,280,067
2,355,730
RTL (Arabic) ligatures problem when extracting text from PDF
<p>When extracting Arabic text from a PDF file using librairies like PyMuPDF or PDFMiner, the words are returned in backward order which is a normal behavior for RTL languages, and you need to use bidi algorithm to be able to display it correctly across UI/GUIs.</p> <p>The problem is when you have ligatures chars that ...
<python><pdfminer><pymupdf><bidi><pdf-extraction>
2023-01-30 03:41:03
2
793
Naourass Derouichi
75,280,031
1,357,015
Pythonic way to reshape dataframe for LSTM input in Keras
<p>I want to build a simple LSTM that takes as input the last 4 observations to make a prediction for the next time point. Each observation is a 5-tuple.</p> <p>I realize LSTM wants something in the format <code>[num_samples, time_steps, features]</code>. For example if I had 100 people, I would want something in the s...
<python><pandas><dataframe><keras><lstm>
2023-01-30 03:32:11
0
11,724
user1357015
75,279,933
12,427,876
shutil.unpack_archive and ziplib both return FileNotFoundError: [Errno 2] No such file or directory
<p>I'm trying to unzip some zip files in Python:</p> <pre><code> print(f&quot;Unzipping:\n{os.getcwd()}\\{constants.DOWNLOADS_FOLDER}\\{case_number}\\{username_hostname}.zip&quot;) 
# with zipfile.ZipFile(f&quot;{os.getcwd()}\\{constants.DOWNLOADS_FOLDER}\\{case_number}\\{username_hostname}.zip&quot;) as z:
 # z.ex...
<python><unzip><shutil>
2023-01-30 03:05:23
1
411
TaihouKai
75,279,859
7,347,911
How can i schedule multiple redshift (plpgsql) stored procedure in Airflow
<p>How can i schedule multiple redshift (plpgsql) stored procedure in Airflow using python ?</p> <p>for eg.</p> <pre><code>call stored_p_1() ; call stored_p_2() ; call stored_p_3() ; </code></pre> <p>I want all of tasks to be running in parallel and all of them are independent of each other (except slight exception...
<python><stored-procedures><airflow><amazon-redshift><plpgsql>
2023-01-30 02:47:27
0
404
manoj
75,279,826
1,256,495
Stop QTimer after a few seconds in PyQt6
<p>I am trying to understand how QTimer works.</p> <p>I have a list to be randomized and I tried to use QTimer to do the randomization every few miliseconds interval, and would like the QTimer to stop after a few seconds after that.</p> <p>Here is my code.</p> <pre><code>class Client(QObject): application = QApplic...
<python><pyqt6>
2023-01-30 02:36:31
1
559
ReverseEngineer
75,279,802
1,812,464
How to find smallest cluster of location which are within a given distance
<p>I have a set of co-ordinates in latitude and longitude format. I need to find the smallest cluster from these coordinates which are within say 50 mile distance to each other.</p> <p>I am new to data science, how can I implement this in Python without using sklearn library.</p>
<python><geolocation><data-science>
2023-01-30 02:30:28
1
2,136
Indranil
75,279,785
5,092,662
How to retrieve month with optional separator?
<p>I tried to write python script to retrieve year and month from string.</p> <p>The requirements are,</p> <ul> <li>year is fixed at 4 characters</li> <li>month is allowed to be two consecutive characters, or one or two characters when followed by a non-numeric value</li> </ul> <pre class="lang-py prettyprint-override"...
<python><regex>
2023-01-30 02:24:20
2
346
Kohei Sugimura
75,279,666
5,987
Safe use of ctypes.create_string_buffer?
<p>Usually in Python when you do an assignment of a variable, you don't get a copy - you just get a second reference to the same object.</p> <pre><code>a = b'Hi' b = a a is b # shows True </code></pre> <p>Now when you use <code>ctypes.create_string_buffer</code> to get a buffer to e.g. interact with a Windows API func...
<python><ctypes>
2023-01-30 01:57:32
1
309,773
Mark Ransom
75,279,532
1,331,446
Implementing my own code to handle "*" and / or "**" on a class
<p>I know what <code>*</code> and <code>**</code> do in Python (e.g. <a href="https://stackoverflow.com/questions/2921847/what-do-the-star-and-double-star-operators-mean-in-a-function-call">What do the * (star) and ** (double star) operators mean in a function call?</a>). But if I want to create my own &quot;dict-like...
<python><python-3.x><dictionary>
2023-01-30 01:17:54
0
5,332
dsz
75,279,531
2,778,405
Guarantee all logs go to file
<p>I need to set up logging so it will always log to a file, no matter what a user or other programmer might setLevel too. For instance I have this logger set up:</p> <p>initialize_logging.py</p> <pre class="lang-py prettyprint-override"><code>import logging filename=&quot;./files/logs/attribution.log&quot;, level=lo...
<python><logging><python-logging>
2023-01-30 01:17:48
1
2,386
Jamie Marshall
75,279,346
8,150,682
Python weasyprint unable to find 'gobject-2.0-0' library
<p>While following the <a href="https://docs.saleor.io/docs/3.x/category/setup" rel="nofollow noreferrer">installation</a> process for <a href="https://github.com/romeopeter/saleor.git" rel="nofollow noreferrer">Saleor</a> headless e-commerce, the Python <a href="https://doc.courtbouillon.org/weasyprint/latest/index.ht...
<python><django><weasyprint>
2023-01-30 00:24:00
1
818
Romeo
75,279,306
6,150,310
Check if any words in two lists are anagrams
<p>I'm trying to write a function where it takes in two lists of any length, and returns <code>True</code> if list_1 has any words that are anagrams in <code>list_2</code>, and false if not.</p> <p>For example:</p> <p>words1 = [“dog”, “kitten”] words2 = [“tiger”, “god”] return True, as “dog” and “god” are anagrams.</p>...
<python><python-3.x><list><anagram>
2023-01-30 00:14:45
2
1,264
mlenthusiast
75,279,304
10,761,353
Why can't Idle import from .py files created after it was launched?
<p>I can't explain this phenomena, other than to assume that Idle <em>somehow</em> works off of a <code>snapshot</code> of the filesystem, taken at launch-time.</p> <p>Repro steps:</p> <ul> <li>create a <code>myLib.py</code> file with (e.g.):</li> </ul> <pre><code>#!/usr/bin/env python3 pre_launch_str = &quot;Pre-laun...
<python>
2023-01-30 00:14:24
2
1,424
Adam Smooch
75,279,176
8,681,882
How to connect from GKE to Cloud SQL using Python and Private IP
<p>I want to connect to my MySQL database from my GKE pods using python using a private IP</p> <p>I've done all the configurations, the connection is working inside a test pod through bash using</p> <pre><code>mysql -u root -p --host X.X.X.X --port 3306 </code></pre> <p>But it doesn't work inside my Python app... maybe...
<python><mysql><kubernetes><google-cloud-platform>
2023-01-29 23:39:24
1
337
Noa Be
75,278,894
4,652,358
youtube-dl :: search for video and listen
<p>One of the features of youtube-dl allows you to search for a video and download.</p> <p>Example: if I want to search for <em><strong>P!NK - Never Gonna Not Dance Again</strong></em> I just need to do:</p> <pre><code>youtube-dl &quot;ytsearch1:P!NK - Never Gonna Not Dance Again&quot; </code></pre> <p>And the video is...
<python><youtube><youtube-data-api><youtube-dl>
2023-01-29 22:38:44
1
12,818
Francesco Mantovani