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
76,095,081
2,219,819
How do I use Kerberos tickets to execute commands via SSH on a remote server?
<p>I would like to host a web service (Jupyterhub) which executes the following steps for a user:</p> <ol> <li>Acquire Kerberos ticket from user</li> <li>Use Kerberos ticket to spawn batch job on remote server</li> </ol> <p>Therefore, I would need some python snippet to handle the authentication part (python-gssapi) an...
<python><ssh><kerberos><paramiko><gssapi>
2023-04-24 18:39:39
0
716
Hoeze
76,094,980
13,717,851
Why my tensorflow model is not learning in logistic regression - binary classification problem?
<p>I am using the following code in tensorflow to fit breast cancer dataset for a binary classification problem. The dataset has 30 features to predict cancer or not. The model is as below:</p> <pre><code>def loss(y, y_pred): return tf.reduce_mean(-y*tf.math.log(y_pred) - (1-y)*tf.math.log(1-y_pred)) class Model: ...
<python><tensorflow><logistic-regression><gradient-descent><sigmoid>
2023-04-24 18:24:45
1
876
Sayan Dey
76,094,836
604,388
How to properly use await with pyscript?
<p>Here is my simplified <a href="https://github.com/custom-components/pyscript" rel="nofollow noreferrer">pyscript</a> -</p> <pre><code>async def auth(brand): async with aiohttp.ClientSession() as session: async with session.post(url_auth) as resp: ... return auth_token_b64 @servic...
<python><python-3.x><pyscript><home-assistant>
2023-04-24 18:05:37
2
20,489
LA_
76,094,806
2,236,231
Translate ISO 639-1 to python locale
<p>My main aim is to correctly setting <code>locale</code> from <code>update.effective_user.language_code</code> in a python telegram bot</p> <pre class="lang-py prettyprint-override"><code>locale.setlocale(locale.LC_ALL, update.effective_user.language_code) </code></pre> <p><code>update.effective_user.language_code</c...
<python><locale><python-telegram-bot>
2023-04-24 18:01:50
0
1,099
Geiser
76,094,637
1,914,781
plot line segments with plotly
<p>I would like to plot line segments with plotly. below demo works but it use different traces per segments, which should not be the right way to do it.</p> <p>How can I implement line segments plot?</p> <pre><code>import pandas as pd import numpy as np import plotly.graph_objects as go from plotly.subplots import ma...
<python><plotly>
2023-04-24 17:38:16
1
9,011
lucky1928
76,094,586
10,981,411
How do I move my label frame to top right side of my window?
<p>below are my codes. I want to move my entire LabelFrame to top right. Its currently shown up right in the middle. How do I do that?</p> <p>I tried using sticky = 'NW' but that didnt work</p> <pre><code>import tkinter from tkinter import ttk from tkinter import messagebox import os import openpyxl from tkinter import...
<python><tkinter>
2023-04-24 17:33:18
1
495
TRex
76,094,577
9,391,359
psycopg2 set proper encoding
<p>I am using <code>psycopg2</code> as database adapter. The connection looks like</p> <pre><code> conn = psycopg2.connect(host=hostname,
 user=username,
 password=password,
 dbname=database
 ) </code></pre> <p>In the result of my query i have rows containing text like <code>&quot;РќР• РўР\xa0ЕБУЕТСЯ&quot;</...
