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
βŒ€
74,947,206
7,472,392
How to filter longitude and latitude that are not within a area
<p>I have a boundary with polygon object that is consisted of longitudes and latitudes.</p> <p>That looks like the below:</p> <pre><code>POLYGON((35.82879102266901 128.7076346641539,35.82707300496909 128.7067790195541,35.82583849984275 128.70867790735832,35.824475124668446 128.70759751110955,35.823661363692246 128.7058...
<python><dictionary><coordinates><polygon>
2022-12-29 04:20:21
0
1,511
Yun Tae Hwang
74,947,071
10,970,202
Which version of python extension support python3.6 in vscode?
<p>I'm shifting from pycharm to vscode for python development and want to check if most of functionality from pycharm such as debugging, gitlab integration, etc... Are possible in VScode.</p> <p>I've learned that you could install python extension so I did install python v.2022.20.1 extension. However this debugging fu...
<python><visual-studio-code><python-3.6>
2022-12-29 03:55:30
1
5,008
haneulkim
74,946,845
19,616,641
AttributeError: module 'numpy' has no attribute 'int'
<p>I tried to run my code in another computer, while it successfully compiled in the original environment, this error can outta nowhere:</p> <pre><code>File &quot;c:\vision_hw\hw_3\cv2IP.py&quot;, line 91, in SECOND_ORDER_LOG original = np.zeros((5,5),dtype=np.int) File &quot;C:\Users\brian2lee\AppData\Local\Packag...
<python><numpy><attributeerror>
2022-12-29 03:01:26
3
421
brian2lee
74,946,711
10,062,025
Why is the response sometimes passing through and sometimes not when using requests httpx in python?
<p>I am trying to scrape this website items, however when I used httpx or even requests sometimes it passes and gets the response sometimes it doesn't. It seems random, that's why I tried doing a rerun of the failed items to get the results. However this does not seem to work 100% of all the time. Is there something th...
<python><httpx>
2022-12-29 02:27:38
0
333
Hal
74,946,568
6,509,883
How to estimate the extrinsic matrix of a chessboard image and project it to bird's eye view such it presents pixel size in meters?
<p>I want to generate an Occupancy Grid (OG) like image with a Bird's Eye View (BEV), i.e., each image pixel has a constant unit measure and everything on the final grid is floor (height=0).</p> <p>I don't know what I'm missing, I'm newbie on the subject and I'm trying to follow a pragmatic step by step to get on the f...
<python><opencv><computer-vision><homography>
2022-12-29 01:53:11
1
1,064
Rafael Toledo
74,946,529
1,513,168
Convert function arguments to str
<p>I wrote a function and call it as below:</p> <pre><code>from lib import base_frequency base_frequency(&quot;AB610939-AB610950.gb&quot;, &quot;genbank&quot;) #This calls the function that uses a BioPython code. </code></pre> <p>How could I pass the function arguments as below?</p> <pre><code>base_frequency(AB610939-...
<python><biopython>
2022-12-29 01:44:06
2
810
Supertech
74,946,433
9,273,406
How to add custom poetry environment to Locust base Docker image?
<p>How do you run Locust (load testing tool) in a stable Docker container with extra poetry dependencies installed? From the docs it's known that <a href="https://docs.locust.io/en/stable/running-in-docker.html" rel="nofollow noreferrer">running Locust in Docker</a> is easily possible through their base image.</p> <pre...
<python><docker><python-poetry><locust>
2022-12-29 01:24:01
1
4,370
azizbro
74,946,296
1,015,595
pyparsing infix notation with non-grouping parentheses
<p>I'm working on a billing application where users can enter arbitrary mathematical expressions. For example, a line item might be defined as <code>(a + b) * c</code>.</p> <p>pyparsing handles the order of operations well enough in this case:</p> <pre class="lang-py prettyprint-override"><code>import pyparsing as pp ...
<python><pyparsing><lexical-analysis><infix-notation>
2022-12-29 00:49:14
1
16,285
Big McLargeHuge
74,946,209
3,795,219
Python map emptied after using tuple or iteration
<p>The following code does not print anything from the <code>for</code> loop; it only prints the result of the <code>tuple</code>. This is very unintuitive because I haven't explicitly modified the <code>cheapest</code> map, yet it behaves as if it is empty after calling <code>tuple</code>.</p> <p>So, what's going on?<...
<python><tuples>
2022-12-29 00:31:56
1
8,645
Austin
74,946,020
14,403,635
Python Selenium: Inputting Email Address and Password and click Continue
<p>I am using the following code to input Email address and password, by clicking the continue element.</p> <p>However I have no idea should I enter driver.switch_to_frame and then webdriver can enter the email and password and click?</p> <pre><code>from selenium import webdriver from selenium.webdriver.chrome.options ...
<python><selenium><selenium-webdriver><css-selectors><webdriverwait>
2022-12-28 23:53:53
2
333
janicewww
74,945,937
13,142,245
How to compute percentile for an external element with given array?
<p>I'm looking for a percentile function that accepts an array and an element where it would return closest percentile of the element.</p> <p>Some examples</p> <pre><code>percentile([1,2,3,4,5], 2) =&gt; 40% percentile([1,2,3,4,5], 2.5) =&gt; 40% percentile([1,2,3,4,5], 6) =&gt; 100% </code></pre> <p>Does anything li...
<python><arrays><numpy><percentile>
2022-12-28 23:35:43
1
1,238
jbuddy_13
74,945,932
1,190,077
plotly: Is it possible to adjust the camera field of view?
<p>For a 3D rendering in <code>plotly</code>, the <a href="https://plotly.com/python/3d-camera-controls/" rel="nofollow noreferrer">documentation</a> explains the camera parameters <code>eye</code>, <code>center</code>, and <code>up</code>.</p> <p>Some websites suggest that one can adjust the &quot;zoom&quot; by reduci...
<python><3d><plotly>
2022-12-28 23:34:34
1
3,196
Hugues
74,945,819
18,758,062
Draw shapes on top of Networkx graph
<p>Given an existing <code>networkx</code> graph</p> <pre class="lang-py prettyprint-override"><code>import networkx as nx import numpy as np np.random.seed(123) graph = nx.erdos_renyi_graph(5, 0.3, seed=123, directed=True) nx.draw_networkx(graph) </code></pre> <p><a href="https://i.sstatic.net/AAEql.png" rel="nofoll...
<python><matplotlib><graph><networkx>
2022-12-28 23:12:22
1
1,623
gameveloster
74,945,783
169,947
Python testing - multiple `tox` environments with parallel runs and coverage reporting
<p>I'm having a hard time figuring out a configuration for Python unit testing that combines:</p> <ol> <li>Multiple environments (specifying e.g. versions of python or dependency packages) given as <code>tox</code> environments</li> <li>Parallel running of the <code>tox</code> environments, for speed (some things being...
<python><unit-testing><parallel-processing><coverage.py>
2022-12-28 23:05:55
1
24,277
Ken Williams
74,945,737
14,141,126
Convert Varying Column Length to Rows in Pandas
<p>I'm trying to create a graph with Seaborn that shows all of the Windows events in the Domain Controller that have taken place in a given time range, which means you have, say, five events now, but when you run the program again in 10 minutes, you might get 25 events.</p> <p>With that said, I've been able to parse th...
<python><pandas><seaborn>
2022-12-28 22:57:42
1
959
Robin Sage
74,945,707
11,574,636
tkinter change color of bg and fg while programme is running
<p>I want to programme my own notepad. As a function, I want to be able to toggle between white mode and dark mode.</p> <p>This is my code so far. I know that the problem is that the variables color_fg and color_bg are not transferred to the top, but I just can't find a solution for it.</p> <pre><code>import tkinter as...
<python><tkinter>
2022-12-28 22:53:32
2
326
Fabian
74,945,681
1,354,930
Is there an easy way to create a CLI "shortcut" arg that implements other args using Python's `argparse`?
<p>Is there an <em>easy</em> way to make a CLI arg &quot;shortcut&quot; (for lack of a better term) using <code>argparse</code>? I also can't think of a better term to try and search for implementations...</p> <p>Basically I'm trying to make something similar to rsync's <code>--archive</code> option:</p> <p><a href="ht...
<python><arguments><command-line-arguments><argparse>
2022-12-28 22:50:18
1
1,917
dthor
74,945,584
2,659,499
Changing order of decimal numbers causing differnet results
<p>I'm learning Python. Maybe this is a silly mistake and not related to Python at all but appreciate some clarity.</p> <p>I have the following code.</p> <pre class="lang-py prettyprint-override"><code>from decimal import Decimal expense = Decimal('10.00') v = Decimal('93.93863013698630136986301369') n = Decimal('46.9...
<python>
2022-12-28 22:35:41
0
1,975
Vahid
74,945,549
1,627,106
Locust - AttributeError when accessing locust web interface
<p>I'm trying to run a very basic locust load testing which did work previously.</p> <pre class="lang-py prettyprint-override"><code>from locust import HttpUser, between, task class QuickstartUser(HttpUser): wait_time = between(1, 5) @task def get_status(self): self.client.get(&quot;/status/&quot...
<python><locust>
2022-12-28 22:28:50
1
1,712
Daniel
74,945,448
12,242,085
What is an interpretation of parts of statsmodels summary of Logistic Regression in Python?
<p>I have results of Logistic Regression from statsmodels in Python like below:</p> <p><a href="https://i.sstatic.net/tpPuc.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/tpPuc.png" alt="enter image description here" /></a></p> <p>My question is: What is interpretation of marked on yellow columns: <code...
<python><logistic-regression><statsmodels><coefficients>
2022-12-28 22:12:23
0
2,350
dingaro
74,945,378
9,820,561
PyLance raises errors due to a misunderstanding of simple logic
<p>I'm coding Python in VScode and started using PyLance to improve my code. However, It isn't pleasing when it does not understand simple logic like the following:</p> <pre><code>if a == 1: test = (1, 2, 4) else: test = [1, 2, 3] if a == 1: print(test) else: test.append(1) </code></pre> <p>In this example...
<python><python-typing><pyright>
2022-12-28 22:00:39
0
362
Mr.O
74,945,313
7,077,532
Python: cannot import librosa library --> OSError: cannot load library 'libsndfile.so' :
<p>I am running my python code on the cloud using paperspace gradient. My code utilizes the librosa library. It was all working fine just a couple weeks ago meaning the entire codebase runs without error.</p> <p>But today it seems like there's something wrong with librosa. When I try to do &quot;import librosa&quot;...
<python><installation><pip><librosa>
2022-12-28 21:49:56
1
5,244
PineNuts0
74,945,288
2,021,144
PySpark least or greatest with dynamic columns
<p>I need to give a dynamic parameter to greatest in pyspark but it seems it doesn't accept that,</p> <pre><code>column_names=['c_'+str(x) for x in range(800)] train_df=spark.read.parquet(train_path).select(column_names).withColumn('max_values',least(col_names)) </code></pre> <p>So what is the way to do this without us...
<python><pyspark>
2022-12-28 21:46:49
1
827
Mahdi
74,945,282
3,788,557
make python interactive popup in a seperate window in vscode
<p>I run my python code in vscode so I can see output as I move along. However, my work monitors in the office aren't the largest and so I don't have a ton of real estate to operate on.</p> <p>Is it possible so that the output from my .py file appears in a physically separate window? For example, my main vscode is on...
<python><visual-studio-code>
2022-12-28 21:46:10
1
6,665
runningbirds
74,945,194
7,394,787
How to avoid variable after statement `for` in python?
<p>When I write programs with python, something offen happens like:</p> <pre><code>for i in range(5): print(&quot;before&quot;,i) for j in range(5): for i in range(5): pass print(&quot;after&quot;,i) </code></pre> <p>which output:</p> <pre><code>before 0 after 4 before 1 after 4 before 2...
<python>
2022-12-28 21:33:06
5
305
Z.Lun
74,945,130
20,176,161
Save each slice of a dataframe into a specific excel sheet
<p>I have a dataframe which looks like this:</p> <pre><code>print(df) city Year ville Asset_Type Titre psqm 0 Agadir 2010.0 Agadir Appart 3225 6276.923077 1 Agadir 2010.0 Agadir Maison_Dar 37 8571.428571 2 Agadir 2010.0 Agadir Villa 107 6279.469027 3 Agadir 2011.0 Agadir Appar...
<python><excel><dataframe><xlsxwriter>
2022-12-28 21:22:55
3
419
bravopapa
74,945,044
6,619,692
Python shebang with conda
<p>Following <a href="https://stackoverflow.com/a/19305076/6619692">best practice</a> I have started an executable Python script with a shebang <em>specific</em> to Python 3:</p> <pre><code>#!/usr/bin/env python3 import spotipy # ...some fancy code </code></pre> <p>One <code>chmod +x</code> later, I'm executing this ...
<python><conda><shebang>
2022-12-28 21:11:54
2
1,459
Anil
74,945,042
7,731,571
Static variables being shared between parent and child classes
<p>I encountered a bug in my code that turned me crazy for a bit. Essentially I have a parent class that instantiates a static variable, and a Child class that instantiates the same static variable, differently. This should be fine, because <code>Parent.variable</code> should be != to <code>Child.variable</code>. Well ...
<python><python-3.x>
2022-12-28 21:11:30
1
531
Alexis
74,945,010
16,179,502
KeyError: WeakRef when using flask-sqlalchemy version 3
<p>I have seen similar answers to this but have not come across any concrete answer. Since upgrading my <code>Flask-SQLAlchemy</code> version from 2.5.1 to 3.0.2, I am encountering the following error anytime I try to query or do any database operations: <code>KeyError: &lt;weakref at 0x10ed004a0; to 'Flask' at 0x10cb5...
<python><flask><sqlalchemy>
2022-12-28 21:07:41
0
349
Malice
74,944,999
6,361,813
Cartopy: set extent for perfectly square map
<p>Assume I need to plot a map with Cartopy and the resulting figure should have square dimensions. In my (simplistic) understanding, this should be easy using the <a href="https://en.wikipedia.org/wiki/Equirectangular_projection" rel="nofollow noreferrer">plate carrΓ©e projection</a>, since longitude and latitude are d...
<python><matplotlib><geospatial><cartopy>
2022-12-28 21:06:18
1
407
Pontis
74,944,887
7,999,308
How can the default list of email addresses be rendered from a variable in Airflow?
<p>I have a lot of Airflow DAGs and I'd like to automatically send email notifications to the same list of recipients (stored in an Airflow variable) on any task failure, so I'm using the following default operator configuration defined at the DAG level:</p> <pre><code>dag = DAG( ... default_args = { .....
<python><airflow><jinja2>
2022-12-28 20:51:49
1
524
Gevorg Davoian
74,944,834
2,088,886
wfastcgi 500 error in flask app when trying to plot
<p>Edit: Originally thought this was IIS issue, but looks like it's FastCgiModule causing the issue.</p> <p>To be clear, the WebApp itself works, it only fails when I choose &quot;Image Test&quot; from the dropdown (see code below) menu on the site. Specifically, it fails on the <code>df.plot</code> line, and I can't f...
<python><flask><fastcgi><wfastcgi>
2022-12-28 20:45:13
0
2,161
David Yang
74,944,818
512,480
Python debugging, language server problem
<p>I'm having very repeatable problems running the Python debugger under VS code 1.74.2 on Mac OS 11.6. I decided to follow some advice in the repository's &quot;reporting issues&quot; article and turn off all extensions. Make that, all extensions except the ones obviously needed for the job. I turned off all extension...
<python><visual-studio-code><debugging><python-language-server>
2022-12-28 20:42:20
1
1,624
Joymaker
74,944,700
9,182,743
Pandas: convert UTC to Local time using timezone, then drop timezone
<p>I have a dataframe with columns:</p> <ul> <li><strong>time</strong>: time in UTC format</li> <li><strong>timezone</strong>: the corresponding timezone.</li> </ul> <pre><code> time timezone 0 2022-12-28T20:16:31.373Z Europe/Athens 1 2022-07-28T20:16:31.373Z Europe/At...
<python><pandas><datetime><timezone>
2022-12-28 20:24:49
0
1,168
Leo
74,944,673
3,215,940
Saving deque to file minding performance and portability
<p>I have a while loop that collects data from a microphone (replaced here for <code>np.random.random()</code> to make it more reproducible). I do some operations, let's say I take the <code>abs().mean()</code> here because my output will be a one dimensional array.</p> <p>This loop is going to run for a LONG time (e.g...
<python><performance><hdf5>
2022-12-28 20:21:45
0
4,270
Matias Andina
74,944,539
12,299,993
Pyspark type mismatch in nested JSON structure stops schema validation
<p>I'm reading a json file with PySpark and validating the schema against a predefined data schema.</p> <p>the data schema:</p> <pre><code>testschema = StructType([ StructField(&quot;_corrupt_record&quot;, StringType(), True), StructField(&quot;a&quot;, StringType(), True), StructField(&quot;b&quot;, String...
<python><pyspark>
2022-12-28 20:03:20
0
304
toaster_fan
74,944,386
8,461,786
Can I make classmethod work with __getitem__?
<p>In the code below, can I somehow keep <code>__getitem__</code> method (which cannot be a classmethod) on <code>Permissions</code> class and at the same time turn <code>as_list</code> into a class method?</p> <p>Technically <code>as_list</code> IS a class method now, but I still need to do <code>cls()[user_type]</cod...
<python>
2022-12-28 19:43:45
1
3,843
barciewicz
74,944,286
4,418,481
Adding file name column to Dask DataFrame
<p>I have a data set of around 400 CSV files containing a time series of multiple variables (my CSV has a time column and then multiple columns of other variables).</p> <p>My final goal is the choose some variables and plot those 400 time series in a graph.</p> <p>In order to do so, I tried to use Dask to read the 400 ...
<python><csv><dask><parquet><dask-dataframe>
2022-12-28 19:32:10
1
1,859
Ben
74,944,041
10,732,434
How to ignore TqdmExperimentalWarning?
<p>Everytime a <code>tqdm_gui</code> object is created, a warning is printed. I tried to suppress it with <code>contextlib</code> but to no avail.</p> <pre class="lang-py prettyprint-override"><code>import contextlib as ctx from tqdm import TqdmExperimentalWarning from tqdm.gui import tqdm_gui total = 0 with ctx.supp...
<python><python-3.x><suppress-warnings><tqdm>
2022-12-28 19:01:05
1
2,197
sanitizedUser
74,943,863
7,800,760
Python redis library not working unlike command line
<p>I have a remote Linux Redis 7.0 server which I reach through a spiped tunnel.</p> <p>Launch spiped locally:</p> <pre><code>spiped -F -e -s 127.0.0.1:6379 -t REMOTESERVER:6379 -k /etc/spiped/redis.key </code></pre> <p>and as expected I can connect to the remote Redis server via the command line utility:</p> <pre><cod...
<python><redis>
2022-12-28 18:39:44
1
1,231
Robert Alexander
74,943,798
12,242,085
Equivalent for predict_proba in statsmodels Logistic Regression in Python?
<p>I created Logisitc Regression Model in statsmodels in Python like below:</p> <pre><code>model = sm.Logit(y_train, X_train[selected_features]).fit(disp = 0) </code></pre> <p>and then I need to calculate probabilities, (NOT prediction model.predict) but probabilities, same like <code>predict_proba</code> in sklearn. B...
<python><scikit-learn><statsmodels>
2022-12-28 18:30:17
0
2,350
dingaro
74,943,730
12,960,701
How do I get the float value of a 1x1 EagerTensor in Tensorflow?
<p>I have a 1x1 EagerTensor object that I'm trying to convert to a single float value. i.e.</p> <p>tf.Tensor([[-0.04473801]], shape=(1, 1), dtype=float32) -&gt; -0.04473801</p> <p>There seemed to be a simple answer that I've used on other tensors in the past - just use the item() method <a href="https://stackoverflow.c...
<python><tensorflow>
2022-12-28 18:23:04
1
382
jgholder
74,943,713
3,472,722
Telegram Bot InlineKeyboardButton, How to know which dynamically button is pressed?
<p>I'm using <a href="https://github.com/python-telegram-bot/python-telegram-bot" rel="nofollow noreferrer">Python Telegram Bot</a> and I'm struggling with handling callback query handlers.</p> <h1>The problem</h1> <p>I've created a list of inlinekeyboard buttons (see image below), and they all trigger the same callbac...
<python><python-telegram-bot>
2022-12-28 18:21:02
1
411
Michael ten Den
74,943,530
6,372,859
Mix histogram and line plots in plotly together
<p>Hi all and Happy Holidays!</p> <p>I am trying to do a combined plot, using plotly, of an histogram and a line plot. I have a large pandas dataframe (shown only the first ten lines):</p> <pre><code> Year Selling_Price 0 8.0 4950.0 1 8.0 4070.0 2 16.0 1738.0 3 12.0 2475.0 4 15.0 1430.0...
<python><pandas><plotly><visualization>
2022-12-28 18:01:18
1
583
Ernesto Lopez Fune
74,943,492
243,031
Disable admin application for django
<p>I am trying to run the django development server and its failed with below error.</p> <pre><code>Exception in thread django-main-thread: Traceback (most recent call last): File &quot;/my/virtual/lib/python3.8/threading.py&quot;, line 932, in _bootstrap_inner self.run() File &quot;/my/virtual/lib/python3.8/th...
<python><django>
2022-12-28 17:56:16
1
21,411
NPatel
74,943,480
3,330,979
Class not found when using dynamic import
<p>I am trying to dynamically import a module using the following:</p> <pre><code>def import_plugin(plugin_name): src = f'plugins.{plugin_name}.plugin' module = __import__(src) return getattr(module, 'Plugin') import_plugin('core') </code></pre> <p>This is the project structure:</p> <ul> <li>main.py</li> <...
<python>
2022-12-28 17:55:14
0
1,927
chrispytoes
74,943,412
17,696,880
Capture substring and send it to a function that modifies it and can replace it in this string
<pre class="lang-py prettyprint-override"><code>import re def one_day_or_another_day_relative_to_a_date_func(input_text): #print(repr(input_text)) #print what you have captured, and you should replace return &quot;aaaaaaaa&quot; def identify(input_text): some_text = r&quot;(?:(?!\.\s*?\n)[^;])*&quot; d...
<python><python-3.x><regex><replace><regex-group>
2022-12-28 17:45:45
1
875
Matt095
74,942,963
192,204
spacy tokenizer is not recognizing period as suffix consistently
<p>I have been working on a custom NER model to extract products that have strange identifiers that I can't control.</p> <p>You can see from this example that in some cases it isn't picking up the period as a suffix. I added a custom tokenizer to handle products with hyphens (below). What do I need to add to handle thi...
<python><nlp><spacy>
2022-12-28 16:58:05
1
9,234
scarpacci
74,942,500
339,167
Split and type cast columns values using Pandas
<p>How do i add an extra column in a dataframe, so it could split and convert to integer types but np.nan for string types</p> <pre><code>Col1 1|2|3 &quot;string&quot; </code></pre> <p>so</p> <pre><code>Col1 ExtraCol 1|2|3 [1,2,3] &quot;string&quot; nan </code></pre> <p>I tried long contorted way but faile...
<python><pandas>
2022-12-28 16:12:12
2
6,500
Rohit Sharma
74,942,497
1,737,830
Different behavior of a loop in a function when else clause is added
<p>There's a simple function:</p> <pre class="lang-py prettyprint-override"><code>users = [ (['bmiller', 'Miller, Brett'], 'Brett Miller'), (['Gianni Tina', 'tgiann', 'tgianni'], 'Tina Gianni'), (['mplavis', 'marcusp', 'Plavis, Marcus'], 'Marcus Plavis') ] def replace_user_login_with_name(login): name...
<python>
2022-12-28 16:12:07
1
2,368
AbreQueVoy
74,942,416
13,162,807
vscode attached to Docker container - module not found
<p>I'm running <code>vscode</code> debugger inside <code>Docker</code> container but it started showing an error: <a href="https://i.sstatic.net/VkA6c.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/VkA6c.png" alt="enter image description here" /></a></p> <p>That is very strange because when I open pytho...
<python><docker><visual-studio-code><vscode-debugger>
2022-12-28 16:05:02
1
305
Alexander P
74,942,299
20,615,590
Difference between pandas functions: df.assign() vs df.reset_index()
<p>So lets say I have a DataFrame:</p> <pre><code> stuff temp id 1 3 20.0 1 6 20.1 1 7 21.4 2 1 30.2 2 3 0.0 2 2 34.0 3 7 0.0 3 6 0.0 3 2 14.4 </code></pre> <p>And I want to drop the index; what method is better to use?</p> <ul> <li><p>T...
<python><python-3.x><pandas><dataframe><coding-efficiency>
2022-12-28 15:52:45
0
423
Pythoneer
74,942,140
11,239,740
Manually trace function in Pyodide without locking main thread
<p>I am trying to build a browser-based debugging tool for Python but I am having trouble combining the Python inner workings with user interactions. My setup looks like <a href="https://jsfiddle.net/ms2t8hjc/37/" rel="nofollow noreferrer">this</a> (jsfiddle link). Essentially I am using <code>sys.settrace</code> to in...
<python><python-3.x><pyodide>
2022-12-28 15:36:24
1
408
Blupper
74,942,103
1,936,966
How can I map multiple Boolean properties into single SQLAlchemy column of binary type?
<p>How can I map multiple Boolean properties into single SQLAlchemy column?</p> <p>I have a class kind of <code>flags</code> :</p> <pre><code>class Thing(db.Model): id = db.Column(db.Integer, primary_key=True) isEnabled = db.Column(db.Boolean, nullable=False, default=False) isAdministrator = db.Column(db.Bo...
<python><sqlalchemy><flask-sqlalchemy>
2022-12-28 15:34:01
1
4,764
filimonic
74,942,021
4,594,063
SQLAlchemy: NotImplementedError when joining with subquery
<p>I'm trying to join a query object with a subquery. I have verified that the two queries work independently.</p> <p>This is the code:</p> <pre><code>from sqlalchemy import create_engine from sqlalchemy.ext.declarative import declarative_base from sqlalchemy.orm import sessionmaker from sqlalchemy import text from pr...
<python><postgresql><sqlalchemy>
2022-12-28 15:24:32
1
1,832
Wessi
74,941,944
11,092,636
Strange grey line appearing tkinter when adding icon with root.iconbitmap
<p>Here is a MRE:</p> <pre class="lang-py prettyprint-override"><code>import tkinter as tk # Window tkWindow: tk.Tk = tk.Tk() tkWindow.resizable(False, False) tkWindow.iconbitmap(&quot;icon.ico&quot;) # Label Welcome text: str = f&quot;Wedfghhhhhhhhjkllllll hojjjjjjjjj hjjjjjjjjj V1.&quot; label_welcome: tk.Text = t...
<python><tkinter><winapi><tk-toolkit>
2022-12-28 15:16:52
2
720
FluidMechanics Potential Flows
74,941,746
2,581,199
Trying to solve the n-parenthesis problem - but failing
<p>I am trying to implement a solution to the 'n-parenthesis problem'</p> <pre><code>def gen_paren_pairs(n): def gen_pairs(left_count, right_count, build_str, build_list=[]): print(f'left count is:{left_count}, right count is:{right_count}, build string is:{build_str}') if...
<python>
2022-12-28 14:56:07
1
391
Kevin
74,941,717
9,430,509
What would a python list (nested) parser look like in pyparsing?
<p>I would like to understand how to use pyparsing to parse something like a nested Python list. This is a question to understand pyparsing. Solutions that circumvent the problem because the list of the example might look like JSON or Python itself should not prevent the usage of pyparsing.</p> <p>So before people star...
<python><recursion><nested><pyparsing>
2022-12-28 14:53:22
2
935
Sergej Herbert
74,941,714
10,291,435
ImportError: cannot import name 'LegacyVersion' from 'packaging.version'
<p>I am using python 3.10.6, and I installed pipenv, version 2022.12.19, I was planning to run a project using runway, so for this I created a folder, did the command <code>pipenv --python 3.10</code>, then updated in the pipfile to include runway, pip file is as follows:</p> <pre><code>[[source]] url = &quot;https://p...
<python><pipenv><pipenv-install>
2022-12-28 14:53:13
3
1,699
Mee
74,941,669
5,900,271
How to interpret the output of statsmodels model.summary() for multivariate linear regression?
<p>I'm using the <code>statsmodels</code> library to check for the impact of confounding variables on a dependent variable by performing multivariate linear regression:</p> <pre><code>model = ols(f'{metric}_diff ~ {&quot; + &quot;.join(confounding_variable_names)}', data=df).fit() </code></pre> <p>This is how my data l...
<python><statistics><linear-regression><statsmodels>
2022-12-28 14:49:32
2
2,127
Wojtek Wencel
74,941,514
7,320,594
Read CSV file with quotechar-comma combination in string - Python
<p>I have got multiple csv files which look like this:</p> <pre><code>ID,Text,Value 1,&quot;I play football&quot;,10 2,&quot;I am hungry&quot;,12 3,&quot;Unfortunately&quot;,I get an error&quot;,15 </code></pre> <p>I am currently importing the data using the pandas read_csv() function.</p> <pre><code>df = pd.read_csv(f...
<python><pandas><csv>
2022-12-28 14:34:49
3
1,490
Koot6133
74,941,471
4,792,229
How to I install protobufs C++/Python extension?
<p>I'm looking to upgrade to the new protobuf version 4.21.0. I am sharing messages between python and c++, on the <a href="https://developers.google.com/protocol-buffers/docs/news/2022-05-06#python-updates" rel="nofollow noreferrer">release page</a> they mention that this capability breaks, unless I set <code>PROTOCOL...
<python><c++><protocol-buffers>
2022-12-28 14:30:45
1
3,002
Hakaishin
74,941,247
12,284,585
MyPy using other Pyhton version as in venv? (Positional-only parameters are only supported in Python 3.8 and greater)
<p>MyPy thinks it has to check for Python &lt;3.8 when instead it should use 3.10</p> <p>As you can see, Python3.10 is active</p> <pre><code>(myvenv) gitpod /workspace/myfolder (mybranch) $ python --version Python 3.10.7 </code></pre> <p>however mypy think its &lt;3.8?</p> <pre><code>(myvenv) gitpod /workspace/myfolder...
<python><version><mypy><python-poetry><gitpod>
2022-12-28 14:07:54
1
1,333
tturbo
74,941,203
339,167
Compare and match two data frames with multiple criteria
<p>Given a dataframe</p> <pre><code>multival date string others 23|34|45 12/05/1991 name1 xyz 31|46|25 16/02/1990 name2 abc </code></pre> <p>how can I create an index and lookup in above data series using values from another data series such that it match on</p> <ul> <li>value in mult...
<python><pandas><dataframe>
2022-12-28 14:03:17
2
6,500
Rohit Sharma
74,941,179
4,865,723
Refactor a if-elif-block into a pythonic dictionary
<p>I have a big <code>if-elif-else</code> block in my code like this</p> <pre><code>if counted == 2: score = None elif counted == 1: score = (sum(values) - 3) / 6 * 100 elif counted == 0: score = (sum(values) - 4) / 8 * 100 else: raise Exception('Should not be reached!') </code></pre> <p>With python ...
<python><lambda>
2022-12-28 14:00:40
4
12,450
buhtz
74,941,065
14,224,948
How to create a zip with multiple files from one folder and send it to the browser in modern Django
<p>I was struggling with sending the downloadable Django zip with many files to browser, because many tutorials in the web are obsolete, like the one which was my inspiration to come up with what I will share with you:</p> <p><a href="https://stackoverflow.com/questions/12881294/django-create-a-zip-of-multiple-files-an...
<python><python-3.x><django><django-4.0>
2022-12-28 13:50:25
1
1,086
Swantewit
74,940,964
8,981,425
How to extend SQLalchemy Base class with a static method
<p>I have multiple classes similar to the following:</p> <pre><code>class Weather(Base): __tablename__ = &quot;Weather&quot; id = Column(Integer, primary_key=True, nullable=False, autoincrement=True) temperature = Column(Integer) humidity = Column(Integer) wind_speed = Column(Float) wind_directi...
<python><pandas><sqlalchemy>
2022-12-28 13:40:10
2
367
edoelas
74,940,732
3,324,314
How to generate unique name in Faker based on a seed?
<p>I need to generate a fake username based on unique user attribute. For simplicity, let's assume each user in my system has an ID, and I want to generate fake names for them based on this attribute. I can't understand if it's possible.</p> <p>In other words, I want something like this:</p> <pre class="lang-py prettyp...
<python><faker>
2022-12-28 13:15:45
1
920
fbjorn
74,940,661
6,737,387
tensorboard not showing projector data on colab
<p>I'm trying to visualize the embeddings in tensorboard but the projector tab isn't showing anything on colab.</p> <p>When I downloaded the logs folder to my pc and than ran it locally, it worked perfectly fine. Does anybody have any idea why it isn't working in google colab ?</p> <p>The command i'm using to show the ...
<python><tensorflow><jupyter-notebook><google-colaboratory><tensorboard>
2022-12-28 13:08:52
1
2,683
Hisan
74,940,611
2,577,122
With pandas cut function how to list the missing bin values
<p>I have a requirement where I need to group report execution counts. The input data looks like below.</p> <pre><code>REPORT,TIME_SEC Report1,1 Report1,5 Report3,4 Report2,158 Report2,20 Report3,131 </code></pre> <p>I need to group the reports and show the count of execution for each of the following time ranges '<cod...
<python><python-3.x><pandas><group-by>
2022-12-28 13:03:56
1
307
Swap
74,940,550
1,835,818
Django- How to replace list of items of a related set
<p>I have table Group and UserConfig</p> <ul> <li>A group has many users, each user in a group has a config item</li> <li>UserConfig: unique (group_id, user_id)</li> </ul> <p>Example:</p> <pre><code>class Group(models.Model): id = models.BigAutoField(primary_key=True) name = models.CharField(max_length=255, uni...
<python><django>
2022-12-28 12:57:56
1
473
kietheros
74,940,403
5,833,865
FASTAPI Delete Operation giving Internal server error
<p>I have this code for delete operation on a Postgresql DB:</p> <pre><code>@app.delete(&quot;/posts/{id}&quot;, status_code=status.HTTP_204_NO_CONTENT) def delete_post(id: int): print(&quot;ID IS &quot;,id) cursor.execute(&quot;&quot;&quot;DELETE FROM public.&quot;Posts&quot; WHERE id = %s&quot;&quot;&quot;, (...
<python><postgresql><crud><fastapi>
2022-12-28 12:44:04
2
770
Devang Sanghani
74,940,265
12,858,691
apply() custom function on all columns increase efficiency
<p>I apply this function</p> <pre><code>def calculate_recency_for_one_column(column: pd.Series) -&gt; int: &quot;&quot;&quot;Returns the inverse position of the last non-zero value in a pd.Series of numerics. If the last value is non-zero, returns 1. If all values are non-zero, returns 0.&quot;&quot;&quot; ...
<python><pandas><performance>
2022-12-28 12:29:17
2
611
Viktor
74,940,133
4,002,633
Django query to get frequency-per-day of events with a DateTimeField
<p>I have a model with events that each have a DateTimeField and can readily write a query that gets me the count of events per day:</p> <pre class="lang-py prettyprint-override"><code>MyEvents.objects.annotate(day=TruncDate('date_time')).values('day').annotate(count=Count('id')) </code></pre> <p>which produces (Postgr...
<python><django><postgresql><django-queryset><django-aggregation>
2022-12-28 12:14:49
0
2,192
Bernd Wechner
74,940,013
9,668,481
How to check if user defined functions is missing on the file from which it was imported using pylance?
<p>I'm refactoring a large codebase. And I have migrated many function here and there.</p> <p>I want to filter pylint output to show me error like <code>my_function</code> doesn't exist in <code>helper.py</code> function anymore.</p> <pre class="lang-py prettyprint-override"><code># ------ Before refactor ------ # Fil...
<python><pylint>
2022-12-28 12:01:46
1
846
Saurav Pathak
74,939,968
2,573,075
Dockerfile installs newer python insteam of FROM source
<p>I'm trying to make a new image for python dockerfile, but keeps installing Python 3.10 instead of Python 3.8.</p> <p>My Dockerfile looks like this:</p> <pre><code>FROM python:3.8.16 COPY requirements.txt requirements.txt RUN pip install --no-cache-dir -r requirements.txt ## follow installation from xtb-python gith...
<python><docker><dockerfile>
2022-12-28 11:56:26
0
633
Claudiu
74,939,758
12,985,993
Camelot: DeprecationError: PdfFileReader is deprecated
<p>I have been using camelot for our project, but since 2 days I got following errorMessage. When trying to run following code snippet:</p> <pre><code>import camelot tables = camelot.read_pdf('C:\\Users\\user\\Downloads\\foo.pdf', pages='1') </code></pre> <p>I get this error:</p> <pre><code>DeprecationError: PdfFileRea...
<python><pypdf><python-camelot>
2022-12-28 11:35:44
9
498
Said Akyuz
74,939,689
9,781,350
Python Selenium with Proxy is unpredictable
<p>I have been working on a web scraper, it works fine without proxy, but on some website I need a proxy to avoid getting an Access Denied. The problem is that the proxy is far away from me and the page gets loaded very slowly, it takes around from 80 to 100 seconds to fully load and most of the time it just fails, lik...
<python><selenium><proxy>
2022-12-28 11:28:57
0
325
Ivan Lo Greco
74,939,407
159,072
Anynchronously update a web page using Flask
<p>I want to write a Flask+JavaScript based program that has two files <code>app.py</code> and <code>index.html</code> where we will run a lengthy task that takes one minue to finish and when the task finishes it will automatically update the <code>index.html</code> page asynchronously.</p> <p>So I wrote:</p> <p><stron...
<javascript><python><flask><asynchronous>
2022-12-28 11:01:31
1
17,446
user366312
74,939,380
8,681,229
VS Code Terminal: How to use pip version of activated venv=
<p>how can I instruct VS Code to use the <code>pip</code> version linked to the activated venv in VS Code Terminal?</p> <p><strong>What I tried</strong></p> <p>After activating the same <code>conda virtual env</code> in both Mac Terminal and VS Code Terminal, when I execute <code>which python</code> both return the sam...
<python><visual-studio-code><terminal><pip><conda>
2022-12-28 10:58:09
1
3,294
Seymour
74,939,367
5,398,127
How do I download all the libraries and dependencies?
<p>Suppose if there is a python script which uses libraries like numpy, pandas, keras, tensorflow etc.</p> <p>Now how do I download all the libraries locally so that script is not breaking due to any updates in libraries.</p> <p>What I mean is what if certain library is discontinued in future and I want to use it to a ...
<python><dependencies>
2022-12-28 10:56:33
2
3,480
Stupid_Intern
74,939,314
3,650,983
How to comment/uncomment a single line in vim
<p>I'm new with vim and working on Mac with python, and want to know how to comment/uncomment a single line with vim. Most of the IDEs that I've worked with use Cmd+/ it there something similar? I tried to find the answer but everything I found was about multiple lines!</p>
<python><macos><vim>
2022-12-28 10:51:04
2
4,119
ChaosPredictor
74,939,274
20,878,436
How to print mid popular summary of random post of certain topic from Wikipedia?
<p>I want to print mid popular summary of random post of certain topic from Wikipedia using Wikipedia API but I am getting completely random topic.</p> <p>I have tried this:</p> <pre><code>import requests def get_wikipedia(topic): response = requests.get(f&quot;https://en.wikipedia.org/api/rest_v1/page/summary/{to...
<python><mediawiki><wikipedia><wikipedia-api>
2022-12-28 10:46:45
1
368
Shounak Das
74,939,137
17,718,587
Reading .csv file with Python and DictReader missing columns
<p>I have the following <code>.csv</code> file I'm trying to read as a whole:</p> <pre><code>--------------------------------------------------------------- #INFO | | | | | | --------------------------------------------------------------- #Study name | g1 | ...
<python><csv>
2022-12-28 10:33:34
2
2,772
ChenBr
74,938,992
9,960,645
How to send command from bot to discrord chanel
<p>For example channel have /some_command[prompt]</p> <p>How to call with command and prompt instead text ?</p> <pre><code>async def on_ready(): await client.wait_until_ready() channel = client.get_channel(int(chanel_id)) await channel.send(&quot;/some_command[test]&quot;) </code></pre>
<python><discord>
2022-12-28 10:19:23
1
696
Руслан ΠœΠΈΡ€ΠΎΠ²
74,938,977
19,100,318
How to exclude objects when importing a python module
<p>Suppose this package which contains only one module:</p> <pre><code>mypackage/ __init__.py mymodule.py </code></pre> <p>The <code>__init__.py</code> file is empty. The module <code>mymodule.py</code> is as follows:</p> <pre><code>from math import pi def two_pi(): return 2 * pi </code></pre> <p>This is t...
<python><python-3.x><python-import>
2022-12-28 10:17:21
3
450
cruzlorite
74,938,915
10,437,727
VSCode Test Explorer not finding module despite PYTHONPATH defined
<p><strong>EDIT</strong></p> <p>Thanks the comment below, I've managed to get the command to work from the CLI. However, I'm still struggling to make it work using VSCode's test explorer. Here's my current settings.json:</p> <pre class="lang-json prettyprint-override"><code>{ ... &quot;python.testing.pytestEnab...
<python><python-3.x><visual-studio-code><python-unittest>
2022-12-28 10:10:47
0
1,760
Fares
74,938,891
5,006,606
Is it possible to provide a scoring metric to sklearn RFE?
<p>I need to get subsets of top 1, top 2, top 3, etc. features, and performance of my model on each of these subsets. Something like this:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Number of features</th> <th>Features</th> <th>Performance</th> </tr> </thead> <tbody> <tr> <td>1</td> <t...
<python><machine-learning><scikit-learn><feature-selection><rfe>
2022-12-28 10:09:28
0
315
Charlie
74,938,816
1,866,576
Reuse environment on Tox 4
<p>This is my tox.ini file:</p> <pre><code># Tox (https://tox.readthedocs.io/) is a tool for running tests # in multiple virtualenvs. This configuration file will run the # test suite on all supported python versions. To use it, &quot;pip install tox&quot; # and then run &quot;tox&quot; from this directory. # # See als...
<python><tox>
2022-12-28 10:01:37
2
331
Marcus
74,938,477
13,596,591
Reducing Item by -10 in Class Based View
<p>I have a button when clicked should reduce an Item by 10, it is possible to achieve using a function not as_view, please help on reproducing the same effect on a ListView</p> <p>Views.py:</p> <pre><code> def subs(request, pk): sw = get_object_or_404(Swimmers,id=pk) c_s = sw.sessions - 10 sw.sessions = c...
<python><django><django-rest-framework><django-views><django-forms>
2022-12-28 09:27:52
0
431
d3vkidhash
74,938,342
10,847,096
Pyspark DataFrame Filter column based on a column in another DataFrame without join
<p>I have a pyspark dataframe called <code>df1</code> that looks like this:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th style="text-align: center;">ID1</th> <th style="text-align: center;">ID2</th> </tr> </thead> <tbody> <tr> <td style="text-align: center;">aaaa</td> <td style="text-ali...
<python><dataframe><pyspark>
2022-12-28 09:13:20
1
993
Ofek Glick
74,938,100
10,480,181
How to set up imports correctly in Python?
<p>I have the following directory structure for my python project.</p> <pre><code>. β”œβ”€β”€ AUTHORS.rst β”œβ”€β”€ CONTRIBUTING.rst β”œβ”€β”€ HISTORY.rst β”œβ”€β”€ MANIFEST.in β”œβ”€β”€ Makefile β”œβ”€β”€ README.rst β”œβ”€β”€ __pycache__ β”‚ └── test.cpython-310.pyc β”œβ”€β”€ docs β”œβ”€β”€ logs β”œβ”€β”€ python_server_copy β”‚ β”œβ”€β”€ __init__.py β”‚ β”œβ”€β”€ cli.py β”‚ β”œβ”€β”€ copy.py β”‚ ...
<python><python-3.x><import><python-import><modulenotfounderror>
2022-12-28 08:46:51
1
883
Vandit Goel
74,938,028
947,506
python dict pop could not return pytorch tensor
<p>My code is as follows:</p> <pre><code>import torch mydict = {&quot;state0&quot;: torch.tensor(12345.6), &quot;state1&quot;:torch.tensor(23456.7)} print(f&quot;mydict: {mydict}&quot;) val = mydict.pop(&quot;state0&quot;) print(f&quot;val={val}&quot;) </code></pre> <p>The output is:</p> <pre><code>mydict: {'state0':...
<python><pytorch>
2022-12-28 08:39:24
1
377
silence_lamb
74,937,949
3,375,378
Pandas changing value of columns before saving to mysql
<p>I've got a mysql table defined as follows:</p> <pre><code>CREATE TABLE series_info ( series_id INT NOT NULL PRIMARY KEY, s_area VARCHAR(40) NOT NULL, s_code VARCHAR(10) NOT NULL, dataset_version VARCHAR(20) NOT NULL ); </code></pre> <p>In my Python module, I'm trying to save a Pandas DataFrame into t...
<python><mysql><pandas>
2022-12-28 08:28:53
1
2,598
chrx
74,937,926
979,974
Python plot heatmap from csv pixel file with panda
<p>I would like to plot a heatmap from a csv file which contains pixels position. This csv file has this shape:</p> <pre><code>0 0 8.400000e+01 1 0 8.500000e+01 2 0 8.700000e+01 3 0 8.500000e+01 4 0 9.400000e+01 5 0 7.700000e+01 6 0 8.000000e+01 7 0 8.300000e+01 8 0 8.900000e+01 9 0 8.500000e+01 10 0 8.300000e+01 </cod...
<python><csv><heatmap><pixel>
2022-12-28 08:26:48
1
953
user979974
74,937,869
7,317,408
ValueError: cannot reindex on an axis with duplicate labels when adding EMAs via group_by
<p>Sorry for the noob question.</p> <p>I have a bunch of minute data like so:</p> <pre><code> timestamp open high low close volume trade_count vwap symbol volume_10_day 0 2021-06-28 11:15:00+00:00 1.8899 1.89 1.8899 1.8900 1200 2 1.889942 AADI 10202...
<python><pandas><numpy><stock><pandas-ta>
2022-12-28 08:21:22
0
3,436
a7dc
74,937,551
6,684,751
Flask Socket application deployment using nginx and gunicorn in Ubuntu 22.04 is not working. Getting 404 error from nginx
<p>When I run the below code from a local Ubuntu machine, the socket connection is successfully established; however, when I deploy it to an Ubuntu server, it does not work.</p> <p>This is the error message I received from Nginx.</p> <pre><code>- [28/Dec/2022:07:29:10 +0000] &quot;GET /media HTTP/1.1&quot; 404 153 &quo...
<python><sockets><nginx><flask>
2022-12-28 07:45:35
0
906
arun n a
74,937,536
719,001
read variable value from bash executable
<p>I have a script:</p> <p>x.sh:</p> <pre><code>#!/bin/bash echo nir </code></pre> <p>config.sh:</p> <pre><code>#!/bin/bash x=$(/home/nir/x.sh) </code></pre> <p>script.py:</p> <pre><code>#!/usr/bin/env python3 #execute config.sh and read x into y print(y) </code></pre> <p>terminal:</p> <pre><code>$ ] ./x.sh nir $ ] . ....
<python><python-3.x><bash>
2022-12-28 07:44:08
1
2,677
Nir
74,937,459
11,693,768
Converting a column of strings with different formats that contains year from 2 digits (YY) to 4 digits (YYYY) in python pandas
<p>I have a dataframe with the following column. Each row contains different format strings.</p> <pre><code>col | ---------------------- GRA/B TPP BBMY ... SOCBBA 0 MAX CMBD 0 MAX EPR 5.75 MAX ... PMUST 5.57643 02/15/34 LEO 0 12/30/2099 RGB 3.125 09/15/14 RGB 3.375 04/15/20 </code></pre> <p>I want to c...
<python><pandas><string><date><replace>
2022-12-28 07:35:40
1
5,234
anarchy
74,937,236
5,810,015
Python unable to process heavy files
<p>I have a zipped (.gz) log file logfile.20221227.gz. I am writing a python script to process it. I did a test run with file which had 100 lines and the script worked fine. When i ran the same script on actual log file which is almost 5GB the script gets broken. Note that i was able to process log files upto 2GB. Unfo...
<python><out-of-memory><limit><sigkill>
2022-12-28 07:06:25
1
417
data-bite