QuestionId
int64
74.8M
79.8M
UserId
int64
56
29.4M
QuestionTitle
stringlengths
15
150
QuestionBody
stringlengths
40
40.3k
Tags
stringlengths
8
101
CreationDate
stringdate
2022-12-10 09:42:47
2025-11-01 19:08:18
AnswerCount
int64
0
44
UserExpertiseLevel
int64
301
888k
UserDisplayName
stringlengths
3
30
75,399,418
1,848,244
Pandas: Multi Index hierarchical join - populating missing level values from one join side
<p>I have some hierarchical data. Portions of it are scattered through 2 files.</p> <p>The first file contains all hierarchy levels, but due to circumstances outside of my control, sometimes rows for particular level <em>values</em> are ommitted (the external system that produces the data omits rows where the value is ...
<python><pandas>
2023-02-09 13:38:40
1
437
user1848244
75,399,229
962,190
Testing if warnings are sent as logmessages
<p>I have set <code>logging.captureWarnings(True)</code> in an application, and would like to test if warnings are logged correctly. I'm having difficulties understanding some of the behavior I'm seeing where tests are influencing each other in ways that I don't quite get.</p> <p>Here is an example test suite which rep...
<python><logging><pytest><python-logging>
2023-02-09 13:23:17
1
20,675
Arne
75,399,141
10,357,604
AttributeError: module 'cv2' has no attribute 'setNumThreads'
<p>I have installed Python 3.9 and the pkg opencv-contrib-python 4.6.0.66 (also on another computer, and there all work fine).</p> <p>What I do is</p> <pre><code>from ultralytics import YOLO ~\anaconda3\lib\site-packages\ultralytics\yolo\utils\__init__.py in &lt;module&gt; ... ---&gt; 96 cv2.setNumThreads(0) # ...
<python><opencv>
2023-02-09 13:15:54
1
1,355
thestruggleisreal
75,399,094
1,772,898
Distinguish between blank lines by their position (beginning, in-between or end of paragraphs)
<p>Please look at following example</p> <blockquote> <p>[BLANK LINE/S]</p> <p>First Paragraph</p> <p>[BLANK LINE Between Paragraphs]</p> <p>Second Paragraph</p> <p>[BLANK LINE Between Paragraphs]</p> <p>Third Paragraph</p> <p>[BLANK LINE/S End of Paragraphs]</p> </blockquote> <p>Here are blank lines at the beginning, m...
<python><python-3.x>
2023-02-09 13:12:06
1
14,440
Ahmad Ismail
75,398,970
519,852
Python Pip automatically increment version number based on SCM
<p>Similar questions like this were raised many times, but I was not able to find a solution for my specific problem.</p> <p>I was playing around with <code>setuptools_scm</code> recently and first thought it is exactly what I need. I have it configured like this:</p> <p>pyproject.toml</p> <pre><code>[build-system] req...
<python><pip><setuptools><setuptools-scm>
2023-02-09 13:02:00
1
1,374
Matthias
75,398,715
6,630,397
SQLAlchemy engine keeps some idle PostgreSQL database connection opened even when using a context manager
<p>When using an <a href="https://www.sqlalchemy.org/" rel="nofollow noreferrer">SQLAlchemy</a> <a href="https://docs.sqlalchemy.org/en/20/core/engines.html#sqlalchemy.create_engine" rel="nofollow noreferrer">engine</a> for <a href="https://geopandas.org/" rel="nofollow noreferrer">GeoPandas</a> <a href="https://geopan...
<python><pandas><postgresql><sqlalchemy><geopandas>
2023-02-09 12:38:32
1
8,371
swiss_knight
75,398,496
12,968,928
how to Find derivative of a LHS expression with respect to a variable in the RHS of a Sympy Eq
<p>Suppose I have an eq1 such that</p> <pre><code>from sympy import symbols, solve, plot, Eq, diff a, b, X, Y, U = symbols('a b X Y U') eq1 = Eq(U, X**a*Y**b) </code></pre> <p>$U=(X^a)(Y^b)$</p> <p>but When I run diff(eq1 , X) the differential does not evaluate I merele just get the DU/DX symbol but not evaluated</p> <...
<python><sympy>
2023-02-09 12:17:23
1
1,511
Macosso
75,398,474
6,758,739
How to run a unix command and which requires dynamic console input in python and how to run this without manual intervention
<p><strong>Command: /opt/oracle/admin/bin/dboc configure dbfs --home /oracle/client/18.3.0/</strong></p> <blockquote> <p>When we run the above command on linux terminal it expects 3 inputs one by one as below</p> <p>Validating DBFS Client : asdjascads</p> <p>Enter Connectstring for dbaas : akxhsakc</p> <p>Enter passwo...
<python><subprocess>
2023-02-09 12:15:26
0
992
LearningCpp
75,398,291
3,395,802
Dynamically add schema to sqlalchemy func
<pre><code>from sqlalchemy import func data = db.session.query(func.your_schema.your_function_name()).all() </code></pre> <p>I have two schemas which have the same function. In this scenario, how can I dynamically pass the schema name to func?</p>
<python><postgresql><sqlalchemy>
2023-02-09 11:59:55
0
1,105
Nithin
75,398,224
6,849,045
How do I get the indexwise average of a array column with pyspark
<p>I have a df with a column <code>fftAbs</code> (absolute values acquired after an fft). The type of df['fftAbs'] is a <code>ArrayType(DoubleType())</code>. I want to get the indexwise average of all the values. So if the column holds</p> <pre><code>// Random data ||fftAbs || ------------ |[0, 1, 2] | |[2, 3, 12]| |[...
<python><arrays><pandas><numpy><pyspark>
2023-02-09 11:54:24
2
1,072
Typhaon
75,397,986
17,487,457
How to generate expanded list from two short list
<p>I have two lists, one for attributes the other for statistics:</p> <pre class="lang-py prettyprint-override"><code>l1 = ['speed', 'accel'] l2 = ['min', 'max', 'mean', 'std'] </code></pre> <p>I want to generate this expanded list of attributes' statistics:</p> <pre class="lang-py prettyprint-override"><code>l3 = ['sp...
<python><python-3.x><list>
2023-02-09 11:32:02
1
305
Amina Umar
75,397,940
2,755,116
Debugging mako NameError("Undefined")
<p>Is there any way of obtaining more information about what happens when <code>NameError(&quot;Undefined&quot;)</code> is raised in Mako templates.</p> <p>In <a href="https://pythonhosted.org/Flask-Mako/#error-handling" rel="nofollow noreferrer">Flask-Mako</a> there is a solution, but I'm not using flask. So I need a ...
<python><debugging><mako>
2023-02-09 11:27:45
1
1,607
somenxavier
75,397,861
10,811,647
Python dash return several values inside for loop
<p>For my dash app, in order to update some graphs dynamically, I have to use a function that I named <code>update_graphs</code> inside a for loop. Some of the graphs contain several traces while some others only have one. The <code>update_graphs</code> function is called inside a callback and returns a <code>dict</cod...
<python><for-loop><callback><return><plotly-dash>
2023-02-09 11:20:19
1
397
The Governor
75,397,763
3,386,779
keyword "sleep" not working in robotframework
<p>I'm using robot framework with selenium2Library .While using sleep 30s getting the below error as</p> <pre><code>No keyword with name 'Sleep 30s' found. Did you mean: BuiltIn.Sleep </code></pre> <p>Any dependent library I missed to include</p>
<python><robotframework>
2023-02-09 11:10:28
1
7,263
user3386779
75,397,736
4,451,521
Poetry install on an existing project Error "does not contain any element"
<p>I am using Poetry for the first time. I have a very simple project. Basically</p> <pre><code>a_project | |--test | |---test_something.py | |-script_to_test.py </code></pre> <p>From a project I do <code>poetry init</code> and then <code>poetry install</code></p> <p>I get the following</p> <pre><code> poetry instal...
<python><python-poetry>
2023-02-09 11:08:22
5
10,576
KansaiRobot
75,397,536
19,556,055
Filter DataFrame where a set of values are the same in another DataFrame
<p>I have a dataset with some employee information, and I would like to see if certain records appear in another DataFrame. However, there may be duplicate IDs (I know...), so I wanted to filter where the ID AND date of birth are the same. I tried doing it with a merge, but then all the columns get added, which I don't...
<python><pandas><dataframe>
2023-02-09 10:49:55
1
338
MKJ
75,397,487
782,564
Prevent ListBoxItems from being resized (specifically shrunk)
<p>I have a Gtk Listbox to which I'm adding a large number of items (basically text labels). I've put the ListBox inside a ScrolledWindow but if I add too many items then the height of each item is reduced until the text on the label is no longer readable.</p> <p>How can I prevent the ListBox items from being reduced i...
<python><gtk3><pygtk>
2023-02-09 10:46:03
1
1,618
Carcophan
75,397,439
694,360
Deriving Heron's formula with Sympy using Groebner basis
<p>I'm trying to implement with Sympy the procedure described <a href="https://www.andrew.cmu.edu/course/15-355/lectures/lecture12.pdf" rel="nofollow noreferrer">in this lecture</a>, where Groebner basis is used to derive <a href="https://en.wikipedia.org/wiki/Heron%27s_formula" rel="nofollow noreferrer">Heron's formul...
<python><sympy><computational-geometry><groebner-basis>
2023-02-09 10:42:34
1
5,750
mmj
75,397,364
11,692,632
Google colab not detecting changes in .py files
<p>I'm importing a .py file in Google Colab. I do as usual, mounting Drive, inserting the directory and importing the file:</p> <pre><code>from google.colab import drive drive.mount('/content/drive', force_remount=True) import sys sys.path.insert(0, '/content/drive/My Drive/Colab Notebooks/working_folder/') import my...
<python><google-colaboratory>
2023-02-09 10:36:39
1
773
chococroqueta
75,397,168
8,618,242
ROS setBool service always False
<p>I'm using ROS <strong>service server</strong> in <code>python</code>:</p> <pre class="lang-py prettyprint-override"><code>#! /usr/bin/env python3 import rospy from std_srvs.srv import SetBool, SetBoolResponse class StateController: def __init__(self): rospy.init_node(&quot;state_controller&quot;, anonym...
<javascript><python><service><ros>
2023-02-09 10:19:21
1
4,115
Bilal
75,396,938
5,213,451
What makes Rich display wrong characters on Powershell 7?
<p>I've been a happy user of <a href="https://github.com/Textualize/rich" rel="nofollow noreferrer">Rich</a> for Python for some time now, but recently started having issues where colors and special characters are not displayed properly anymore. Here is an example output of printing a <code>Table</code> in <em>Powershe...
<python><powershell><encoding><rich>
2023-02-09 09:58:28
0
1,000
Thrastylon
75,396,863
7,290,602
How to force assumption of past dates when year is ambiguous
<p>I have dates in DD/MM/YY format, where year is ambiguous. These are recorded dates so will always be in the past.</p> <p>At the time of writing, a date for '69 is correctly interpreted as 1969:</p> <pre><code>&gt;&gt;&gt; datetime.datetime.strptime('01/06/69','%d/%m/%y') datetime.datetime(1969, 1, 1, 0, 6) </code></...
<python><datetime>
2023-02-09 09:52:10
3
941
otocan
75,396,692
11,710,304
How can I strip string columns in a df with mixed datatype in polars?
<p>I want to strip a dataframe based on its data type per column. If it is a string column, a strip should be executed. If it is not a string column, it should not be striped. In pandas there is the following approach for this task:</p> <pre><code>df_clean = df_select.copy() for col in df_select.columns: if...
<python><python-polars>
2023-02-09 09:37:01
1
437
Horseman
75,396,615
5,556,466
ModuleNotFoundError: No module named 'aws_cdk'
<p>I am trying to use <code>aws_cdk</code> in my project. I am using visual studio as a IDE and I setup my <code>virtualenv</code> doing this:</p> <ol> <li>Install <a href="https://nodejs.org/en/" rel="nofollow noreferrer">https://nodejs.org/en/</a>.</li> <li>Through npm, install cdk from cmd window: <code>npm install ...
<python><aws-cdk>
2023-02-09 09:30:57
3
3,243
mrc
75,396,343
4,451,521
Poetry does not install pytest neither generates basic test
<p>I am following <a href="https://realpython.com/dependency-management-python-poetry/" rel="nofollow noreferrer">this tutorial on Poetry</a></p> <p>I do as written</p> <pre><code>poetry new rp-poetry </code></pre> <p>However when I inspect the folder structure, I notice that the file <code>test_rp_poetry.py</code> is ...
<python><pytest><python-poetry>
2023-02-09 09:05:31
1
10,576
KansaiRobot
75,396,255
235,921
AWS Lambda to get file from ZIP on S3 without download
<p>I have a zip file on S3 and I need to get a single file from the zip. I would like to avoid downloading the whole ZIP, I don't know what size the ZIP may have and I only need a small file from that ZIP. I want to do this with a Lambda function (it can be nodejs or python).</p>
<python><node.js><amazon-web-services><amazon-s3><aws-lambda>
2023-02-09 08:57:36
0
2,978
CC.
75,396,216
4,906,156
Problem building a ANN Regressor model with Autoencoder in Tensorflow 2.11
<p>My input is a 2D numpy array of dimensions (364660, 5052). The target is (364660, 1), a regression variable. I a trying to build a guided autoencoder + ANN regressor where encoded layer of autoencoder serves as input to ann regressor. I would like to train both models at one go. However, the loss for autoencoder sho...
<python><tensorflow><keras><regression><autoencoder>
2023-02-09 08:54:09
1
383
areddy
75,396,079
14,673,832
TypeError: 'int' object is not subscriptable while doing s-expression in Python
<p>I am trying to write a basic s-expression calculator in Python using s-expression which can contains add or multiply or both or none or just an integar number.</p> <p>I tried the following snippet:</p> <pre><code>def calc(expr): print(expression[0]) if isinstance(expr, int): return expr elif expr...
<python><recursion><s-expression>
2023-02-09 08:39:15
1
1,074
Reactoo
75,395,892
3,262,484
Writing a tuple search with Django ORM
<p>I'm trying to write a search based on tuples with the Django ORM syntax.</p> <p>The final sql statement should look something like:</p> <pre><code>SELECT * FROM mytable WHERE (field_a,field_b) IN ((1,2),(3,4)); </code></pre> <p>I know I can achieve this in django using the extra keyword:</p> <pre><code>MyModel.objec...
<python><django><django-queryset>
2023-02-09 08:20:40
4
383
Bob Morane
75,395,863
3,459,293
Getting Categories data from rows in columns and matching values for actuals (y) and predicted (yhat) python
<p>I have a data frame like this, where Groups, Entity, Year they can have different categories. I have shown just one example.</p> <pre><code>TimePeriod Groups Entity Category Year Quarter Predictions Value 1/1/2021 CO UK Model_Q1_2022 2021 1 yhat 25379.12223 1/1/2021 ...
<python><pandas><data-wrangling>
2023-02-09 08:16:33
1
340
user3459293
75,395,481
7,368,045
Order in Python for loop (LeetCode 219 Contains Duplicate II)
<p><a href="https://goodtecher.com/leetcode-219-contains-duplicate-ii/" rel="nofollow noreferrer">https://goodtecher.com/leetcode-219-contains-duplicate-ii/</a></p> <p>In this Python solution, why does <code>visited[nums[i]] = i</code> have to come after the if condition? I don't understand why the code wouldn't work i...
<python><python-3.x>
2023-02-09 07:32:39
1
463
Ashley Liu
75,395,322
7,340,317
How to get dictionary of df indices that links the same ids on different days?
<p>I've following toy-dataframe:</p> <pre><code> | id| date -------------- 0 | a | d1 1 | b | d1 2 | a | d2 3 | c | d2 4 | b | d3 5 | a | d3 </code></pre> <pre><code>import pandas as pd df = pd.DataFrame({'id': ['a', 'b', 'a', 'c', 'b', 'a'], 'date': ['d1', 'd1', 'd2', 'd2', 'd3', 'd3']}) </code></pre>...
<python><pandas><dictionary>
2023-02-09 07:11:45
2
1,480
Quant Christo
75,395,297
657,693
Pandas Join into Comma Separated String, But One Record For Each Value in a Column
<p>I am trying to do some data manipulation on a Pandas DataFrame and I want to group by / categorize by a single column, but do so for each different corresponding group of rows.</p> <p>For example, I have the below DataFrame -</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>sport</th> <th...
<python><pandas><dataframe>
2023-02-09 07:09:42
1
1,366
mattdonders
75,395,204
3,136,710
Why is this giving me a bad estimation of pi (Leibniz formula)
<p>Leibniz formula is</p> <p>π/4 = 1 - 1/3 + 1/5 - 1/7 + 1/9 - ...</p> <p>Or, π = 4 ( 1 - 1/3 + 1/5 - 1/7 + 1/9 - ... )</p> <p>I don't really understand why my code is producing a bad result. There is another way of doing this, but what is wrong with my code specifically? It seems like it should give me a good result.<...
<python>
2023-02-09 06:59:06
1
652
Spellbinder2050
75,395,037
6,013,016
python using super(), can't access variable from second parent class
<p>This is probably very simple question. In a child class, which is inherited from two parent classes, I can't access variable from second parent class using super(). Here is my code:</p> <pre><code>class Core: def __init__(self): self.a_from_Core = 7 class Extra: def __init__(self): self.b_f...
<python><class><inheritance><multiple-inheritance><super>
2023-02-09 06:37:56
2
5,926
Scott
75,394,933
10,437,110
How to gather outputs from joblib.Parallel in Python into one csv file?
<p>I have received a previously inactive code to make some changes to the code. It reads an input csv file, loops over the row, calls a function, and gets an output row which is stored in the output csv file.</p> <p>Here is the code:</p> <pre><code>import pandas as pd from joblib import Parallel, delayed </code></pre> ...
<python><pandas><csv>
2023-02-09 06:22:28
0
397
Ash
75,394,708
6,856,361
how to specify exact env variable from configmap in airflow kubernetespodoperator
<p>I'm defining the env vars for the pythons airflow dags as follow:</p> <pre class="lang-py prettyprint-override"><code>from airflow.kubernetes.secret import Secret db_pass = Secret('env', 'DB_PASS', 'db-credentials', 'db_user') envs = { 'JAVA_OPTS':'-XX:MaxRAMPercentage=65.0' } with DAG( 'my_dag', ...
<python><kubernetes><airflow>
2023-02-09 05:50:59
1
2,162
Izbassar Tolegen
75,394,675
16,780,162
Plotting pcolormesh in python from csv data
<p>I am trying to make a pcolormesh plot in python from my csv file. But I am stuck with dimension error.</p> <p>My csv looks like this:</p> <pre><code>ratio 5% 10% 20% 30% 40% 50% 1.2 0.60 0.63 0.62 0.66 0.66 0.77 1.5 0.71 0.81 0.75 0.78 0.76 0.77 1.8 0.70 0.82 0.80 0.73 0.80 0.78 ...
<python><python-3.x><csv><matplotlib><plot>
2023-02-09 05:45:59
1
332
Codeholic
75,394,636
14,256,643
how to jump back before for loop and update variable until meet my requirments
<p>I am scraping nested text from parent category and child category. here my loop look like:</p> <pre><code>first for loop will scrape all parent category: ...seond for loop will scrape child1 category of parent category ...third for loop will scrape child2 category of child1 category </code></pre> <p>...
<python><python-3.x><selenium><selenium-webdriver>
2023-02-09 05:40:33
1
1,647
boyenec
75,394,573
51,292
AttributeError: module 'tensorflow.core.function.trace_type' has no attribute 'from_value'
<p>This one line python program fails with the error message above on windows 10 with python 310:</p> <pre><code>from keras.models import Sequential </code></pre> <p>Preceding the keras's with 'tensorflow.' does not help.</p> <p>Edit 1: Seems like none of my pthon files that us tensorflow are now failing with this erro...
<python><python-3.x><tensorflow><keras><tensorflow2.0>
2023-02-09 05:32:14
1
10,041
Ray Tayek
75,394,542
12,331,179
Build Structure using pandas Dataframe
<p>Input Data</p> <p><a href="https://i.sstatic.net/3pt4g.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/3pt4g.png" alt="enter image description here" /></a></p> <pre><code>import pandas as pd import numpy as np a1=[&quot;data.country&quot;, &quot;data.studentinfo.city&quot;,&quot;data.studentinfo.name...
<python><python-3.x><pandas><dataframe>
2023-02-09 05:27:23
1
386
Amol
75,394,318
1,870,832
python text parsing to split list into chunks including preceding delimiters
<p><strong>What I Have</strong></p> <p>After OCR'ing some public Q&amp;A deposition pdfs which have a Q&amp;A form, I have raw text like the following:</p> <pre><code>text = &quot;&quot;&quot;\na\n\nQ So I do first want to bring up exhibit No. 46, which is in the binder in front of\nyou.\n\nAnd that is a letter [to] A...
<python><regex><parsing><nlp><ocr>
2023-02-09 04:49:23
3
9,136
Max Power
75,394,255
6,751,456
write Trino query data directly to s3
<p>Currently we have</p> <ul> <li>Trino query run and fetch data</li> <li>write this to local filesystem</li> <li>upload this file to s3 bucket.</li> </ul> <p>For smaller data this is no issue. But currently with large data volume, this is posing an issue with server even returning <code>502 bad gateway</code>.</p> <p>...
<python><presto><trino><orc>
2023-02-09 04:39:20
1
4,161
Azima
75,394,159
6,037,395
How to adjust the font of tick labels for a percent-formatted axis in matplotlib?
<p>I usually use <code>matplotlib</code> with the following options:</p> <pre class="lang-py prettyprint-override"><code>matplotlib.rcParams['text.latex.preamble'] = r'\usepackage{amsmath}' matplotlib.rc('text', usetex = True) </code></pre> <p>such that the text font looks better (at least to me). However, if I format ...
<python><matplotlib><fonts>
2023-02-09 04:19:19
1
1,654
zyy
75,394,143
19,950,360
OpenAI API error: "No module named 'openai.embeddings_utils'; 'openai' is not a package"
<p>I want to use <code>openai.embeddings_utils import get_embeddings</code> So already install openai</p> <pre><code>Name: openai Version: 0.26.5 Summary: Python client library for the OpenAI API Home-page: https://github.com/openai/openai-python Author: OpenAI Author-email: support@openai.com License: Location: /User...
<python><python-3.x><pip><openai-api><azure-openai>
2023-02-09 04:16:03
9
315
lima
75,394,098
572,575
Python BeautifulSoup cannot file text in webpage
<p>I try to read text Hello World from website <a href="https://www.w3schools.com/python/default.asp" rel="nofollow noreferrer">https://www.w3schools.com/python/default.asp</a> by using BeautifulSoup with this code.</p> <pre><code>from bs4 import BeautifulSoup import requests url = &quot;https://www.w3schools.com/pyth...
<python><beautifulsoup>
2023-02-09 04:06:35
1
1,049
user572575
75,394,057
2,525,940
QTimer: change interval while running, without restarting the interval
<p>As mentioned here <a href="https://stackoverflow.com/a/64301362/2525940">https://stackoverflow.com/a/64301362/2525940</a> calling <code>setInterval</code> on a <code>QTimer</code> restarts the interval.</p> <p>I need a timer that takes account of the already elapsed time.</p> <p>For example: A QTimer is set to trigg...
<python><pyqt5>
2023-02-09 03:59:02
2
499
elfnor
75,394,033
3,713,236
Pipeline & ColumnTransformer: ValueError: Selected columns are not unique in dataframe
<p>Background: I am trying to learn from <a href="https://www.kaggle.com/code/hernnvignolo/house-prices-art-without-data-leakage#5.-Machine-Learning-model-for-predictions" rel="nofollow noreferrer">a notebook</a> used in <a href="https://www.kaggle.com/c/house-prices-advanced-regression-techniques" rel="nofollow norefe...
<python><dataframe><pipeline><transformation><feature-engineering>
2023-02-09 03:55:43
1
9,075
Katsu
75,393,965
134,044
AWS Lambda Python __pycache__ bytecode and local imports without layers
<p>When creating an AWS Lambda using Python:</p> <ol> <li>Can the Lambda access local imports if the modules are included in the Lambda handler zip; and</li> <li>What are the implications of including the <code>__pycache__</code> directories in the zip?</li> </ol> <h3>Question 1: Can the runtime access local imports?</...
<python><amazon-web-services><aws-lambda><bytecode>
2023-02-09 03:40:26
0
4,109
NeilG
75,393,948
109,554
How can I create Quilt data packages with R instead of Python?
<p>Quilt has a <a href="https://pypi.org/project/quilt3/" rel="nofollow noreferrer">Python library</a> (<code>quilt3</code>) but I use <a href="https://www.r-project.org/" rel="nofollow noreferrer">R</a> for all my scientific workflows. Is there an R interface that I can use to take advantage of Quilt's data version co...
<python><r><quiltdata>
2023-02-09 03:38:12
1
3,176
tatlar
75,393,928
1,245,262
How can pandas concat function duplicate behavior of append function in pandas,
<p>I've just inherited some code that uses pandas' <code>append</code> method. This code causes Pandas to issue the following warning:</p> <pre><code>The frame.append method is deprecated and will be removed from pandas in a future version. Use pandas.concat instead. </code></pre> <p>So, I want to use <code>pandas.con...
<python><pandas><dataframe><append><concatenation>
2023-02-09 03:33:59
2
7,555
user1245262
75,393,832
4,285,029
Load Large Excel Files in Databricks using PySpark from an ADLS mount
<p>We are trying to load a large'ish excel file from a mounted Azure Data Lake location using pyspark on Databricks.</p> <p>We have used pyspark.pandas to load and we have used spark-excel to load, not with a lot of success</p> <h4>PySpark.Pandas</h4> <pre><code>import pyspark.pandas as ps df = ps.read_excel(&quot;dbfs...
<python><apache-spark><pyspark><databricks><azure-databricks>
2023-02-09 03:17:24
1
1,184
Lambo
75,393,827
1,029,902
Both selenium and bs4 cannot find div in page
<p>I am trying to scrape a Craigslist results page and neither bs4 or selenium can find the elements in the page even though I can see them on inspection using dev tools. The results are in list items with class <code>cl-search-result</code>, but it seems the soup returned has none of the results.</p> <p>This is my scr...
<python><selenium><selenium-webdriver><web-scraping><beautifulsoup>
2023-02-09 03:16:27
1
557
Tendekai Muchenje
75,393,773
5,709,240
How to remove duplicate strings after grouping?
<p>I would like to group the following Pandas DataFrame by <code>ID</code> column:</p> <pre><code> |----+----------------------------------------+-----------------| | ID | Elements | Colors | |----+----------------------------------------+-----------------| | A | '1st element, 2d...
<python><pandas>
2023-02-09 03:03:29
1
933
crocefisso
75,393,766
15,174,775
How to get current script filename or path in python when instantiate a class?
<pre class="lang-py prettyprint-override"><code># utils.py class Foo: def __init__(): print(__file__) # mod.py from utils import Foo foo = Foo() # This prints /absoulte/utils.py # the expected output is /absoulte/mod.py </code></pre> <p>Is it possible to make the imported class <code>Foo</code> initializa...
<python><python-3.x>
2023-02-09 03:01:15
1
638
HALF9000
75,393,757
6,567,212
How to escape dot (.) in a key to get JSON value with redis-py?
<p>I had some JSON data containing dot(.) in keys that are written to redis using redis-py like this:</p> <pre class="lang-py prettyprint-override"><code>r = redis.Redis() r.json().set(_id, &quot;$&quot;, {'First.Last': &quot;John.Smith&quot;}) </code></pre> <p>It works if reading the whole JSON data like</p> <pre clas...
<python><json><redis>
2023-02-09 02:59:30
1
329
ningl
75,393,747
5,218,497
SignatureDoesNotMatch while uploading file from React.js using boto3 generate_presigned_url
<p>Currently the presigned url is generated from Python Lambda function and testing it on postman to upload the file works perfectly.</p> <p>When uploading file from <strong>React.js</strong> using axios it fails with 403 status code and below error.</p> <p><strong>Code</strong>: SignatureDoesNotMatch</p> <p><strong>Me...
<python><reactjs><amazon-s3><boto3>
2023-02-09 02:58:02
1
2,428
Sharath
75,393,740
8,076,158
How to subclass a frozen dataclass
<p>I have inherited the <code>Customer</code> dataclass. This identifies a customer in the customer DB table.</p> <p><code>Customer</code> is used to produce summary statistics for transactions pertaining to a given customer. It is hashable, hence frozen.</p> <p>I require a <code>SpecialCustomer</code> (a subclass of <...
<python><pydantic><python-dataclasses>
2023-02-09 02:56:30
1
1,063
GlaceCelery
75,393,692
19,425,874
How to run a Python Script from a Google Sheet
<p>I have a Python script that leverages lists in a Google Sheet and sends bulk SMS text messages using Twilio.</p> <p>I'm fairly new to this and have struggled to get this far - any Python script I've created in the past, I've been able to just run off my local computer in VS Code.</p> <p>I am trying to share this wit...
<python><google-apps-script><gspread>
2023-02-09 02:48:02
0
393
Anthony Madle
75,393,656
10,051,099
Does Django save model objects other than `save()` or `create()` methods?
<p>I'm writing something like the following:</p> <pre class="lang-py prettyprint-override"><code>class Foo(models.Model): a = models.CharField() def f(foo: Foo) -&gt; Foo: y = Foo( **{field.name: getattr(foo, field.name) for field in foo._meta.get_fields()} ) # copy foo with pk y.a = &quot;c&q...
<python><django>
2023-02-09 02:37:40
2
3,695
tamuhey
75,393,602
13,324,349
How to pass references of declared variables to C function in python using ctypes
<p>I would like to call a C function from python. This C function is void, thus the &quot;return parameters&quot; (data I want to change) are defined as pointers in the C function's definition.</p> <p>The function in C looks like this (note: I cannot and will not change it as it is generated automatically by <a href="h...
<python><c><ctypes>
2023-02-09 02:24:54
2
588
Brian Barry
75,393,588
16,933,406
separate the abnormal reads of DNA (A,T,C,G) templates
<p>I have millions of DNA clone reads and few of them are misreads or error. I want to separate the clean reads only.</p> <p><strong>For non biological background:</strong></p> <p>DNA clone consist of only four characters (A,T,C,G) in various permutation/combination. Any character, symbol or sign other that &quot;A&quo...
<python><bioinformatics><python-re><biopython><dna-sequence>
2023-02-09 02:22:25
5
617
shivam
75,393,453
8,670,757
Pandas Reindex Multiindex Dataframe Replicating Index
<p>Thank you for taking a look! I am having issues with a 4 level multiindex &amp; attempting to make sure every possible value of the 4th index is represented.</p> <p>Here is my dataframe:</p> <pre><code> np.random.seed(5) size = 25 dict = {'Customer':np.random.choice( ['Bob'], size), 'Grouping': np.random.cho...
<python><pandas><dataframe><numpy>
2023-02-09 01:53:25
1
341
keg5038
75,393,424
9,981,147
Calculate a number to the power of a large integer
<p>I'm trying to help someone calculate the value of 4^3e9.</p> <p>The problem is that most software don't support numbers this large. Is there an alternative way to calculate this?</p> <p>My first attempt is to try to divide the number as it is being calculated by looping from 1 to 3e9. If the intermediate result is &...
<python><math>
2023-02-09 01:48:49
1
481
BrendanOtherwhyz
75,393,420
19,425,874
How to switch python print results to string instead of object?
<p>I'm working on a tool that will send bulk SMS text messages. I am using the Twilio API - I have two lists in a Google Sheet, one that is phone numbers, one that is first names.</p> <p>My script loops through the lists, assigns the name as a variable, then creates the messages.</p> <p>When I reference the lists from...
<python><string><twilio><gspread>
2023-02-09 01:48:16
0
393
Anthony Madle
75,393,385
10,461,632
How to efficiently calculate folder and file sizes in a directory?
<p>How can I efficiently calculate the size of every subfolder and file in a given directory?</p> <p>The code I have so far does what I want, but it is inefficient and slow because of how I have to calculate the parent folder size.</p> <p>Here's my current timing:</p> <pre><code>Section 1: 0.53 s Section 2: 30.71 s </c...
<python><python-3.x>
2023-02-09 01:41:03
1
788
Simon1
75,393,358
11,462,274
Intercalate pandas dataframe columns when they are in pairs
<p>The desired result is this:</p> <pre class="lang-none prettyprint-override"><code>id name 1 A 2 B 3 C 4 D 5 E 6 F 7 G 8 H </code></pre> <p>Currently I do it this way:</p> <pre class="lang-python prettyprint-override"><code>import pandas as pd df = pd.DataFrame({'home_id': ['1', '3', '5', '...
<python><pandas><dataframe>
2023-02-09 01:35:04
3
2,222
Digital Farmer
75,393,016
2,304,905
Is there a way to "dynamically" annotate the return type of a function in Python?
<p>Imagine I have the following class structure with three class families: <code>Parent</code>, <code>Child1</code>, and <code>Child2</code> each with <code>Abstract</code>, <code>Explicit</code> and <code>Implicit</code> flavors.</p> <pre class="lang-py prettyprint-override"><code>from __future__ import annotations im...
<python><generics><python-typing><mypy>
2023-02-09 00:22:31
0
714
Roy Smart
75,392,950
10,426,490
How does python version affect Azure Functions?
<p>I'm <em>developing</em> Azure Functions using Python <strong>3.10.10</strong> on my machine, deploying the Function through Azure DevOps which is <em>building</em> the artifact using Python <strong>3.6.8</strong>, and the <code>Python Version</code> shown for the Function App <em>host</em> is <strong>3.8</strong>.</...
<python><azure-functions><version>
2023-02-09 00:06:44
1
2,046
ericOnline
75,392,836
2,904,824
Accepting an agent forward in a Paramiko Server
<p>Ok, so you implement <a href="https://docs.paramiko.org/en/stable/api/server.html#paramiko.server.ServerInterface.check_channel_forward_agent_request" rel="nofollow noreferrer"><code>paramiko.ServerInterface.check_channel_forward_agent_request</code></a> to accept or deny agent forwarding initiated by the client.</p...
<python><ssh><paramiko>
2023-02-08 23:46:09
1
667
AstraLuma
75,392,825
11,187,883
VS Code connecting to jupyterlab server not selecting kernel
<p>We have recently moved to a JupyterLab Server from another IDE. We are trying to get VS Code hooked up so that we can code in it rather. After much struggle, we got VS Code to connect to our remote JupyterLab server. On the status bar in the bottom, it shows <a href="https://i.sstatic.net/aB568.png" rel="nofollow no...
<python><visual-studio-code>
2023-02-08 23:44:12
1
769
GenDemo
75,392,769
289,784
How to use Apache Arrow IPC from multiple processes (possibly from different languages)?
<p>I'm not sure where to begin, so looking for some guidance. I'm looking for a way to create some arrays/tables in one process, and have it accessible (read-only) from another.</p> <p>So I create a <code>pyarrow.Table</code> like this:</p> <pre class="lang-py prettyprint-override"><code>a1 = pa.array(list(range(3))) ...
<python><ipc><pyarrow><apache-arrow>
2023-02-08 23:34:50
1
4,704
suvayu
75,392,766
2,059,078
How do I render a table in a specific Layout() using the python rich Live() class
<p>Here is the code to create the layout</p> <pre><code>import time from rich.live import Live from rich.table import Table from rich.layout import Layout layout=Layout() layout.split_row( Layout(name=&quot;left&quot;), Layout(name=&quot;right&quot;), ) print(layout) </code></pre> <p>I would like to display the b...
<python><rich>
2023-02-08 23:34:26
1
1,295
MiniMe
75,392,711
11,963,167
Call function and assign result to same named input in python
<p>It's probably a dumb Python question, anyway: let's say I have a function that takes an object as parameter and returns a new one, letting the input object untouched. I want to apply such function to multiple objects, x1, ..., xn, and I want the output to be named the same as the input, ie x1,...xn.</p> <p>Basically...
<python>
2023-02-08 23:26:47
0
496
Clej
75,392,654
15,239,717
Django Filter using Q Objects on two Models
<p>I am working a Django Application where I want to search two Models Profile (surname or othernames fields) and Account (account_number field) using Q objects. From what I did, it is searching only one Model (Account) and any attempt to search any value from the other Model (Profile) triggers an error which says: <st...
<python><django>
2023-02-08 23:17:53
2
323
apollos
75,392,643
19,916,174
Use iterator in function in function parameter
<p>I was trying to create some code that can solve problems with sums. For example, if you want to take the sum of 4*i for all values of i from 3, 109, I want this code to be able to do that. However, it should also be able to deal with more complicated things than just multiplication. See a sample of what I want to do...
<python>
2023-02-08 23:16:43
2
344
Jason Grace
75,392,639
2,801,404
Why are all PyTorch dataloader proccesses in S state (interruptible sleep) except one?
<p><strong>Short version</strong>: I'm using PyTorch dataloading library to load data in parallel for training a deep learning model. When I look at the CPU usage with <code>htop</code>, I see a bunch of processes running the same python script but only one of them is in R state (<em>running or runnable</em>) using 150...
<python><pytorch><multiprocessing><pytorch-dataloader>
2023-02-08 23:16:05
0
451
Pablo Messina
75,392,523
11,092,636
Why can't RegularGridInterpolator not return several values (for a function that outputs in $R^d$)
<p>MRE (with working output and output that doesn't work although I would like it to work as it would be the intuitional thing to do):</p> <pre class="lang-py prettyprint-override"><code>import numpy as np from scipy.interpolate import RegularGridInterpolator, griddata def f(x1, x2, x3): return x1 + 2*x2 + 3*x3, x...
<python><scipy><interpolation>
2023-02-08 22:55:25
1
720
FluidMechanics Potential Flows
75,392,475
2,665,843
How do you delete an axis when plotting data using Datura?
<p>Using <a href="https://datura.readthedocs.io/en/latest/examples.html" rel="nofollow noreferrer">Datura</a>, how do you prevent an axis from appearing in the figure?</p> <p>if you try y_ticks=None, a y-axis still appears:</p> <pre><code>datura.plot([1, 2, 3], [2, 3, 1], y_ticks=None) </code></pre>
<python><visualization>
2023-02-08 22:47:21
1
577
Peter
75,392,443
6,401,858
Fast way to save/load giant Python dictionaries (~50GB)?
<p>I have a bunch of data I need to store in memory as a python dictionary for O(1) fast lookups (millions of key,value pairs). I've been using the json library, which saved the data to a 50GB json file and takes 45min to load every time I start my program. There's gotta be a faster way...</p> <p>The keys are Int64s (e...
<python><json><dictionary><bigdata><pickle>
2023-02-08 22:42:10
1
382
fariadantes
75,392,409
3,056,036
Python + Linux - Excel to HTML (keeping format)
<p>I'm looking for a way to convert excel to html while preserving formatting.</p> <p>I know this is doable on windows due to the availability of some underlying win32 libraries, (eg via <code>xlwings</code> <a href="https://stackoverflow.com/questions/68273994/python-excel-to-html-keeping-format">Python - Excel to HTM...
<python><excel><linux>
2023-02-08 22:36:12
2
309
ateymour
75,392,399
8,176,763
extremely slow to write sql query into csv file
<p>I have a sql query that containers approximately 500k rows and 47 columns and I want this query to be dumped into a csv file , so I can import afterwards the file into a table onto a new database hosted into another server. My code does not use any fancy library that would cause some overhead into the process , but ...
<python><csv><cx-oracle>
2023-02-08 22:34:55
1
2,459
moth
75,392,320
6,100,445
Blocking function sent to_thread not executing if awaited secondly
<p>I am learning Python asyncio and I have created a simple app to get console input and print a counter simultaneously. I know there are packages like aioconsole, aconsole, etc. but I'm looking for an answer to the specific question in the code comments below.</p> <p>UPDATE: This was solved with help from <code>user2...
<python><python-3.x>
2023-02-08 22:20:02
1
927
rob_7cc
75,392,292
7,920,004
Capture Redshift's RAISE data from procedure's loop in Python
<p>At the beginning I prepared simple proc:</p> <pre><code>CREATE OR REPLACE PROCEDURE public.record_example() AS ' DECLARE rec RECORD; BEGIN FOR rec IN SELECT * FROM public.event LOOP RAISE INFO ''eventid = %'', rec.eventid; END LOOP; END; ' LANGUAGE plpgsql; </code></pre> <p>To not save result into temp t...
<python><amazon-web-services><amazon-redshift><plpgsql>
2023-02-08 22:16:31
0
1,509
marcin2x4
75,392,144
9,404,560
Python - Draw Bounding Box Around A Group Of Contours
<p>Hi I have a code that finds and draws contours around objects that are Yellow.</p> <p>Here is the code:</p> <pre><code>import cv2 import numpy as np from PIL import ImageGrab lower_yellow = np.array([20, 100, 100]) upper_yellow = np.array([30, 255, 255]) def test(): while True: imgDef = ImageGrab.grab...
<python><opencv>
2023-02-08 21:56:38
1
1,490
SunAwtCanvas
75,392,099
284,932
Unexpected result trying to plot the regression line using axline without numpy
<p>For studying purposes, I am trying to make a simple linear regression without external libs to calculate the slope and the intercept:</p> <pre><code>import matplotlib.pyplot as plt x = [1.5, 1.6, 1.7, 1.8, 1.9, 2.0, 2.1, 2.2] y = [60, 62, 64, 66, 68, 70, 72, 74] n = len(x) sx = sum(x) sy = sum(y) sxy = sum...
<python><matplotlib><linear-regression>
2023-02-08 21:50:57
1
474
celsowm
75,392,012
12,043,946
In python, how to Combine multiple arrays in the same column + row into one array?
<p>I have a dataframe df with a column named pvalues. Here is the column</p> <pre><code>print(grouped['pvalue'].to_dict()) {0: [array([0.96612999, 0.30348366])] 4: [array([0.66871158, 0.0011381 ]), array([0.18113085, 0.04860657])], 5: [array([0.66871158, 0.0011381 ]), array([0.00000000e+00, 8.54560803e-07])], 6: [ar...
<python><arrays><pandas><dataframe>
2023-02-08 21:39:16
1
392
d3hero23
75,391,852
14,293,020
How to plot lines between points, and change their color based on specific values in Python?
<p><strong>Context:</strong></p> <ul> <li>3x35 <code>values</code> array that associates 1 value per segment</li> <li>4x35x2 <code>matpos</code> array that gathers the coordinates of 4x35 points (hence 3x35 segments).</li> </ul> <p><strong>Question:</strong></p> <p>How can I define each segment's color based on their v...
<python><matplotlib><plot><colors>
2023-02-08 21:19:15
1
721
Nihilum
75,391,797
11,027,207
Celery - assign session dynamicall/reusing connections
<p>Breaking my head for few days for simple task(Thought it simple...not anymore):</p> <p>Main program sends hundreds of sql queries to fetch data from Multiple DBs . I thought Celery can be the right choice as it can scale and also simplify the threading/async orchestration .</p> <p>The &quot;clean&quot; solution woul...
<python><sqlalchemy><celery><distributed>
2023-02-08 21:13:41
0
424
AviC
75,391,656
7,437,221
How to join a dictionary with same key as df index as a new column with values from the dictionary
<p>I have the following data:</p> <p>A dictionary <code>dict</code> with a <code>key: value</code> structure as <code>tuple(str, str,): list[float]</code></p> <pre><code>{ ('A', 'B'): [0, 1, 2, 3], ('A', 'C'): [4, 5, 6, 7], ('A', 'D'): [8, 9, 10, 11], ('B', 'A'): [12, 13, 14, 15] } </code></pre> <p>And ...
<python><pandas><dataframe><numpy><dictionary>
2023-02-08 20:56:28
2
353
Sean Sailer
75,391,594
6,658,209
What's the fastest way to turn json results from an API into a dataframe?
<p>Below is an example of sports betting app I'm working on.</p> <p>games.json()['data'] - contains the game id for each sport event for that day. The API then returns the odds for that specific game.</p> <p>What's the fastest option to take json and turn it into a panda dataframe? currently looking into msgspec.</p> <...
<python><json><pandas><python-requests>
2023-02-08 20:49:48
1
6,395
bbennett36
75,391,482
5,896,319
How to create a new csv from a csv that separated cell
<p>I created a function for convert the csv. The main topic is: get a csv file like:</p> <pre><code>,features,corr_dropped,var_dropped,uv_dropped 0,AghEnt,False,False,False </code></pre> <p>and I want to conver it to an another csv file:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th style...
<python><django>
2023-02-08 20:36:49
1
680
edche
75,391,450
16,319,191
Convert columns to binary (0 or 1) inplace using conditions in pandas
<p>I want to convert column values to 0 or 1s. If the column value is &gt;0 then it should be 1 otherwise if it is &lt;=0 then it should be 0. I have over 100 columns. Example df is:</p> <pre><code>df = pd.DataFrame({ &quot;col1&quot;: [0, 0, 2, 0, 7], &quot;col2&quot;: [121, ...
<python><pandas><dataframe>
2023-02-08 20:34:05
0
392
AAA
75,391,328
6,197,439
Python timestamps not increasing on some platforms?
<p>I just tried the following little Python3 test:</p> <pre class="lang-py prettyprint-override"><code>import time tvar = 1 tsa = time.time() tvar += 1 tsb = time.time() print(&quot;tsb {} tsa {} tsb-tsa {}&quot;.format(tsb, tsa, tsb-tsa)) print(&quot; rate {}&quot;.format(tvar/(tsb-tsa))) tsc = time.monotonic() tvar ...
<python><python-3.x><time><timing>
2023-02-08 20:21:19
0
5,938
sdbbs
75,391,274
20,959,773
Get variable inside DOM before DOM changes when clicking redirecting button
<p>I have been trying for so long to find a way to persist variables between page refreshes and different pages in one browser session opened from selenium python. Unfortunately, neither storing variable in localStorage, sessionStorage or window.name doesn't work after testing so many times and research.</p> <p>So I ha...
<javascript><python><html><selenium>
2023-02-08 20:14:40
1
347
RifloSnake
75,391,230
11,067,209
How to access the value projection at MultiHeadAttention layer in Pytorch
<p>I'm making an own implementation for the <a href="https://arxiv.org/abs/2106.05234" rel="nofollow noreferrer">Graphormer</a> architecture. Since this architecture needs to add an edge-based bias to the output for the key-query multiplication at the self-attention mechanism I am adding that bias by hand and doing the...
<python><pytorch><transformer-model><self-attention><multihead-attention>
2023-02-08 20:10:14
0
665
Angelo
75,391,183
10,452,700
Problem with handling multiple legends in subplots when you use plt.twinx()
<p>I'm struggling to pass the list of my subplots with different scales on sides using <code>plt.twinx()</code> in each subplot to show all labels in a single legend box, but I get the following error:</p> <blockquote> <p>AttributeError: 'list' object has no attribute 'get_label'</p> </blockquote> <p>I have tried the f...
<python><matplotlib><legend><subplot><legend-properties>
2023-02-08 20:05:06
1
2,056
Mario
75,391,105
8,618,242
ROS Publisher is not publishing continuously
<p>My Publisher is not publishing continuously, can you please tell me how can I subscribe/publish and advertise services in the same time? thanks in advance.</p> <pre class="lang-py prettyprint-override"><code>#! /usr/bin/env python3 # -*- coding: utf-8 -*- import json import rospy from std_msgs.msg import String, Boo...
<python><ros><publisher><subscriber>
2023-02-08 19:56:19
1
4,115
Bilal
75,390,940
7,318,120
update pip to be consistent with python in ubuntu 20.04
<p>I have <code>python 3.8</code> as the default install with <code>ubuntu 20.04</code>.</p> <p>I have upgraded to <code>python 3.11</code>.</p> <p>However, if i do <code>pip3 --version</code> is see this:</p> <pre><code>pip 20.0.2 from /usr/lib/python3/dist-packages/pip (python 3.8) </code></pre> <p>In windows i just ...
<python><pip><ubuntu-20.04>
2023-02-08 19:39:34
0
6,075
darren
75,390,927
7,343,922
Pyspark: How to avoid python UDF as a driver operation?
<p>I have a python UDF that needs to be run in a pyspark code, Is there any way of calling that UDF using mappartitions, so that I can avoid that python operation not just run only in the driver node and use the full cluster, because If I just use the UDF directly on the dataframe, that would run as a driver operation,...
<python><pyspark>
2023-02-08 19:38:14
1
306
user7343922