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,761,115
8,489,602
Collapse identical rows / columns in pandas DataFrame to intervals
<p>Let's imagine a DataFrame with some patterns that do intersect.<br /> A sample code for a <a href="https://stackoverflow.com/help/minimal-reproducible-example">minimal reproducible example</a>:</p> <pre class="lang-python prettyprint-override"><code>import pandas as pd from random import randint as ri from random im...
<python><pandas><intervals>
2022-12-11 13:12:26
1
661
DiMithras
74,761,083
815,612
How can I have subcommands with a "fallthrough" behavior?
<p>I have a program which is basically a kind of web client, so mostly the user will be running it with a single parameter, a URL:</p> <pre><code>myclient https://example.com </code></pre> <p>But occasionally the user might want to configure the program using a subcommand:</p> <pre><code>myclient configure-this ... myc...
<python><argparse>
2022-12-11 13:07:53
0
6,464
Jack M
74,761,075
4,865,723
Drop empty categories in sub groups using groupby in pandas?
<p>I have a resulting table</p> <pre><code>Year mycat 2019 A 2 B 1 2020 A 0 B 1 </code></pre> <p>In the 3rd row (<code>2020, A</code>) you see zero. I want to get rid of lines like this.</p> <pre><code>Year mycat 2019 A 2 B 1 2020 B 1 </code></pre...
<python><pandas>
2022-12-11 13:06:46
1
12,450
buhtz
74,761,068
4,613,465
Caching tensorflow dataset before iteration results in empty dataset
<p>I'm using the <code>from_generator</code> Method of the Dataset API in TensorFlow. However, when I iterate through the dataset (to count the samples) with caching enabled, the dataset is empty:</p> <pre class="lang-py prettyprint-override"><code>output_signature = (tensorflow.TensorSpec(shape=(64, 64, 2), dtype=tens...
<python><tensorflow><machine-learning><caching><dataset>
2022-12-11 13:05:35
0
772
Fatorice
74,760,976
6,232,816
List of product categories to a dict of product categories
<p>I would like to create a product category representation as a python dictionary. The input is the following list of product categories, represented as list of lists:</p> <pre><code>categories_list = [ ['computer', 'laptop'], ['computer', 'desktop'], ['computer', 'processor', 'Intel'], ['computer', 'p...
<python>
2022-12-11 12:52:03
2
469
Attila Toth
74,760,884
4,169,571
Minimum per row in numpy array
<p>I have a numpy array and want to calculate the minimum in each row:</p> <pre><code>import numpy as np data=np.array([[ 9.052878e+07, 1.666794e+08, 9.783935e+07, 7.168723e+07], [ 1.033552e+04, 1.902951e+04, 1.117015e+04, 8.184407e+03], [ 1.000000e+15, 5.740625e+15, 3.419288e+15, 2.549149e+15],...
<python><numpy><numpy-ndarray>
2022-12-11 12:38:49
2
817
len
74,760,856
6,587,020
How to extract <p> matching specific text considering it also has <b>?
<p>How can I find a paragraph HTML element that has a bold element inside? The bold element changes. It can be Michal and then Luis.</p> <pre><code>from bs4 import BeautifulSoup import re html = &quot;&lt;p&gt;Hello&lt;b&gt;Michael&lt;/b&gt;&lt;/p&gt;&quot; # it could be &quot;&lt;p&gt;Hello&lt;b&gt;Luis&lt;/b&gt;&lt...
<python><html><web-scraping><beautifulsoup>
2022-12-11 12:33:49
1
333
dank
74,760,802
4,451,315
Percentage of total by group
<p>Say I start with:</p> <pre class="lang-py prettyprint-override"><code>In [1]: import polars as pl In [2]: df = pl.DataFrame({ 'group1': ['a', 'a', 'b', 'c', 'a', 'b'], 'group2': [0, 1, 1, 0, 1, 1] }) In [3]: df Out[3]: shape: (6, 2) β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β” β”‚ group1 ┆ group2 β”‚ β”‚ --- ┆ --- β”‚ β”‚ str ┆ i6...
<python><dataframe><python-polars>
2022-12-11 12:26:03
1
11,062
ignoring_gravity
74,760,548
3,394,220
Ubuntu 22.04 python3.10 and boost 1.80 compile warning
<p>After migrating our code to support ubuntu 22.04 with python 3.10 and latest stable boost 1.80 i cannot find the reason\solution for the compile warning.</p> <ul> <li>ubuntu 18.04 boost 1.76 python 3.6 was clean without errors\warnings</li> </ul> <p>boost is build from source using the configuration</p> <pre><code>....
<python><c++><boost><python-3.10>
2022-12-11 11:50:58
1
554
Ilia
74,760,516
12,725,674
Extract pdf pages which contains an image
<p>I have a number of pdf files in which some pages contain images and others not. Is there a way to extract only those pages of the pdf which contains an image? Unfortunately, its not sufficient to simply extract the images. I need to make sure that the whole page that contains the image is extracted.</p>
<python><pdf>
2022-12-11 11:45:43
1
367
xxgaryxx
74,760,492
5,991,801
Convert a string, representing a list of timestamps, to list of timestamps
<p>I have a string input representing a list of timestamps.</p> <p>An example of such string is shown below:</p> <pre><code>'[Timestamp('2022-08-13 17:25:00'), Timestamp('2022-08-13 18:02:00'), Timestamp('2022-08-13 18:46:00')]' </code></pre> <p>I need to convert it to a list of timestamps in python.</p> <p>How can I d...
<python><pandas><datetime><timestamp>
2022-12-11 11:42:25
3
598
HoseinPanahi
74,760,440
859,227
Appending dataframes from right column
<p>In the following code, in every iteration, a csv file is read as a data frame and it is concatenated to an result data frame (initially empty) from right.</p> <pre><code>result = pd.DataFrame() for bench in benchmarks: df = read_raw(bench) print(df) result = pd.concat([result, df], axis=1, join=&quot;inn...
<python><pandas><dataframe>
2022-12-11 11:34:36
1
25,175
mahmood
74,760,252
8,106,583
Selenium can't find file from '/tmp/' directory to populate file-input
<p>I want to upload a file using the selenium Firefox driver. The file is dynamically generated and does not need to persist so I would like to place it under <code>/tmp/</code>.</p> <p>While selecting files from my <code>home</code> directory works perfectly fine:</p> <pre><code>from selenium import webdriver from pat...
<python><selenium><selenium-webdriver><file-access>
2022-12-11 11:04:15
1
2,437
wuerfelfreak
74,760,205
1,312,718
How to get ONLY magic methods for given class/object in Python?
<p>I wonder what check I should make to check whether method is magic? Not dunder (two underscore before and after), ONLY and ONLY magic methods. If be more specific methods that not goes through <code>__getattr__</code></p> <p>This is my current solution, but I want to simplify set of <code>__ignore_attributes__ </cod...
<python><reflection>
2022-12-11 10:57:03
0
1,798
mblw
74,760,184
13,636,407
manim copy and property propagation (rectangle grid_xstep)
<p>I'm starting with manim (<code>Manim Community v0.17.1</code>) and I got behaviors that I can't explain on some very basic example, any help appreciated.</p> <pre class="lang-py prettyprint-override"><code>class SquareScene(Scene): def construct(self): kwargs = {&quot;fill_opacity&quot;: 1, &quot;stroke_...
<python><manim>
2022-12-11 10:54:01
1
3,572
paime
74,760,102
12,902,027
How can I invoke python' class dunder method in C?
<p>I'm writing some Python Module using the C extension API. And I want to implement insert() and is_greater() methods. both methods should take an argument of int type or any user-defined object which has implemented __gt__() method. To make it simple, need the interface like below.</p> <pre class="lang-py prettyprint...
<python><c><python-c-api>
2022-12-11 10:42:15
0
301
agongji
74,759,976
12,906,445
Using ffmpeng in swift code using PythonKit
<p>I have a python script that uses <code>ffmpeng</code>. I installed it using <code>brew install ffmpeg</code>. If I run the python script on python IDE it runs perfectly.</p> <p>But I wanted to run this python script on my macOS app, so using PythonKit I tried running it:</p> <pre><code>static func make_audio(dict: [...
<python><swift><swift-pythonkit>
2022-12-11 10:24:36
0
1,002
Seungjun
74,759,968
10,718,214
convert json to table and avoid memory error
<p>I have a large json file with 38 GB as this structure:</p> <pre><code>{&quot;Text&quot;: [ { &quot;a&quot; : 6, &quot;b&quot; : 2022, &quot;c&quot; : 11, &quot;d&quot; : &quot;2022-11-24&quot;, &quot;e&quot; : &quot;567&quot;, &quot;f&quot; : &quot;ww&quot;, ...
<python><json>
2022-12-11 10:23:12
0
495
Fatima
74,759,875
9,490,400
How to send a list of lists as query parameter in FastAPI?
<p>I'm using FastAPI framework and I want to send a list of lists using <code>Query</code> parameters. I can send a list using the below syntax, but I am unable to pass list of lists.</p> <pre><code>sections_to_consider: Optional[List[str]] = Query(None) </code></pre> <p>I get the below output.</p> <p><a href="https://...
<python><fastapi>
2022-12-11 10:07:11
1
336
Prince
74,759,796
7,168,098
pyhton pandas mapping the columns names series with map to a dict & handling missing values
<p>I would like to apply the map function to the columns of a dataframe as follows:</p> <pre><code>d = {'one': [1, 2], 'two': [3, 4], 'three':[3,3]} df = pd.DataFrame(data=d) recodes = {'one':'A', 'two':'B'} c = df.columns.map(recodes) c #result: Index(['A', 'B', nan], dtype='object') </code></pre> <p>All fine</p> <p>...
<python><pandas><dictionary><default>
2022-12-11 09:56:08
1
3,553
JFerro
74,759,702
17,034,564
Transfer learning (or fine-tuning) pre-trained model on non-text data
<p>I am currently fine-tuning a <a href="https://huggingface.co/unideeplearning/polibert_sa" rel="nofollow noreferrer">sentiment analysis bert-based model</a> using <a href="https://huggingface.co/docs/transformers/training#train-with-pytorch-trainer" rel="nofollow noreferrer">PyTorch Trainer</a> from hugging face. So ...
<python><artificial-intelligence><bert-language-model><pre-trained-model><fine-tuning>
2022-12-11 09:40:51
0
678
corvusMidnight
74,759,691
5,257,450
Unstable lightgbm results on every new process when I restarted the server
<p>This is the python code I used for generating trees from my data.</p> <pre class="lang-py prettyprint-override"><code>params = { 'objective': 'binary', 'deterministic': True, 'force_row_wise': True, 'num_threads': 8, 'learning_rate': 0.05, 'max_depth': 3, 'tree_learner': 'data', 'boos...
<python><random><lightgbm>
2022-12-11 09:38:47
0
3,284
xxx222
74,759,543
2,975,438
How to vectorize and speed-up double for-loop for pandas dataframe when doing text similarity scoring
<p>I have the following dataframe:</p> <pre><code>d_test = { 'name' : ['South Beach', 'Dog', 'Bird', 'Ant', 'Big Dog', 'Beach', 'Dear', 'Cat'], 'cluster_number' : [1, 2, 3, 3, 2, 1, 4, 2] } df_test = pd.DataFrame(d_test) </code></pre> <p>I want to identify similar names in <code>name</code> column if those name...
<python><pandas><vectorization><fuzzy-search><fuzzywuzzy>
2022-12-11 09:11:55
4
1,298
illuminato
74,759,494
4,882,300
Number of the possible arrays that can be formed from a string of digits ( Leetcode 1416. Restore The Array )
<p>Given the leetcode question <a href="https://leetcode.com/problems/restore-the-array/description/" rel="nofollow noreferrer">1416. Restore The Array</a>:</p> <blockquote> <p>A program was supposed to print an array of integers. The program forgot to print whitespaces and the array is printed as a string of digits s ...
<python><arrays><algorithm><backtracking>
2022-12-11 09:00:07
2
942
Ruan
74,759,447
12,575,770
What is the time complexity of this custom function?
<p>Is it correct to say that the time complexity of the following code snippet is O(n^2)? My main doubt is whether I can consider <code>triplets.append(sorted([array[i], array[j], twoSum - array[j]]))</code> as constant time since it does not depend on N and is always sorting an array of fixed size of length 3.</p> <p>...
<python><time-complexity>
2022-12-11 08:52:43
1
959
ChaoS Adm
74,759,417
20,554,684
"ModuleNotFoundError" when importing modules
<p>A similar question was asked at: <a href="https://stackoverflow.com/questions/66117109/python-subpackage-import-no-module-named-x">Python subpackage import &quot;no module named x&quot;</a> But I was still not able to solve my problem.</p> <p>For the first time, I divided my python code into modules and packages. He...
<python><code-organization><modulenotfounderror>
2022-12-11 08:44:59
2
399
a_floating_point
74,759,317
19,060,245
How to get only observations with maximum values after using groupby.sum?
<p>Sample data:</p> <pre><code>df = pd.DataFrame({ 'Company': ['A', 'A', 'A', 'A', 'B', 'B', 'B', 'B'], 'Model': ['A1', 'A2', 'A1', 'A3', 'A1', 'A2', 'A2', 'A3'], 'Units_sold': [55, 67, 58, 72, 52, 64, 68, 83] }) </code></pre> <p>After using groupby with sum function</p> <pre><code>df.groupby(['Company', 'M...
<python><pandas>
2022-12-11 08:24:54
1
314
salman
74,759,260
7,077,761
pip install -e . vs setup.py
<p>I have been locally editing (inside a conda env) the package <code>GSTools</code> cloned from the github repo <a href="https://github.com/GeoStat-Framework/GSTools" rel="nofollow noreferrer">https://github.com/GeoStat-Framework/GSTools</a>, to adapt it to my own purposes. The package is c++ wrapped in python (cytho...
<python><openmp><cython>
2022-12-11 08:15:14
1
966
math_lover
74,759,087
1,455,354
How to read JSON file from Python Wheel Package
<p>I have created a .whl package using <code>python3.9 setup.py bdist_wheel</code> and also I have checked that all files gets included in this .whl file. Below is the .whl file structure:</p> <pre><code>MyPackage/ - api/ - workflow - cfg - data1.json - data2.json - data3.json...
<python><setuptools><python-packaging>
2022-12-11 07:35:36
1
4,616
Rakesh Shetty
74,758,832
13,313,572
How to Quit / terminate / exit a particular Excel File in Python?
<p>I want to close/quit/terminate a particular excel file only. Based on my script, it closes all open/active excel files. My intention is to force close a particular file only. How to resolve it?</p> <p>For Example, In my case I open, more than 3 excel files in active mode(open), Now I Run the script, to append data ...
<python><python-3.x><openpyxl><win32com>
2022-12-11 06:33:51
1
653
Kumar
74,758,688
9,257,578
Beautiful soup returns none data
<p>I am new to web scraping the <code>soup.find()</code> cannot find the data it returns none here i want to find price my code is</p> <pre><code>destination = &quot;nepal&quot; check_in_year = 2022 check_in_month = 12 check_in_day = 13 check_out_year = 2022 check_out_month = 12 check_out_day = 17 adults = 2 total_chil...
<python><web-scraping><beautifulsoup>
2022-12-11 05:59:39
1
533
Neetesshhr
74,758,616
480,118
vscode multi-root workspace: specifying python path in env files
<p>I have the following folder structure. Project1 and Project2 are part of a multi-root workspace. <a href="https://i.sstatic.net/CGN9A.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/CGN9A.png" alt="enter image description here" /></a></p> <p>I will be developing on windows, but running on linux. so ...
<python><visual-studio-code>
2022-12-11 05:38:16
1
6,184
mike01010
74,758,611
586,543
solving math equation for data loading problem
<p>I'm having a dataframe df_N with n observations. I'd want to write a code that would create new dataframe df_M with records from df_N. The number of observations in df_M ( ie m observations ) is several orders greater that the number of observations on df_N. The number of observations on df_M can be represented in ...
<python><numpy><math>
2022-12-11 05:36:45
1
409
Rajesh Kazhankodath
74,758,536
16,869,702
Unrecognized Option in subprocess.run()
<p>I want to run this command <code>ebsynth -style source_photo.png -guide source_segment.png target_segment.png -output output.png</code>.</p> <p>This works perfectly in cmd but not in python subprocess.run()</p> <p>Python Code</p> <pre><code>import subprocess process = subprocess.run([ 'ebsynth', '-style', '...
<python><subprocess>
2022-12-11 05:14:43
1
435
Meet Gondaliya
74,758,525
15,298,943
Python - trying to convert time from utc to cst in api response
<p>Below is code I am using to get data from an api. And below that is the response. I am trying to convert <code>datetime</code> from UTC to CST and then present the data with that time zone instead. But I am having trouble isolating <code>datetime</code></p> <pre><code>import requests import json weather = requests....
<python><json><python-requests>
2022-12-11 05:11:54
1
475
uncrayon
74,758,516
2,720,402
Dask will often have as many chunks in memory as twice the number of active threads - How to understand this?
<p>I read the captioned sentence in <a href="https://docs.dask.org/en/stable/array-best-practices.html#select-a-good-chunk-size" rel="nofollow noreferrer">dask’s website</a> and wonder what it means. I have extracted the relevant part below for ease of reference:</p> <blockquote> <p>A common performance problem among ...
<python><dask><dask-distributed>
2022-12-11 05:09:19
2
2,553
Ken T
74,758,409
10,634,126
Update global variable when worker fails (Python multiprocessing.pool ThreadPool)
<p>I have a Python function that requests data via API and involves a rotating expiring key. The volume of requests necessitates some parallelization of the function. I am doing this with the multiprocessing.pool module ThreadPool. Example code:</p> <pre><code>import requests from multiprocessing.pool import ThreadPool...
<python><multiprocessing><threadpool>
2022-12-11 04:41:51
1
909
OJT
74,758,399
5,618,172
Cast string to int64 is not supported
<p>I have problem using subclass keras Api. First I read data from TF record as following</p> <pre><code>train_ds = tf.data.TFRecordDataset(['./data.tfrecord']) val_ds = tf.data.TFRecordDataset(['./data_validate.tfrecord']) train_ds = train_ds.cache().prefetch(buffer_size=AUTOTUNE) val_ds = val_ds.cache().prefetch(buff...
<python><tensorflow><keras><deep-learning>
2022-12-11 04:39:16
0
1,964
Kero
74,758,335
368,453
Build a graph with the biggest distance (edges) between two nodes is equal than two
<p>I have to build an algorithm using Python:</p> <ol> <li>This algorithm has to build a graph that has the minimum possible number of edges given a number <code>n</code> of nodes.</li> <li>we have to go from one node to another node using at most two edges.</li> <li>some nodes cannot be adjacent to each other.</li> <l...
<python><algorithm>
2022-12-11 04:23:36
1
17,488
Alucard
74,757,907
1,935,424
python-docx how to add space before/after a table
<p>I have a table defined in python-docx. To add a bit of space before/after that table, I'm just using an empty paragraph. That's ok but I would like to add a half/line worth space instead of a full line's worth of space.</p> <p>Found these:</p> <ul> <li><a href="http://www.datypic.com/sc/ooxml/a-w_topFromText-1.html"...
<python><python-docx>
2022-12-11 02:10:40
0
899
JohnA
74,757,873
986,612
Diverting the output of a c++ that calls python mangles it
<p>I have a c++ (VS2019) app</p> <pre><code>#include &lt;stdio.h&gt; #include &lt;Python.h&gt; void main(int argc, char *argv[]) { printf( &quot;- before\n&quot; ); FILE* file; Py_SetPath( L&quot;c:\\Python37\\Lib&quot; ); Py_Initialize(); file = fopen( &quot;abc.py&quot;, &quot;r&quot; ); PyR...
<python><c++><windows>
2022-12-11 02:03:02
0
779
Zohar Levi
74,757,793
13,022,556
Module could not be found err or loading dependencies Pytorch Python
<p>I'm trying to install PyTorch into my Conda environment using Anaconda Prompt(Miniconda3) but running into a similar issue seen <a href="https://stackoverflow.com/questions/74594256/pytorch-error-loading-lib-site-packages-torch-lib-shm-dll-or-one-of-its-depen">here</a></p> <p>First, I created my Conda environment:</...
<python><pytorch><conda><miniconda>
2022-12-11 01:40:55
0
414
Lui Hellesoe
74,757,750
18,308,393
Recursively find values for each key-value pair with matching keys
<p>I have an example dictionaty for <code>rules, quantifiers, and transformations</code>, essentially, inside each <code>key</code> there belongs another key containing <code>ids</code> equal to <code>id</code>. I am trying to find all those that match and return these id's that match as a dictionary in this format:</...
<python>
2022-12-11 01:28:33
1
367
Dollar Tune-bill
74,757,531
14,460,824
How can color names be more accurately recognised and extracted from strings?
<p>It may be a naΓ―ve approach that I use to recognise and extract colour names despite slight variations or misspellings in texts, which in a first throw also works better in English than in German, but the challenges seem to be approximately the same.</p> <ul> <li><p>Different spellings <code>grey/gray</code> or <code...
<python><string><search><word2vec><cosine-similarity>
2022-12-11 00:21:11
2
25,336
HedgeHog
74,757,483
5,967,025
What is the main intention of creating a subtype with NewType?
<p>I thought I could pass a value of a subtype where a value of a base type is expected. What I mean by saying that is as follows.</p> <pre class="lang-py prettyprint-override"><code>from typing import NewType BaseType = NewType(&quot;BaseType&quot;, int) SubType1 = NewType(&quot;SubType1&quot;, BaseType) SubType2 =...
<python><types>
2022-12-11 00:11:38
1
638
vildhjarta
74,757,418
4,169,571
Reading lines from file and assigning content to variables
<p>I have a file with many lines. Each line has the same length.</p> <p>The first three lines are:</p> <pre><code>0 MSG_201901010100.nc [98.22227, 0.00014308207] [3948.8948, 0.0057524233] 1 MSG_201901010200.nc [197.27554, 0.00028737469] [9986.71, 0.014547813] 2 MSG_201901010300.nc [218.46107, 0.00031823604] ...
<python><pandas><dataframe><numpy><numpy-ndarray>
2022-12-10 23:56:04
1
817
len
74,757,344
7,211,014
python search a file for text based on other text found (look ahead)?
<p>I have a massive html file that I need to find text for every .jpg image in the file. The process I want to perform is:</p> <ul> <li>search for the the image's name referenced in an href.</li> <li>if found look ahead for the first instance of a regex</li> </ul> <p>Here is a part of the file. There are many many entr...
<python><html><beautifulsoup>
2022-12-10 23:40:27
1
1,338
Dave
74,757,050
9,381,966
How to deploy locally multiple flows using Prefect 2.0?
<p>I'm reading Prefect documentation and trying to understand how local deployment works. I can deploy a flow locally following the below steps.</p> <p>First, I build the flow:</p> <pre><code>prefect deployment build ./log_flow.py:log_flow -n log-simple -q test </code></pre> <p>Where ./log_flow.py:log_flow are, respect...
<python><prefect>
2022-12-10 22:40:43
2
1,590
Lucas
74,756,687
4,653,234
Reading HLS stream from Amazon IVS with timestamped metadata using PYTHON
<p>I'm trying to read HLS stream (Amazon IVS) using python (So I could process it with openCV for computer vision purposes). I can read simple stream with OpenCV although I notice a huuuuge latency (20+ seconds) comparing to what I see in a Live console of AWS. But putting that aside, I also want to be able to read tim...
<python><amazon-web-services><amazon-ivs>
2022-12-10 21:33:57
0
763
JFCorleone
74,756,670
6,282,576
Groupby using Django's ORM to get a dictionary of lists between two models
<p>I have two models, <code>User</code> and <code>Gift</code>:</p> <pre class="lang-py prettyprint-override"><code>class User(models.Model): name = models.CharField(max_length=150, null=True, blank=True) ... class Gift(models.Model): user = models.ForeignKey( &quot;User&quot;, related_name...
<python><django><django-models><group-by><django-orm>
2022-12-10 21:30:32
1
4,313
Amir Shabani
74,756,596
230,866
Error when running sudo snap revert through SSH using Fabric under Jenkins
<p>I am trying to use Fabric to run a <code>snap revert</code> command in a remote Ubuntu 18.14 machine through ssh. The command works when I run it manually, but it fails when I try to run it through Jenkins.</p> <p>Here is the code I use:</p> <pre><code>from fabric import Config, Connection connection = Connection( ...
<python><ubuntu><jenkins><fabric><snapcraft>
2022-12-10 21:18:46
1
1,101
chaos.ct
74,756,517
19,425,874
Appending data to a Google Sheet using Python
<p>I have 3 different tables I'm looking to directly push to 3 separate tabs in a Google Sheet. I set up the GSpread connection and that's working well. I started to adjust my first print statement into what I thought would append the information to Tab A (waveData), but no luck.</p> <p>I'm looking to append the inform...
<python><pandas><google-sheets><google-sheets-api><gspread>
2022-12-10 21:04:17
1
393
Anthony Madle
74,756,513
2,597,213
Iterate over json string items in jinja2
<p>Hi I need to send data in string format to my jinja templates, and the render them. The only way I found is to format my data as JSON and send it as a string to the renderer. But I donΒ΄t know how to use it in the templates, it seems that the <code>tojson</code> filter itΒ΄s not for this purpose, because it keeps rend...
<python><templates><jinja2>
2022-12-10 21:03:58
1
4,885
efirvida
74,756,452
12,035,877
How to close a pdf opened with fitz if I've replaced its variable name?
<p>This is a simple issue. I use jupyter notebook for python and usually deal with pdfs using pymupdf.</p> <p>I usually define <code>pdf = fitz.open('dir/to/file.pdf')</code> but somethimes I forget to close the file before i redefine <code>pdf = fitz.open('dir/to/other_file.pdf')</code></p> <p>Sometimes I need to (for...
<python><pdf><pymupdf>
2022-12-10 20:51:37
2
547
JosΓ© Chamorro
74,756,311
520,556
Efficient way for additional indexing of pandas dataframe
<p>I am working on a rather large, binary (n-hot encoded) dataframe, which structure is similar to this toy example:</p> <pre><code>import pandas as pd data = { 'A' : [0, 0, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0], 'B' : [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0], 'C' : [0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1], ...
<python><pandas>
2022-12-10 20:28:27
1
1,598
striatum
74,756,290
16,667,945
How to speed up my sequential port scanner using multi-threading & return successful values only?
<p>I was trying convert sequential code of port scanner to become fast as it's so slow :(.</p> <p><strong>Sequential code</strong></p> <pre class="lang-py prettyprint-override"><code>import sys ,socket from datetime import datetime from threading import Thread def target(): t=input(str(&quot;Enter target:&quot;))...
<python><sockets><python-multithreading>
2022-12-10 20:25:52
1
321
AbdullahSaidAbdeaaziz
74,756,281
3,618,854
In numpy, multipy two structured matrices concisely
<p>I have two matrices. The first has the following structure:</p> <pre><code>[[1, 0, a], [0, 1, b], [1, 0, c], [0, 1, d]] </code></pre> <p>where <code>1</code>, <code>0</code>, <code>a</code>, <code>b,</code> <code>c</code>, and <code>d</code> are scalars. The matrix is 4 by 3</p> <p>The second is just a 2 by 3 mat...
<python><numpy><matrix-multiplication><kronecker-product>
2022-12-10 20:25:04
3
3,432
Yakov Dan
74,756,223
2,773,607
Factory-boy fuzzy DateTimeField always the same date when using create_batch
<p>I am using factory-boy for creating instances of a Django model, and I am always getting the same value returned when using <code>factory.fuzzy.FuzzyDateTime</code>.</p> <p>Minimal example:</p> <pre><code># factory class class FooFactory(DjangoModelFactory): class Meta: # models.Foo has a dt_field that ...
<python><django><datetime><factory-boy>
2022-12-10 20:13:02
1
2,481
mprat
74,756,178
3,199,871
How can I run a Selenium app with Chromedriver and Headless Chrome on Github Actions?
<p><strong>Context</strong></p> <p>I've created a python app that uses selenium, chromedriver &amp; chrome to automate actions on a website (roughly similar to the one here: <a href="https://yasoob.me/posts/web-automation-with-selenium/" rel="nofollow noreferrer">https://yasoob.me/posts/web-automation-with-selenium/</a...
<python><selenium><google-chrome><selenium-webdriver><selenium-chromedriver>
2022-12-10 20:05:55
0
1,391
Sekoul
74,756,001
1,964,692
What other types of classes are there in Python?
<p>I just found out about <code>dataclasses</code> and was reading some tutorials on how to use them. One <a href="https://realpython.com/python-data-classes/#more-flexible-data-classes" rel="nofollow noreferrer">tutorial</a> described data classes as:</p> <pre><code>A data class is a class typically containing mainly ...
<python><python-dataclasses>
2022-12-10 19:39:47
2
1,599
Korean_Of_the_Mountain
74,755,994
18,108,767
Closest true value to zero in Python
<p>A long time ago I read about the closest true value to zero, like <code>zero = 0.000000001</code>, something like that. In the article they mentioned about this value in Python and how to achieve it. Does anyone knows about this? I have look up here in SO but all the answers are about the closest value to zero of an...
<python>
2022-12-10 19:38:42
1
351
John
74,755,608
9,760,446
Plot multindex series with trend line
<p>Sample data for MWE:</p> <pre><code>d = [{'Date': Timestamp('2022-08-02 00:00:00'), 'A': 'Unknown'}, {'Date': Timestamp('2022-09-14 00:00:00'), 'A': 'Unknown'}, {'Date': Timestamp('2022-01-18 00:00:00'), 'A': 'Yes'}, {'Date': Timestamp('2022-01-19 00:00:00'), 'A': 'Unknown'}, {'Date': Timestamp('2022-01-20 00:00...
<python><pandas><seaborn><trend>
2022-12-10 18:35:01
1
1,962
Arthur Dent
74,755,265
12,945,785
how to get different parameters in a python function
<p>I would like to have the different options in a python function or equivalent ie I would like to get the different options in</p> <pre><code>sns.set_style(&quot;&quot;) </code></pre> <p>how to get the &quot;grid&quot;, &quot;dark&quot;...parameters with python instruction ?</p> <p>It is an example of what I would l...
<python><seaborn>
2022-12-10 17:48:19
1
315
Jacques Tebeka
74,755,137
389,806
List static member with no value in a Protocol class
<p>This example only prints <code>STATIC_MEMBER_1</code>. It does not list <code>STATIC_MEMBER_2</code>. I'd like a way to list both of them.</p> <pre><code>class Foo(Protocol): MY_STATIC_MEMBER_1: int = 42 MY_STATIC_MEMBER_2: int print(dir(Foo)) </code></pre> <p>I've tried using <code>inspect</code> and <code...
<python>
2022-12-10 17:30:44
1
1,981
Philip
74,755,130
15,893,581
DataFrame: IF-condition in lambda asks about Series, but single element is needed to be checked
<pre><code>import numpy as np import pandas as pd #create DataFrame df = pd.DataFrame({'str': [700,705,710,715,720,1095,1100,1105,1110,1115,1120,1125,1130,1135,1205,1210,1215,1220,1225,1230,1235,1240,1245,1250,1255], 'P': [0.075,0.075,0.075,0.075,0.075,17.95,19.75,21.85,24.25,26.55,29.2,31.9,35.05,37.7,98.6,102.15,10...
<python><dataframe><lambda>
2022-12-10 17:29:30
3
645
JeeyCi
74,754,965
13,285,583
How to load images with different image shape to tf.data pipe?
<p>My goal is to have a preprocessing layers so it can handle any image size. This is because the <a href="https://www.kaggle.com/datasets/chrisfilo/fruit-recognition" rel="nofollow noreferrer">data set that I use</a> have 2 different image shape. The solution is simple, just resize it when I load the image. However, I...
<python><tensorflow>
2022-12-10 17:07:39
2
2,173
Jason Rich Darmawan
74,754,884
4,298,200
Error with missing kw parameters in Pytests tmpdir mkdir method
<p>I have a class <code>Foo</code>. Its supposed to persist files in some folder. First it ensures the folder and all its parents exist.</p> <pre><code>class Foo: def persist_stuff(self, in_folder: Path): in_folder.mkdir(parents=True, exist_ok=True) # TODO: persist stuff </code></pre> <p>I test thi...
<python><pytest>
2022-12-10 16:56:47
1
6,008
Georg Plaz
74,754,779
6,619,692
How and where is PyTorch's cross-entropy loss implemented?
<p>Where is the workhorse code that actually implements cross-entropy loss in the PyTorch codebase?</p> <p>Starting at <a href="https://github.com/pytorch/pytorch/blob/9ef1d55e6b85f089f5d1f5a221b2dda4e7c052b2/torch/nn/modules/loss.py#L1032" rel="nofollow noreferrer">loss.py</a>, I tracked the source code in PyTorch for...
<python><c++><pytorch>
2022-12-10 16:40:16
2
1,459
Anil
74,754,552
17,795,398
SQLite: unable to use PRIMARY KEY (sqlite3.OperationalError)
<p>I'm trying to create a <code>PRIMARY KEY</code> with <code>sqlite3</code> but I get an error.</p> <p>Code:</p> <pre><code>import sqlite3 class DataBaseManager: def __init__(self, database): self.database = database self.tablevideos = &quot;videos&quot; self.cols = ( ...
<python><sqlite><sql-insert><primary-key><create-table>
2022-12-10 16:11:07
1
472
Abel GutiΓ©rrez
74,754,497
6,226,980
how do I find out what "pandas._libs.tslibs.timestamps.Timestamp" is aliased to without googling
<p><strong>Train of thoughts:</strong><br /> how do we check datatypes in pandas?<br /> many ways, <code>isinstance()</code>, <code>type()</code>, <code>sr.dtype</code>, <code>df.dtypes</code> etc</p> <p>the next step is, what's the exact word I should put in your source code to do this:<br /> <code>type(myvar) == &lt;...
<python><pandas>
2022-12-10 16:04:53
0
2,489
eliu
74,754,313
5,080,612
SQLITE db files not closed. db-shm and db-wal files remain
<p>I want to write some basic code to do querys on read only mode on sqlite databases</p> <p>These are daily db files so it is important after closing the connections not to leave other files in the server like <em>db-shm</em> or <em>db-wal</em> files associated</p> <p>I have been reading the documentation and it seems...
<python><sqlite>
2022-12-10 15:38:37
1
1,104
gis20
74,753,898
14,661,648
psycopg2.ProgrammingError: no results to fetch (fetchall SELECT EXISTS)
<pre><code>Traceback (most recent call last): File &quot;/app/main.py&quot;, line 324, in that_function links = cur.fetchall()[0] File &quot;/app/.heroku/python/lib/python3.10/site-packages/psycopg2/extras.py&quot;, line 104, in fetchall res = super().fetchall() psycopg2.ProgrammingError: no results to fetc...
<python><postgresql><psycopg2>
2022-12-10 14:43:29
0
1,067
Jiehfeng
74,753,755
12,285,101
list comprehension with Regex to match whole item if it has matching number between two specific characters
<p>This question is the continuation <a href="https://stackoverflow.com/questions/74744103/regex-python-find-match-items-on-list-that-have-the-same-digit-between-the-sec/74744288?noredirect=1#comment131931854_74744288">of this post.</a> I have the following list :</p> <pre><code>list_paths=[imgs/foldeer/img_ABC_21389_1...
<python><regex><list>
2022-12-10 14:25:48
1
1,592
Reut
74,753,748
11,440,563
pytorch - optimizer that favors true positives
<p>I have a beginner high level question about pytorch optimizer, namely is there a non-custom way to optimize for true positives? Let's say that i have a list of labels:</p> <pre><code>labels=[0,0,0,0,0,0,0,0,0,1] </code></pre> <p>And I would like a model to fit to those labels in a way that would favor a true positiv...
<python><pytorch><loss-function>
2022-12-10 14:24:54
1
363
pawelofficial
74,753,606
7,454,513
DRF - How to using serializer to load related data
<p>I have a self related table <code>Employee</code>, and <code>Project</code> table has foreignkey to related to <code>Employee</code> table.</p> <pre><code>class Employee(models.Model): eid = models.CharField(primary_key=True, max_length=10) name = models.CharField(max_length=10) pmid = models.ForeignKey(...
<python><django><django-rest-framework>
2022-12-10 14:05:46
1
683
Relax ZeroC
74,753,574
1,196,540
How to remove or disable unwanted languages in Django 4.1.1
<p>I had a question about translations in Django... So I have a project with 4 languages defined in my settings.py</p> <pre><code>LANGUAGES = [ ('en', _('English')), ('fr', _('French')), ('de', _('German')), ('it', _('Italy')), ] </code></pre> <p>now I want to disable all languages except english, so I'...
<python><django>
2022-12-10 14:02:31
2
733
vladimir
74,753,477
2,482,149
Boto3 - Copy Object to a newly generated S3 location and return name in http body
<p>I have a lambda that runs via a http trigger in API Gateway.</p> <p>My goal is to:</p> <ol> <li>Copy files from <code>input-bucket</code> (where the user uploads his/her files)</li> <li>Create a UUID as a new location/folder in a separate bucket (<code>output-bucket</code>)</li> <li>Paste those objects in that new l...
<python><amazon-web-services><amazon-s3><aws-lambda><terraform>
2022-12-10 13:47:51
2
1,226
clattenburg cake
74,753,455
2,276,831
How to split up an email body that contains replies (i.e. an email thread)?
<p>I am reading an email body using the python <code>imap</code> and <code>email</code> libraries:</p> <pre class="lang-py prettyprint-override"><code>import imaplib from email import message_from_bytes imap = imaplib.IMAP4_SSL(host) imap.login(email_address, pw) _, output = imap.fetch(&quot;100&quot;, &quot;(RFC822)&...
<python><email><imap>
2022-12-10 13:44:23
0
4,515
mic
74,753,293
12,361,700
Tensorflow fit history is noisier than expected
<p>I've fitted a model and this is the plot i get with te following code:</p> <pre><code>hist = model.fit( xs, ys, epochs=300, batch_size=100, validation_split=0.1, callbacks=[K.callbacks.EarlyStopping(patience=30)] ) plt.figure(dpi=200) plt.plot(hist.history[&quot;loss&quot;]) plt.plot(hist.history[&quot;val_l...
<python><tensorflow><keras><deep-learning><neural-network>
2022-12-10 13:22:39
0
13,109
Alberto
74,753,277
5,452,365
How to get first element from lxml using xpath
<p>Minimal example:</p> <pre><code>In [1]: from lxml import etree In [2]: etree.fromstring('&lt;who&gt;syslogd&lt;/who&gt;').xpath('/who/text()') Out[2]: ['syslogd'] </code></pre> <p>currently I'm using helper function:</p> <pre><code>def safe_xpath_one(tree: Element, xpath: str) -&gt; Union[Element, None]: res =...
<python><xpath><lxml><libxml2>
2022-12-10 13:20:15
2
11,652
Rahul
74,753,081
20,078,696
How to create an MPLClassifier from weights and biases? (Python 3)
<p>I am trying to create an MPLClassifier with predefined weights and biases so that I can save them to a file and then</p> <p>If I train the network like this:</p> <pre><code>import numpy as np from sklearn.neural_network import MLPClassifier data = np.load(&quot;data.npy&quot;) labels = np.load(&quot;labels.npy&quot...
<python><scikit-learn><deep-learning>
2022-12-10 12:53:20
1
789
sbottingota
74,753,015
12,500,949
Decode Httrack encoded urls in Python?
<p>I have downloaded a full website using Httrack Website Copier and now I want to retrieve all image source ('src') urls using Python 3.7.</p> <p>Already did that but for further use I need those urls to be in plain text but instead they are something like this:</p> <pre><code>cid:httpsX3aX2fX2fcommonsX2emX2ewikimedi...
<python><python-3.x><utf-8><urldecode><httrack>
2022-12-10 12:44:20
0
439
YoYoYo
74,752,844
6,551,439
How can i pass validated data to another custom validator class in DRF?
<p>I Have this kind of serializer.py</p> <pre><code>class PostSerializer(serializers.ModelSerializer): title = serializers.CharField(validators=[TitleValidator()]) slug = serializers.CharField(validators=[SlugsValidator()], max_length=100, required=False) </code></pre> <p>and i have two class validators for thi...
<python><django><django-rest-framework>
2022-12-10 12:19:39
0
1,575
Andrew
74,752,810
10,266,059
Why do I get "ModuleNotFoundError: No module named 'TAP'" when TAP is installed?
<p>I am trying to use Rx to validate a YAML document against a schema, but python can't find the TAP module even though I've just installed it and I can see it's right there:</p> <pre><code>[:~/git/Rx/python] [my-venv] master* Β± python3 rx-test.py Traceback (most recent call last): File &quot;/home/atsaloli/git/Rx/py...
<python>
2022-12-10 12:13:39
0
1,676
Aleksey Tsalolikhin
74,752,799
4,169,571
Extract columns of numpy array consisting of lists
<p>I have a variable <code>var</code></p> <p>When I print it in jupyter, it gives:</p> <pre><code>var #array([list([9166855000000.0, 13353516.0]), # list([7818836000000.0, 11389833.0]), # list([20269756000000.0, 29527304.0]), # list([66886956000000.0, 97435384.0]), # list([58686560000000.0, 854...
<python><list><numpy><numpy-ndarray>
2022-12-10 12:10:48
2
817
len
74,752,610
3,809,375
How to use argparse to create command groups like git?
<p>I'm trying to figure out how to use properly builtin <a href="https://docs.python.org/3/library/argparse.html" rel="noreferrer">argparse</a> module to get a similar output than tools such as git where I can display a nice help with all &quot;root commands&quot; nicely grouped, ie:</p> <pre><code>$ git --help usage: ...
<python><python-3.x><argparse>
2022-12-10 11:43:51
1
9,975
BPL
74,752,491
11,462,274
Boolean Series key reindexed when trying to generate a malleable filter to traverse a DataFrame
<p>I found <a href="https://stackoverflow.com/questions/41710789/boolean-series-key-will-be-reindexed-to-match-dataframe-index">this question</a> but I couldn't understand the problem and I couldn't adjust it for my case:</p> <p>Usage example:</p> <p>let's assume that I want to get the value of <code>competition</code>...
<python><pandas><dataframe>
2022-12-10 11:27:10
1
2,222
Digital Farmer
74,752,403
18,308,393
Button not clicking with scrapy playwright
<p>I am attempting to click on an sso login for a platform by testing its button functionality with scrapy playwright. I have inputted an incorrect email and so after clicking the button, it should throw a text error that the email is incorrect. However, nothing seems to happen.</p> <p>For example:</p> <pre><code>impor...
<javascript><python><scrapy><playwright>
2022-12-10 11:14:58
0
367
Dollar Tune-bill
74,752,394
7,032,967
Python file name on create
<p>I'm trying to learn files in Python and I have this set of codes, this code used to create a normal file in the development server which I used to play, but in production, the files output as <strong>'2022-12-10 10:40:14.599578+00:00.webm'</strong> , enclosed within single quotes, now I'm not sure if I manually ...
<python><python-3.x><file>
2022-12-10 11:14:02
1
1,314
Ranu Vijay
74,752,390
14,082,033
How can I reduce outliers in the output of a regression model?
<p>I am using a Keras model for regression which inputs are sensor measurements, and the output is the attitude of the sensor. This model consists of CuDNNLSTM and CNN. I need to reduce the number or range of outliers in the output.</p> <p>The mean error is reasonable and low, but there are so many outliers in the outp...
<python><tensorflow><keras><deep-learning>
2022-12-10 11:13:46
1
331
Arman Asgharpoor
74,752,386
5,381,753
API to get all pincodes inside a radius
<p>I'm working on a python application where we need to get all the pincodes within a specific radius. We have a base location and a radius of 10Km is drawn from this base pincode.</p> <p>Do we have any API where this can be achieved?</p> <p>FYA - Mainly looking for Indian PostalCodes.</p>
<python><django><google-api><maps>
2022-12-10 11:13:23
1
771
Aravind Pillai
74,752,303
6,300,872
Backtrader, using mongodb as datafeed instead CSV
<p>I'm quite new to backtrader and since I've started I couldn't stop wondering why there's no database support for the datafeed. I've found a page on the official website where's described how to implement a custom datafeed. The implementation should be pretty easy, but on github (or more in general on the web) I coul...
<python><mongodb><backtrader>
2022-12-10 11:02:32
0
847
Paolo Ardissone
74,752,253
5,684,405
Efficient edit pandas column values based on column value which is list of strings
<p>How to EFFICIENTLY (fast way) edit pandas DF column based on a condition on string, where the column values are lists of strings.</p> <p>eg find all rows with a string from set <code>{'Adam', 'bbb'}</code> in df column <code>string_lists</code> (which is a list of strings) and remove this strings (<code>'Adam', 'bbb...
<python><pandas>
2022-12-10 10:53:17
1
2,969
mCs
74,752,251
10,773,616
Read Process Memory doesn't seem to give the right value
<p>I am trying to read memory from a process (gameboy advance emulator) in Python using ReadProcessMemory. There is a memory viewer and I am supposed to get 81 at 0xD273 (see picture). I am new to this, I tried to do everything correctly by adding reference in the ReadProcessMemory, but there might be some things that ...
<python><emulation><ctypes><readprocessmemory><gameboy>
2022-12-10 10:52:57
1
371
JΓ©rΓ©my Talbot-PΓ’quet
74,752,181
17,795,398
Python and terminal: keep python environment after the file has been executed
<p>I have to run a Python file from the Windows terminal (Windows PowerShell). I want that after the file has been executed (<code>python foo.py</code>), python keeps open with the variables defined in the file.</p> <p>If it is unclear what I want, I want the same behavior as IDLE, after the file has been executed, you...
<python><linux><windows>
2022-12-10 10:40:17
1
472
Abel GutiΓ©rrez
74,752,120
11,963,167
Waiting for an external response without consuming resources
<p>I have a simple python program that needs to apply a function to circles based on their radius. My issue is, I need to fetch the radius from a third-party API, which may take up to several hours to send me the radius sizes, as a csv file for instance.</p> <p>To be clearer:</p> <pre class="lang-py prettyprint-overrid...
<python><python-asyncio><pickle><external>
2022-12-10 10:32:02
0
496
Clej
74,752,014
1,272,975
Structure of importable pytest plugin
<p>I have some data/fixtures that are common across several projects. So the sensible thing to do is to refactor them into a standalone project and import them in the projects. Structure of the project I'm about to refactor looks like this:</p> <pre><code>my-project/ src/ db/ __init__.py ...
<python><pytest><directory-structure>
2022-12-10 10:13:16
1
734
stevew
74,751,979
13,860,217
How to scrape dynamic content displayed in tooltips using scrapy
<p>I'd like to extract the text inside the class &quot;spc spc-nowrap&quot; using scrapy and the container software docker to scrape dynamically loaded content.</p> <pre><code>&lt;div id=&quot;tooltipdiv&quot; style=&quot;position: absolute; z-index: 100; left: 637.188px; top: 625.609px; display: none;&quot;&gt; &lt;...
<python><web-scraping><scrapy><web-crawler><tooltip>
2022-12-10 10:07:51
1
377
Michael
74,751,950
1,265,955
How to set cell formula using odfpy
<p>I keep getting Err:508 or #Name? (Err:525) when opening a spreadsheet created with odfpy and putting a formula in a cell with the following code:</p> <pre><code>tc = TableCell( valuetype=&quot;string&quot;, formula=calc, value=0 ) </code></pre> <p>In the spreadsheet, the formula looks fine, and any edit to it togeth...
<python><odfpy>
2022-12-10 10:03:14
1
515
Victoria
74,751,832
5,618,856
pandas dataframe to_sql - how to preserve data types
<p>I have a dataframe (from a nested json) with</p> <pre><code>df.dtypes name string nested1 object nested2 object a_number float64 </code></pre> <p>writing it to a database with sqlite3 (<code>df.to_sql(table, connection)</code>) ...
<python><pandas><sqlite>
2022-12-10 09:42:47
1
603
Fred