QuestionId
int64
74.8M
79.8M
UserId
int64
56
29.4M
QuestionTitle
stringlengths
15
150
QuestionBody
stringlengths
40
40.3k
Tags
stringlengths
8
101
CreationDate
stringdate
2022-12-10 09:42:47
2025-11-01 19:08:18
AnswerCount
int64
0
44
UserExpertiseLevel
int64
301
888k
UserDisplayName
stringlengths
3
30
76,222,599
5,568,409
How to modify ax.set_title to include differents colors?
<p>I am plotting a specific figure using the following program:</p> <pre><code>alpha, beta = 0.5, 0.5 fig, ax = plt.subplots(1, 1, figsize = (6,3)) ax.set_title(r&quot;Predicted $x$ with Bayes Factor w.r.t. $\beta(1,1)$:&quot; + &quot;\n&quot; + &quot;&gt; 3 (green) or &lt; 3 (blue)&quot; + &quot;\n&quot;...
<python><matplotlib><text-coloring>
2023-05-10 21:14:37
0
1,216
Andrew
76,222,558
32,584
How to POST customFieldValues with SynchroTeam API using Python request?
<p>Q: How should one update the customFieldValues in SynchroTeam using a Python POST request?</p> <p><a href="https://api.synchroteam.com/#custom-field-values" rel="nofollow noreferrer">https://api.synchroteam.com/#custom-field-values</a></p> <p>I spent the past day working on this getting a Error 500 response, and no ...
<python><post>
2023-05-10 21:05:36
1
1,655
Steve L
76,222,450
2,726,900
Cannot establish SSL connection to cluster, getting SSLHandshakeException: "error:100000f7:SSL routines:OPENSSL_internal:WRONG_VERSION_NUMBER"
<p>I'm trying to save a PySpark dataframe to Cassandra DB with Datastax Spark Cassanra Connector.</p> <p>I set <code>spark.cassandra.connection.ssl.enabled</code>, create a SparkSession and try to save my dataframe. And I got the following error message in Cassandra logs:</p> <pre><code>WARN [epollEventLoopGroup-5-32]...
<python><ssl><pyspark><cassandra><spark-cassandra-connector>
2023-05-10 20:48:13
1
3,669
Felix
76,222,409
1,416,371
How to create python C++ extension with submodule that can be imported
<p>I'm creating a C++ extension for python. It creates a module <code>parent</code> that contains a sub-module <code>child</code>. The <code>child</code> has one method <code>hello()</code>. It works fine if I call it as</p> <pre class="lang-py prettyprint-override"><code>import parent parent.child.hello() &gt; 'Hi, Wo...
<python><c++><cpython><python-extensions>
2023-05-10 20:41:22
5
316
BlacKow
76,222,383
1,870,832
Python Panel Dashboard - Multi-Page app not updating as expected
<p>I want a Python Panel app which shows different page content based on a radio button selection in the sidebar.</p> <p>There's some example code for doing exactly this in the way I want, shown as &quot;Option 3&quot; here: <a href="https://discourse.holoviz.org/t/multi-page-app-documentation/3108/3?u=maxpower" rel="n...
<python><dashboard><holoviz><holoviz-panel>
2023-05-10 20:37:11
1
9,136
Max Power
76,222,369
19,079,397
Intersect a set polygons/multi-polygons at once and get the intersected polygon
<p>I have a <code>Geopandas</code> data frame with five multi-polygons geometries. Now, I want to intersect all the geometries at once and get the intersected polygon out of it. I tried using unary union and <code>polygonize</code> but this is giving me a list of polygons but I want only one polygon that has the inters...
<python><geopandas><intersection><multipolygons>
2023-05-10 20:35:43
1
615
data en
76,222,354
494,134
Why would requests throw an immediate ReadTimeout error?
<p>In our production environment (which unfortunately I do not have direct access to), we have some code that looks like this:</p> <pre><code>data = &quot;xml document&quot; auth = username, password response = requests.patch(url, data=data, auth=auth, headers={'Content-type': 'application/xml'}, timeout=10) </code...
<python><python-requests>
2023-05-10 20:32:51
0
33,765
John Gordon
76,222,227
903,051
Accept cookies with Selenium in Python
<p>I am aware that similar questions have been asked numerous times, but I have tried everything to no avail.</p> <p>I am scrapping <a href="https://www.loterie.lu/content/portal/fr/playnow/lotto/results.html" rel="nofollow noreferrer">this website</a></p> <p>The following used to work:</p> <pre><code>WebDriverWait(dri...
<python><selenium-webdriver><cookies><popup>
2023-05-10 20:10:23
1
543
mirix
76,222,022
14,301,911
How to use categorical data type with pyarrow dtypes?
<p><strong>I'm working with the arrow dtypes with pandas</strong>, and my dataframe has a variable that should be categorical, <strong>but I can't figure out how to transform it into pyarrow data type for categorical data (dictionary)</strong></p> <p>According to pandas (<a href="https://arrow.apache.org/docs/python/pa...
<python><pandas><types><pyarrow><dtype>
2023-05-10 19:34:32
1
504
HappilyCoding
76,222,016
10,918,680
Python 3 Pandas: Custom sorting a list of strings
<p>I need to sort a list of strings such that &quot;non-numeric&quot; values are sorted alphabetically first, followed by &quot;numeric&quot; values, in ascending order.</p> <p>For example, suppose the list is:</p> <pre><code>l = ['2.9', '-1', '0', 'ab2', 'xyz', 'ab'] </code></pre> <p>I'd like the output to be:</p> <pr...
<python><pandas>
2023-05-10 19:34:12
1
425
user173729
76,221,977
14,500,576
Fill time series pandas dataframe with synthetic data that has a similar shape as the original data
<p>I have a time series in pandas with a large gap in between, I would like to fill that gap with &quot;synthetic&quot; data that resembles the same shape and trend of the data that is existing.</p> <p>Some of the methods that I've tried have been linear, cubic, spline interpolation, but the noise and general shape of ...
<python><pandas><null>
2023-05-10 19:28:58
2
355
ortunoa
76,221,895
2,562,058
MultiIndex names when using pd.concat disappeared
<p>Consider the following dataframes <code>df1</code> and <code>df2</code>:</p> <pre><code>df1: sim_names Model 1 signal_names my_y1 my_y2 units °C kPa (Time, s) 0.0 0.738280 1.478617 0.1 1.078653 0.486527 0.2 0.794123 ...
<python><pandas><dataframe>
2023-05-10 19:16:27
1
1,866
Barzi2001
76,221,815
396,014
scipy.interpolate.BSpline: Are there rules of thumb for the length of the enlarges x vector?
<p>I have code working to smooth some accelerometer x,y,z values in columns (toy data):</p> <pre><code>import numpy as np import pandas as pd from scipy.interpolate import make_interp_spline, BSpline idx = [1,2,3,4] ts_length = 200 idx = np.array(idx,dtype=int) accel = [[-0.7437,0.1118,-0.5367], [-0.5471,0.00...
<python><scipy><spline>
2023-05-10 19:06:24
1
1,001
Steve
76,221,700
5,980,143
Is it correct to use one instance of ChromeDriverManager for all unittests
<p>I am using <code>ChromeDriverManager</code> for writing automation tests. I am trying to figure out what is the correct way to initialize a driver for the tests.</p> <p>Should I initialize one driver which should be used for <strong>all</strong> tests? <br> Or should the driver be initialized for <strong>each</stron...
<python><unit-testing><selenium-webdriver><e2e-testing>
2023-05-10 18:47:05
0
4,369
dina
76,221,585
785,404
How can I extract the contents of a Python xar file?
<p>I have a <code>.xar</code> file. <a href="https://github.com/facebookincubator/xar/blob/main/README.md" rel="nofollow noreferrer">.xar is an exectuable archive file format developed by Meta/Facebook for creating self-contained Python binaries.</a> I would like to extract its contents into a directory so I can look a...
<python><xar>
2023-05-10 18:28:38
1
2,085
Kerrick Staley
76,221,461
2,133,814
How to generate python type hints in generated grpc code
<p>Can PEP compliant type hints be automatically added to generated source code, or dynamically created, for python and gRPC? Specifically in the <a href="https://grpc.io/docs/languages/python/basics/#simple-rpc-1" rel="nofollow noreferrer">basics tutorial</a> in the client section for <code>feature = stub.GetFeature(p...
<python><grpc><type-hinting><grpc-python>
2023-05-10 18:11:03
2
2,681
user2133814
76,221,354
913,098
get the bbox of a padding in numpy, without creating the padded array
<p>I have a numpy array (can assume 2d):</p> <pre><code>a = np.zeros((w_world, h_world)) </code></pre> <p>and a box given as ltwh relative to that array [can be out of bounds]</p> <pre><code>b = np.zeros((w_box, h_box)) </code></pre> <p>I would like to find where <code>b</code> would lie in <code>a</code> if I padded i...
<python><arrays><numpy><padding>
2023-05-10 17:57:11
0
28,697
Gulzar
76,221,322
1,203,941
Exec fails when applied to a code with a new type
<p>I have a file <code>multiply.py</code> with the following contents:</p> <pre class="lang-py prettyprint-override"><code>from typing import NamedTuple class Result(NamedTuple): product: int desc: str def multiply(a: int, b: int) -&gt; Result: return Result( product=a * b, desc=f&quot;mul...
<python><python-3.x>
2023-05-10 17:52:11
1
507
grześ
76,221,272
6,024,751
How to make bond lines thicker with Rdkit
<p>I am using RDkit to draw a molecule in 2D. I am trying to use <code>DrawingOptions.bondLineWidth</code> to control the bond thickness but it doesn't seem to be working (the bond lines remain the same thickness regardless of the value I set it to). Any idea?</p> <pre><code>from rdkit.Chem import Draw from rdkit.Chem....
<python><matplotlib><rdkit>
2023-05-10 17:45:27
1
790
Julep
76,221,268
6,395,775
Is It possible convert PKCS7 to PkiPath with OpenSSL?
<p>I'm trying to translate a code written in clojure to openssl (I want to use this instead of clojure), but I came across the following line of code:</p> <pre><code>(def cert-path-encoded (.getEncoded cert-path &quot;PkiPath&quot;)) (def cert-path-encoded-b64 (.encodeToString (java.util.Base64/getEncoder) ...
<python><clojure><openssl><certificate>
2023-05-10 17:44:46
1
592
Thales
76,221,191
21,420,742
Creating columns from counts in pyhton
<p>I have a dataset</p> <pre><code> Manager_Name Hire_Type Person_Hired Status Adam FT James Pending Adam PT Emily Approved Ben FT Paul Approved Ben FT Sarah Appro...
<python><python-3.x><pandas><dataframe><numpy>
2023-05-10 17:34:05
0
473
Coding_Nubie
76,221,157
5,127,199
Create a list or array of date time using pandas
<p>I am trying to create a list of date time in python using <code>pandas</code>. I want something like:</p> <pre><code>2023-05-10_00:00:00 2023-05-10_01:00:00 2023-05-10_02:00:00 ..... ..... 2023-05-10_23:00:00 </code></pre> <p>So basically I want data with datetime with 1 hour increment. I tried the following</p> <pr...
<python><pandas>
2023-05-10 17:29:46
2
1,029
Shreta Ghimire
76,221,113
10,637,327
Refactoring pandas using an iterator via chunksize
<p>I am looking for advice on using a <code>pandas</code> iterator.</p> <p>I performed a parsing operation using Python <code>pandas</code>, the size of the input files (a bioinformatics program called eggNOG) is resulting in 'RAM bottleneck' phenomenon. It's just not processing the file.</p> <p>The obvious solution is...
<python><pandas><csv><iterator><refactoring>
2023-05-10 17:24:26
2
636
M__
76,221,016
12,167,708
Find similarity in a very precise numerical environment
<p>I have a list of 100+ sentences, and I need to find which is the closest to a user prompt. The thing is that we are dealing with very precise, nuanced prompt, because we analyze numeric data. Eaxmple:</p> <pre><code>1. Did variable x changed at least 5% in the past week ? 2. show me variable x change in the past wee...
<python><nlp><spacy>
2023-05-10 17:11:06
1
441
hkrlys
76,221,009
7,895,542
Index numpy array by matrix of two arrays
<p>I have a 2D numpy array like</p> <pre><code>weights = np.array( [ [1, 2, 3], [4, 5, 6], [7, 8, 9], ] ) </code></pre> <p>And i have two 1-D numpy arrays that i want to use to index into weights</p> <pre><code>positions1 = np.array([2, 1, 0]) positions2 = np.array([1, 1, 0]) </code></pr...
<python><arrays><numpy>
2023-05-10 17:10:25
2
360
J.N.
76,220,904
12,279,326
Boto3 KeyConditionExpression works and get_item does not
<p>I am new to DynamoDB and finding my way around DocumentDBs versus Relational DBs.</p> <p>My code is running via AWS Lambda functions with a Python runtime. <strong>It works</strong>.</p> <pre><code>def get_item_by_id(table_name: str, partition_key: str, partition_value: str) -&gt; List[dict]: &quot;&quot;&quot; ...
<python><amazon-dynamodb>
2023-05-10 16:54:58
2
948
dimButTries
76,220,875
9,640,992
In PyCharm, how do you import a project as a whole (not only its modules) from another one?
<p>I have two projects: <code>project_main</code>, <code>utils</code></p> <p>Anywhere in project_main, I would like to do <code>from utils import ua, ub</code></p> <p>It is the same problem that has been answered here <a href="https://stackoverflow.com/questions/39648578/in-pycharm-how-do-you-add-a-directory-from-one-p...
<python><pycharm><dependencies><project>
2023-05-10 16:51:05
0
806
Valentin Fabianski
76,220,790
21,376,217
In network programming, must the accepting end close both sockets?
<p>I raised a question earlier, and one of the answers involved another question.</p> <p>That is to say, in general, the accepting end should create two sockets to establish the accepting end. like this:</p> <h3>Python</h3> <pre class="lang-py prettyprint-override"><code>from socket import * sockfd = socket(...) # ... ...
<python><c><sockets>
2023-05-10 16:39:11
4
402
S-N
76,220,715
6,326,147
Type "vector" does not exist on postgresql - langchain
<p>I was trying to embed some documents on postgresql with the help of <a href="https://github.com/pgvector/pgvector" rel="noreferrer">pgvector</a> extension and <a href="https://github.com/hwchase17/langchain" rel="noreferrer">langchain</a>. Unfortunately I'm having trouble with the following error:</p> <pre class="la...
<python><postgresql><vectorization><langchain>
2023-05-10 16:28:47
6
1,073
Rijoanul Hasan Shanto
76,220,639
14,992,339
Entity resolution - creating a unique identifier based on 3 columns
<p>I'm trying to find a way to create a unique identifier by using 3 columns (user_id, universal_id and session_id). Column &quot;expected_result&quot; is what this unique_id should be after processing other 3 columns.</p> <ul> <li>Sometimes user_id is not available, and in that case the other two columns should be use...
<python><apache-spark><pyspark>
2023-05-10 16:19:27
1
307
mare011
76,220,612
5,899,370
VSCode: running the exact same terminal command produces different results depending on if it was run by clicking a UI button
<h1>problem</h1> <p>Consider the following terminal command:</p> <p><code>PS C:\dev&gt; c:; cd 'c:\dev'; &amp; C:\Users\{user}\AppData\Local\Microsoft\WindowsApps\python3.11.exe' 'c:\Users\{user}\.vscode\extensions\ms-python.python 2023.6.1\pythonFiles\lib\python\debugpy\adapter/../..\debugpy\launcher' '60106' '--' 'c...
<python><visual-studio-code>
2023-05-10 16:13:32
1
427
John VanZwieten
76,220,528
12,750,353
How to suppress tokens in whisper
<p>Consider the following decoding script</p> <pre class="lang-py prettyprint-override"><code>from transformers import ( WhisperProcessor, WhisperForConditionalGeneration,) MODEL_NAME=&quot;openai/whisper-tiny.en&quot; processor = WhisperProcessor.from_pretrained(MODEL_NAME) model = WhisperForCondition...
<python><openai-whisper>
2023-05-10 16:02:19
1
14,764
Bob
76,220,250
7,168,098
creating a new column in polars applying a function to a column
<p>I have the following code for manipulating a polars dataframe that does not work</p> <pre class="lang-py prettyprint-override"><code>import polars as pl import xml.etree.ElementTree as ET # create a sample dataframe df = pl.DataFrame({ 'A': [1, 2, 3], 'B': ['&lt;p&gt;some text&lt;/p&gt;&lt;p&gt;bla&lt;/p&gt...
<python><xml><apply><python-polars>
2023-05-10 15:31:33
2
3,553
JFerro
76,220,202
7,693,707
How to draw a plot but not showing it in matplotlib
<p>I wish to utilize the easy plotting feature of Matplotlib to generate some bitmaps as templates or (rather large) convolution kernels.</p> <p>I followed <a href="https://stackoverflow.com/questions/35355930/matplotlib-figure-to-image-as-a-numpy-array">this post</a> to convert the plot into a Numpy array:</p> <pre><c...
<python><matplotlib><google-colaboratory>
2023-05-10 15:25:40
1
1,090
Amarth Gûl
76,220,054
353,337
Replace three dashes, but only if significant characters follow in the same line
<p>In a multiline text, I would like to replace triple dashes, <code>---</code>, by <code>X</code>. There need to be exactly three dashed in a row, not two or four. Another restriction: If <code>---</code> is the last character in the line (except possible trailing whitespace), don't replace it.</p> <p>So far, I got</p...
<python><regex>
2023-05-10 15:08:47
1
59,565
Nico Schlömer
76,220,019
2,236,315
How to make a completely independent copy of a Python pandas object?
<p>I am trying to make a completely independent copy of a Python pandas object and it feels like I am either missing some key Python understanding about Python objects or not finding the right copy tool. Here is an example (extended from <a href="https://pandas.pydata.org/pandas-docs/stable/reference/api/pandas.DataFra...
<python><pandas><dataframe><copy><deep-copy>
2023-05-10 15:05:48
0
465
ximiki
76,219,942
6,435,921
Numpy: multiply slices of final dimension by another array
<p>I have an array <code>x</code> of dimension <code>(N, M)</code> and an array <code>y</code> of dimension <code>(N, M, 2)</code>. For any <code>i, j</code> I would like to multiply each <code>y[i, j, :]</code> by <code>x[i, j]</code>. How can I do this?</p> <pre class="lang-py prettyprint-override"><code>import numpy...
<python><python-3.x><numpy><numpy-ndarray>
2023-05-10 14:59:07
1
3,601
Euler_Salter
76,219,783
5,759,359
Download all files from all sub-directories from Azure data lake Gen2 path using python
<p>I need to download all the files from all the folders listed inside the source folder from AZURE ADLS Gen2 space. The path looks like below</p> <pre><code>abfss://abc@xyz.dfs.core.windows.net/rock/final_update/ROCK_OrdersDetails </code></pre> <p>There are multiple folders inside ROCK_OrdersDetails, I need to visit e...
<python><azure-blob-storage><azure-data-lake-gen2>
2023-05-10 14:43:43
1
477
Kashyap
76,219,721
1,019,455
IndexError: index out of range in self
<p><code>gpt2_fine_tune.py</code></p> <pre class="lang-py prettyprint-override"><code>from datasets import load_dataset from transformers import GPT2Tokenizer, GPT2LMHeadModel, Trainer, TrainingArguments # Step 1: Load the pre-trained GPT-2 model model = GPT2LMHeadModel.from_pretrained('gpt2') # Step 2: Tokenize the ...
<python><python-3.x><machine-learning>
2023-05-10 14:37:47
1
9,623
joe
76,219,643
2,404,492
Python subprocess output is logged by systemd twice
<p>In my application, I have the following code:</p> <pre><code>def ifdown(iface): rc = subprocess.run(['/sbin/ifdown', iface]).returncode if rc: print(f'ifdown({iface}) returned {rc}') return False return True </code></pre> <p>This application is run as a systemd service, the issue is when ...
<python><debian><systemd><debian-buster>
2023-05-10 14:28:45
0
1,046
Alexandr Zarubkin
76,219,628
610,569
How to get the null count for every column in a polars dataframe?
<p>In pandas, one can do:</p> <pre><code>import pandas as pd d = {&quot;foo&quot;:[1,2,3, None], &quot;bar&quot;:[4,None, None, 6]} df_pandas = pd.DataFrame.from_dict(d) dict(df_pandas.isnull().sum()) </code></pre> <p>[out]:</p> <pre><code>{'foo': 1, 'bar': 2} </code></pre> <p>In polars it's possible to do the same by...
<python><dataframe><null><python-polars>
2023-05-10 14:26:35
2
123,325
alvas
76,219,507
9,488,023
Replace a value in a column in a Pandas dataframe if another column contains a certain string
<p>I have a very long and complicated Pandas dataframe in Python that looks something like this:</p> <pre><code>df_test = pd.DataFrame(data = None, columns = ['file','comment','number']) df_test.file = ['file_1', 'file_1_v2', 'file_2', 'file_2_v2', 'file_3', 'file_3_v2'] df_test.comment = ['none: 5', 'Replacing: file_1...
<python><pandas><dataframe>
2023-05-10 14:16:35
2
423
Marcus K.
76,219,432
8,678,015
How to build a BallTree with haversine distance metric?
<p>I have been studying how to implement a <code>sklearn.neighbors.BallTree</code> with <code>sklearn.metrics.pairwise.haversine_distances</code> metric.</p> <p>Despite my efforts, I couldn't reach a working script.</p> <p>Despite the standard example from the sklearn documentation <a href="https://scikit-learn.org/st...
<python><scikit-learn><distance><haversine>
2023-05-10 14:09:38
1
1,076
Philipe Riskalla Leal
76,219,351
1,648,641
How do I call __import__ when dynamically importing in python
<p>I am just playing around with the dynamically importing a module example as they do in 16.15 of dive into python.</p> <p>I am doing something like</p> <pre><code>modulenames = ['my_module'] modules = list(map(__import__, modulenames)) modules[0].process() </code></pre> <p>However my model is in a subdirectory (calle...
<python>
2023-05-10 14:01:54
2
1,870
Lieuwe
76,219,204
18,671,446
Microsoft ODBC Driver 17 for SQL Server Communication link failure (0) state:"08S01" using Python SQLAlchemy 1.4.41
<p>We have a Dockerized FastAPI <code>fastapi==0.87.0</code>, <code>SQLAlchemy==1.4.41</code> OS: <code>Linux Ubuntu</code> which communicates to a remote MSSQL database OS:<code>Windows Server 2019</code> <code>Microsoft SQL Server 2017 (RTM-GDR) (KB5021127) - 14.0.2047.8 (X64)</code></p> <p>We have been using the fol...
<python><python-3.x><sql-server><sqlalchemy>
2023-05-10 13:46:16
0
1,045
Kostas Nitaf
76,219,137
21,420,742
Creating a column in one DF that compares another column from other DF in pandas
<p>I have two datasets that I need to see how many names are different in one dataset to another. I used this question for reference and the code I used only found 1 issue is there are others.</p> <p><a href="https://stackoverflow.com/questions/50449088/check_if-value-from-one-dataframe-exists-in-another-dataframe">Che...
<python><python-3.x><pandas><dataframe><numpy>
2023-05-10 13:38:58
2
473
Coding_Nubie
76,219,074
3,484,568
Call wrapped function with different arguments
<p>I am looking for a pythonic way to pass the expected list of arguments to a wrapped function. The problem is that the expected arguments differ by the function that is passed to the wrapper.</p> <p>In my case, I want to refactor (repetitive) code that simulates multiple types of time series in a recursive manner. Ex...
<python><refactoring>
2023-05-10 13:32:19
0
618
Jhonny
76,219,053
19,283,541
How to efficiently structure a python script intended to be run in parts from the command line?
<p>Suppose I have a script like so:</p> <pre><code>import argparse def set_up(): # Code that takes a while to run initial_number = 5 return initial_number def add_n(initial_number, n): # Code that doesn't take so long result = initial_number + n return result if...
<python><command-line><module>
2023-05-10 13:29:51
1
309
radishapollo
76,219,039
12,559,770
Formate a table with two lines in pandas
<p>Hello I have a dataframe such as</p> <pre><code>Start End Feature Qualifier Function 1 35 CDS Product Gene1 36 67 CDS Product Putative_actin 69 123 CDS Product 1_hypothetical protein 345 562 CDS Product 2_hypothetical protein </code></pre> <p>And I would like to format this tabl...
<python><python-3.x><pandas>
2023-05-10 13:28:50
3
3,442
chippycentra
76,218,937
585,806
How to load and save model with image-super-resolution repo?
<p>I'm trying to use <a href="https://github.com/idealo/image-super-resolution" rel="nofollow noreferrer">this github repo</a> I'm able to run training with my own dataset but I can't fin how to load and save weights ?</p> <p>This is my code:</p> <pre><code>from ISR.models import RRDN from ISR.models import Discriminat...
<python><tensorflow><github>
2023-05-10 13:19:10
1
2,271
Entretoize
76,218,924
10,164,750
Deriving value of new column based on Group Pyspak
<p>I have a use case where I want to derive the <code>gender</code> of a <code>person</code> by doing <code>GroupBy</code>.</p> <p>If the <code>GroupBy</code> contains <code>MALE</code> and <code>NEUTRAL</code> title. We can consider ther person <code>male</code>.</p> <p>If the <code>GroupBy</code> contains <code>FEMAL...
<python><dataframe><apache-spark><pyspark>
2023-05-10 13:17:26
1
331
SDS
76,218,923
13,916,049
How to remove everything after the last occurrence of a delimiter?
<p>I want to remove everything after the last occurrence of the <code>_</code> delimiter in the <code>HTAN Parent Biospecimen ID</code> column.</p> <pre><code>import pandas as pd df_2[&quot;HTAN Parent Biospecimen ID&quot;] = df_2[&quot;HTAN Parent Biospecimen ID&quot;].str.rsplit(&quot;_&quot;, 1).str.get(0) </code></...
<python><pandas>
2023-05-10 13:17:16
3
1,545
Anon
76,218,874
7,253,901
How do I run a function that applies regex iteratively in pandas-on-spark API?
<p>I am using pandas-on-spark in combination with regex to remove some abbreviations from a column in a dataframe. In pandas this all works fine, but I have the task to migrate this code to a production workload on our spark cluster, and therefore decided to use pandas-on-spark. I'm experiencing issues with the functio...
<python><apache-spark><pyspark-pandas>
2023-05-10 13:13:34
1
2,825
Psychotechnopath
76,218,830
10,332,049
Maximum Variance Unfolding with CVXPY
<p>I am trying to reproduce the results from <a href="http://www.cs.cornell.edu/%7Ekilian/papers/AAAI06-280.pdf" rel="nofollow noreferrer">this paper</a> (Weinberger and Saul, 2004, doi/10.5555/1597348.1597471), in which the authors use Maximum Variance Unfolding (MVU) to learn a low dimensional representation of a few...
<python><python-3.x><mathematical-optimization><cvxpy><convex-optimization>
2023-05-10 13:09:22
1
1,697
Saucy Goat
76,218,718
1,272,975
Setuptools with dash or underscore
<p>My question is related to <a href="https://stackoverflow.com/questions/19097057/pip-e-no-magic-underscore-to-dash-replacement">this question</a> but I'm hoping for an updated answer for 2023. My project name originally contained a '-' (e.g., abc-def) and I've received a warning that '-' is becoming deprecated in set...
<python><pip><setuptools>
2023-05-10 12:59:14
1
734
stevew
76,218,589
9,488,023
Extract part of string in Pandas column to a new column
<p>I have a simple Pandas dataframe in Python consisting of a few columns like in the example below:</p> <pre><code>df_test = pd.DataFrame(data = None, columns = ['file','comment']) df_test.file = ['file_1', 'file_1_v2', 'file_2', 'file_2_v2', 'file_3', 'file_3_v2'] df_test.comment = ['none: 5', 'Replacing: file_1', 'n...
<python><pandas><dataframe><split>
2023-05-10 12:43:53
1
423
Marcus K.
76,218,341
12,396,154
How to query Wonderware live values with python?
<p>I'd like to query live tag value from Wonderware historian with python. The following sql query works inside SQL server management studio and returns the live value of the tag:</p> <pre><code>USE Runtime DECLARE @TempTable TABLE(Seq INT IDENTITY, tempTagName NVARCHAR(256)) INSERT @TempTable(tempTagName) VALUES ('TA...
<python><sql><sql-server><wonderware>
2023-05-10 12:19:39
3
353
Nili
76,218,324
13,676,552
how do i parse a date field column effectively for a machine learning model
<p>I am try to predict the stock price of IBM. but I have gotchas on handling the date column field for model training in a linear regression algorithm. this is how my dataset looks like:</p> <pre><code> Date Open High Low Close Adj Close Volume 0 1962-01-02 7.713333 7.713333 7.626667 ...
<python><python-3.x><pandas><dataframe><scikit-learn>
2023-05-10 12:17:29
1
467
geek
76,218,209
1,783,739
Mapping a rdd list to a function of two arguments
<p>I have a function that compares images from same folder, against themselves - with an output of a similarity prediction. The function runs fine in python but I want to leverage the power of pyspark parellelisation.</p> <p>Here, I use Spark by simply parallelizing the list i.e. turn it into an RDD.</p> <pre><code>img...
<python><image><pyspark><rdd>
2023-05-10 12:06:12
1
864
Mikee
76,218,088
3,247,006
How to run a query with an inner query in it in Django?
<p>I'm trying to run a query with an inner query in it as shown below:</p> <pre class="lang-py prettyprint-override"><code> # Inner query Product.objects.filter(category__in=Category.objects.get(pk=1)) </code></pre> <p>But, I got the error below:</p> <blockquote> <p>TypeError: 'Catego...
<python><django><object><django-queryset><inner-query>
2023-05-10 11:54:13
2
42,516
Super Kai - Kazuya Ito
76,218,020
1,424,462
Python "requests" library targeting multiple redundant hosts
<p>We have a Python library that uses the &quot;requests&quot; package and acts as a client to a HW device that provides a REST API. In the setup of the data centers, there are multiple redundant such HW devices. Any one of them can be used by the client library because they synchronize their data.</p> <p>We would like...
<python><python-requests><urllib3>
2023-05-10 11:48:11
1
3,182
Andreas Maier
76,217,969
86,047
Why ansible script sees different environment than SSH?
<p>I created simple check.py script:</p> <pre><code>import getpass import sys import os print(getpass.getuser()) print(sys.executable) print(os.popen(&quot;which python3&quot;).read()) print(os.popen(&quot;cmake --version&quot;).read()) </code></pre> <p>I use ansible the script inside of mac machine and read output. A...
<python><macos><ansible>
2023-05-10 11:42:12
1
2,051
jing
76,217,925
778,942
Check if one number is within one percentage of another number in python
<p>I have 2 numbers.</p> <pre><code>a = 134 b = 165 </code></pre> <p>I want to find out by what percentage number a is less than number b. My aim is to find if first number (a) is within 1% of second number (b). I created function as follow</p> <pre><code>def is_what_percent_of(num_a, num_b): return (num_a / num_b)...
<python><python-3.x>
2023-05-10 11:36:52
1
19,252
sam
76,217,781
610,569
How to continue training with HuggingFace Trainer?
<p>When training a model with Huggingface Trainer object, e.g. from <a href="https://www.kaggle.com/code/alvations/neural-plasticity-bert2bert-on-wmt14" rel="noreferrer">https://www.kaggle.com/code/alvations/neural-plasticity-bert2bert-on-wmt14</a></p> <pre><code>from transformers import Seq2SeqTrainer, Seq2SeqTraining...
<python><machine-learning><huggingface-transformers><huggingface-trainer>
2023-05-10 11:20:53
1
123,325
alvas
76,217,767
5,539,782
compare 2 list of lists partially
<p>I have 2 list of lists:</p> <pre><code>a = [[1, 2, 3], [1, 2, 8], [1, 3, 3]] b = [[1, 2, 5], [1, 2, 9], [5, 3, 3]] </code></pre> <p>I want to only get the lists from b that have the same 2 first elements with lists in a from my example return <code>[1, 2, 5]</code> and <code>[1, 2, 9]</code></p>
<python>
2023-05-10 11:18:16
3
547
Khaled Koubaa
76,217,649
7,678,074
How to decode `piexif` metadata strings containing both plain text and bytes characters?
<p>I have a string containing both human-readable parts and bytes/control characters (I guess), like the following:</p> <pre><code>weird_string = 'Nikon\x00\x02\x00\x00\x00II*\x00\x08\x00\x00\x00\x15\x00\x01\x00\x07\x00\x04\x00\x00\x00\x00\x02\x00\x00\x02\x00\x03\x00\x02\x00\x00\x00\x00\x00\x00\x00\x03\x00\x02\x00\x06\...
<python><string><character-encoding><metadata><piexif>
2023-05-10 11:05:21
2
936
Luca Clissa
76,217,518
420,157
Python to C, SWIG design pattern for a function with input and output void pointer arguments
<p>I have the following scenario:</p> <p>Function header along with request and response structures:</p> <pre><code>struct request1 { int a1; int b1; }; struct response1 { int y1; int z1; }; struct request2 { int a2; int b2; }; struct response2 { int y2; int z2; }; int initialize(int type, void ...
<python><c><python-3.x><design-patterns><swig>
2023-05-10 10:50:34
1
777
Maverickgugu
76,217,268
9,488,023
How to correctly determine if a Pandas dataframe has replaced values in a column based on a string in another column
<p>I have a really large Pandas dataframe in Python with three important columns; 'file', 'comment', and 'number'. It is a list of many different files with assigned id-numbers, but some of these files replaces old files and should have the same id-numbers instead of separate ones. An example is:</p> <pre><code>df_test...
<python><pandas><dataframe><compare>
2023-05-10 10:19:40
1
423
Marcus K.
76,217,189
5,997,555
Create xarray Dataset with observations and averages that has combined index
<p>Suppose I have the following dataarray containing observations for different locations over time:</p> <pre class="lang-py prettyprint-override"><code>import numpy as np import pandas as pd import xarray as xr np.random.seed(42) data = xr.DataArray( np.random.randint(1,100, (36, 3)), dims=(&quot;time&quot;...
<python><time-series><python-xarray>
2023-05-10 10:10:03
1
7,083
Val
76,217,127
3,231,250
pypy pandas correlation slower than python
<p>I just wanted to give a try PyPy for pandas operations and I was thinking to use some part of code might be faster with PyPy but apparently it is slower than python.</p> <p>What is the reason behind that?</p> <p>That's my code sample, just reads example data from csv and computes correlation.</p> <p>with python: <st...
<python><pandas><pypy>
2023-05-10 10:02:45
1
1,120
Yasir
76,217,125
3,247,006
Celery beat cannot update currency exchange rates with django-money
<p>I use <a href="https://github.com/django-money/django-money" rel="nofollow noreferrer">django-money</a>, then I ran celery beat to update currency exchange rates every 60 minutes with the code below. *I followed <a href="https://django-money.readthedocs.io/en/latest/#working-with-exchange-rates" rel="nofollow norefe...
<python><django><celerybeat><currency-exchange-rates><django-money>
2023-05-10 10:02:40
1
42,516
Super Kai - Kazuya Ito
76,217,066
713,200
How to keep only first word of each list elements in python?
<p>I have list that looks something like this</p> <pre><code>images =['atr5500-ve-7.8.1 version=7.8.1 [Boot image]' , 'atr5300-ve-3.4.4','atr5600-ve-7.6.6','atr5300-ve-3.4.4', 'atr2300-ve-8.7.8','atr1200-ve-1.2.2','atr5600-ve-3.2.2'] </code></pre> <p>basically I'm looking for that keyword that will help to get only th...
<python><python-3.x><string><list><slice>
2023-05-10 09:55:39
2
950
mac
76,217,044
12,383,245
Iceberg with Hive Metastore does not create a catalog in Spark and uses default
<p>I have been experiencing some (unexpected?) behavior where a catalog reference in Spark is not reflected in the Hive Metastore. I have followed the Spark configuration according to the <a href="https://iceberg.apache.org/docs/latest/spark-configuration/" rel="nofollow noreferrer">documentation</a>, which looks like ...
<python><apache-spark><hive><hive-metastore><apache-iceberg>
2023-05-10 09:53:50
0
512
thijsvdp
76,217,015
1,928,362
How to calculate the first point where a line intersects a circle radius on a map, efficiently?
<p>I am using geopy to calculate the first point where a straight line intersects a circle on a map, this code works perfectly as expected but I believe is quite inefficient as it has to compute the lat/lng of every point of the line until it reaches the circle radius.</p> <p>Is there a more efficient way to do this wi...
<python><math><geopy><haversine>
2023-05-10 09:49:21
1
997
KillerKode
76,216,894
16,813,096
How to put a tkinter canvas item in top of other tkinter widgets placed in the same canvas?
<p>I am trying to put a tkinter widget (placed inside canvas) <strong>behind a canvas item</strong>. I tried <code>tag_raise</code> method but it is not working. <strong>Moreover, I want them in the same canvas.</strong></p> <p><em>Is there any other possible way?</em></p> <pre class="lang-py prettyprint-override"><cod...
<python><tkinter><canvas><tkinter-canvas><tkinter-button>
2023-05-10 09:34:33
2
582
Akascape
76,216,802
8,547,163
File path error while converting .md to .pdf
<p>In a python script I'm trying to convert a <code>.md</code> file to <code>.pdf</code> using subprocess and pandoc module as given below</p> <pre><code>subprocess.run([&quot;pandoc&quot;, &quot;--standalone&quot;, &quot;--pdf-engine=xelatex&quot;, &quot;/file/path/file.md&quot;, &quot;-o&quot;, &quot;/file/path/file....
<python><subprocess><pandoc>
2023-05-10 09:23:08
1
559
newstudent
76,216,794
1,804,173
How to modify specific blocks in an Azure Block Blob with the Python API?
<p>The <a href="https://learn.microsoft.com/en-us/rest/api/storageservices/understanding-block-blobs--append-blobs--and-page-blobs#about-block-blobs" rel="nofollow noreferrer">Azure documentation on block blobs</a> describes that it is possible to:</p> <blockquote> <p>You can modify an existing block blob by inserting,...
<python><azure><azure-blob-storage>
2023-05-10 09:22:28
1
27,316
bluenote10
76,216,763
9,510,800
Can we only use keras model with low loss in its epoch without saving the model?
<p>I have a neural network model built using TF Keras and I am running for n epochs. But is it possible to choose the model which has low loss during its epoch run without saving the model in the first place ? I know there exists callbacks, which saves the best weight of the model. But do we have any other method witho...
<python><tensorflow><keras>
2023-05-10 09:18:27
0
874
python_interest
76,216,700
719,276
Add the mean in box plots with plotly express?
<p>I have the following figure:</p> <p><a href="https://i.sstatic.net/Hgm1c.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Hgm1c.png" alt="Box plot from plotly express" /></a></p> <p>and I would like to add the mean.</p> <p>Is it possible with Plotly Express, without using Graph Objects <code>go.Box()</...
<python><boxplot><plotly><plotly-express>
2023-05-10 09:10:52
2
11,833
arthur.sw
76,216,656
719,276
Make the x labels different from the legend in plotly with go.Box
<p>I add multiple <code>go.Box()</code> in my figure, and I want the x axis labels to be different from the legend. How can I do that?</p> <p><a href="https://i.sstatic.net/ZixMw.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/ZixMw.png" alt="Plotly boxplot" /></a></p> <p>More precisely:</p> <ul> <li>I w...
<python><plotly>
2023-05-10 09:05:16
1
11,833
arthur.sw
76,216,548
671,013
Why does PySpark casts/converts when comparing columns of different types?
<h1>TL;DR</h1> <p>When using <code>filter</code> and comparing values in different columns that have different data types, PySpark casts the values implicitly. This can lead to some unexpected results. See the details below.</p> <p>The question is why does it behave this way? This behavior has serious side effects as d...
<python><apache-spark><pyspark>
2023-05-10 08:52:30
0
13,161
Dror
76,216,055
11,611,632
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xff in position 0: invalid start byte; Python-dotenv
<p>After cloning a personal Django project from Github on to my computer, some environment variables were written to a <code>.env</code> file. The variables encompass a Django generated <code>SECRET_KEY</code> surrounded my single quotes and setting <code>DEBUG</code> to a string of <code>'False'</code>. I installed <c...
<python><django><python-dotenv>
2023-05-10 07:46:28
0
739
binny
76,215,743
7,047,604
How to prevent Py_Finalize closing stderr?
<p>I have a c++ code that loads a python interepter which uses stderr:</p> <pre><code>intereptor.pyx stderr_dup = os.fdopen(sys.stderr.fileno(), 'wb', 0) </code></pre> <p>The problem is that after Py_Finalize is called, stderr is closed and I can't use it in c++. should I just reopen it in c++ by</p> <pre><code>open(st...
<python><c++><cython><pythoninterpreter>
2023-05-10 07:05:26
2
464
Atheel Massalha
76,215,725
5,602,871
Python script file missing in Singularity image
<p>In AWS, created a docker image with a python script to print a string(<code>basicprint.py</code>)</p> <p>docker file:</p> <pre><code>FROM python COPY ./basicprint.py ./ CMD [&quot;python&quot;, &quot;basicprint.py&quot;] </code></pre> <p>It works fine then saved docker image as <code>.tgz</code> file.</p> <p>copy t...
<python><amazon-web-services><dockerfile><singularity-container>
2023-05-10 07:03:46
1
2,641
Subbu VidyaSekar
76,215,685
18,604,870
How to show image from body of post request in flask api?
<p>I am trying to display the image captured from the browser/html canvas. A user would basically draw something, and I want to send it to my flask api so i can further process it with opencv, but i am having trouble just displaying the image.</p> <p>HTML</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;!--[if lt IE 7]&gt; ...
<javascript><python><html><flask>
2023-05-10 06:58:44
1
512
benwl
76,215,411
4,537,160
VS Code Python, entry in Run&Debug not present in launch.json
<p>I just started using VS Code to develop in Python, I have the official Python extension installed, and I'm trying to configure the Run&amp;Debug menu.</p> <p>In one of my workspaces, I created the following launch.json file, with THREE configurations (test.py, preview.py and Project Tests):</p> <pre><code>{ &quo...
<python><visual-studio-code>
2023-05-10 06:22:18
1
1,630
Carlo
76,215,339
9,827,719
Python session on Google Cloud Run automatically logs out
<p>I am running a website on Google Cloud Run that I have written in Python. The site runs in a Docker image that uses <code>python:latest</code>. The code works, however after some time the user is logged out and I dont know why the session does not lasts.</p> <p><strong>main.py:</strong></p> <pre><code>&quot;&quot;&q...
<python><google-cloud-run>
2023-05-10 06:08:44
2
1,400
Europa
76,215,223
6,223,346
Pandas reading CSV with ^G as separator
<p>The CSV file has a delimiter of <strong>^G</strong>. I am using pandas, the current separator is a comma. I have a new requirement to read the <strong>^G</strong>-separated CSV. Are there any supported libraries associated? Also, all the columns are enclosed in quotes.</p> <p>Sample CSV data</p> <pre><code>&quot;219...
<python><pandas><dataframe><csv>
2023-05-10 05:43:43
1
613
Harish
76,215,137
1,527,415
Typing class attributes with default value None - best practices?
<p>I am trying to introduce type hints to legacy Python 2.7 code. Many classes declare class attributes with a default value of <code>None</code> (to avoid mutable defaults) and then assign the value in the constructor, like so:</p> <pre class="lang-py prettyprint-override"><code>class Myclass(object): _myList = No...
<python><python-2.7><typing><pylance><pyright>
2023-05-10 05:22:47
1
1,385
FvD
76,215,066
678,572
How to make Docker container automatically activate a conda environment?
<p>I'm working on dockerizing a conda environment so I've created a toy example. My main goal is to end up with the following:</p> <ul> <li>A docker image</li> <li>A docker container that automatically loads the conda environment</li> <li>A docker container that can accept arguments for executables in the conda enviro...
<python><bash><docker><anaconda><conda>
2023-05-10 05:04:40
2
30,977
O.rka
76,214,975
1,380,626
Implementation of the discriminator in CGAN
<p>I am trying to implement CGAN with convolutions. I have written a discriminator. The code is running but I am not sure if it is correct or not. Below is my code</p> <pre><code>import torch import torch.nn as nn import torch.optim as optim from torchvision.utils import save_image from torch.utils.data import DataLoad...
<python><pytorch><convolution><generative-adversarial-network><cgan>
2023-05-10 04:46:14
0
6,302
odbhut.shei.chhele
76,214,922
4,420,797
Pytorch nn.DataParallel: RuntimeError: Input type (torch.cuda.FloatTensor) and weight type (torch.FloatTensor) should be the same
<p>I am implementing <code>nn.DataParallel</code> class to utilize multiple GPUs on single machine. I have followed some stack overflow questions and answers but still get a simple error. I have no idea why I am getting this error.</p> <p><strong>Followed Questions</strong></p> <ol> <li><p><a href="https://stackoverflo...
<python><pytorch><gpu><dataparallel>
2023-05-10 04:34:15
1
2,984
Khawar Islam
76,214,887
2,825,403
When caching a class will all future instances refer to the exact same id as the original cached instance?
<p>I was looking at how caching of classes works as I thought it would be a reasonable solution to one of the issues in the code I'm currently working on.</p> <p>I've been testing the instance creation using this simple class:</p> <pre><code>from functools import lru_cache @lru_cache class Foo: def __init__(self, ...
<python><class><caching>
2023-05-10 04:27:12
1
4,474
NotAName
76,214,835
2,966,197
llama-index unstructured simple directory reader not working
<p>I am trying to use <code>Unstrcutred.io</code> version of <code>llama-index</code> as defined <a href="https://github.com/emptycrown/llama-hub/tree/main/loader_hub/file/unstructured" rel="nofollow noreferrer">here</a></p> <p>I have a <code>pdf</code> file and a <code>html</code> file in my data directory and when I ...
<python><llama-index>
2023-05-10 04:12:53
1
3,003
user2966197
76,214,724
17,028,242
Vertex AI Pipelines. Batch Prediction 'Error state: 5.'
<p>I have been trying to run a Vertex AI pipeline using Kubeflow Pipelines and the google-cloud-pipeline-components library. The pipeline is entirely custom container components with the exception of the batch predictions.</p> <p>The code for my pipeline is of the following form:</p> <pre><code># GCP infrastructure res...
<python><google-cloud-platform><google-cloud-vertex-ai><kubeflow-pipelines>
2023-05-10 03:37:52
2
458
AndrewJaeyoung
76,214,622
14,625,334
Post data with field in django REST framework
<p>I am designing my API using <code>serializers.ModelSerializer</code> and <code>viewsets.ModelViewSet</code>. I can post the <code>foreignKey</code> value using the <code>id</code>, but I want to post it using the <code>name</code>. Here is an example of what I mean:</p> <p>I can post on this:</p> <pre><code>curl --r...
<python><django><django-models><django-rest-framework>
2023-05-10 03:04:54
1
876
Max
76,214,572
7,133,942
How to set a starting solution in Pymoo
<p>i want to use a starting solution for pymoo in the algorithms NSGA2. For that I have the following code</p> <pre><code>intial_solution = ICSimulation.simulateDays_ConventionalControl() algorithm = NSGA2( pop_size=5, n_offsprings=2, sampling=FloatRandomSampling(), crossover=SBX(prob=0.7, eta=20), ...
<python><optimization><pymoo>
2023-05-10 02:46:19
1
902
PeterBe
76,214,531
2,334,092
How to create a nested pie chart
<p>I have a dataframe as such</p> <pre><code>error_code, num_errors, event_type 404,78,GET 403,8,GET 504,54,POST 304,67,UP </code></pre> <p>I would like to create a nested ie chart where the first layer would show the breakdown (each slice represents fraction of num_errors) with respect to <code>error_code</code> colum...
<python><pandas><dataframe><matplotlib><pie-chart>
2023-05-10 02:35:13
1
8,038
AbtPst
76,214,445
11,462,274
Merge rows that have the same value in a specific column without change/sorted lines and use the first non-empty value for each column
<p>The line sequence cannot be modified or sorted (I tried using <code>group</code> but that modified/sorted the sequence when using <code>id</code> column as a reference).</p> <p>In all my dataframes I have a reference column called <code>id</code> and I will concatenate them to maintain the sequence of importance of ...
<python><pandas><dataframe>
2023-05-10 02:04:06
1
2,222
Digital Farmer
76,214,437
6,556,398
AttributeError: 'ModelData' object has no attribute 'design_info'
<p>I am unable to perform annova on a linear regression model. I have attached the simplified code below. How can I fix it?</p> <pre><code>import statsmodels.api as sm import numpy as np # define the data x1 = np.random.rand(100) x2 = np.random.rand(100) y = 2*x1 + 3*x2 + np.random.normal(size=100) # build the model ...
<python><statsmodels><anova>
2023-05-10 02:00:51
1
301
randomGeek4