QuestionId
int64
74.8M
79.8M
UserId
int64
56
29.4M
QuestionTitle
stringlengths
15
150
QuestionBody
stringlengths
40
40.3k
Tags
stringlengths
8
101
CreationDate
stringdate
2022-12-10 09:42:47
2025-11-01 19:08:18
AnswerCount
int64
0
44
UserExpertiseLevel
int64
301
888k
UserDisplayName
stringlengths
3
30
75,106,061
7,641,854
Azure ML Pipeline prohibit file upload
<p>When creating a Pipeline with Python SDK V2 for Azure ML all contents of my current working directory are uploaded. Can I blacklist some files being upload? E.g. I use <code>load_env(&quot;.env&quot;)</code> in order to read some credentials but I don't wan't it to be uploaded.</p> <p>Directory content:</p> <pre><co...
<python><azure><azure-machine-learning-service>
2023-01-13 07:31:26
1
760
Ken Jiiii
75,105,937
21,539
How to center text along a path with svgwrite
<p>I have a path I've created in svgwrite and I want to have my text to be centered along that path.</p> <p>It's confusing since the svgwrite API doesn't appear to offer any mechanism for doing so</p>
<python><svg><svgwrite>
2023-01-13 07:16:38
1
24,816
Zain Rizvi
75,105,739
2,955,827
How can I make pandas apply faster if I only use pandas built-in function in it?
<p>For example I have a dataframe <code>df</code> :</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th style="text-align: left;">trade_date</th> <th style="text-align: right;">01</th> <th style="text-align: right;">02</th> <th style="text-align: right;">03</th> <th style="text-align: right;">0...
<python><pandas><numpy>
2023-01-13 06:50:33
1
3,295
PaleNeutron
75,105,658
19,950,360
how to user insert_rows_from_dataframe?? Python to Bigquery
<p>Example My DataFrame</p> <pre><code>df = pd.DataFrame({'a': [4,5,4], 'b': ['121233', '45a56', '0000'], 'c':['sas53d1', '1asdf23', '2asdf456']}) </code></pre> <p>my Bigquery Table Path</p> <pre><code>table = 'tutorial.b' </code></pre> <p>So i make a Table with</p> <pre><code>client.load_table_from_dataframe(df,table)...
<python><sql><google-cloud-platform><google-bigquery>
2023-01-13 06:37:43
1
315
lima
75,105,373
10,715,700
Comparing two values in a structfield of a column in pyspark
<p>I have Column where each row is a StructField. I want to get max of two values in the StructField.</p> <p>I tried this</p> <pre class="lang-py prettyprint-override"><code>trends_df = trends_df.withColumn(&quot;importance_score&quot;, max(col(&quot;avg_total&quot;)[&quot;max&quot;][&quot;agg_importance&quot;], col(&q...
<python><apache-spark><pyspark><apache-spark-sql>
2023-01-13 05:55:11
1
430
BBloggsbott
75,105,205
818,072
Use an older python version in Ubuntu when executing a binary from Java using ProcessBuilder
<p>I have a Java SpringBoot app that does audio processing and builds to a docker container based on Ubuntu. The app uses a third-party binary tool (<a href="https://github.com/shaka-project/shaka-packager" rel="nofollow noreferrer">https://github.com/shaka-project/shaka-packager</a>) like</p> <pre><code>ProcessBuilder...
<python><java><ubuntu><conda>
2023-01-13 05:28:54
1
1,660
Egor
75,105,181
4,504,945
How do you create a polygon that fills the area between 2 circles?
<p>I'm trying to create a function that can create a specific polygon with Pygame.</p> <p>My snippet of code:</p> <pre class="lang-py prettyprint-override"><code>def draw_line_round_corners_polygon(surf, point_1, point_2, color, circle_radius): point_1_vector = pygame.math.Vector2(point_1) point_2_vector = pyga...
<python><python-3.x><pygame>
2023-01-13 05:25:35
1
1,984
3kstc
75,105,038
4,531,757
Pandas - Build sequnce in the group while resetting on defined condition
<p>I am kind of stuck with my learning knowledge. I thought this is the time I seek help from experts.</p> <p>Here I have to build a 'result column' based on my patient &amp; schedule columns. -- Condition 1: Sequence need to be reset if a patient change in the patient column -- Condition 2. The sequence needs to reset...
<python><pandas><dataframe>
2023-01-13 05:02:01
1
601
Murali
75,105,035
14,261,423
Why set.discard doesn't throw an error when a set is passed to it in Python?
<p>My question is quite simple.</p> <p>When I run</p> <pre><code>someSet = {1,2,3,4} someSet.discard([5]) </code></pre> <p>It gives the error:</p> <pre><code>Traceback (most recent call last): File &quot;File.py&quot;, line 2, in &lt;module&gt; someSet.discard([5]) TypeError: unhashable type: 'list' </code></pre>...
<python><python-3.x><list><set>
2023-01-13 05:01:22
1
749
Keshav Saraf
75,104,870
9,510,800
Generate time series dataframe with min and max time with the given interval pandas
<p>How can I generate a time series dataset with min and max date range with the specific interval in pandas?</p> <pre><code> min_date = 18 oct 2022 Max_date = 20 Oct 2022 interval = 1 hour Min_date Max_date 18/10/2022 00:00:00 18/10/2022 01:00:00 18/10/2022 01:00:00 18/10/2022 02:00:00 18/10/2022 0...
<python><pandas><numpy>
2023-01-13 04:31:49
1
874
python_interest
75,104,841
14,791,134
How to match regular expression characters in right position, wrong order?
<p>Say my string is <code>bucs</code>. I would want to match <strong>buc</strong>caneer<strong>s</strong>, tampa bay <strong>buc</strong>caneer<strong>s</strong>, and <strong>bucs</strong>, but not &quot;falcons&quot;.</p> <p>I'm fairly new to regex, I tried:</p> <pre class="lang-py prettyprint-override"><code>re.finda...
<python><regex>
2023-01-13 04:24:41
1
468
earningjoker430
75,104,648
9,430,855
OpenAPI spec generated from FastAPI not showing missing values allowed as dict values
<p>Take this simple service:</p> <pre><code># main.py import typing as t from pydantic.types import StrictStr from fastapi import FastAPI from pydantic import BaseModel, StrictBool, StrictInt, StrictStr Value = t.Optional[StrictBool] | t.Optional[StrictInt] class Example(BaseModel): x: dict[StrictStr, Value] ...
<python><fastapi><openapi><pydantic>
2023-01-13 03:40:11
0
3,736
dave-edison
75,104,569
2,951,230
How to extend one tensor with another if they do not have the same size
<pre><code>a = tensor([ [101, 103], [101, 1045] ]) b = tensor([ [101, 777, 227], [101, 888, 228] ]) </code></pre> <p>How to I get this tensor c from a and b:</p> <pre><code>c = a + b = tensor([ [101, 103, 0], [101, 1045, 0], [101, 777, 227], [101, 888, ...
<python><python-3.x><pytorch><artificial-intelligence><tensor>
2023-01-13 03:25:32
1
1,239
Brana
75,104,512
17,103,465
Pandas where multiple conditions are met ; concatenate the result to create a new column
<p>I have a code below and you can see I am using <code>np.select</code> to identify if the string in my column contains any of the codes and create a reference column with the description based on the logic.</p> <pre><code># Creating Score column col = 'codes_desc' conditions = [(df_merged[col].str.contains('...
<python><pandas><dataframe>
2023-01-13 03:15:14
1
349
Ash
75,104,389
17,696,880
Define capture regex for name recognition of composite people connected by a connector
<pre class="lang-py prettyprint-override"><code>import re def register_new_persons_names_to_identify_in_inputs(input_text): #Cases of compound human names: name_capture_pattern = r&quot;(^[A-Z](?:\w+)\s*(?:del|de\s*el|de)\s*^[A-Z](?:\w+))?&quot; regex_pattern = name_capture_pattern + r&quot;\s*(?i:se\s*tr...
<python><python-3.x><regex><string><regex-group>
2023-01-13 02:49:01
1
875
Matt095
75,104,325
7,959,614
Use multiple INNER JOINS to transpose one column in multiple columns
<p>I have the following table</p> <pre><code>CREATE TABLE &quot;holes&quot; ( &quot;tournament&quot; INTEGER, &quot;year&quot; INTEGER, &quot;course&quot; INTEGER, &quot;round&quot; INTEGER, &quot;hole&quot; INTEGER, &quot;stimp&quot; INTEGER, ); </code></pre> <p>With the following small...
<python><sqlite><group-by><case><conditional-aggregation>
2023-01-13 02:36:10
2
406
HJA24
75,104,206
10,836,714
What causes a type error when subscribing to list?
<p>I have the following code im running in CoLab with Python Version 3.8 (not 3.9):</p> <pre><code>from typing import List, Dict def get_embedding(text: str, model: str=EMBEDDING_MODEL) -&gt; list[float]: result = openai.Embedding.create( model=model, input=text ) return result[&quot;data&quot;...
<python><typeerror><python-typing>
2023-01-13 02:11:21
0
1,221
Mark Wagner
75,104,127
6,419,790
Why does my function return a all upper case answer instead of a all lower case answer?
<p>I want to write a function that greets ‘Batman’ or ‘Black Widow’ in uppercase and all others in lowercase text.</p> <pre><code>def hello(name): if name == &quot;Batman&quot; or &quot;Black Widow&quot;: print(f&quot;Hello {name.upper()}&quot;) else: print(f&quot;Hello {name.lower()}&quot;) ...
<python><function>
2023-01-13 01:55:54
1
927
Minho
75,104,089
2,951,230
How to pad a tensor
<p>How would I pad this tensor by adding element 100 on the end</p> <pre><code>a = tensor([[ 101, 103], [ 101, 1045, 223], [ 101, 777, 665 , 889], [ 101, 888]]) </code></pre> <p>So the result would be:</p> <pre><code> b = tensor([[ 101, 103, 100, 100], [ 101, 1045, 223, 100], [ 101, 777, 665 , ...
<python><python-3.x><pytorch><artificial-intelligence>
2023-01-13 01:49:47
2
1,239
Brana
75,103,799
2,951,230
How to extend one tensor with another. So the result contains all the elements from the 2 tensors, see example
<pre><code>a = tensor([ [101, 103], [101, 1045] ]) b = tensor([ [101, 777], [101, 888] ]) </code></pre> <p>How to I get this tensor c from a and b:</p> <pre><code>c = a + b = tensor([ [101, 103], [101, 1045], [101, 777], [101,...
<python><python-3.x><pytorch><artificial-intelligence><tensor>
2023-01-13 00:52:08
1
1,239
Brana
75,103,692
8,081,835
Handling class mismatch in ImageDataGenerator for training and validation sets
<p>How do I work around when my training image dataset have different number of classes than validation set.</p> <p>Directory structure:</p> <pre><code>- train - class1 - class2 - class3 - test - class1 - class3 </code></pre> <pre class="lang-py prettyprint-override"><code>idg = ImageDataGenerator( prepro...
<python><tensorflow><keras>
2023-01-13 00:32:08
2
771
Mateusz Dorobek
75,103,687
8,901,144
Reindex Pyspark Dataframe with dates in Year-Week format for each group
<p>I have the following Pyspark dataframe:</p> <pre><code>id1 id2 date col1 col2 1 1 2022-W01 5 10 1 2 2022-W02 2 5 1 3 2022-W03 3 8 1 5 2022-W05 5 3 2 2 2022-W03 2 2 2 6 2022-W05 4 1 2 8 20...
<python><date><pyspark><group-by><reindex>
2023-01-13 00:29:32
1
1,255
Marco
75,103,628
6,676,101
What is an alternative to using `__getattr__()` method for wrapper classes?
<p>Suppose that I have two classes:</p> <blockquote> <ol> <li>a class named <code>Swimmer</code></li> <li>a class named <code>Person</code></li> </ol> </blockquote> <p>For my particular application, we can <em><strong>NOT</strong></em> have <code>Swimmer</code> inherit from <code>Person</code>, although we want somethi...
<python><python-3.x><inheritance><attributes><dynamic-programming>
2023-01-13 00:17:50
1
4,700
Toothpick Anemone
75,103,548
2,132,478
How to access context from a custom django-admin command?
<p>I have been using django.text client to examine the context of some URLs from several unit tests with a code similar to the following:</p> <pre><code>from django.test import TestCase class MyTests(TestCase): def example_test(self): response = self.client.get('/') # I can access ...
<python><django><django-4.0>
2023-01-13 00:00:34
1
575
Alfonso_MA
75,103,514
11,462,274
How to find the last element loaded on the page to use in WebDriverWait to be as reliable as possible about full page loading?
<p>This page has dynamic loading with different elements loading at different times:</p> <p><a href="https://www.globo.com/" rel="nofollow noreferrer">https://www.globo.com/</a></p> <p>I use an element that I've noticed takes a little longer than the others:</p> <pre class="lang-python prettyprint-override"><code>WebDr...
<python><selenium><webdriverwait>
2023-01-12 23:54:44
2
2,222
Digital Farmer
75,103,492
3,247,006
What is "list_display_links" for Django Admin?
<p>I have <strong><code>Person</code> model</strong> below:</p> <pre class="lang-py prettyprint-override"><code># &quot;store/models.py&quot; from django.db import models class Person(models.Model): first_name = models.CharField(max_length=30) last_name = models.CharField(max_length=30) age = models.Inte...
<python><django><hyperlink><django-admin><changelist>
2023-01-12 23:51:12
1
42,516
Super Kai - Kazuya Ito
75,103,288
1,448,412
Python IDE autocomplete missing some methods from AppDaemon plugin class
<p>I'm trying to use autocomplete for the <code>Hass</code> class from the Python <a href="https://github.com/AppDaemon/appdaemon" rel="nofollow noreferrer">AppDaemon</a> package. Autocomplete is showing some of the inherited methods from the superclass such as <code>get_state()</code>, but some methods are missing, su...
<python><plugins><autocomplete><package>
2023-01-12 23:18:19
1
725
Tim
75,103,237
2,515,265
How to install private Python package from an AWS S3 repository using Poetry?
<p>I'm using Poetry 1.3.2, created a virtual env with Python 3.8 and now trying to install the dependencies of my project via <code>poetry install</code>.</p> <p>The project has a private dependency which is stored in an AWS S3 bucket repository, so I added the address of this channel via <code>poetry source add --seco...
<python><amazon-s3><dependencies><python-poetry>
2023-01-12 23:08:52
1
2,657
Javide
75,103,179
6,115,999
Why would I get an AttributeError here if I provide an if statement to get around it?
<p>I've been inspired by the code here: <a href="https://towardsdatascience.com/stock-news-sentiment-analysis-with-python-193d4b4378d4" rel="nofollow noreferrer">https://towardsdatascience.com/stock-news-sentiment-analysis-with-python-193d4b4378d4</a></p> <p>I'm basically scraping news from a financial website using Be...
<python><html><beautifulsoup>
2023-01-12 22:58:39
1
877
filifunk
75,103,140
11,925,053
Python process not recognized with service file
<p>I have a process <a href="https://github.com/YashTotale/goodreads-user-scraper" rel="nofollow noreferrer">goodreads-user-scraper</a> that runs fine within a cron scheduler script that I run from my Ubuntu terminal.</p> <p>From my Ubuntu server terminal, I navigate to the directory containing scheduler.py and write:<...
<python><ubuntu><service>
2023-01-12 22:52:00
1
309
costa rica
75,103,127
13,171,500
Getting "NotImplementedError: Could not run 'torchvision::nms' with arguments from CUDA backend" despite having all necessary libraries and imports
<p>The full error:</p> <pre><code>NotImplementedError: Could not run 'torchvision::nms' with arguments from the 'CUDA' backend. This could be because the operator doesn't exist for this backend, or was omitted during the selective/custom build process (if using custom build). If you are a Facebook employee using PyTorc...
<python><pytorch><yolo>
2023-01-12 22:50:03
6
770
Vincent Casey
75,102,992
14,403,266
Fill blank cells of a pandas dataframe column by matching with another datafame column
<p>I have a pandas dataframe, lets call it <code>df1</code> that looks like this (the follow is just a sample to give an idea of the dataframe):</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Ac</th> <th>Tp</th> <th>Id</th> <th>2020</th> <th>2021</th> <th>2022</th> </tr> </thead> <tbody> <...
<python><pandas><dataframe>
2023-01-12 22:35:06
1
337
Valeria Arango
75,102,924
6,676,101
How might we write a decorator which captures all standard output printed by some function?
<p>Suppose that a function contains a lot of print-statements.</p> <p>I want to capture all of those print statements in a string, or save them to text file.</p> <p>What kind of function decorator might do that for us?</p> <pre class="lang-python prettyprint-override"><code>log_file = open(&quot;log.txt&quot;, &quot;w&...
<python><python-3.x><printing><stream><stdout>
2023-01-12 22:26:27
2
4,700
Toothpick Anemone
75,102,809
2,744,388
Get databases from SQL managed instance using azure-mgmt-sql
<p>I use the library azure-mgmt-sql to get all the SQL servers and databases with the following code:</p> <pre><code>resources = sql_client.servers.list_by_resource_group(&quot;myresourcegroup&quot;) for r in resources: databases = sql_client.databases.list_by_server(&quot;myresourcegroup&quot;, r.name) for d i...
<python><azure><azure-sdk-python>
2023-01-12 22:09:41
1
2,183
Miguel Febres
75,102,685
1,045,755
Scattermapbox in Plotly super laggy with fairly few data points
<p>I am using Plotly and Mapbox to plot some data points on a map.</p> <p>In a data frame I have roughly 700 rows, where each row contains a pair of coordinates, i.e. I need to draw a line between each pair. It also have some info about each line so that I can change the color and such for each individual line-pair.</p...
<python><plotly><mapbox>
2023-01-12 21:52:58
1
2,615
Denver Dang
75,102,575
3,579,144
Python typevar signature for function that extracts objects of a specific type from a nested dictionary
<p>I have some data organized into the following structure:</p> <pre><code>T = TypeVar(&quot;T&quot;) my_data: Dict[type[T], Dict[str, List[T]]] = dict() </code></pre> <p>Thus, given a type <code>T</code>, this dictionary will return another dictionary that is keyed by a string identifier, mapping to a list of objects...
<python><types><pyright>
2023-01-12 21:39:46
0
1,541
Vranvs
75,102,428
1,930,758
python package office365 installation crashes os on pqy5 dependency installation
<p>I Noticed this behaviour 2 times, but this package installation is literally leaking memory and crashing the OS.</p> <p>Any approach how to solve this ?</p> <pre><code> pip install office365 </code></pre> <p><a href="https://i.sstatic.net/pEp9i.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/pEp9i.png...
<python><installation><pip><package><office365>
2023-01-12 21:21:03
1
1,598
zhrist
75,102,298
6,932,839
Tkinter - Change Label Text/Entry on Button Click
<p>I have two labels and entry fields (<strong>A &amp; B</strong>). When I enter the username/password for &quot;<em>A Username/A Password</em>&quot;, I want to click the &quot;Submit&quot; button, then have the labels/entry fields change to &quot;<em>B Username/B Password</em>&quot; and be able to click the &quot;Subm...
<python><tkinter><button><label><tkinter-entry>
2023-01-12 21:06:59
1
1,141
arnpry
75,102,295
3,987,085
Finding the singular or plural form of a word with regex
<p>Let's assume I have the sentence:</p> <pre class="lang-py prettyprint-override"><code>sentence = &quot;A cow runs on the grass&quot; </code></pre> <p>If I want to replace the word <code>cow</code> with &quot;some&quot; special token, I can do:</p> <pre class="lang-py prettyprint-override"><code>to_replace = &quot;co...
<python><regex>
2023-01-12 21:06:43
2
5,645
gorjan
75,102,245
15,537,675
Read txt file with pandas into dataframe
<p>I want to read the txt file from <a href="https://github.com/odota/core/wiki/MMR-Data" rel="nofollow noreferrer">here</a> with Dota 2 mmrs for different players. It has the form as below:</p> <pre><code> 1) &quot;103757918&quot; 2) &quot;1&quot; 3) &quot;107361667&quot; 4) &quot;1&quot; ...
<python><pandas><dataframe><text-files>
2023-01-12 21:00:21
3
472
OLGJ
75,102,146
1,611,396
Flet page.update() does not update my table
<p>In my code I am trying to update a table which is called bag_table (in the row of the container of the right column). And when running my code it does show the table initially, but when I hit the submit button the backed is working. It is actually updating the bag_table variable, but it does not update in the gui it...
<python><user-interface><flet>
2023-01-12 20:47:40
1
362
mtjiran
75,102,116
7,385,923
trim a string of text, after a hyphen media in python
<p>I just started with python, now I see myself needing the following, I have the following string:</p> <pre><code>1184-7380501-2023-183229 </code></pre> <p>what i need is to trim this string and get only the following characters after the first hyphen. it should be as follows:</p> <pre><code>1184-738 </code></pre> <p>...
<python><string>
2023-01-12 20:44:07
2
1,161
FeRcHo
75,102,100
7,984,318
pandas groupby and count same column value
<p>I have a DataFrame, you can have it by running:</p> <pre><code>import pandas as pd from io import StringIO df = &quot;&quot;&quot; case_id scheduled_date status_code 1213 2021-08 success 3444 2021-06 fail ...
<python><pandas><dataframe>
2023-01-12 20:42:30
2
4,094
William
75,102,042
517,752
Problem in generating logger file to a specific path in a greengrass
<p>I am trying to generate a log file to a specific folder and path in greengrass v2. however the log file is created at the current directory.</p> <p>The current directory at which the logger file is generated is</p> <pre><code>/sim/things/t1_gateway_iotgateway_1234/greengrass/packages/artifacts-unarchived/com.data.io...
<python><logging>
2023-01-12 20:36:28
2
1,342
Pankesh Patel
75,101,954
2,817,520
Can pip handle concurrency?
<p>I want to allow multiple users to manipulate the same virtual environment. What happens if multiple processes try to install/update/delete the same package using <code>pip</code>? Should I use <a href="https://en.wikipedia.org/wiki/File_locking#Lock_files" rel="nofollow noreferrer">file locking</a>?</p> <p>Here is t...
<python><pip><concurrency>
2023-01-12 20:26:13
1
860
Dante
75,101,932
20,536,016
PagerDuty Export All Historical Incidents
<p>Does anyone have a way to export all historical incidents from PagerDuty? I can't seem to make it work by using any of the options in here:</p> <p><a href="https://developer.pagerduty.com/api-reference/9d0b4b12e36f9-list-incidents" rel="nofollow noreferrer">https://developer.pagerduty.com/api-reference/9d0b4b12e36f9...
<python><pagerduty>
2023-01-12 20:24:25
1
389
Gary Turner
75,101,850
5,924,264
How to compute a column that is shifted from an existing column in a dataframe and truncate the first and last rows of each group?
<p>I have a dataframe as follows:</p> <pre><code>df = integer_id begin 0 13 0 15 0 18 0 19 1 10 1 15 1 17 </code></pre> <p>I want to compute a 3rd column <code>end</code> where <code>df.end</code> is defined by the next <code>df.start</code> for the give...
<python><pandas><dataframe>
2023-01-12 20:16:55
1
2,502
roulette01
75,101,804
5,203,628
Import "jsonschema" could not be resolved from sourcePylance
<p>I am attempting to use the jsonschema package to validate uploaded JSON payloads from the user.</p> <p>I have run <code>pip install jsonschema</code> inside my venv and received a message confirming it's installation.</p> <p>Running <code>pip freeze</code> confirms this.<br /> <a href="https://i.sstatic.net/wuP12.pn...
<python><visual-studio-code><jsonschema>
2023-01-12 20:12:04
1
1,146
Rob S.
75,101,629
1,289,801
How to encode Hex representation of bytes as Python byte values?
<p>The below values are Hex representations of bytes, ie. <code>41</code> at the top left is 'A'. How can I convert all values to Python bytes, i.e. <code>41</code> would become <code>b\x41</code>.</p> <pre><code>41 61 30 41 61 31 41 61 32 41 61 33 41 61 34 41 61 35 41 61 36 41 61 37 41 61 38 41 61 39 41 62 30 41 62 31...
<python><byte>
2023-01-12 19:53:49
1
3,441
TMOTTM
75,101,591
2,474,025
Plotly dash local css only loaded by hot reload
<p>My local css file is not loaded at the start of the application. But if I modify the css file and have hot reload active it loads.</p> <p>In the example below I have css in the file assets/my.css which colors the dropdown dark after I start the server and then add a whitespace to the css file.</p> <p>How can I make ...
<python><plotly-dash>
2023-01-12 19:49:49
1
1,033
phobic
75,101,486
11,701,675
How to swap out single elements between two lists when they are greater then each other
<p>I have two lists where I want to control the first element of both lists and when the element of the second list is smaller swap them.</p> <p>This is my code for that:</p> <pre><code>if yListe[0] &lt; xListe[0]: xListe[0], yListe[0] = yListe[0], xListe[0] if yListe[1] &lt; xListe[1]: xListe, yListe = yListe ...
<python>
2023-01-12 19:38:27
2
647
natyus
75,101,474
12,596,824
Assign operator method chaining str.join()
<p>I have the following method chaining code and want to create a new column. but i'm getting an error when doing the following.</p> <pre><code>( pd.pivot(test, index = ['file_path'], columns = 'year', values = 'file') .fillna(0) .astype(int) .reset_index() .assign(hierarchy = file_path.str[1:-...
<python><pandas><string><method-chaining>
2023-01-12 19:37:21
1
1,937
Eisen
75,101,276
15,176,150
How do you set the opacity of a Plotly Chart's bars individually?
<p>I'm working on bar chart using <a href="https://plotly.com/python/discrete-color/" rel="nofollow noreferrer">plotly express</a>. I'd like to use discrete colours and set the opacity of each bar individually. At the moment I'm using the following code:</p> <pre><code>import plotly.express as px df1 = pd.DataFrame(dic...
<python><graph><plotly><bar-chart><opacity>
2023-01-12 19:16:00
2
1,146
Connor
75,101,254
304,684
Use regex to remove a substring that matches a beginning of a substring through the following comma
<p>I haven't found any helpful Regex tools to help me figure this complicated pattern out.</p> <p>I have the following string:</p> <pre><code>Myfirstname Mylastname, Department of Mydepartment, Mytitle, The University of Me; 4-1-1, Hong,Bunk, Tokyo 113-8655, Japan E-mail:my.email@example.jp, Tel:00-00-222-1171, Fax:00...
<python><regex>
2023-01-12 19:13:38
1
12,097
Brett
75,101,224
13,600,944
Inherit multiple Django choices classes in one choices class
<p>Let's say we have two <code>choices</code> classes in Django like:</p> <pre class="lang-py prettyprint-override"><code>from django.db import models class C1(models.TextChoices): attr1 = &quot;ATTR1&quot;, &quot;Attr 1&quot; attr2 = &quot;ATTR2&quot;, &quot;Attr 2&quot; class C2(models.TextChoices): a...
<python><django><django-models><django-rest-framework><enums>
2023-01-12 19:10:41
1
625
Hammad
75,101,128
12,871,587
Polars Reading CSV Files Causing Errors
<p>Often when reading messy csv files I end up seeing different kind of errors due to inconsistency of the data types in the column, for instance:</p> <pre><code>ComputeError: Could not parse `22.4` as dtype Int64 at column 59. The current offset in the file is 433793 bytes. </code></pre> <p>When the file/data is not y...
<python><dataframe><csv><data-cleaning><python-polars>
2023-01-12 18:59:47
1
713
miroslaavi
75,101,127
7,800,760
Pytests doesn't find a test if explicitely named
<p>Have the following project tree (just a tutorial to learn pytest):</p> <pre><code>(pytest) bob@Roberts-Mac-mini ds % tree . ├── ds │ └── __init__.py └── tests ├── __pycache__ │ ├── test_compare.cpython-311-pytest-7.2.0.pyc │ ├── test_square.cpython-311-pytest-7.2.0.pyc │ └── test_stack.cpytho...
<python><pytest>
2023-01-12 18:59:34
1
1,231
Robert Alexander
75,101,106
14,391,779
Compare the two versions of dataframes for Upsert and list out changes
<p>I am doing upsert operation in databricks. Now I want to check what is changed between two upsert operation.</p> <p>My original <code>df1</code> look like this&gt;&gt; <a href="https://i.sstatic.net/2aajU.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/2aajU.png" alt="My 1st Dataframe" /></a></p> <p>M...
<python><apache-spark><pyspark><databricks><delta-lake>
2023-01-12 18:57:01
1
650
Suraj Shejal
75,101,058
11,313,496
Pandas: Create new column with repeating values based on non-repeating values in another column
<p>I have a dataframe with the following column the follows this format:</p> <pre><code>df = pd.DataFrame(data={ 'value': [123, 456, 789, 111, 121, 34523, 4352, 45343, 623] 'repeatVal': ['NaN', 2, 'NaN', 'NaN', 3, 'NaN', 'NaN', 'NaN', 'NaN'], }) </code></pre> <p>I want to create a new column that takes the values ...
<python><pandas><numpy><repeat>
2023-01-12 18:52:35
2
316
Whitewater
75,101,002
979,099
List available topic on MQTT connection with paho
<p>I've got ay MQTT client setup with Paho, and the broker I'm connecting to publishes a topic of <code>device/****/report</code></p> <p>The issue is that **** is actually a dynamic value, and is actually the serial number of the device that I need to pull into my code.</p> <p>Is there anyway that in the on_connect met...
<python><python-3.x><mqtt>
2023-01-12 18:47:01
1
6,315
K20GH
75,100,921
1,686,236
TensorFlow Keras make ThresholdedReLU Theta optimizable
<p>I've built a seq-to-seq model to take N periods of continuous input data and predict M periods of continuous response data (M&lt;N). Because my response is sparse - usually 0, I want to squish predictions that are &quot;small&quot; to 0, so have added a Thresholded ReLU as my final layer. The model, with a single en...
<python><tensorflow><keras><deep-learning><lstm>
2023-01-12 18:39:17
0
2,631
Dr. Andrew
75,100,829
10,450,752
Shapely Buffering, not working as expected
<p>Why does buffering one of my geometries have an unexpected hole in it?</p> <pre><code>from shapely import LineString from geopandas import GeoDataFrame l = LineString([ (250,447), (319,446), (325,387), (290,374), (259,378), (254,385), (240,409), (244,440), (250,447), ]) assert l.is_valid assert l...
<python><gis><geopandas><shapely><apache-sedona>
2023-01-12 18:31:19
1
704
A. West
75,100,823
10,083,382
Pandas Group by and get corresponding Value
<p>Assuming that we have a Pandas Data Frame as below</p> <pre><code>data = {'date':['2022-10-01', '2022-10-01', '2022-10-02', '2022-10-02', '2022-10-02'], 'price': [10, 20, 30, 40, 50], 'store': ['A', 'B', 'A', 'C', 'B'] } df = pd.DataFrame(data) </code></pre> <p>I want to group by <code>date</code> and get max price ...
<python><pandas><dataframe><group-by>
2023-01-12 18:30:34
1
394
Lopez
75,100,754
5,437,090
selenium.common.exceptions.TimeoutException: Message: timeout: Timed out receiving message from renderer: 298,437
<p>I am doing web scraping using <code>selenium</code> in python using the following code:</p> <pre><code>from selenium import webdriver from webdriver_manager.chrome import ChromeDriverManager from selenium.webdriver.common.by import By from selenium.webdriver.chrome.service import Service from selenium.webdriver.chro...
<python><selenium><web-scraping><timeoutexception>
2023-01-12 18:23:47
2
1,621
farid
75,100,563
496,289
Print an xlsx file with charts/pictures to pdf on Linux using Python
<p>I've read following and many more:</p> <ol> <li><a href="https://askubuntu.com/questions/437331/print-xlsx-file-from-command-line-using-ghostscript-and-libreoffice">print xlsx file from command line using ghostscript and libreoffice</a></li> <li><a href="https://stackoverflow.com/questions/16683376/print-chosen-work...
<python><excel><linux><pdf><printing>
2023-01-12 18:05:00
0
17,945
Kashyap
75,100,542
7,984,318
How to modify date value to only keep month value
<p>I have a data frame, you can have it by running:</p> <pre><code>import pandas as pd from io import StringIO df = &quot;&quot;&quot; case_id scheduled_date code 1213 2021-08-17 1 3444 2021-06-24 3 4566 2021-07-20 ...
<python><pandas><dataframe>
2023-01-12 18:02:55
4
4,094
William
75,100,477
10,229,768
flake8 & pycodestyle/pep8 not showing E721 errors
<h5>Versions</h5> <pre class="lang-bash prettyprint-override"><code>λ python --version Python 3.10.6 λ flake8 --version 5.0.4 (mccabe: 0.7.0, pycodestyle: 2.9.1, pyflakes: 2.5.0) CPython 3.10.6 on Linux # and on Windows ## Edit: after update λ flake8 --version 6.0.0 (mccabe: 0.7.0, pycodestyle: 2.10.0, pyflakes: 3.0...
<python><pep8><flake8><pycodestyle>
2023-01-12 17:56:37
1
2,268
Nealium
75,100,323
2,706,344
Elements of one column that don't have a certain value in another column
<p>I have a DataFrame, let's assume the following one:</p> <pre><code>df=pd.DataFrame({'person':['Sebastian','Sebastian','Sebastian', 'Maria', 'Maria', 'Maria', 'Achim','Achim','Achim'],'item':['house','garden','sink','sink','gold','house','stone','gold','wood']}) </code></pre> <p>Now I want to get a list of all person...
<python><pandas><numpy>
2023-01-12 17:41:46
3
4,346
principal-ideal-domain
75,100,261
20,901,192
Is there a way to get the file import dependencies for different files in a Python project?
<p>I'm working with a Python project consisting of multiple files and nested directories. I want to get a dictionary consisting of all existing files and their references to other files (nesting not required), for example:</p> <pre><code>dependencies = { &quot;file1.py&quot;: [&quot;file2.py&quot;,&quot;file4.py&qu...
<python>
2023-01-12 17:36:43
1
374
Matt Eng
75,100,102
20,677,182
Get app version from pyproject.toml inside python code
<p>I am not very familiar with python, I only done automation with so I am a new with packages and everything.<br /> I am creating an API with Flask, Gunicorn and Poetry.<br /> I noticed that there is a version number inside the pyproject.toml and I would like to create a route /version which returns the version of my ...
<python><python-packaging><python-poetry><python-importlib>
2023-01-12 17:23:32
6
365
pgossa
75,100,088
5,437,090
Error handling of python subprocess to run bash script with multiple input arguments vs successful running of bash script with hardcoded inputs
<p>I have a Rest API to execute <code>curl</code> command in bash script to retrieve newspaper information from a national library website as follows. I can run this bash script in two different ways:</p> <ol> <li><code>$ bash sof.sh # input arguments are hardcoded! WORKS OK!</code></li> <li><code>$ python file.py # in...
<python><linux><bash><shell><subprocess>
2023-01-12 17:22:02
1
1,621
farid
75,100,067
2,463,570
Django Views not getting POST Data from api call
<p>I am not using django rest frame work</p> <p>but in normal views.py I have a simple views</p> <p>#views.py</p> <pre><code>def api_post_operations(request): pdb.set_trace() if request.POST: print(request.POST[&quot;name&quot;]) print(request.POST[&quot;address&quot;]) </code></pre> <p>...
<python><python-3.x><django>
2023-01-12 17:20:07
0
12,390
Rajarshi Das
75,100,065
6,676,101
If you were to explicitly call the `__enter__()` and `__exit_()` methods instead of using a `with` statement, what would the code look like?
<p>If you were to explicitly call the <code>__enter__()</code> and <code>__exit_()</code> methods instead of using a <code>with</code> statement, what would the code look like?</p> <p>Code using a <code>with</code> statement:</p> <pre class="lang-python prettyprint-override"><code>with open(&quot;test.txt&quot;, &quot;...
<python><python-3.x><with-statement>
2023-01-12 17:19:50
1
4,700
Toothpick Anemone
75,099,888
514,149
FileNotFoundError with shared memory on Linux
<p>I am trying to create a shared memory for my Python application, which should be used in the parent process and in another process that is spawned from that parent process. In most cases that works fine, however, sometimes I get the following stacktrace:</p> <pre class="lang-py prettyprint-override"><code>Traceback ...
<python><linux><multiprocessing><python-multiprocessing><shared-memory>
2023-01-12 17:04:37
1
10,479
Matthias
75,099,842
1,440,565
Find poetry installation used by PyCharm
<p>I am trying to set up a Poetry virtual environment in PyCharm. I am doing the following:</p> <ol> <li>Press Ctrl+Alt+S to open the Project Settings</li> <li>Go to Project -&gt; Python Interpreter</li> <li>Click on Add Intepreter -&gt; Add Local Interpreter...</li> <li>Select Poetry Environment</li> <li>Select Poetry...
<python><pycharm><python-poetry>
2023-01-12 17:00:38
0
83,954
Code-Apprentice
75,099,551
8,081,835
How to clean GPU memory when loading another dataset
<p>I'm training the CNN network on audio spectrograms comparing 2 types of input data (3 seconds and 30 seconds). This results in different spectrogram sizes in experiments.</p> <p>I'm using this to get data:</p> <pre class="lang-py prettyprint-override"><code>def get_data(data_type, batch_size): assert data_type i...
<python><tensorflow><keras><gpu>
2023-01-12 16:36:39
1
771
Mateusz Dorobek
75,099,533
6,676,101
What would cause the inner contents of a `with` statement to not execute?
<p>When I run the following code, no error messages are printed, and it seems to fail silently. I expected the string <code>&quot;BLAH&quot;</code> to be printed to the console.</p> <pre class="lang-python prettyprint-override"><code>from contextlib import redirect_stdout import io # the initialism `io` represents `INP...
<python><python-3.x><with-statement><silent>
2023-01-12 16:35:48
1
4,700
Toothpick Anemone
75,099,470
848,277
Getting current execution date in a task or asset in dagster
<p>Is there an easier way than what I'm doing to get the current date in an <code>dagster</code> asset, than what I'm currently doing?</p> <pre><code>def current_dt(): return datetime.today().strftime('%Y-%m-%d') @asset def my_task(current_dt): return current_dt </code></pre> <p>In <code>airflow</code> these ...
<python><dagster>
2023-01-12 16:30:50
1
12,450
pyCthon
75,099,457
8,869,570
Is there a vectorized way to find overlap in intervals between 2 dataframes?
<p>I have 2 dataframes: <code>df1, df2</code>. e.g.,</p> <pre><code>df1: id start end 1 0 15 1 15 30 1 30 45 2 0 15 2 15 30 2 30 45 df2 = id start end 1 0 1.1 1 1.1 11.4 1 11.4 34 1 34 46 2 0 1.5 2 ...
<python><pandas><dataframe><vectorization>
2023-01-12 16:29:24
1
2,328
24n8
75,099,407
7,984,318
pandas how to check if the following 2 rows have the same column value
<p>I have a df:</p> <pre><code>df = pd.DataFrame([[1,2], [9,0],[3,4], [3,4]], columns=list('AB')) </code></pre> <p>output:</p> <pre><code> A B 0 1 2 1 9 0 2 3 4 3 3 4 </code></pre> <p>The length of the df is always even. I need to divide the rows by 2 ,it means ,first row compare with second row ,t...
<python><pandas><dataframe>
2023-01-12 16:25:35
2
4,094
William
75,099,352
8,081,835
ReduceLRonPlateau keeps decreasing LR across multiple models
<p>I'm using <code>ReduceLROnPlateau</code> for multiple experiments, but I'm getting lower and lower initial learning rate for each conjsecutive modewl run.</p> <pre class="lang-py prettyprint-override"><code>from tensorflow.keras.callbacks import ReduceLROnPlateau for model in models: reduce_lr = ReduceLROnPlat...
<python><tensorflow><keras><callback><learning-rate>
2023-01-12 16:21:20
0
771
Mateusz Dorobek
75,099,272
14,649,310
Drawbacks of executing code in an SQLAlchemy managed session and if so why?
<p>I have seen different &quot;patterns&quot; in handling this case so I am wondering if one has any drawbacks comapred to the other. So lets assume that we wish to create a new object of class <code>MyClass</code> and add it to the database. We can do the following:</p> <pre><code> class MyClass: pass d...
<python><sqlalchemy>
2023-01-12 16:14:53
1
4,999
KZiovas
75,099,182
20,025,773
Stable Diffusion Error: Couldn't install torch / No matching distribution found for torch==1.12.1+cu113
<p>I am trying to install locally Stable Diffusion. I follow the presented steps but when I get to the last one &quot;run webui-use file&quot; it opens the terminal and it's saying &quot;Press any key to continue...&quot;. If I do so the terminal instantly closes. I went to the SB folder, right-clicked open in the term...
<python><pytorch><stable-diffusion>
2023-01-12 16:07:58
4
404
Oliver
75,099,092
7,886,651
Where is it possible to find python documentation for training spacy model/pipelines
<p>I have been looking through the spacy documentation on training/fine-tuning spacy models or pipelines, however, after walking through the following guide <a href="https://spacy.io/usage/training" rel="nofollow noreferrer">https://spacy.io/usage/training</a> I found that it all comes down to creating and configuring ...
<python><spacy-3>
2023-01-12 16:00:21
1
2,312
I. A
75,098,999
9,354,364
Python beautifulsoup not able to extract a hyperlink from href tag
<p>I am trying to scrape the data from a website. It has an excel sheet inside the tag a and href. I have tried multiple ways using requests and beautifulsoup but i am not getting the link of the excel sheet.</p> <p>Website url - <a href="https://ppac.gov.in/prices/international-prices-of-crude-oil" rel="nofollow noref...
<python><web-scraping><beautifulsoup><python-requests>
2023-01-12 15:52:49
2
1,443
Hunaidkhan
75,098,860
5,595,377
Access to marshmallow field value
<p>I begin with marshamallow and I try to validate a field. My schema is very simple.</p> <pre class="lang-py prettyprint-override"><code>class MySchema(Schema): pid = fields.String(required=true) visibility = fields.String(validate=OneOf(['public','private']) @validates('visibility') def visibility_ch...
<python><marshmallow>
2023-01-12 15:42:02
1
389
Renaud Michotte
75,098,813
7,267,480
using scipy.optimize curve_fit to find parameters of a curve and getting 'Covariance of the parameters could not be estimated'
<p>I am trying to use scipy.optimize to fit experimental data and got:</p> <pre><code>optimizeWarning: Covariance of the parameters could not be estimated warnings.warn('Covariance of the parameters could not be estimated', </code></pre> <p>Here is the data I am trying to fit <strong>with exponential curve</strong>:<...
<python><curve-fitting><scipy-optimize>
2023-01-12 15:37:40
1
496
twistfire
75,098,803
1,295,422
Robot 6 DOF pick object with camera
<p>I have a 6 DOF robotic arm (<a href="https://docs.niryo.com/dev/pyniryo2/v1.0.0/en/index.html" rel="nofollow noreferrer">Niryo Ned 2</a>) and a RGB-D camera (<a href="https://github.com/luxonis/depthai-python/blob/main/examples/SpatialDetection/spatial_tiny_yolo.py" rel="nofollow noreferrer">Depth AI OAK-D</a>).</p>...
<python><coordinates><robotics>
2023-01-12 15:36:56
1
8,732
Manitoba
75,098,734
12,985,993
Camelot pdf extraction has an issue while copying texts among span cells
<p>I am extracting data from PDFs using camelot and am faced with the following issue on 3. page of <a href="https://www.onsemi.com/pdf/datasheet/fdb9406_f085-d.pdf" rel="nofollow noreferrer">this</a> datasheet. The problematic table is shown below:</p> <p><a href="https://i.sstatic.net/2NB9H.png" rel="nofollow norefer...
<python><pdf><python-camelot><pdf-extraction>
2023-01-12 15:32:07
0
498
Said Akyuz
75,098,696
13,827,112
Numpy loadtxt in python - except some colums
<p>Is it possible in np.loadtxt to load all columns except the first one, or except some particular ones, please?</p> <p>What does usecols = (0,) mean, please? Is it possible to use sliders?</p> <p>I have 55 columns, and I would like to load all except one. Is there better way than writing <code>usecols = (1, 2, 3, 4, ...
<python><numpy><python-3.6>
2023-01-12 15:28:42
1
1,195
Elena Greg
75,098,621
12,568,761
How do I use torch.profiler.profile without a context manager?
<p>In the <a href="https://pytorch.org/docs/stable/autograd.html#profiler" rel="nofollow noreferrer">pytorch autograd profiler documentation</a>, it says that the profiler is a &quot;Context manager that manages autograd profiler state and holds a summary of results.&quot; However, in a <a href="https://pytorch.org/tut...
<python><pytorch><profiler><torchvision><autograd>
2023-01-12 15:22:07
2
550
tiberius
75,098,618
12,596,824
Recursive Function to get all files from main folder and subdirectories inside it in Python
<p>I have a file directory that looks something like this. I have a larger directory, but showing this one just for explanation purposes:</p> <pre><code>. ├── a.txt ├── b.txt ├── foo │ └── w.txt │ └── a.txt └── moo └── cool.csv └── bad.csv └── more └── wow.csv </code></pre> <p>I want to write a ...
<python><pandas><operating-system>
2023-01-12 15:22:05
0
1,937
Eisen
75,098,522
15,112,773
tokenize apostrophe and dash python
<p>I'm tokenizing sentences with the following function using regular expressions.</p> <pre><code>def tokenize2(text): if text is None: return '' if len(text) == 0: return text # 1. Delete urls text = re.sub( r&quot;((https?|ftps?|file)?:\/\/)?(?:[\w\d!#$&amp;'()*\+,:;=?@[\]\-_.~]|(?:%[0-9a-fA-F]...
<python><regex><tokenize>
2023-01-12 15:15:09
1
383
Rory
75,098,471
8,841,193
Extract a Word table from multiple docx files using python docx
<p>I have a quite a few word files that have same table structure that I need to extract and save them into a csv/excel as a separate sheet (in .xls) for each word.docx.</p> <p>Below only extracts first table.. and doesn't loop through whole docx.. is there a way we can loop through entire .doc and all the files in the...
<python><python-3.x><pandas><pip><python-docx>
2023-01-12 15:11:05
1
305
sunny babau
75,098,403
10,866,873
Python Mutli-Language XMLs as string resources
<p>I want to implement language XML into my project and change all hard-code strings into language.xml references based on the way Android uses string resources. (I have not found anything that does this)</p> <p>en_gb.xml:</p> <pre class="lang-xml prettyprint-override"><code>&lt;resource&gt; &lt;section1&gt; &lt;...
<python><python-3.x><python-class>
2023-01-12 15:06:27
1
426
Scott Paterson
75,098,321
10,260,806
Anyone know why my .bash_profile is adding "export pyenv" everytime i open terminal?
<p>I had an issue where vscode was loading terminal in a blank screen and i got an error message in vscode saying &quot;Unable to resolve your shell environment&quot;.</p> <p>So i decided to check my <code>.bash_profile</code> file and was suprised to find it was over 700 lines where it was mainly just the following co...
<python><macos><pyenv>
2023-01-12 15:01:34
1
982
RedRum
75,098,058
3,816,498
Gunicorn preload config parameter not working
<p>My <code>config.py</code> file for gunicorn looks like that:</p> <pre><code>preload = True loglevel = &quot;debug&quot; </code></pre> <p>I run gunicorn with the following command:</p> <pre><code>gunicorn -c config.py --bind 0.0.0.0:1234 app.index:server </code></pre> <p>The log looks like this:</p> <pre><code>servic...
<python><gunicorn>
2023-01-12 14:44:22
1
1,383
felice
75,098,036
10,286,813
Remove elements stored as a list in a dataframe column from list structures and convert to a string
<p>Is it possible to remove the comma separated date elements under the column <code>df['date']</code> from the list structure and store as a string instead? example dataframe:</p> <pre><code>df=pd.DataFrame({'date':[['2022-06-24'],['2021-07-07','2021-07-14'],\ ['2021-08-11','2021-12-17','2021-...
<python><pandas><list><dataframe>
2023-01-12 14:42:48
1
1,049
Nev1111
75,097,671
6,296,626
Draw a text in the correct "pieslice" in a circle using PIL
<p>I was able to generate using Python <a href="https://pillow.readthedocs.io/en/stable/" rel="nofollow noreferrer">PIL</a> library the following wheel with colored segments:</p> <p><a href="https://i.sstatic.net/h6ukn.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/h6ukn.png" alt="enter image descriptio...
<python><math><geometry><python-imaging-library><trigonometry>
2023-01-12 14:15:17
1
1,479
Programer Beginner
75,097,652
506,824
How to unit-test a Flask-Caching memoized function?
<p>I'm using:</p> <pre><code>Python 3.9.13 pytest==7.2.0 pytest-mock==3.10.0 Flask==2.2.2 Flask-Caching==2.0.1 </code></pre> <p>This is my class being tested:</p> <pre><code>@dataclass(frozen=True) class NominationData: title: str url: str is_approved: bool articles: list[ArticleData] hooks: list[Ho...
<python><flask><pytest><flask-caching>
2023-01-12 14:14:10
1
2,177
Roy Smith