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,315,486
6,930,340
Map values in a pandas series according to MultiIndex values
<p>I have a <code>pd.Series</code> with a multiindex.</p> <pre><code>import pandas as pd # Create the Series data = { (&quot;long_only&quot;, &quot;Security_1&quot;): -1, (&quot;long_only&quot;, &quot;Security_3&quot;): 1, (&quot;long_only&quot;, &quot;Security_5&quot;): 1, (&quot;short_only&quot;, &qu...
<python><pandas><dictionary>
2023-05-23 13:44:05
2
5,167
Andi
76,315,436
13,647,125
HTML iframe with dash output
<p>I have 2 pretty simple dashboards and I would like to run this two dashboards with flask using main.py for routing.</p> <p>app1.py</p> <pre><code>import dash from dash import html, dcc app = dash.Dash(__name__) app.layout = html.Div( children=[ html.H1('App 1'), dcc.Graph( id='graph...
<python><html><iframe><plotly-dash>
2023-05-23 13:38:13
1
755
onhalu
76,315,421
19,556,911
FME - How to manipulate attribute values of all features (in PythonCaller ?)
<p>I would like to manipulate whole ''column'' (list of attribute values) in a PythonCaller but I don't really understand how I can do that. For example in the example here below, I create a new attribute in <code>input</code> (=iterating over each each feature, right ?) ; what I am trying to do :</p> <ol> <li><p>...
<python><fme>
2023-05-23 13:36:40
0
327
mazu
76,315,335
5,640,161
Can a Python package and its corresponding PyPi project have different names?
<p>For example, I'm wondering how is it possible that <code>scikit-learn</code> is the name of a PyPi package while the actual Python module is named <code>sklearn</code>. The reason I'm asking is that I have a local Python package <code>packageA</code> that I can't upload to PyPi since that name happens to already be ...
<python><pip><pypi><python-packaging>
2023-05-23 13:28:06
1
863
Tfovid
76,315,248
10,413,428
Errors when using | instead of typing.Union in dataclasses type hints
<p>I am using Python 3.11.3 on Linux and currently for my union types in dataclasses I am using the following type hints:</p> <pre class="lang-py prettyprint-override"><code>from dataclasses import dataclass from typing import Union import numpy as np @dataclass class Test: data: Union[np.array, list[tuple]] i...
<python><python-3.x><python-3.11>
2023-05-23 13:18:28
0
405
sebwr
76,315,246
9,571,575
How to count results with SQLAlchemy Select API?
<p>All answers to this question (i.e. counting results from queries in SQLAlchemy) that I could find, where given for Query API. But in my application I am using AsyncSession which does not support query and I have to use select. I have no idea how to get count of all results from query using select API as count() simp...
<python><sqlalchemy><fastapi>
2023-05-23 13:18:26
1
831
ugabuga77
76,315,191
1,934,212
Read arrays from csv
<p>Parsing a csv file with the content</p> <pre><code>time,X,Y,status1,status2 1659312306212,&quot;[-53, -70]&quot;,&quot;[-1512, -1656]&quot;,-65,18.44140625 1659312421965,&quot;[25, -34]&quot;,&quot;[-1532, -1520]&quot;,-71,18.43359375 </code></pre> <p>using</p> <pre><code>import pandas as pd df = pd.read_csv(&quot;h...
<python><pandas>
2023-05-23 13:11:47
1
9,735
Oblomov
76,315,110
736,312
Extraction of position of an image in a PDF file
<p>I am using pyMuPdf library to extract images from a pdf file. I want to get the position of the images (origin) and the size of them.<br> I could get the sizes. However I can't get the position correctly using:</p> <pre><code>def extract_images_from_pdf(_input_pdf_file_name, _output_folder): _pdf_file_document =...
<python><pymupdf>
2023-05-23 13:03:33
1
796
Toyo
76,314,996
1,632,519
Update requirements.txt without installing packages
<p>I have a <code>requirements.txt</code> with dependencies pinned using <code>==</code>. The pinning using <code>==</code> is a requirement to ensure reproducibility. I'd like to update all of them to the most recent version. I do not want to install any of them, I only want to modify <code>requirements.txt</code></p>...
<python><pip><requirements.txt>
2023-05-23 12:56:25
1
2,126
Philippe
76,314,792
3,842,823
Python: Catching (and then re-throw) warnings from my code
<p>I want to catch and then re-throw warnings from my Python code, similarly to <code>try</code>/<code>except</code> clause. My purpose is to catch the warning and then re-throw it using my logger.</p> <p>The warnings are issued from whatever packages I'm using, I would like something that is totally generic, exactly l...
<python><python-3.x><warnings>
2023-05-23 12:31:52
1
1,951
Xxxo
76,314,724
5,287,366
Annotations - a method is given a type as a generic argument. Annotate the return type that should be exacly the same as given in the argument
<p>Similar to a <code>classmethod</code>, there is a method that takes a generic type as the first argument (not an object of the type). I want to annotate its return type as precisely the same type that is given in the first argument.</p> <pre><code>ChildT= typing.TypeVar(&quot;ChildT&quot;) def load_child(child_type...
<python><python-typing>
2023-05-23 12:24:07
1
485
JD.
76,314,711
17,877,528
Best approach to fix this JSON file
<p>i have a huge JSON file that looks like this. I'm pasting an image because i think it's better to see the problem.</p> <p><a href="https://i.sstatic.net/XY1Md.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/XY1Md.png" alt="enter image description here" /></a></p> <p>It's not inside brackets and there'...
<python><json><format>
2023-05-23 12:22:40
0
774
José Carlos
76,314,512
13,836,083
AsyncIO appears to be slower than multithreaded even if tasks are only bound to I/O
<p>I am creating 8000 text files and writing 100 bytes of data to each file in both asyncio and multithread version. I was expecting asyncio version of the code to be completed before multithread version of the code , as all tasks related to I/O bound and I have understood that asyncio will perform better but the situa...
<python><multithreading><python-asyncio>
2023-05-23 12:00:11
1
540
novice
76,314,511
2,072,457
s3fs.put into empty and non-empty S3 folder
<p>I am copying folder to <code>S3</code> with <code>s3fs.put(..., recursive=True)</code> and I experience weird behavior. The code is:</p> <pre><code>import s3fs source_path = 'foo/bar' # there are some &lt;files and subfolders&gt; inside target_path = 'S3://my_bucket/baz' s3 = s3fs.S3FileSystem(a...
<python><amazon-s3><python-s3fs>
2023-05-23 11:59:50
1
969
Pepacz
76,314,456
20,220,485
How do you add a condition to a generator function based on the previous output?
<p>I am trying to reconcile <code>id_label_token</code>, which is a list of tuples containing a tokenized string, label, and character index, with the original string <code>string</code>.</p> <p>I have some working code that uses a generator to do this. However, it can't handle instances where there is a label for a to...
<python><string><iteration><generator><tokenize>
2023-05-23 11:54:27
2
344
doine
76,314,345
10,755,032
TypeError: Input has ['int', 'str'] as feature name / column name types
<p>I am trying to fit a ML model and I am getting the following error:</p> <p><code>TypeError: Feature names are only supported if all input features have string names, but your input has ['int', 'str'] as feature name / column name types. If you want feature names to be stored and validated, you must convert them all ...
<python><machine-learning><scikit-learn>
2023-05-23 11:40:06
1
1,753
Karthik Bhandary
76,314,312
774,575
Is it possible to use 'sharey=row' with 'subplot_mosaic'
<p>Is there a possibility to use <a href="https://matplotlib.org/stable/api/_as_gen/matplotlib.pyplot.subplots.html" rel="nofollow noreferrer">sharey='row'</a> with <code>plt.subplot_mosaic()</code>? I know I could <a href="https://matplotlib.org/stable/api/_as_gen/matplotlib.axes.Axes.sharey.html" rel="nofollow norefe...
<python><matplotlib>
2023-05-23 11:36:36
0
7,768
mins
76,314,287
12,415,855
Selenium / click on "View More"-button not possible?
<p>i try to click on the &quot;Click More&quot; - Button on this site: <a href="https://www.hublot.com/en-ch/find-your-hublot/big-bang" rel="nofollow noreferrer">https://www.hublot.com/en-ch/find-your-hublot/big-bang</a></p> <p><a href="https://i.sstatic.net/x698v.png" rel="nofollow noreferrer"><img src="https://i.ssta...
<python><selenium-webdriver>
2023-05-23 11:34:39
1
1,515
Rapid1898
76,314,278
4,045,275
Why is a SQLite Select statement so much slower than numpy.select? Any way to speed it up?
<h3>What I am trying to do</h3> <p>I am trying to export and import tables between <code>pandas</code> and a <code>sqlite</code> database. The reasons for doing this are a combination of:</p> <ul> <li>needing to store certain data in sqlite format, and</li> <li>finding the sqlite syntax clearer and easier to read than ...
<python><pandas><performance><sqlite><sqlalchemy>
2023-05-23 11:33:17
1
9,100
Pythonista anonymous
76,314,273
9,589,875
Is it possible to install a single submodule from Matplolib?
<p>I am using the submodule pyplot from Matplotlib and then packaging my app into an installer. I want to limit the size of this installer, is it possible to install this submodule on its own or a subset of Matplotlib? Currently I'm including the entire Matplotlib library in my installer which seems very excessive and ...
<python><matplotlib><pip><package>
2023-05-23 11:33:01
1
905
MJ_Wales
76,314,229
7,800,760
How to download spaCy models in a Poetry managed environment
<p>I am writing a Python Jupyter notebook that does some NLP processing on Italian texts.</p> <p>I have installed spaCy 3.5.3 via Poetry and then attempt to run the following code:</p> <pre class="lang-py prettyprint-override"><code>import spacy load_model = spacy.load('it_core_news_sm') </code></pre> <p>The <code>impo...
<python><nlp><spacy><python-poetry><virtual-environment>
2023-05-23 11:29:10
1
1,231
Robert Alexander
76,314,184
8,671,089
Unable to connect to kafka running in docker container
<p>I am unable to connect to kafka running in container.</p> <p>I have .env file</p> <pre><code>KAFKA_BROKER_ID=1 KAFKA_ENABLE_KRAFT=true KAFKA_CFG_PROCESS_ROLES=broker,controller KAFKA_CFG_CONTROLLER_LISTENER_NAMES=CONTROLLER KAFKA_CFG_CONTROLLER_QUORUM_VOTERS=1@127.0.0.1:9094 ALLOW_PLAINTEXT_LISTENER=yes KAFKA_CFG_LI...
<python><docker><apache-kafka><kafka-python>
2023-05-23 11:23:29
0
683
Panda
76,314,158
11,357,695
Spyder Kernels, anaconda and Python 3.9
<p>--</p> <p>Edit - pip uninstall not working</p> <pre><code>pip uninstall primer3 WARNING: Ignoring invalid distribution -umpy (c:\anaconda3\lib\site-packages) WARNING: Ignoring invalid distribution -umexpr (c:\anaconda3\lib\site-packages) WARNING: Ignoring invalid distribution -iopython (c:\anaconda3\lib\site-package...
<python><python-3.x><installation><anaconda><spyder>
2023-05-23 11:20:20
1
756
Tim Kirkwood
76,313,775
7,505,228
Combine more than two dict at once (summing the values that appear in more than one dict)
<p>Inspired from <a href="https://stackoverflow.com/questions/11011756/is-there-any-pythonic-way-to-combine-two-dicts-adding-values-for-keys-that-appe">this question</a></p> <p>I have an arbitrary number of dictionaries (coming from a generator)</p> <pre><code>a = {&quot;a&quot;: 1, &quot;b&quot;: 2, &quot;c&quot;: 3} ...
<python><dictionary>
2023-05-23 10:33:19
3
2,289
LoicM
76,313,685
10,755,032
Python Pandas dataframe - KeyError: 'date'
<p>I have looked this one up: <a href="https://stackoverflow.com/questions/52341766/keyerror-date">KeyError: &#39;Date&#39;</a> and this one as well: <a href="https://stackoverflow.com/questions/62889178/pandas-dataframe-keyerror-date">Pandas DataFrame - KeyError: &#39;date&#39;</a> it did not help. I am getting KeyErr...
<python><pandas><dataframe><date>
2023-05-23 10:24:50
2
1,753
Karthik Bhandary
76,313,592
8,932,411
import langchain => Error : TypeError: issubclass() arg 1 must be a class
<p>I want to use langchain for my project.</p> <p>so I installed it using following command : <code>pip install langchain</code></p> <p>but While importing &quot;langchain&quot; I am facing following Error:</p> <pre><code>File /usr/lib/python3.8/typing.py:774, in _GenericAlias.__subclasscheck__(self, cls) 772 if se...
<python><nlp><data-science><chatbot><langchain>
2023-05-23 10:09:47
7
764
M. D. P
76,313,575
3,165,683
Widgets not rendering in Voila
<p>I have code which executes widgets fine in jupyter labs but does not render the widgets in voila. See the image for the example from the voila github. <a href="https://i.sstatic.net/1ISdd.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/1ISdd.png" alt="enter image description here" /></a></p> <p>Python...
<python><jupyter-notebook><ipywidgets><voila>
2023-05-23 10:07:17
0
377
user3165683
76,313,341
5,462,551
Is it possible to use pytest fixture that returns a list as parameters list of a test?
<p>Consider the following code example, which is an abstraction of real code that I have:</p> <pre class="lang-py prettyprint-override"><code>import os import pytest class Files: def __init__(self): self.file1 = &quot;file1&quot; self.file2 = &quot;file2&quot; self.file3 = &quot;file3&quot;...
<python><pytest>
2023-05-23 09:42:34
1
4,161
noamgot
76,313,229
11,155,419
Mock a function before importing a module
<p>I have an Airflow DAG that</p> <pre><code># my_dag.py from my_module import my_function MY_VAR = 'Hello World' with DAG( schedule_interval=my_function(), ... ): .... </code></pre> <p>and then I have a test that imports from <code>my_dag</code>:</p> <pre><code># test_my_dag.py from my_dag import MY_...
<python><airflow><pytest>
2023-05-23 09:29:40
2
843
Tokyo
76,313,015
4,495,790
How to interpret sklearn's NearestNeighbors' kneighbors on another array?
<p>I used to find nearest neighbours in data array <code>X</code> with <code>sklearn.neighbors.NearestNeighbors</code> like this:</p> <pre><code>from sklearn.neighbors import NearestNeighbors import numpy as np nn = NearestNeighbors(n_neighbors=2).fit(X) distances, indices = nn.nkneighbors(X) </code></pre> <p>In this c...
<python><scikit-learn><nearest-neighbor>
2023-05-23 09:05:36
1
459
Fredrik
76,312,965
17,659,993
PyInstaller app with cefpython throws ERROR:icu_util.cc(133)] Invalid file descriptor to ICU data receiv
<p>I've been developing a <strong>Tkinter</strong> GUI application with <strong>CEFPython</strong> for browser integration. My application runs smoothly when executed as a Python script. However, I've been running into issues when trying to compile it into a standalone executable using <strong>PyInstaller</strong>.</p>...
<python><tkinter><pyinstaller><cefpython>
2023-05-23 09:00:52
1
333
Cassano
76,312,923
8,087,322
Include variable content inline in documentation
<p>I want to have something in my document like</p> <blockquote> <p>This module uses the constant of 150000 m/s as the speed of light.</p> </blockquote> <p>where the 150000 was generated programmatically from the module. This would reduce the maintainance of my documentation, as often just these numbers get updated.</p...
<python><python-sphinx><restructuredtext>
2023-05-23 08:56:32
0
593
olebole
76,312,879
1,497,720
Avoid changing powershell script directory when running python virtualenv
<p>for the powershell script below</p> <pre><code>function jl1 { cd C:\Users\MyUser Envs\huggingface\Scripts\activate cd &quot;D:\Working&quot; jupyter lab } Set-Alias jl jl1 </code></pre> <p>I always run <code>jl</code> on my active directory</p> <pre><code>D:\Working123 &gt; jl </code></pre> <p...
<python><python-3.x><powershell><virtualenv>
2023-05-23 08:51:24
1
18,765
william007
76,312,844
1,021,819
How can I exit Dask cleanly?
<p>I am starting Dask with a containerized LocalCluster but on closing the cluster and client I usually (but intermittently) receive a diverse range of exceptions - see for example the one below.</p> <p>The cleanup code is:</p> <pre class="lang-py prettyprint-override"><code>cluster.close() client.close() </code></pre>...
<python><dask><dask-distributed><contextmanager>
2023-05-23 08:45:41
1
8,527
jtlz2
76,312,641
6,145,828
Apache Beam: merge branches after write outputs
<p>I am trying to write an apache beam pipeline where the pipeline divides into three branches, where each branch writes into BigQuery, and then merges into one to write another Bigquery Table for logging.</p> <p>I am unable to merge the branches, here is the code:</p> <pre><code>pipeline_options = PipelineOptions(None...
<python><google-cloud-dataflow><apache-beam>
2023-05-23 08:21:31
1
830
Francesco Pegoraro
76,312,424
19,950,360
latest version pyarrow can't serialize and deserialize? (module 'pyarrow' has no attribute 'serialize')
<p>I want my bigquery table data saving GCS to an arrow file(.arrow):</p> <pre class="lang-py prettyprint-override"><code>import pyarrow as pa query = f&quot;&quot;&quot; SELECT * FROM `{table_path}.{table_id}` &quot;&quot;&quot; query_results = b_client.query(query).result() table = query_results.to_...
<python><google-cloud-platform><serialization><google-cloud-storage><pyarrow>
2023-05-23 07:54:02
1
315
lima
76,312,410
18,551,983
How to generate a PSSM matrix using PSI BLAST from BioPython
<p>Is there any to generate PSSM matrix from PSI BLAST using the python package BioPython? Indeed, I have 8000 sequences in .fasta file. Every sequence length is also long?</p> <p>I am using this below code:</p> <pre><code>for fasta in files: alignment = AlignIO.read(fasta, &quot;fasta&quot;) summary_align = AlignInfo....
<python><python-3.x><biopython><ncbi>
2023-05-23 07:52:28
1
343
Noorulain Islam
76,312,254
2,132,157
How can I have a list of all the file used by a Jinja2 template?
<p>I have a jinja2 template that uses other templates with <code>include</code> and <code>extends</code> statements. I would like to retrieve a list of all the templates that are involved in the construction of the template.</p> <pre><code>import jinja2 environment = jinja2.Environment() template = environment.get_temp...
<python><templates><jinja2>
2023-05-23 07:31:45
1
22,734
G M
76,312,142
11,426,624
groupby with dictionary comprehension
<p>I have a dataframe</p> <pre><code>df = pd.DataFrame({'id':[1,2,3,1, 1], 'time_stamp_date':['12','12', '12', '14', '14'], 'sth':['col1','col1', 'col2','col2', 'col3']}) d time_stamp_date sth 0 1 12 col1 1 2 12 col1 2 3 12 col2 3 1 14 col2 4 1 14 col3 </c...
<python><pandas><dataframe><group-by><aggregation>
2023-05-23 07:13:38
3
734
corianne1234
76,311,912
364,088
How to install wheel while using a python virtual environment?
<p>I followed instructions to install a wheel while my virtualenv was active. When I went to use it I found it wasn't available but when I deactivated the venv it was, so it appears that although the venv was active during the install the package was installed into 'plain old python'.</p> <p>How can I install a wheel a...
<python><ubuntu><virtualenv><python-3.9><python-wheel>
2023-05-23 06:40:10
1
8,432
shearichard
76,311,807
1,167,194
AttributeError: 'Adam' object has no attribute 'build' during unpickling
<p>I'm training a Keras model and saving it for later use using pickle.</p> <p>When I unpickle I get this error:</p> <p><code>AttributeError: 'Adam' object has no attribute 'build'</code></p> <p>Here's the code:</p> <pre><code>from tensorflow.keras.models import Sequential from tensorflow.keras.layers import Dense impo...
<python><tensorflow><keras><pickle>
2023-05-23 06:25:40
2
3,659
ColBeseder
76,311,676
1,804,024
Access gRPC python server with "localhost" security in WSL2 docker from windows
<p>The issue is this. I am getting a zip file made by pyinstaller. Inside the file there is a setting making the server listen only to localhost <code>server.add_insecure_port(f'localhost:{port_num}')</code>. I want to run this python file from a centos docker. Docker is running on WSL2.</p> <p>So far I was able to run...
<python><docker><grpc><windows-subsystem-for-linux>
2023-05-23 06:05:21
1
457
Andrey Dobrikov
76,311,461
11,098,908
Incorrect value returned by tkinter method canvas.winfo_width
<p>I've just started learning how to create a game with <code>tkinter</code>. I found it so difficult to find information for all the available methods in the module. This <a href="https://tcl.tk/man/tcl8.6/" rel="nofollow noreferrer">website</a> seemed comprehensive but was difficult to navigate to find relevant info ...
<python><tkinter>
2023-05-23 05:16:33
1
1,306
Nemo
76,311,436
2,966,197
How does Llamaindex elasticsearch vector work
<p>I am building an app to use Opensearch as vecotr store with Llamaindex using <a href="https://gpt-index.readthedocs.io/en/latest/examples/vector_stores/OpensearchDemo.html" rel="nofollow noreferrer">this</a> example. Here is the code I have:</p> <pre><code> endpoint = getenv(&quot;OPENSEARCH_ENDPOINT&quot;, &quot...
<python><elasticsearch><amazon-opensearch><llama-index>
2023-05-23 05:10:20
1
3,003
user2966197
76,311,313
1,040,718
django: request.POST is empty
<p>I have the following rest API endpoint:</p> <pre><code>def post(request, *args, **kwargs): print(request.POST) short_description = request.POST.get(&quot;short_description&quot;, &quot;&quot;) long_description = request.POST.get(&quot;long_description&quot;, &quot;&quot;) # rest of the code goes here </...
<python><django><rest><django-rest-framework><django-views>
2023-05-23 04:32:20
2
11,011
cybertextron
76,311,170
188,331
Compute corpus-level BLEU score for translations in Python via SacreBLEU
<p>I have more than 100K pairs of the parallel corpus. Samples:</p> <pre><code>[ [&quot;How are you doing today&quot;, &quot;comment allez-vous aujourd'hui&quot;], [&quot;Look out! He is a thief&quot;, &quot;Chercher! C'est un voleur&quot;], ...(and a lot more pairs of English-French translations) ] </code></pr...
<python><bleu>
2023-05-23 03:44:40
1
54,395
Raptor
76,311,127
6,824,121
SyntaxError: (unicode error) 'unicodeescape' codec can't decode bytes in position
<p>I saw here <a href="https://stackoverflow.com/a/35651859/6824121">https://stackoverflow.com/a/35651859/6824121</a> that you can launch python script directly in your terminal in <strong>windows</strong> like this:</p> <pre><code>&gt; python -c exec(&quot;&quot;&quot;import sys \nfor r in range(10): print('rob') &quo...
<python><windows><unicode>
2023-05-23 03:30:19
1
1,736
Lenny4
76,310,993
17,560,347
Pickling tuple of ndarrays which share memory consumes double space
<pre class="lang-py prettyprint-override"><code>import numpy as np import pickle a = np.random.rand(4000) b = a.T assert np.shares_memory(a, b) tup = (a, b) s = pickle.dumps(tup) print(len(s)) # 64187 s1 = pickle.dumps(a) print(len(s1)) # 32151 </code></pre> <p>Since <code>a</code> and <code>b</code> share the same...
<python><numpy><serialization><pickle>
2023-05-23 02:44:18
0
561
吴慈霆
76,310,974
4,399,016
Extracting a CSV file from XML Response
<p>I have this code that returns an XML response.</p> <pre><code>import requests url = &quot;https://www-genesis.destatis.de/genesisWS/web/ExportService_2010?method=TabellenExport&amp;kennung=DEB924AL95&amp;passwort=P@ssword123&amp;name=42151-0002&amp;bereich=Alle&amp;format=csv&amp;strukturinformation=false&amp;kompr...
<python><pandas><csv><request><xml-parsing>
2023-05-23 02:36:38
2
680
prashanth manohar
76,310,847
815,653
Issues with "!pip install PyDither" on Google colab
<p>when i did &quot;!pip install PyDither&quot; on Google colab, I got the following error message. How can I fix it?</p> <pre><code>Looking in indexes: https://pypi.org/simple, https://us-python.pkg.dev/colab-wheels/public/simple/ Collecting PyDither Downloading PyDither-0.0.1.tar.gz (2.2 kB) Preparing metadata (s...
<python><opencv><pip>
2023-05-23 01:53:22
1
10,344
zell
76,310,718
3,427,777
pandas: mark duplicate rows using subset of MultiIndex levels, not columns
<p>I have a <code>df</code> with a many-leveled <code>MultiIndex</code>. Early on I need to mark certain rows to keep; in subsequent sorting and processing these rows will always be kept.</p> <p>I have working code, but it's not very attractive and I'm wondering if there's a prettier / more efficient way to do it.</p> ...
<python><pandas>
2023-05-23 01:07:25
2
22,862
fantabolous
76,310,696
2,745,148
Django staticfiles.W004 warning when using os.path.join
<p>I'm getting this warning:</p> <blockquote> <p>?: (staticfiles.W004) The directory '/home/user/Desktop/Projects/project/project/project/static' in the STATICFILES_DIRS setting does not exist.</p> </blockquote> <p>But only when I use this definition for the staticfiles dir</p> <pre><code>BASE_DIR = Path(__file__).reso...
<python><django><os.path>
2023-05-23 00:57:01
0
813
Chuox
76,310,662
3,476,463
calculate distance from address using geopandas
<p>I have the python 3.7 code below. I'm using it to calculate the distance in miles between a point that I specify, the target_address, and a couple points that I have in a pandas dataframe. The code uses the latitude and longitude of the street address to create a shapely point and then calculates the difference in...
<python><dataframe><geopandas><geopy>
2023-05-23 00:43:48
1
4,615
user3476463
76,310,625
8,311,330
Loss function does not train
<p>We are training a QuestionAnswering model for the SQUAD v2 dataset.</p> <p>A RoBERTa encoder, with a classifier on top. Predicting the answer span works perfectly. However, we wanted to add a front classifier to predict the answerability of a question (as suggested in the paper &quot;Retrospective Reader for Machine...
<python><machine-learning><pytorch><nlp><classification>
2023-05-23 00:30:35
1
960
Daan Seuntjens
76,310,591
1,224,336
Why does VSCode try running wsl.exe when debugging an Azure Function?
<p>I'm trying to work through the Microsoft Azure Functions tutorial <a href="https://learn.microsoft.com/en-us/azure/azure-functions/create-first-function-vs-code-python" rel="nofollow noreferrer">Quickstart: Create a function in Azure with Python using Visual Studio Code</a> and I'm getting stuck on the &quot;Run the...
<python><visual-studio-code><azure-functions>
2023-05-23 00:14:51
1
687
Ray Depew
76,310,575
3,247,006
How to make the urls with and without a language prefix work in Django i18n?
<p>This is my <code>django-project</code> as shown below. *I'm learning <a href="https://docs.djangoproject.com/en/4.2/topics/i18n/translation/" rel="nofollow noreferrer">Translation</a> with <strong>Django 4.2.1</strong>:</p> <pre class="lang-none prettyprint-override"><code>django-project |-core | |-settings.py |...
<python><django><django-views><django-urls><django-i18n>
2023-05-23 00:09:22
1
42,516
Super Kai - Kazuya Ito
76,310,548
12,548,458
argparse: How to use required positionals and subparsers together?
<p>I'm encountering a simple use-case that <code>argparse</code> surprisingly doesn't seem to handle. I would like to have a required positional argument in addition to having multiple subparsers. The rationale is that this CLI application supports one use-case very readily with a concise syntax, with more granular opt...
<python><argparse>
2023-05-22 23:57:16
1
3,289
dlq
76,310,533
3,482,266
How to fix "Trainer: evaluation requires an eval_dataset" in Huggingface Transformers?
<p>I’m trying to do a finetuning without an evaluation dataset. For that, I’m using the following code:</p> <pre><code>training_args = TrainingArguments( output_dir=resume_from_checkpoint, evaluation_strategy=&quot;epoch&quot;, per_device_train_batch_size=1, ) def compute_metrics(pred: EvalPrediction): ...
<python><pytorch><huggingface-transformers><pre-trained-model><huggingface-trainer>
2023-05-22 23:54:01
5
1,608
An old man in the sea.
76,310,356
14,584,978
How do I refresh an excel query and get the results into a pandas datafame
<p>I need to access data in sharepoint files in python using the machine user's access to the file. I need pandas output and a reliable method to refresh the query. I am thinking of using excel to run SharePoint queries.</p> <p>I cannot use GraphAPI to do so.</p> <p>What are some options?</p>
<python><sharepoint><powerquery>
2023-05-22 23:00:55
1
374
Isaacnfairplay
76,310,336
11,001,751
What theme/styling is used in the Plotly Dash Documentation? Or: how to create a thoroughly "dark" Dash App
<p>Plotly's Dash has a very nice dark themed <a href="https://dash.plotly.com" rel="nofollow noreferrer">documentation</a>, whose styling however does not seem readily available to the user (the default Dash app is unstyled). I would like to create a dark themed Dash app whose components look pretty much like the Dash ...
<python><plotly-dash>
2023-05-22 22:53:43
1
1,379
Sebastian
76,310,293
880,874
I moved a working Python script from one server to another, but now it's suddenly not working
<p>I moved a working Python script to a new server and I am suddenly getting errors.</p> <p>I installed Python and all it's dependicies on the new server, but for some reason I get this error:</p> <pre><code>Exception has occurred: ObjectNotExecutableError Not an executable object: 'EXECUTE dbo.sp_GatherInventory' Attr...
<python><python-3.x><sqlalchemy>
2023-05-22 22:40:01
1
7,206
SkyeBoniwell
76,310,224
21,420,742
Getting count of a specific value grouped by ID in pandas
<p>I cam trying to get counts of everyone with a 1 in a specific column and tie the sum to a manager.</p> <p>DF</p> <pre><code> ID Full-Time Manager ID 101 0 103 102 1 103 103 1 110 104 0 107 105 1 103 106 1 ...
<python><python-3.x><pandas><dataframe><group-by>
2023-05-22 22:17:55
3
473
Coding_Nubie
76,310,185
3,595,231
selenium not able to click this dropdown link in my UI
<p>I have a selenium test case written in python, where the UI looks like this: <a href="https://i.sstatic.net/Q6Hvl.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Q6Hvl.png" alt="enter image description here" /></a></p> <p>As you may find, I want to click the drop-down button that is circled in red, th...
<python><selenium-webdriver><selenium-chromedriver>
2023-05-22 22:07:19
1
765
user3595231
76,310,061
12,144,502
Increasing The Amount Of Neurons In Hidden Layer
<p>I am working to understand how to build my own ANN from scratch.</p> <p>I have looked around and found a simple two layer architecture and the <code>init_parameters</code> function is like this.</p> <pre class="lang-py prettyprint-override"><code>def init_parameters(): W1 = np.random.normal(size=(10, 784)) * np....
<python><python-3.x><machine-learning><neural-network>
2023-05-22 21:38:25
1
400
zellez11
76,310,030
3,523,464
Fast Pandas column encoding
<p>I've been trying to speed up the following code that encodes Pandas columns as ints.</p> <pre><code> with cpu_pool as p: results = p.amap(encode_int_column, jobs) while not results.ready(): time.sleep(4) tmp_df = pd.DataFrame({k: v for k, v in results.get()}) </code></pre> <p>with <code>encode_in...
<python><pandas>
2023-05-22 21:30:23
2
2,382
sdgaw erzswer
76,309,931
662,911
Understanding the results of Python's timeit module
<p>I'm new to using Python's timeit module to benchmark code, but the results I'm getting make me think that I'm misunderstanding how to interpret the results.</p> <p>This question has two parts:</p> <p>Part A. In the code below, I'm using timeit to measure the speed of Python's <code>sort()</code> method for lists. In...
<python><benchmarking><timeit>
2023-05-22 21:10:51
2
3,292
Rebitzele
76,309,737
10,258,933
Parametric optimization in Python
<p>I have the following function which I wish to maximize:</p> <p><img src="https://chart.googleapis.com/chart?cht=tx&amp;chl=%5Clog%20%5Cmathcal%20L%20%3D%20%5Csum_%7Bn%2Cm%7D%20%5Clog(1%20%2B%20x_%7Bnm%7D%5Ctheta_n%20%5Cphi_m)" alt="1" /></p> <p>where each <img src="https://chart.googleapis.com/chart?cht=tx&amp;chl=x...
<python><scipy><scipy-optimize><scipy-optimize-minimize>
2023-05-22 20:38:43
2
806
Filip
76,309,688
1,964,489
Pandas: Add column with values matching keys from a dictionary
<p>I have a Pandas data frame with several columns including <code>date, address, value</code>, and <code>type</code>. I also have a dictionary with key: value pairs as <code>address: alias</code>. I want to create a new database which will have columns: <code>date, address, value, type, alias</code> in such a way tha...
<python><pandas>
2023-05-22 20:30:04
2
3,541
Ziva
76,309,664
11,666,502
How to import pandas df as variable into html
<p>I am using flask to write an app that displays a pandas df on part of a webpage. Here is my html template:</p> <pre><code>&lt;!--user_input.html--&gt; &lt;html&gt; &lt;body&gt; &lt;form action=&quot;&quot; method=&quot;post&quot;&gt; &lt;input type=&quot;text&quot; name=&quot;user_input&quot;...
<python><html><pandas><flask>
2023-05-22 20:26:23
0
1,689
connor449
76,309,647
8,584,998
PyAudio distorted recording when while loop too busy
<p>I have a Python script that monitors an audio stream in real time and uses a moving average to determine when there is audio and set start and stop points based on when it is above or below a given threshold. Because the script runs 24/7, I avoid excessive memory usage by removing part of the audio stream after abou...
<python><audio><real-time><pyaudio>
2023-05-22 20:23:08
1
1,310
EllipticalInitial
76,309,389
13,608,794
Python - tkinter.messagebox with DLL resource icons
<p>By default, <code>tkinter.messagebox</code> uses 4 icons located in <code>user32.dll</code> resource. (or other that look like that)</p> <img src="https://i.sstatic.net/OdUik.png"> <hr /> <p>However, when browsing resource DLL files in Nirsoft IconsExtract utility, I found some fancy icons located in <code>comres.dl...
<python><tkinter><icons><messagebox>
2023-05-22 19:38:26
1
303
kubinka0505
76,309,287
4,759,176
Python Flask, display an image stored as a binary blob in MySQL database
<p>I'm trying to display an image that is stored in a <code>LONGBLOB</code> column in a <code>MySQL</code> database, using Flask:</p> <p><strong>app.py</strong>:</p> <pre><code>@app.route('/get_image', methods=['GET']) def get_image(): args = request.args image_id = args.get('image_id') image = # code for ...
<python><python-3.x><flask>
2023-05-22 19:18:49
1
5,239
parsecer
76,309,194
1,717,931
find subsets in python that sum less than or equal a target value
<p>I've seen different variations of this problem and I am unable to get a solution to this particular one: &quot;Given a list of positive integers and a target t, find all maximal subsets whose sum is less than or equal to t. Each element must appear only as many times as they appear in the given input list&quot;</p> ...
<python><algorithm>
2023-05-22 19:03:19
1
2,501
user1717931
76,309,157
9,049,108
How to make a list of unique sets in python?
<p>I wanted to make a list of empty sets for my program. This works for making a list of unique zeros.</p> <pre><code>x=5 l=[0]*x print(l) m[0]=1 #[1,0,0,0,0] </code></pre> <p>If you try the same with sets or a list of list it doesn't work.</p> <pre><code>x=5 l=[set()]*x l[0].add(1) print(l) #[{1},{1},{1},{1},{1}] </co...
<python><list><set>
2023-05-22 18:56:10
0
576
Michael Hearn
76,308,912
3,045,182
Is it possible to get the entity from SQLAlchemys "do_orm_execute" event?
<p>We're trying to implement a History table for some select classes. All the queries are written for SQLAlchemy Core 1.x and passed to the <code>execute()</code> method on the <code>Session</code> object. That means we cannot use the more straight forward events such as &quot;before_flush&quot;.</p> <p>According to th...
<python><postgresql><sqlalchemy>
2023-05-22 18:15:16
1
477
HenrikM
76,308,874
1,232,087
VsCode - Python: Create Environment not available
<p>The question is about <a href="https://code.visualstudio.com/docs/python/environments" rel="nofollow noreferrer">Using Python environments in VS Code</a>.</p> <p>The section <a href="https://code.visualstudio.com/docs/python/environments#_using-the-create-environment-command" rel="nofollow noreferrer">Using the Crea...
<python><visual-studio-code><virtual-environment>
2023-05-22 18:09:37
1
24,239
nam
76,308,825
344,669
Python 10, on Windows how it shows this folder exists /home/appuser/temp
<p>In my python program, want to check directory exists before using it. When I check <code>/home/appuser/temp</code> folder, it returns <code>True</code>. Since its Linux path, I expect to return False, not sure why its returning True.</p> <pre><code>&gt;&gt;&gt; import os &gt;&gt;&gt; os.path.exits(&quot;/home/appus...
<python><python-3.x>
2023-05-22 18:00:44
0
19,251
sfgroups
76,308,800
3,482,266
Merging/joining on candidates index in row
<p>In a pandas dataframe, there's a column called <code>candidates</code>. This column gives a list with several indices.</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Index</th> <th>Column 1</th> <th>Candidates</th> </tr> </thead> <tbody> <tr> <td>0</td> <td>34</td> <td>[2,3,22]</td> </t...
<python><pandas>
2023-05-22 17:55:55
1
1,608
An old man in the sea.
76,308,776
11,021,252
How to extract the coordinate of the shaded region when LineString and circular Polygon geometries intersects?
<p>I have geometries, as shown in the figure. three circular Polygon geometries (circle1,circle2 and circle3) and nineteen LineStrimgs (line0,line1,...,line18). I want to extract the coordinates of the grey-shaded region (area between circle1 and circle, which has been equally divided by the passing line strings) in th...
<python><geometry><gis><geopandas><shapely>
2023-05-22 17:51:26
1
507
VGB
76,308,700
21,420,742
Merging dataframes on differently-named columns in pandas while only keeping a subset of columns
<p>I have 2 datasets and I need to merge over only specific columns but none of the fields have the same name.</p> <p>DF1</p> <pre><code> Name ID Job_Type Emp_Type Adam 101 Full-Time Employee Ben 102 Part-Time Contractor Cathy 103 Part-Time Employee Doug...
<python><python-3.x><pandas><dataframe>
2023-05-22 17:40:52
2
473
Coding_Nubie
76,308,673
11,360,794
Kombu - RabbitMQ - Pytest - [Errno 104] Connection reset by peer
<p>I'm using Kombu to connect to RabbitMQ, and found myself in some strange behavior. I have a generic producer function (see below), that I use throughout our code base. This works very well in most cases, but some of our unit tests started failing here. The connection is closed when opening the with block and opening...
<python><rabbitmq><celery><kombu>
2023-05-22 17:35:01
1
790
Niels Uitterdijk
76,308,664
19,968,680
Tables are different accessing database with SQLAlchemy and psql
<p>The tables in my PostgreSQL database are different when I connect with psql and SQLAlchemy. The results are not the same when doing a simple SELECT using the following two methods. Using psql results in an old version of the data without any data, while I am able to update and fetch the most recent data using SQLAlc...
<python><database><postgresql><sqlalchemy><orm>
2023-05-22 17:34:03
0
322
gbiz123
76,308,628
12,098,671
How to download images attached to a tweet from the tweet link?
<p>Since the Twitter API is no longer free how to download images from tweet links using Python?</p>
<python><web-scraping>
2023-05-22 17:28:39
1
759
Yash Khasgiwala
76,308,514
5,252,492
How to implement MASE (Mean Absolute Scaled Error) in python
<p>I have Predicted values and Actual values, and I can calculate Mean Absolute Percentage Error by doing:</p> <pre><code>abs(Predicted-Actual)/ Predicted *100 </code></pre> <p>How do I calculate MASE with respect to my Predicted and Actual values?</p>
<python><statistics>
2023-05-22 17:13:05
2
6,145
azazelspeaks
76,308,496
4,035,257
Find the exact location of an element in pandas dataframe
<p>I have the following pandas dataframe:</p> <p><code>df = pd.DataFrame({&quot;A&quot;: [1,2,3], &quot;B&quot;: [-2,8,1], &quot;C&quot;: [-451,23,326]})</code></p> <p>Is there any function that returns the exact location of an element? Assuming that the element exists in the table and no duplicate. E.g. if <code>eleme...
<python><pandas><dataframe>
2023-05-22 17:09:19
2
362
Telis
76,308,481
11,942,410
error while updating table in MySQL : mysql.connector.errors.DatabaseError: 1412 (HY000): Table definition has changed, please retry transaction
<p>I am working on one personal project. There is multiple similar questions on this forum however everyone is case specific. In my case i am creating and loading temp table, i am joining that table with existing table in DB and updating the same table based on temp table results. while executing <code>db.execute_inser...
<python><mysql><pyspark>
2023-05-22 17:06:25
1
326
vish
76,308,468
836,026
Moving class call using registry from module to Jupyter notebook
<p>I'm trying to test some code initially written to be run in class module but I'm moving it to run in Jupyter notebook. The code uses class registry to create objects in &quot;<strong>init</strong>.py&quot; (see below code). I believe I copied all relevant classes , but still getting error message saying &quot;objec...
<python><pytorch>
2023-05-22 17:04:31
0
11,430
user836026
76,308,393
1,471,980
how do you convert dict data type fo json in python
<pre><code>r3={'result':[{'serverId':101, 'serverName':'abc', 'data'[{'percentUsed':10, 'value':1, 'rvalue':20}]},{'serverId':102,'serverName':'eee', 'data'[{'percentUsed':30, 'value':3, 'rvalue':24}]}} print(type(r3)) dict </code></pre> <p>I need to convert this r3 to json</p> <p>I have tried this</p> <pre><code>json...
<python><json><dictionary>
2023-05-22 16:54:48
1
10,714
user1471980
76,308,299
2,221,360
PyQt/ PySide control widgets' actions from diffreent class or file
<p>I am working on a GUI project that was started as simple but growing in size now. Therefore, I have created multiple classes in multiple files to make the code easily understandable.</p> <p>What I want is that each class should do specific tasks when clicking a particular button or widget.</p> <p>Here is the simple ...
<python><pyqt><pyside><pyside6><pyqt6>
2023-05-22 16:40:24
1
3,910
sundar_ima
76,308,180
8,040,369
pymodbus: get data from input registers paralleling using multiprocessing in python
<p>I am using <strong>pymodbus</strong> library to get data from sensors using the below multiprocessing code</p> <pre><code>def Get_Latest_Sensor_Data(tInput_Device_ID_List): sub_df = tInput_df[tInput_df[&quot;device_id&quot;] == tInput_Device_ID_List] sub_df = sub_df.reset_index() tIP_Addr = sub_d...
<python><multiprocessing><pymodbus>
2023-05-22 16:23:02
0
787
SM079
76,308,144
817,824
Having trouble opening a virtual environment in python3.9
<p>I have installed python3.9 through apt in my Ubuntu 18.04.6 LTS. Then I was trying to create a new virtual environment that runs on 3.9. This is the process I did:</p> <pre><code>$ python3.9 -m venv /home/user1/py3.9 Error: Command '['/home/user1/py3.9/bin/python3.9', '-Im', 'ensurepip', '--upgrade', '--default-pip'...
<python><python-3.x><virtualenv><python-venv>
2023-05-22 16:19:02
1
477
ponir
76,308,129
15,055
Is there a way to serialize and resume async functions between interpreter restarts?
<p>Say I have some async code like so:</p> <pre><code> async def start(self): name = await self.text_prompt(&quot;Hi there! What's your name?&quot;) await self.send_message(f&quot;Hello, {name}! How are you?&quot;) # --- crash --- await asyncio.sleep(1) await self.send_message...
<python><serialization><async-await>
2023-05-22 16:16:14
0
230,589
Claudiu
76,308,118
10,266,106
Finding Percentiles and Values From Calculated Gamma Distribution
<p><strong>Background</strong></p> <p>I am working on computing a series of best-fit gamma curves for a 2-D dataset in Numpy (ndarray), a prior question for the genesis of this can be found <a href="https://stackoverflow.com/q/75598344/10266106">here</a>.</p> <p>Scipy was previously utilized (scipy.gamma.stats), howeve...
<python><numpy><cdf><gamma-distribution>
2023-05-22 16:15:20
2
431
TornadoEric
76,307,932
468,455
Python class method not running
<p>I'm new to Python. I'm confused as to why the method innerMethod in the code below does not run when being called from another method in the class or from the instantiated object. I don't get an error but the print command is not called.</p> <pre><code># create a class class Room: length = 0.0 breadth = 0.0 ...
<python><class>
2023-05-22 15:52:45
0
6,396
PruitIgoe
76,307,855
3,231,250
Why does pandas not use NumPy correlation method?
<p>Recently I have realised that NumPy correlation function is much faster then comparing to pandas.</p> <p>If I perform pair-wise correlation to the ~18k features, with NumPy It is 100x time faster.</p> <pre><code>%timeit np.corrcoef(df.values) 5.17 s ± 0 ns per loop (mean ± std. dev. of 1 run, 1 loop each) %timeit d...
<python><pandas><numpy>
2023-05-22 15:42:01
1
1,120
Yasir
76,307,777
3,453,901
How to use GitHub fine-grained access tokens in production across many repos when the max expiration is a year?
<p>I am trying to transition from the GitHub <code>Personal Access Tokens</code> classic version to the currently beta version <code>fine-grained tokens</code>. My issue is the token expiration max age is 1 year, whereas before the classic tokens could be set to not have any expiration. I know the simplest solution is ...
<python><github><requirements.txt><personal-access-token><github-fine-grained-tokens>
2023-05-22 15:31:25
1
2,274
Alex F
76,307,761
6,011,446
Time-series plot doesn't look right
<p>I downloaded data from INTERMAGNET for my research and I've been trying to plot the data between 1 Jan 2013 to 31 Dec 2013. The plot generated by the INTERMAGNET site looks like this:</p> <p><a href="https://i.sstatic.net/OtLXk.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/OtLXk.png" alt="enter imag...
<python><pandas><matplotlib>
2023-05-22 15:29:29
0
1,660
Nikhil Raghavendra
76,307,724
8,052,809
Numerical algorithm to decide whether a matrix is nilpotent
<p>I am looking for a numerical stable algorithm which decides whether a matrix is nilpotent (A matrix <code>A</code> is nilpotent if <code>A^dim</code> is the zero matrix)</p> <p>(I have a similar question about generating nilpotent matrices here: <a href="https://stackoverflow.com/q/76307680/8052809">Numerical algori...
<python><r><math><matrix><numerical-methods>
2023-05-22 15:25:37
0
778
tommsch
76,307,666
785,404
How can I check if a Python package provides another package?
<p>The <a href="https://packaging.python.org/en/latest/overview/" rel="nofollow noreferrer">Python docs say</a></p> <blockquote> <p>Python and PyPI support multiple distributions providing different implementations of the same package. For instance the unmaintained-but-seminal PIL distribution provides the PIL package,...
<python><pypi><python-packaging>
2023-05-22 15:19:22
0
2,085
Kerrick Staley
76,307,373
926,918
dask frame: efficiently drop rows that do not have minimum count of the row's corresponding reference element
<p>I have a dataframe of integers with no missing numbers. Due to the size of the problem, I need to find a Dask-based solution that I am unable to for the following problem.</p> <p>Using the reference value under the column ('ref') and a cut-off k, retain only those rows that have the row's corresponding element at le...
<python><pandas><dask>
2023-05-22 14:47:27
0
1,196
Quiescent