<python><character-encoding><psycopg2>
2023-04-24 17:31:59
1
941
Alex Nikitin
76,094,568
7,447,976
pad_sequences changes the whole array in TensorFlow - Python
<p>I am practicing the LSTM networks in <code>tensorflow</code>. I am currently learning about masking and padding that are used in different lengths of inputs. However, when I use <code>pad_sequences</code> method, I am observing a strange behavior.</p> <pre><code>import numpy as np import tensorflow as tf max_length...
<python><tensorflow><keras><lstm><padding>
2023-04-24 17:30:20
1
662
sergey_208
76,094,461
4,271,392
Fail to setup octave magic commands on Google Colab: module 'oct2py' has no attribute 'octave'
<p>I am trying to draft a MATLAB/Octave tutorial on Google Colab, and was hoping to use magic commands <code>%octave</code> and <code>%%octave</code> to write most of the cells. However, when I tried to setup the environment using the below commands</p> <pre><code>!apt-get install octave !pip install oct2py %load_ext o...
<python><google-colaboratory><ipython><octave><oct2py>
2023-04-24 17:17:21
1
1,564
FangQ
76,094,405
11,628,437
How do I count the frequency of a specific word within each cell?
<p>Here is my Pandas dataframe -</p> <pre><code># Import pandas library import pandas as pd # initialize list elements data = {'Company': ['Nike', 'Levi', 'Dell'], 'Items': ['Running Shoes, Walking Shoes, Socks', 'Jeans, Jackets, Designer Shoes', 'Laptops'], 'Specified_Word':['Shoes', 'Shoes', 'Laptops...
<python><pandas>
2023-04-24 17:10:28
4
1,851
desert_ranger
76,094,384
5,942,100
Create multiple identical columns with different names within a dataframe using Pandas
<p>I would like to create multiple identical columns with different names within a dataframe using Pandas.</p> <p><strong>Data</strong></p> <pre><code>ID type name series date AA all sue 111 1/1/2023 AA ok devon 222 1/1/2023 ...
<python><pandas><numpy>
2023-04-24 17:07:29
2
4,428
Lynn
76,094,275
19,003,861
Changing Folium Geocoder icon
<p>I am trying to change the default <code>geocoder</code> icon with <code>folium</code>.</p> <p>I thought using something like <code>i = folium.Icon(color='black')</code> would work, as I use a similar code to change my the icons of other markers.</p> <p>But the code does not seem responsive.</p> <p>What am I missing?...
<python><leaflet><folium>
2023-04-24 16:53:14
0
415
PhilM
76,094,147
178,757
What's the encoding used in the output of Linux commands like find, accessed from Python?
<p>Python provides a <code>subprocess</code> import that allows fine-grained control of processes, but when I'm creating a process in Unix such as <code>find</code>, what's the encoding of the output of these standard Gnu commands?</p> <pre><code>import subprocess myProcess = subprocess.Popen(shlex.split('find ./dir -m...
<python><unix><encoding><subprocess>
2023-04-24 16:38:37
2
30,459
Jez
76,094,113
2,924,546
package with pip install does install it but same package with setup.py does not get installed
<p>I am trying to install some packages using <em>pip</em>, which is working fine but if I try to install it using <code>setup.py</code> then it does not install it.</p> <p>For example:</p> <pre class="lang-none prettyprint-override"><code>pip install ruamel-yaml-clib==0.2.7 </code></pre> <p>does install the package.</...
<python><pip><setuptools><setup.py>
2023-04-24 16:34:35
1
2,048
Sanjay
76,094,097
347,298
Can I mock a constant string value that is referenced in the class under test?
<p>I have class <em>A</em> in module <em>a.py</em>, which has a method <em>do_thing</em>. The method <em>do_thing</em> uses a constant definition <em>CONST_VAL</em>, defined in <em>a_definitions.py</em> as 'Some String'. <em>a_definitions</em> is imported into <em>a.py</em>.</p> <p>I have a unit test that instantiates ...
<python><python-unittest>
2023-04-24 16:31:39
1
364
Dana
76,093,956
4,612,370
Calling a python argparse interface from python without Subprocess
<p>Consider <strong>the following toy python application</strong>, which only have argparse CLI argparse interface.</p> <pre><code>import argparse def main(): parser = argparse.ArgumentParser(description=&quot;Printer&quot;) parser.add_argument(&quot;message&quot;) args = parser.parse_args() print(args...
<python><command-line-interface><argparse>
2023-04-24 16:14:56
1
838
n0tis
76,093,885
6,722,075
'mpremote' is not recognized as an internal or external command
<p>I installed python and mpr by using it as well. But now after installing mpr <code>pip install --user mpr</code> and using mpr command I got following error in windows.</p> <pre class="lang-none prettyprint-override"><code>c:\&gt;mpr version 'mpremote' is not recognized as an internal or external command </cod...
<python><python-3.x><micropython>
2023-04-24 16:06:10
1
2,544
Tohid Makari
76,093,883
172,277
Configuring an asynciohttp_retry client and using later
<p>I have a simple sample code aroung <code>asynchttp_retry</code>.</p> <pre class="lang-py prettyprint-override"><code>import aiohttp import aiohttp_retry from aiohttp_retry import RetryClient import asyncio retry_statuses = [500, 404] async def run_http_client(): retry_options = \ aiohttp_retry.Exponent...
<python><python-asyncio>
2023-04-24 16:05:43
1
7,591
AsTeR
76,093,781
14,729,041
Import problems in FastAPI-based backend with Docker
<p>I am running a FastAPI-based backend and I am running into the following error:</p> <pre><code>File &quot;/app/main.py&quot;, line 6, in &lt;module&gt; backend-backend-1 | from app.api.api_v1.api import api_router backend-backend-1 | ModuleNotFoundError: No module named 'app' </code></pre> <p>This is an import...
<python><docker><docker-compose><python-import><fastapi>
2023-04-24 15:52:15
0
443
AfonsoSalgadoSousa
76,093,727
10,459,366
Search strings in dataframe column for specific pattern and update with another column
<p>Let's say I have the following sample dataframe:</p> <pre><code># Create DataFrame from Dict technologies = { 'Val':[5, 9], 'Stuff':[&quot;[demography_form][1]&lt;div&gt;&lt;/table&lt;text-align&gt;[demography_form_date][1]&quot;, &quot;&lt;text-ali&gt;[geography_form][1]&lt;div&gt;&lt;/table&lt;text-align&g...
<python><pandas><string><dataframe>
2023-04-24 15:47:07
1
878
Andrea
76,093,721
7,598,774
EC.element_to_be_clickable condition executes successfully, however in the following line same element's click fails
<p><strong>Query:</strong> As mentioned in the title, if below line has successfully executed:</p> <pre class="lang-py prettyprint-override"><code>element = wait.until(EC.element_to_be_clickable((By.XPATH, &quot;//a[text()='See all teams']&quot;))) </code></pre> <p>Why the below line throws <code>Element is not clickab...
<python><selenium-webdriver><seleniumwaits><element-to-be-clickable>
2023-04-24 15:46:20
1
9,177
Shawn
76,093,692
3,417,379
postgresql15-contrib installation on Amazon Linux 2 fails on Python shared lib dependency
<p>I'm using an EC2 on AWS running Amazon Linux 2. I'm trying to install Postgresql version 15 server along with the contrib libraries for various extension.</p> <p>This is how I installed Posgres15</p> <pre><code>sudo rpm --import https://yum.postgresql.org/RPM-GPG-KEY-PGDG-15 sudo yum update -y sudo yum install -y po...
<python><linux><postgresql><postgresql-15>
2023-04-24 15:43:46
0
562
maxTrialfire
76,093,567
8,512,262
Error with win32event.OpenEvent when trying to get a handle to a named Windows event
<p>I've created a Windows service in Python that will launch my main application (an executable built in Python) after some inactivity timeout. That service uses <code>win32event</code> to set up a synchronization event for communication between itself and my main application. The event named <code>'EXIT_EVENT'</code> ...
<python><windows><events><service><pywin32>
2023-04-24 15:29:21
0
7,190
JRiggles
76,093,477
3,398,324
Rearrange Dataframe
<p>I would like to rearrange my df from this:</p> <pre><code>data = {'date': ['1/1/2022', '1/2/2022','1/3/2022'], 'ticker1': [11, 21, 31], 'ticker2': [12, 22, 32], 'ticker3': [13, 23, 33]} df = pd.DataFrame(data) </code></pre> <p>to this (where the dates still correspond to the correct rows):</p> <pre><code>data = {'d...
<python><pandas><stack>
2023-04-24 15:20:14
1
1,051
Tartaglia
76,093,365
353,337
Read Python XML with tag and text in one element
<p>I have the XML file</p> <pre class="lang-xml prettyprint-override"><code>&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt; &lt;document&gt; &lt;title&gt; &lt;tag&gt;A&lt;/tag&gt; X &lt;/title&gt; &lt;/document&gt; </code></pre> <p>and I'd like to read it with Python such that I could recon...
<python><xml>
2023-04-24 15:08:53
4
59,565
Nico Schlömer
76,093,277
127,320
How to create a ParquetFile object from a Table (or Dataset) in Pyarrrow
<p>I have access to a <code>Dataset</code> or <code>Table</code></p> <pre><code>ds = pyarrow.dataset.dataset(PARQUET_FILE_PATH, filesystem=fs) table = ds.to_table() </code></pre> <p>I need to get the parquet metadata, which is only available through <code>ParquetFile</code>. Tried the following but failed with an error...
<python><parquet><pyarrow>
2023-04-24 14:59:53
0
80,467
Aravind Yarram
76,093,259
1,063,647
Qt - break long running GUI-update / event handling, e.g. by ESC key
<p>My Qt-Application (currently on PySide2 (Qt 5.15.6)) uses QTreeViews and appropriate Models to show big hierarchical structures, some of them really deep and/or containing reference loops. For displaying only nodes that match a given QRegExp I derived <code>QSortFilterProxyModel</code> and reimplemented <code>filter...
<python><qt><event-handling><pyside2>
2023-04-24 14:58:36
1
394
Zappotek
76,093,153
5,547,553
How to read partitioned parquet file into polars?
<p>I'd like to read a partitioned parquet file into a polars dataframe.</p> <p>In spark, it is simple:</p> <pre><code>df = spark.read.parquet(&quot;/my/path&quot;) </code></pre> <p>The polars documentation says that it should work the same way:</p> <pre><code>df = pl.read_parquet(&quot;/my/path&quot;) </code></pre> <p>...
<python><dataframe><parquet><python-polars>
2023-04-24 14:46:08
4
1,174
lmocsi
76,093,096
5,114,342
How to assign a list without changing the address?
<p>I have a subroutine that is given a list which is used at another part in the program, and the subroutine is to modify that list.<br /> In particular, it is supposed to trim the list.</p> <p>Let's say the code looks like this so far:</p> <pre><code>class Foo: array = [0,1,2,3,4,5] def modify(target, length)...
<python>
2023-04-24 14:41:13
1
3,912
Aziuth
76,092,964
5,510,713
Remove pincushion lens distortion in Python
<p>I have the following image which is computer generated</p> <p><a href="https://i.sstatic.net/YXMYF.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/YXMYF.png" alt="enter image description here" /></a></p> <p>It is fed as an input to an optical experiment results in the following image:</p> <p><a href="...
<python><opencv><camera-calibration><fisheye>
2023-04-24 14:27:20
3
776
DhiwaTdG
76,092,929
6,387,095
pandas using any(1) has suddenly started giving errors?
<p>My code was working perfectly, I updated <code>openpyxl</code> now when I try:</p> <pre><code>data = {'Col1': ['Charges', 'Realized P&amp;L', 'Other Credit &amp; Debit', 'Some Other Value'], 'Col2': [100, 200, 300, 400], 'Col3': ['True', False, 'True', 'False']} df = pd.DataFrame(data) # keep rows w...
<python><python-3.x><pandas>
2023-04-24 14:23:29
2
4,075
Sid
76,092,904
14,986,784
Use deep learning models from other containers
<h2>What I want to do</h2> <p>Let's say I want to use ModelA and ModelB. Each model's environment is inside a container Container1 and Container2. Those environment are conflicting, I cannot merge them.</p> <p>I would like to use both models in the same Python script, something like:</p> <pre class="lang-py prettyprint...
<python><docker><deep-learning><development-environment>
2023-04-24 14:21:23
0
474
MufasaChan
76,092,877
7,230,328
python 3 regex to contain the create table statement from sql for azure databricks sql
<p>I have this oracle SQL Statement. I need a regex that captures only the create table statement with the constraints of primary and foreign keys.</p> <pre><code>CREATE TABLE &quot;OWB_RUN&quot;.&quot;TOKEN_CARD_STATUS_HISTORY&quot; ( &quot;TOKEN_CARD_WH&quot; NUMBER NOT NULL ENABLE, &quot;TOKEN_STATUS&quot;...
<python><sql><python-3.x><regex>
2023-04-24 14:18:41
2
413
KRStam
76,092,767
5,048,010
Install black[d] from conda
<p>I want to run black as a code formatter in PyCharm. The black website gives specific instructions on how to do so, which is very helpful: <a href="https://black.readthedocs.io/en/stable/integrations/editors.html" rel="nofollow noreferrer">https://black.readthedocs.io/en/stable/integrations/editors.html</a> . However...
<python><pycharm><conda><python-black>
2023-04-24 14:05:47
1
1,653
Gianluca Micchi
76,092,703
3,734,059
Keep only rows until elements in DateTimeIndex are consecutively continued in pandas dataframe
<p>I have a pandas <code>DataFrame</code> with a <code>DateTimeIndex</code> that looks as follows:</p> <pre><code>import pandas as pd df = pd.DataFrame( index=pd.date_range( start=pd.Timestamp(&quot;2023-03-20 12:00:00+0000&quot;, tz=&quot;UTC&quot;), end=pd.Timestamp(&quot;2023-03-20 15:00:00+000...
<python><pandas>
2023-04-24 13:58:15
1
6,977
Cord Kaldemeyer
76,092,559
7,256,443
mypy {{cookiecutter.project_slug}} is not a valid Python package name
<p>I am building a cookiecutter template for a python package, and I want to run a bunch of checks for the template repo itself with pre-commit.</p> <p>A skeleton of the repo looks like this:</p> <pre><code>my_cookiecutter_template | .pre-commit-config.yaml | cookiecutter.json | |___{{cookiecutter.project_slug}} ...
<python><mypy><cookiecutter>
2023-04-24 13:43:41
1
1,033
Ben Jeffrey
76,092,533
14,875,027
Class instance mutability issue
<p>I'm defining classes that pass arguments through index notation. To do this, I use the <code>__class_getitem__</code> method. Here is my implementation.</p> <pre><code> def __class_getitem__(cls, parameters): if type(parameters) != tuple: parameters = (parameters,) if len(parameters) ...
<python><class-method>
2023-04-24 13:40:05
2
370
dvr
76,092,486
19,155,645
mask edges are not continuous - how to solve
<p>my ML model is producing a binary mask (separate file) for each object.</p> <p>The objects are not &quot;filled out&quot; (that is, there are very often &quot;holes&quot; inside the objects).</p> <p>The issue is that when the &quot;holes&quot; are too close to the edge, the object edges are not continuous, and there...
<python><opencv><image-processing><computer-vision><mask>
2023-04-24 13:35:54
0
512
ArieAI
76,092,461
9,965,155
Why is doc.spans empty after spans are assigned to the doc object in Spacy?
<p>I am trying to convert a two-dimensional list with entity labels <code>(0, 1, -1)</code> into a <code>spaCy doc</code> object with <code>Spans</code> as entity labels. The 2-D list corresponds to token labels for the <code>tokens_</code> variable, which is basically a list of words. So basically, spans will have the...
<python><spacy>
2023-04-24 13:33:16
1
2,006
PinkBanter
76,092,382
10,499,034
Is Neighbor-Joining Clustering Availalble in SciPy
<p>I would like to use scipy.cluster.hierarchy to perform neighbor joining on a distance matrix. However, I have been unable to locate in the documentation that this is an available option. The reason I would like to use scipy.cluster.hierarchy specifically is because I am already using it for UPGMA clustering of the...
<python><scipy><hierarchical-clustering>
2023-04-24 13:21:55
0
792
Jamie
76,092,263
14,923,024
Column- and row-wise logical operations on Polars DataFrame
<p>In Pandas, one can perform boolean operations on boolean DataFrames with the <code>all</code> and <code>any</code> methods, providing an <code>axis</code> argument. For example:</p> <pre class="lang-py prettyprint-override"><code>import pandas as pd data = dict(A=[&quot;a&quot;,&quot;b&quot;,&quot;?&quot;], B=[&quo...
<python><dataframe><python-polars>
2023-04-24 13:09:11
2
457
AAriam
76,092,151
1,788,771
Django model based on queryset rather than table
<p>I have a model called <code>Event</code> and a viewset called <code>UserEventViewSet</code> that defines the following method:</p> <pre><code>def get_queryset(self): return ( Event.objects.select_related( 'user', ).values( 'user_id', 'type' ).annotate(...
<python><django><django-rest-framework>
2023-04-24 12:56:44
0
4,107
kaan_atakan
76,091,986
11,616,106
QtWebEngine Issue when I run executable format
<p>I've a python Pyside6 gui, it is working when I run the code on Pycharm. But after that I want to convert executable format in my MacOS. So I installed pyinstaller in file path file_path/var/site-packeges/ Project using 3.8 version of Python with below commands:</p> <pre><code> pyinstaller --onefile test1.py 65 I...
<python><pyinstaller>
2023-04-24 12:39:21
0
521
hobik
76,091,717
9,220,442
Pivot pandas dataframe by filled values
<p>I want to transform/pivot the following dataframe to indicate the immediate data flow from (source) to (target).:</p> <pre class="lang-py prettyprint-override"><code> l0 l1 l2 l3 sum 0 IN TOTAL &lt;NA&gt; &lt;NA&gt; 1 1 &lt;NA&gt; TOTAL OUT_A OUT_B 2 2 &lt;NA&gt; ...
<python><pandas>
2023-04-24 12:09:25
4
1,302
Thomas
76,091,636
2,828,006
Regular expression to match string starting with and numbers in it
<p>I have strings like :</p> <pre><code>merge_req_title1 = &quot;JARVIS-17442: Enable Fees report&quot; merge_req_title2= &quot;Resolve JARVIS-15887 'integration new'&quot; </code></pre> <p>i am using python to extract the substring out of them which is as <code>JARVIS-&lt;number&gt;</code></p> <p>example output for be...
<python><python-3.x><regex>
2023-04-24 12:00:39
2
1,474
Scientist
76,091,424
17,174,267
selenium: Handle "Allow this site to open the XXX link with YYY"
<p>How do I handle this popup with python/selenium? (Chrome and Firefox answers appreciated.)</p> <p>A. How do I cancel it?</p> <p>B. How would I do the open link?</p> <p>C. Are there any Chrome Options/Firefox Profiles to ignore this popup?</p> <p><a href="https://i.sstatic.net/mvPsZ.png" rel="nofollow noreferrer"><im...
<python><selenium-webdriver>
2023-04-24 11:32:41
0
431
pqzpkaot
76,091,366
14,253,961
Converting From .h5 model to .pt model :Convert model from keras h5 to pytorch
<p>How can I use a .h5 model in Pytorch file; I worked with Keras with TensorFlow backend so here is my saved model:</p> <pre><code>model = tf.keras.applications.ResNet50(include_top=False, weights=None, input_tensor=tf.keras.Input(shape=(224, 224, 3)), pooling=None) ....#training model.save(&quot;mymodel.h5&quot;) mo...
<python><pytorch><conv-neural-network><tf.keras>
2023-04-24 11:23:51
1
741
seni
76,091,228
11,579,184
Cannot find AwaitableTriggerDagRunOperator anymore for Airflow [Python]
<p>I'm working on a python project using Airflow. In the project there is no <code>requirements.txt</code> file so I simply installed the latest version of the libraries by putting their name inside a <code>requirement.txt</code> file and I've been trying to make it work.</p> <p>The import which is causing trouble is t...
<python><airflow><airflow-2.x>
2023-04-24 11:03:51
1
1,802
Gerardo Zinno
76,091,214
15,178,267
Django: python manage.py runserver exits with ‘Performing system checks, what is the possible issue?
<p>I am working on a django project and have been using <code>python manage.py runserver</code> to spin up my development local server, but it just started exiting at <code>Performing system checks</code>. This is the first time i am encountering such issue, have any one experienced this issue before, please how do i g...
<python><django><django-rest-framework>
2023-04-24 11:02:06
0
851
Destiny Franks
76,091,160
11,552,661
TypeError: isinstance() arg 2 must be a type or tuple of types" while using WriteToBigQuery in Apache Beam
<p>I am trying to use Apache Beam with Python to fetch JSON data from an API and write it to a BigQuery table. Here is the code I am using:</p> <pre><code>import argparse import json import requests import apache_beam as beam from apache_beam.io import WriteToBigQuery from apache_beam.options.pipeline_options import Pi...
<python><apache-beam>
2023-04-24 10:54:22
0
1,354
tbone
76,091,077
1,200,914
Django's bulk_create doubts
<p>I'm adding this function to my Django app, but I have a couple of questions I need to know and which I couldn't find in Google.</p> <ol> <li>Does it insert all records in the order the list is given? Or can they be suffle? Can I know which id corresponds to the index in the list of the items to give?</li> <li>In cas...
<python><django><django-models>
2023-04-24 10:44:05
1
3,052
Learning from masters
76,091,043
7,318,120
pd.to_datetime() does not work in windows terminal
<p>I have been running python scripts in <code>windows power shell</code> for quite some time.</p> <p>All of a sudden this morning I get this error message:</p> <pre><code> line 3802, in get_loc return self._engine.get_loc(casted_key) File &quot;pandas\_libs\index.pyx&quot;, line 138, in pandas._libs.index.Index...
<python><pandas><string-to-datetime>
2023-04-24 10:40:29
0
6,075
darren
76,090,979
21,722,065
'XlsxWriter' object has no attribute 'save'. Did you mean: '_save'?
<p>I'm trying to save data from a DataFrame to an Excel file using pandas. I tried the following code:</p> <pre class="lang-py prettyprint-override"><code>import pandas as pd import xlsxwriter data = {'Name': ['John', 'Jane', 'Adam'], 'Age': [25, 30, 35], 'Gender': ['M', 'F', 'M']} df = pd.DataFrame(data) writer = pd....
<python><pandas><excel><attributeerror><xlsxwriter>
2023-04-24 10:34:33
2
641
Straniero95
76,090,869
1,484,522
Python 3.10 - iterating through directory of files says "this file does not exist"
<h2>summary</h2> <p>Creating a Python 3.10 program to read a directory of mp3 files and produce a playlist. I would like this program to be portable across operating systems so it would just use the relative path to mp3files instead of a full OS path.</p> <p>No matter what filespec I use getting error with the file nam...
<python><filereader>
2023-04-24 10:20:53
1
355
lonstar
76,090,845
21,787,377
how to add Comment form inside a post detailed
<p>Is there any way I can add a comment form inside a post's details? I have a view that shows a model object, and I want to allow users to comment on that view. I have tried to use <a href="https://djangocentral.com/creating-comments-system-with-django/" rel="nofollow noreferrer">this method</a>, but using that method...
<python><django>
2023-04-24 10:17:58
1
305
Adamu Abdulkarim Dee
76,090,820
12,125,395
Create frequency matrix using pandas
<p>Suppose I have the following data:</p> <pre><code>import pandas as pd df = pd.DataFrame([ ['01', 'A'], ['01', 'B'], ['01', 'C'], ['02', 'A'], ['02', 'B'], ['03', 'B'], ['03', 'C'] ], columns=['id', 'category']) </code></pre> <p>How do I create a frequency matrix like this?</p> <pre><code...
<python><pandas>
2023-04-24 10:15:09
1
889
wong.lok.yin
76,090,694
5,306,861
How to find all matching objects in an image with SIFT
<p>I have a picture of a diamond card, and a small picture of one diamond, I'm trying to find all the diamonds in the big picture</p> <p>Below are the pictures:</p> <p><a href="https://i.sstatic.net/zzBUd.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/zzBUd.png" alt="enter image description here" /></a>...
<python><c#><c++><opencv><computer-vision>
2023-04-24 09:59:08
1
1,839
codeDom
76,090,515
726,730
Datetime objects set to dict list
<pre class="lang-py prettyprint-override"><code>#recalculate start and end datetime current_datetime = self.start_datetime counter = -1 for schedule_item_final in schedule_items_final: counter += 1 schedule_items_final[counter][&quot;start_datetime&quot;] = copy.deepcopy(current_datetime) schedu...
<python><datetime>
2023-04-24 09:33:19
0
2,427
Chris P
76,090,442
5,775,358
Xarray apply function
<p>I have a large dataset and I want to do some computing on some groups of values.</p> <p>That works fine, but I am left with the following information:</p> <pre><code> Array Chunk Bytes 17.81 kiB 480 B Shape (38, 1, 60) (1, 1, 60) Count 57288 Tasks 38 Chunks Type float64 numpy.ndarray...
<python><parallel-processing><dask><python-xarray>
2023-04-24 09:25:06
1
2,406
3dSpatialUser
76,090,332
6,117,017
Azure (Python) Function Code Deployment --- Zip Deployments' trigger does not work
<p>I have an Azure Linux Function App that I am deploying using TerraForm.</p> <p>I have Linux Function + Consumption Plan.</p> <p>The .zip function contains <code>3 .py scripts, one __init__.py and function.json</code>.</p> <p>The code deployment goes well, but the triggering does not work (the function is an Azure St...
<python><azure><terraform><azure-functions><devops>
2023-04-24 09:11:54
3
15,173
Timbus Calin
76,090,279
855,472
Add usage examples into swagger
<p>We're using swagger to document our API. We need to add some API usage examples. Not just how to call some endpoint, but what endpoint in which order the user need to call to achieve some goals. Something like usage scenarios.</p> <p>Is it possible to add in Swagger? Or maybe there is some alternative that does that...
<python><flask><swagger><documentation><openapi>
2023-04-24 09:05:27
1
3,499
Djent
76,090,247
10,967,961
Unable to perform a dask merge
<p>I have a huge dataframe called Network consisting of two columns (integers): &quot;NiuSup&quot;, &quot;NiuCust&quot; and 5 Million observations. I am trying to perform a merge using dask as follows:</p> <pre><code>import dask.dataframe as dd NetworkDD = dd.from_pandas(Network, npartitions=Network['NiuSup'].nunique()...
<python><merge><dask><space>
2023-04-24 09:02:33
0
653
Lusian
76,090,182
16,589,565
why pyinstaller available in virtual environment even I did not install it
<p>I created a python virtual environment by virtualenv and activate it, then I found I can use pyinstaller in this vir-env, but I had not &quot;pip install pyinstaller&quot; in it, why? And as comparison, I wrote 'import &lt;not_installed_module&gt;' in code, then it threw up 'module unfound' and it is as expected.</p...
<python><pip><virtualenv><pyinstaller><virtual-environment>
2023-04-24 08:54:46
1
317
leotsing
76,090,165
5,386,595
Call custom colormap by name
<p>I've seen many posts about creating custom colormaps in <code>matplotlib</code>, however I couldn't find whether it is possible to call such custom colormap by name (which I guess requires first some way to add the custom colormap to the list of findable/built-in colormaps).</p> <p>As an example, I'd like to do some...
<python><matplotlib><colormap>
2023-04-24 08:52:30
1
762
duff18
76,090,143
13,506,329
Use numpy masked array on an array of arrays without getting a flattened output
<p>Consider the following code</p> <pre><code>x = np.array([[1, 2, 3], ['NaN', 4, 'NaN'], [7, 8, 9]]) # Convert 'NaN' strings to masked values mask = np.ma.masked_where(x == 'NaN', x) # Get a boolean array indicating where the original array is not masked bool_arr = ~mask.Mask # Filter the original array using the b...
<python><arrays><python-3.x><numpy><vectorization>
2023-04-24 08:49:32
2
388
Lihka_nonem
76,090,058
18,949,720
Under-sampling leads to poor results for no apparent reason
<p>I am using Random Forest for a semantic segmentation task, with 3 classes, which are imbalanced. First, I just trained the algorithms on random subsets containing 20% of all the pixels (else my memory cannot handle training the algorithms), and got IoU and Balanced accuracy scores of 0.83 and 0.91 on my test dataset...
<python><random-forest><image-segmentation><imbalanced-data>
2023-04-24 08:37:00
2
358
Droidux
76,089,813
11,075,360
Pinecone Error when connecting with OpenAi: MaxRetryError
<p>I have a simple app that lets you upload a pdf, splits it in chunks, make the embeddings and then uploads it to pinecone. But when I run <code>docsearch = Pinecone.from_texts([t.page_content for t in texts], embeddings, index_name=index_name)</code> I get the following error:</p> <pre><code>SSLEOFError ...
<python><openai-api><langchain>
2023-04-24 08:04:44
3
301
Nordic Guy
76,089,733
18,206,100
Using attrs is it ok to set init=False to an attribute with no default value
<p>I use <code>attrs</code> library.</p> <p>I use some attributes that are set by the <code>__attrs_post_init__</code> method.</p> <p>For them, I want to prevent them from being part of the constructor.</p> <p>Is it ok to not put a default value, or is it an implicit requirement of putting <code>init=False</code>?</p> ...
<python><python-attrs>
2023-04-24 07:57:05
1
919
Floh
76,089,622
4,404,709
Polars map_batches on list type raises InvalidOperationError
<p>There is a conundrum I cannot solve in Polars:</p> <p>This behaves as expected:</p> <pre class="lang-py prettyprint-override"><code>df = pl.DataFrame( { &quot;int1&quot;: [1, 2, 3], &quot;int2&quot;: [3, 2, 1] } ) df.with_columns( pl.struct('int1', 'int2') .map_batches(lambda x: x....
<python><dataframe><python-polars>
2023-04-24 07:42:49
3
960
erap129
76,089,602
19,325,656
Validate choice field DRF
<p>Hi all I have my model and its serializer, what I discovered when testing is that serializer is saved no matter what I have in my choice field but in Django admin choice field is empty when the data is wrong and when the data is right I can see the correct option</p> <p>so,</p> <pre><code>-&gt; wrong choice data -&g...
<python><django><serialization><django-rest-framework>
2023-04-24 07:39:30
1
471
rafaelHTML
76,089,581
1,159,488
How to get native points on a elliptic curve from an existing addition of points
<p>I'm working on elliptic curves with SageMath.<br /> I know :</p> <ol> <li><p>The equation of the curve E defined by y^2 = x^3 + ... : <code>E = EllipticCurve( GF(K), [m, n] )</code></p> </li> <li><p>the addition of points A and B (A+B) : <code>(x3;y3)</code></p> </li> <li><p>the substraction of points A and B (A-B) ...
<python><cryptography><sage><elliptic-curve>
2023-04-24 07:36:12
0
629
Julien
76,089,515
6,691,564
TensorFlow on Apple M1 without Metal - is it possible?
<p>I have a 2017 Intel iMac on which I develop TensorFlow apps. I am on the latest version of everything (as at April 2023) - Python 3.11.3, Tensorflow 2.12.0, numpy 1.24.2.</p> <p>I have bought a cheap secondhand Mac Mini (2020 M1) to offload some of the training. The experiments I have done with Metal give me worse p...
<python><tensorflow><apple-m1>
2023-04-24 07:26:58
1
321
Julian7
76,089,499
2,085,438
workaround for k-means to use levenshtein distance in scikit?
<p>I have tried to apply a custom distance to my kNN model for the reasons I detail below.</p> <p>Here is my metric:</p> <pre class="lang-py prettyprint-override"><code>def distance_fun(df, text_feat, num_feat): # len(text_feat) levenshtein # len(num_feat) euclidian # rest dice num_indices = list(range(...
<python><scikit-learn><knn><levenshtein-distance>
2023-04-24 07:25:09
0
2,663
Chapo
76,089,304
8,040,369
ModbusTcpClient: How to read long integer values from Input registers in python
<p>I am trying to get data from a sensor using ModbusTcpClient as below</p> <pre><code>client = ModbusTcpClient('xx.xx.xx.xx', port=502) connection = client.connect() request = client.read_input_registers(220,2, unit=51, debug=False) result = request.registers print(result) </code></pre> <p>With this result i am gettin...
<python><python-2.7><modbus><modbus-tcp>
2023-04-24 07:01:43
2
787
SM079
76,089,130
11,479,825
Group a list column
<p>I have a data frame, containing the following data:</p> <pre><code>| img | list_col1 | list_col2 | |------|--------------|-----------------------------| | img1 | [str1] | [[list1], [list2]] | | img1 | [str2, str3] | [[list3], [list4]] | | img2 | [str3] | [[list5], ...
<python><dataframe><group-by>
2023-04-24 06:33:30
4
985
Yana
76,089,076
4,586,761
DFS recursively searching the values in a list of dictionaries for each key
<p>Given the list of dictionaries:</p> <pre><code>[{&quot;a&quot;: [&quot;b&quot;, &quot;c&quot;, &quot;d&quot;]}, {&quot;b&quot;: [&quot;e&quot;, &quot;z&quot;, &quot;g&quot;]}, {&quot;g&quot;: [&quot;c&quot;, &quot;f&quot;, &quot;z&quot;]}, {&quot;z&quot;: [&quot;w&quot;, &quot;y&quot;, &quot;x&quot;]}] </code><...
<python><depth-first-search>
2023-04-24 06:22:54
2
642
Maxwell Chandler
76,089,043
966,365
How can I add a progress indicator to numpy.loadtxt?
<p>I need to load very large text CSV files into RAM using numpy <a href="https://numpy.org/doc/stable/reference/generated/numpy.loadtxt.html" rel="nofollow noreferrer">loadtxt</a>. Is there a way to add a progress indicator to show that the file is being read? My code looks like this:</p> <pre><code>import numpy as np...
<python><numpy>
2023-04-24 06:18:16
2
322
tobi delbruck
76,089,003
12,883,179
Geopandas checking whether point is inside polygon
<p>I have ocean geopandas which contains 1 multipolygon (source: <a href="https://www.naturalearthdata.com/download/downloads/10m-physical-vectors/" rel="nofollow noreferrer">naturalearthdata.com</a>)</p> <p>I also have another dataframe that contains at lot of longitude and latitude information</p> <p>I want to add a ...
<python><pandas><geopandas>
2023-04-24 06:12:20
2
492
d_frEak
76,088,919
5,940,776
Downgrade setuptools inside tox dependencies
<p>I have a gdal dependency in my tests.</p> <p>I use rocky-linux 8. epel 8 provides gdal 3.0.4, so I must install the same version in python, but this version is incompatible with the latest version of setuptools. (See: <a href="https://stackoverflow.com/questions/69123406/error-building-pygdal-unknown-distribution-op...
<python><setuptools><gdal><tox><gdal-python-bindings>
2023-04-24 05:56:03
1
896
Balaïtous
76,088,868
11,258,263
Cast from Python object back to struct
<p>I have declared a struct for embedded Python via:</p> <pre class="lang-cpp prettyprint-override"><code>struct Report { int Count; }; PYBIND11_EMBEDDED_MODULE(embedded, m) { pybind11::class_&lt;Report&gt;(m, &quot;Report&quot;) .def(pybind11::init&lt;&gt;()) .def_readwrite(&quot;Count&quot;, ...
<python><c++><pybind11>
2023-04-24 05:46:56
0
470
DLT
76,088,766
3,735,871
Spark submit error - cannot load main class from jar - PySpark
<p>I'm running the below spark submit command, and got an error that says <code>cannot load main class from jar file:/path/to/dependency.zip</code> I'm struggling to understand why it looks for main class in the zip file, since I supplied the <code>application.py</code>, which has the main class?</p> <p>What did I miss...
<python><apache-spark><pyspark><spark-submit>
2023-04-24 05:23:42
0
367
user3735871
76,088,611
9,542,989
Fuzzy Matching Optimization in PySpark
<p>I am trying to perform some fuzzy matching on some data through PySpark. To accomplish this I am using the <code>fuzzywuzzy</code> package and running it on Databricks.</p> <p>My dataset is very simple. It is stored in a CSV file and contains two columns: Name1 and Name2. However, I don't just want to compare the tw...
<python><pyspark><databricks><fuzzywuzzy><fuzzy-comparison>
2023-04-24 04:37:02
2
2,115
Minura Punchihewa
76,088,262
754,136
Reproducibility with multithreading and multiprocessing in Python (how to fix random seed)
<p>My code does the following:</p> <ul> <li>Starts processes to collect data</li> <li>Starts processes to test model</li> <li>One thread takes care of training (read data from collect processes)</li> <li>One thread takes care of testing (read data from test processes)</li> <li>Every time the training thread does a step...
<python><multithreading><multiprocessing><random-seed><reproducible-research>
2023-04-24 02:36:50
2
5,474
Simon
76,088,230
9,049,108
Which version of SageMath was I using? In 2018 that allowed this code to run?
<p>At some point the code bellow was working but now I need to replace the map line with something else. I'm wondering what version of SageMath I was using that my code was working. It may have been SageMath for python2 because It also had xrange() in the code. Additionally the new version throws errors on ^ ^ which wa...
<python><version-control><sage>
2023-04-24 02:26:30
1
576
Michael Hearn
76,088,055
9,580,869
Groupby a dataframe on column A and column B and sum column C based on few values of column A
<p>For a dataframe which looks like the below</p> <pre><code>A B C foo 1 2 foo 3 3 bar 3 4 bar 3 4 else 4 5 else 2 1 </code></pre> <p>We need to groupby the dataframe based on column A and sum values in column B only if the values in column A = 'foo' or 'bar', but sum all the v...
<python><pandas><dataframe><group-by><sum>
2023-04-24 01:26:27
2
1,212
zsh_18
76,087,984
16,895,246
why is re.findall regex matching only one group?
<p>I am attempting to build a regex to parse some HTTP requests e.g.</p> <pre><code>146.204.224.152 - feest6811 [21/Jun/2019:15:45:24 -0700] &quot;POST /incentivize HTTP/1.1&quot; 302 4622 197.109.77.178 - kertzmann3129 [21/Jun/2019:15:45:25 -0700] &quot;DELETE /virtual/solutions/target/web+services HTTP/2.0&quot; 203 ...
<python><regex>
2023-04-24 01:01:36
0
1,441
Pioneer_11
76,087,822
111,808
How can I use Tkinter with Python 3.11.3 that I built from source?
<p>How can I use <code>Tkinter</code> with Python 3.11.3 that I built from source?</p> <p>I have another version of Python (3.10.6) that came with my distribution (Pop!_OS) and on that version I can successfully import tkinter.</p> <p>But when I run Python 3.11.3 that I build from source I get the following messages:</...
<python><python-3.x><tkinter>
2023-04-23 23:59:42
1
3,595
Richard Fuhr
76,087,725
2,658,898
Calling Super when Dynamically Create Types using Multiclass Inheritance in Python
<p>How does one dynamically create a <code>type</code> that inherits from multiple base classes via cooperative inheritance? I have tried a couple options, each of which have had their own issues. My current code works like so:</p> <pre><code> cls_map = {&quot;SomeClass&quot; : SomeClass, &quot;OtherClass&quot; : Ot...
<python><python-3.x><dynamic><multiple-inheritance>
2023-04-23 23:22:53
1
492
CCD
76,087,576
2,169,327
Polars - invalid column type integer when reading sqlite database
<p>I tried to use Polars to read data from my SQLite database:</p> <pre><code>conn = 'sqlite://'+pathToDB querystring = &quot;SELECT * FROM table1&quot; msgt1SAT = pl.read_database(querystring, conn) </code></pre> <p>However I got an error:</p> <pre><code>RuntimeError: Invalid column type Integer at index: 1, name: uni...
<python><sqlite><python-polars>
2023-04-23 22:27:49
0
2,348
bjornasm
76,087,259
19,467,973
How to do data checks in the fastapi endpoint correctly
<p>I am writing a small api for creating different objects. And I wanted to carry out a routine check that can be found on every website with registration. But I came across such an unpleasant use of the if operator.</p> <pre><code>class AuthenticateController(RegisterCRUD, Controller): prefix = &quot;/api/auth&quo...
<python><http><fastapi>
2023-04-23 21:01:53
0
301
Genry
76,087,171
6,830,361
How to extract line with specific word from text file
<p>I need to extract all lines from a text file that contain the word true.</p> <p>Example line in text file looks like this:</p> <pre class="lang-none prettyprint-override"><code>fficialprobl3mzombie@gmail.com | Full Name = Richard Shafer | Points Saved = false | Points = 0 | Member = True fficialprobl3mzombie@gmail...
<python>
2023-04-23 20:40:40
1
419
Leo Bogod
76,087,059
10,452,700
What is the best practice to chain DL model into sklearn Pipeline() stages and still access hyperparameters e.g, batch_size \ epochs in pipeline?
<p>I want to experiment DL regression model over time-series data by implementing the model using <a href="/questions/tagged/sklearn" class="post-tag" title="show questions tagged &#39;sklearn&#39;" aria-label="show questions tagged &#39;sklearn&#39;" rel="tag" aria-labelledby="tag-sklearn-tooltip-container">sklearn</a...
<python><machine-learning><scikit-learn><pipeline><hyperparameters>
2023-04-23 20:14:18
1
2,056
Mario
76,086,914
2,236,231
Receiving multiline string from user input in a python telegram bot
<p>I am using python-telegram-bot. This is my Python handler for the CommandHandler:</p> <pre><code>async def bulk_q(update: Update, context: ContextTypes.DEFAULT_TYPE) -&gt; None: questions_user = ' '.join(context.args[:]) </code></pre> <p>It is intended to allow the user to send questions in bulk, one question at...
<python><python-telegram-bot>
2023-04-23 19:44:24
2
1,099
Geiser
76,086,748
11,546,773
How to combine columns in dask horizontally?
<p>I'm trying to combine multiple columns into 1 column with python Dask. However I don't seem to find an (elegant) way to combine columns into a list.</p> <p>I only need to combine column &quot;b - e&quot; into 1 column. Column &quot;a&quot; needs to stay exactly as it is now. I've tried using apply to achieve this. D...
<python><pandas><dataframe><dask>
2023-04-23 19:08:33
1
388
Sam
76,086,714
16,510,888
Can I set a variable with the result of "match"?
<p>Setting a variable with a <code>match</code> can be done simply like this:</p> <pre class="lang-py prettyprint-override"><code>Mode = 'fast' puts = '' match Mode: case &quot;slow&quot;: puts = 'v2 k5' case &quot;balanced&quot;: puts = 'v3 k5' case &quot;fast&quot;: puts = 'v3 k7' ...
<python>
2023-04-23 19:01:55
3
364
baronsec
76,086,623
1,595,350
Query a JSON object with Python based on two or more filters on different levels
<p>I am a bit lost when trying to query a json object which looks like the following. I want to query by the sub key <code>&quot;type&quot;: &quot;header1&quot;</code> and the sub sub key <code>&quot;type&quot;: &quot;simpletext&quot;</code>. And i want to receive all results where i can loop through.</p> <p>This is t...
<python><json>
2023-04-23 18:41:20
1
4,326
STORM
76,086,317
6,431,715
Num.to_bytes - OverflowError: int too big to convert
<p>In order to convert <strong>-10947726235</strong> into byte array I ran:</p> <pre><code>Num = -10947726235 ByteArray = Num.to_bytes(4, byteorder='little', signed=True) </code></pre> <p>I got:</p> <pre class="lang-none prettyprint-override"><code>OverflowError: int too big to convert </code></pre> <p>Can you please a...
<python><byte>
2023-04-23 17:39:00
1
635
Zvi Vered
76,085,977
1,421,907
Why the efficiency of numpy is decreasing fastly?
<p>I have a question about efficiency in numpy when increasing the number of elements in a matrix/vector operation.</p> <p>If you look at the example below, for a number of elements in the array of <code>10_000</code> the time length of each step is approximatively the same. Operations, 31, 32 and 33 took about 450ms. ...
<python><numpy>
2023-04-23 16:22:45
1
9,870
Ger
76,085,850
3,593,301
Uploading a Text File to Azure Blob with Python - Local Variable in Byte Format Error
<p>I'm currently working on a project where I need to upload a local text file to an Azure Blob using Python. I wrote the following code to accomplish this:</p> <pre><code>def upload_blob(self, file_name, local_file_path): file_name = 'upload_test.txt' blob_service_client = BlobServiceClient.from_connection_string(self...
<python><azure><file-upload><azure-storage>
2023-04-23 15:55:48
1
492
Shadiqur
76,085,734
12,226,377
Regex not retuning the expected results
<p>I have a problem where I am using some regular expression patterns to identify key themes in my &quot;Feedback&quot; column.</p> <p>I am using the following code:</p> <pre><code># creating regex patterns pattern1 = re.compile(r'respond query|email|fast response|email|response time|responses email slow|long time|long...
<python><pandas>
2023-04-23 15:31:34
2
807
Django0602