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,740,916
18,616,461
How do I make my Discord ban function work?
<p>I am trying to make my Discord bot able to ban people, but the function is not working:</p> <p>The relevant code is as follows:</p> <pre><code>banned_member = get(bot.get_all_members(), id=int_offender_id) banned_member.ban(reason=&quot;Test&quot;) </code></pre> <p>It can find the banned_member object, but it canno...
<python><python-3.x><discord><discord.py>
2023-03-15 05:41:51
1
1,086
Alan Shiah
75,740,766
8,481,155
Publish Pandas Dataframe rows as PubSub Message
<p>I have a task to publish the rows of a <a href="/questions/tagged/pandas" class="post-tag" title="show questions tagged &#39;pandas&#39;" aria-label="show questions tagged &#39;pandas&#39;" rel="tag" aria-labelledby="tag-pandas-tooltip-container">pandas</a> <a href="/questions/tagged/dataframe" class="post-tag" titl...
<python><python-3.x><pandas><dataframe><google-cloud-pubsub>
2023-03-15 05:11:15
1
701
Ashok KS
75,740,655
10,613,037
Access state within nested utility functions
<p>I've created a <code>metadata</code> object in my <code>transformations.py</code>. I want to access it in utility functions such as <code>utils/some_fn</code> . What is the best way to do so?</p> <pre class="lang-py prettyprint-override"><code># metadata.py class Metadata: def __init__(self, year, sheet_nam...
<python><pandas><software-design>
2023-03-15 04:50:35
0
320
meg hidey
75,740,652
1,519,468
FastAPI StreamingResponse not streaming with generator function
<p>I have a relatively simple FastAPI app that accepts a query and streams back the response from ChatGPT's API. ChatGPT is streaming back the result and I can see this being printed to console as it comes in.</p> <p>What's not working is the <code>StreamingResponse</code> back from FastAPI. The response gets sent all ...
<python><python-requests><streaming><fastapi><openai-api>
2023-03-15 04:48:33
5
533
Robert Ritz
75,740,543
24,039
How do I convert a timezone aware string literal into a datetime object in Python
<p>I have a string from a 3rd party log file that I need to convert into a <code>datetime</code> object. The log entry is in the form:</p> <pre><code>... timestamp=datetime.datetime(2023, 2, 25, 15, 59, 21, 410787, tzinfo=tzlocal()), ... </code></pre> <p>I have tried extracting into a tuple/list and using the datetime ...
<python><python-3.x><datetime><timezone><python-datetime>
2023-03-15 04:25:48
1
81,221
Simon
75,740,280
2,717,373
Importing python module from another directory, which then imports a second module from that directory
<p>I have a bunch of data processing scripts in the root directory of my Python application that I want to clean up by putting into their own directory, but I can't get it to work properly.</p> <p>This is my file structure:</p> <pre><code>. +-- Root | |-- main_script.py | +-- utils | | | |--...
<python><module>
2023-03-15 03:29:51
0
1,373
guskenny83
75,740,156
13,849,446
Ensure browser is closed even if script is forced exited
<p>I am trying to close browser even if the script is not exited normally. I have tried few methods which I found on internet but failed to do so. First was to use try/except and finally. I implemented it but if does not works if the script execution is forcefully stopped. I have reproduced the code I have. It is not c...
<python><selenium-webdriver><webdriver>
2023-03-15 03:03:56
2
1,146
farhan jatt
75,740,088
3,573,626
Pandas dataframe - transform selected cell values based on their suffix
<p>I have a dataframe as below:</p> <pre><code>data_dict = {'id': {0: 'G1', 1: 'G2', 2: 'G3'}, 'S': {0: 35.74, 1: 36.84, 2: 38.37}, 'A': {0: 8.34, 1: '2.83%', 2: 10.55}, 'C': {0: '6.63%', 1: '5.29%', 2: 3.6}} df = pd.DataFrame(data_dict) </code></pre> <p>I want to multiply all the values in the data frame with 1000...
<python><pandas><dataframe><type-conversion>
2023-03-15 02:42:07
3
1,043
kitchenprinzessin
75,739,929
726,802
Issue while trying to submit ajax form in django
<p><strong>Server Side Code</strong></p> <pre><code>@csrf_protect def Authenticate(request): if request.method == &quot;POST&quot;: return JsonResponse({&quot;success&quot;: False}) </code></pre> <p><strong>Form</strong></p> <pre><code>&lt;form class=&quot;row&quot; id=&quot;frmLogin&quot;&gt; {% csrf_t...
<python><jquery><django>
2023-03-15 02:07:48
1
10,163
Pankaj
75,739,919
15,975,987
Count number of occurrences in Pandas column with some multiples
<p>I have a Pandas dataframe with a column called <code>specialty</code> that looks like this:</p> <pre><code>0 1,5 1 1 2 1 3 1 4 1 5 1,5 6 3 7 3 8 1 9 1,3 10 1 11 1,2,4,6 </code></pre> <p>I want to count the numbe...
<python><pandas><numpy><where-clause><series>
2023-03-15 02:04:39
2
429
Hefe
75,739,877
2,783,767
How to make sure timerseriesAI/tsai uses GPU
<p>I am using tsai 0.3.5 for timeseries classification. But it is taking unusual time for training an epoch. Can somebody please let me know how to make sure that tsai uses GPU and not CPU.</p> <p>Please find below my code.</p> <pre><code>import os os.chdir(os.path.dirname(os.path.abspath(__file__))) from pickle import...
<python><pytorch><time-series>
2023-03-15 01:54:39
1
394
Granth
75,739,619
11,163,122
Library housing CNN shape calculation in a function?
<p>I find myself continually re-implementing the same free function for a convolutional neural network's output shape, given hyperparameters. I am growing tired of re-implementing this function and occasionally also unit tests.</p> <blockquote> <p><a href="https://i.sstatic.net/DDQh6.png" rel="nofollow noreferrer"><im...
<python><numpy><tensorflow><pytorch><conv-neural-network>
2023-03-15 00:50:04
1
2,961
Intrastellar Explorer
75,739,529
6,778,374
Can a Python program query LC_CTYPE locale settings?
<p>In C++ (and C) you can use the functions in <a href="https://en.cppreference.com/w/cpp/header/cwctype" rel="nofollow noreferrer">&lt;cwctype&gt;</a> to query LC_CTYPE character classes for a given character in the active locale.</p> <p>Is there a way to access these options in Python? <strong>Specifically, can I tes...
<python><locale>
2023-03-15 00:26:42
1
675
NeatNit
75,739,475
1,114,872
reveal_type gives me a type, but it does not exist
<p>So, I have a code that typechecks, but when I try to run it, it complains about the type not existing</p> <pre><code>import pyrsistent a = pyrsistent.pset([1,2,3]) #reveal_type(a) #mypy file.py, gives type pyrsistent.typing.PSet[buildins.int] #b : pyrsistent.typing.PSet[int] = a #when running: AttributeError: mod...
<python><python-import><mypy><python-typing>
2023-03-15 00:14:28
1
1,512
josinalvo
75,739,438
4,507,231
AttributeError: module 'pandas' has no attribute 'core' in Statsmodels - broken Conda environment inside Pycharm
<p>I've been trying to upgrade Pandas to version 1.4.4 (was 1.4.1) inside Pycharm, with the project pointing to a Conda environment. I decided to make a new conda environment and do it that way. That was a big mess, but &quot;something&quot; has affected the original conda environment, which I left well alone - and rig...
<python><pandas><pycharm><conda><statsmodels>
2023-03-15 00:06:59
0
1,177
Anthony Nash
75,739,383
318,938
python access /Library on macos
<p>I am trying to write an install file to the /Library folder if the user doesn't have it. I can run the code in &quot;sudo python ...&quot; and it works.</p> <p>However using pyinstaller and creating a packaged app gives me an Error 13 permission denied.</p> <blockquote> <p>[Errno 13] Permission denied: '/Library/......
<python><macos><info.plist>
2023-03-14 23:54:39
1
2,842
msj121
75,739,362
2,913,864
number of groups in a polars groupby
<p>For a polars groupby object, what is the equivalent of the pandas <code>ngroups</code> attribute on a pandas groupby object? Or in any case, what is the idiomatic what to get the number of groups in a polars groupby object?</p>
<python><dataframe><group-by><python-polars>
2023-03-14 23:47:18
1
9,650
Alan
75,739,323
9,749,972
Why doesn't numpy ndarray have a __dict__ attribute?
<p>I created a numpy array and tried to get its attributes with '<strong>dict</strong>', but failed.</p> <pre><code>&gt;&gt;&gt; import numpy as np &gt;&gt;&gt; a = np.arange(12) &gt;&gt;&gt; a.reshape(3,4) array([[ 0, 1, 2, 3], [ 4, 5, 6, 7], [ 8, 9, 10, 11]]) &gt;&gt;&gt; type(a) &lt;class 'numpy...
<python><numpy>
2023-03-14 23:38:48
1
691
Leon Chang
75,739,308
2,373,145
AEAD authentication with huge input that doesn't fit into RAM
<p>Say I've got a file on disk that doesn't fit in the computer's main memory. The file consists of two sections, a small section of less than 100 bytes at the beginning of the file, and a large section, consisting of the rest of the file.</p> <p>I need to use AEAD (either ChaCha20-Poly1305 or AES-GCM) to encrypt the s...
<python><python-3.x><cryptography><pycrypto><aes-gcm>
2023-03-14 23:35:09
0
363
user2373145
75,739,294
5,054,505
Can I use a Google credential json file for authentication in a Dataflow job?
<p>I want to use a credential json file (or string) to authenticate a Beam job to read from a GCS bucket. Notably, the credentials are provided by a user (in an existing process so I'm stuck using the json file rather than a service account in my own GCP project).</p> <h2>What I've tried</h2> <ul> <li>Using <code>fsspe...
<python><google-cloud-storage><google-cloud-dataflow><apache-beam><apache-beam-io>
2023-03-14 23:31:56
1
610
Patrick
75,739,264
7,966,156
How to interact with PyBullet GUI in jupyter notebook?
<p>I used the following code in a jupyter notebook</p> <pre class="lang-py prettyprint-override"><code>p.connect(p.GUI) </code></pre> <p>which creates a popup window that looks like this:</p> <p><a href="https://i.sstatic.net/XiUez.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/XiUez.png" alt="enter ima...
<python><macos><jupyter-notebook><popup><pybullet>
2023-03-14 23:27:11
0
628
Nova
75,739,211
952,870
function to validate dates from a list and return a tuple with findings
<p>I need help to create a function that receives the 2 values below and returns a tuple with 2 lists inside as detailed below.</p> <pre><code>initial_date = date(2021, 11, 30) today = date.today() balance_dates = { 1: date(2020, 5, 31), 2: date(2020, 6, 20), 3: date(2020, 6, 20), 4: date(2020, 8, 30), 5: date(...
<python>
2023-03-14 23:15:00
1
2,815
Pabluez
75,739,170
8,030,874
Can't find Python on MACBOOK M1 even python being installed
<p>I'm getting the error <strong>&quot;Error: Can't find Python executable &quot;python&quot;, you can set the PYTHON env variable&quot;</strong></p> <p>when running the <strong>npm install</strong> command on a React project in Visual Studio Code on <strong>Macbook M1</strong>.</p> <p>Python is installed with brew but...
<python><reactjs><npm><apple-m1>
2023-03-14 23:08:20
1
386
Sabrina B.
75,738,915
258,483
How to join arbitrary parts of url in Python?
<p><code>urljoin</code> corrupts the data</p> <pre><code>from urllib.parse import urljoin base = &quot;https://dummy.restapiexample.com/api/v1&quot; tail = &quot;/employees&quot; urljoin(base, tail) </code></pre> <p>returns</p> <pre><code>'https://dummy.restapiexample.com/employees' </code></pre> <p>eating &quot;/api/v...
<python><url>
2023-03-14 22:25:11
1
51,780
Dims
75,738,739
17,158,703
Repeat-fill 3D numpy array with matching planes
<p>I have two 3D numpy arrays of large size <code>(~1.2b elements, e.g. 80k x 500 x 30)</code>. These two arrays have the same size on 2 dimension but differ on the third, which is related to timestamps. I also have two arrays containing the timestamp values corresponding to the planes along the size differing axis. I ...
<python><numpy><numpy-ndarray><array-broadcasting>
2023-03-14 21:55:05
2
823
Dattel Klauber
75,738,705
8,505,509
Google Vision Rest API - KeyError: 'responses'
<p>I am using the Google Vision Rest API to extract text from an image</p> <pre class="lang-py prettyprint-override"><code>VISION_API_ENDPOINT = 'https://vision.googleapis.com/v1/images:annotate' def get_response(self, img_bytes): # Payload for text detection request data = { &quot;requests&quot;: [{ ...
<python><google-vision><vision-api>
2023-03-14 21:48:17
0
1,205
Ganesh Tata
75,738,643
4,183,877
Sharing models between Django apps yields: django.core.exceptions.AppRegistryNotReady: Apps aren't loaded yet
<p>I have a Django project with multiple apps set up like:</p> <pre><code>myproject/ - apps/ - app1/ - app2/ </code></pre> <p>Everything works when running <code>python manage.py runserver</code> until I need to <a href="https://stackoverflow.com/questions/4137287/sharing-models-between-django-apps?noredirect=1&amp...
<python><python-3.x><django><django-models><plotly-dash>
2023-03-14 21:39:20
0
1,305
hubbs5
75,738,404
8,769,787
Why do matplotlib transforms not work as expected?
<p>I am trying to move from data coordinates to axes coordinates in matplotlib.</p> <p>Here is my code:</p> <pre><code> a, b = (.5,2) x = np.linspace(-1,4,100) y = [psi(xv,a,b) for xv in x] plt.figure(figsize=(10,5)) ax = plt.gca() point = (a,1) display = (369, 316.8) trans1 = ax.transData.transform([0,0...
<python><matplotlib>
2023-03-14 21:07:59
0
408
Kiwiheretic
75,738,335
5,495,860
Converting h3 hex id to polygon in python
<p>I'm trying to take a h3 hex id and convert it to a polygon to use in a geodataframe (and eventually export as a shapefile). All of the methods in h3 documented online don't seem to work for me, and cannot figure out what method to use.</p> <p>I'm using h3 3.7.6</p> <pre><code>import h3 h3.cells_to_multi_polygon('862...
<python><geospatial><h3>
2023-03-14 20:58:29
2
472
Geoff
75,738,231
1,441,592
Beautify pandas.DataFrame.apply calls if they applied to same column
<p>I have such data preprocessing code:</p> <pre class="lang-py prettyprint-override"><code>df['age'] = df['resume'].apply(lambda x: x['age'] if 'age' in x else None) df['gender'] = df['resume'].apply(lambda x: x['gender']['id'] if 'gender' in x else None) ... </code></pre> <p>All <code>.apply</code> calls are applied ...
<python><pandas>
2023-03-14 20:46:37
1
3,341
Paul Serikov
75,738,160
9,576,988
Flask WTForms don't always submit (gunicorn + nginx)
<p>I recently migrated my site to another environment (PythonAnywhere to Vultr) and need to set servers up myself now. I've gotten everything running, but I've noticed my form POSTs don't always submit. It seems like 50% of POSTs work, and the other 50% don't. It doesn't matter if the page is refreshed or not, each sub...
<python><nginx><flask><gunicorn><flask-wtforms>
2023-03-14 20:38:23
1
594
scrollout
75,737,860
10,317,162
Selenium How to click on div inside IFrame
<p>I am building a application that should help smaller local business to get google reviews from there customers easier. For that I am using Selenium in Python.</p> <p>This is the procedure explained:</p> <ol> <li>In chrome i open the direct review link.</li> <li>The review link first loads the google maps page and th...
<python><selenium-webdriver><iframe><automation>
2023-03-14 20:01:36
1
464
Nightscape
75,737,733
272,023
Why is BytesIO not splitting binary file correctly by newlines?
<p>I have a BytesIO buffer into which is being written the contents of a file in S3. That file has <a href="https://github.com/py-bson/bson" rel="nofollow noreferrer">pybson</a> BSON objects written to it, separated by <code>\n</code> characters, i.e. binary characters separated by new lines.</p> <p>I want to parse the...
<python><bson>
2023-03-14 19:46:45
0
12,131
John
75,737,649
4,173,059
Unable to find unique elements in 2 dataframes
<p>I have two dataframes -<br></p> <blockquote> <p>df1 = Dataset file which contains info about <code>img</code> files<br> df2 = It is a simple Pandas data frame of number of files in a folder which I created using below code -</p> </blockquote> <pre><code>binary_folder_files = os.listdir(binary_folder_path) binary_lis...
<python><pandas>
2023-03-14 19:37:13
2
809
Beginner
75,737,611
1,982,032
How can convert '\\u5de5' into '\u5de5'?
<p>They are different:</p> <pre><code>len('\\u5de5') 6 len('\u5de5') 1 </code></pre> <p>How can write a function to convert <code>\\u5de5</code> into <code>\u5de5</code>?</p> <pre><code>def con_str(arg): some_code_here return result con_str('\\u5de5') \u5de5 </code></pre>
<python><character-encoding><python-unicode>
2023-03-14 19:32:41
1
355
showkey
75,737,455
11,050,535
Get Body Items for Unread Emails from an specific Mail ID in an Outlook Account
<p>Would Like to appreciate the answer for below Question</p> <p>I have trying to read the latest 5 Unread emails from an Specific mail Id and fetch the Mail Body data in a variable.</p> <p>I have tried using Below Code :</p> <pre><code>import win32com.client import os from datetime import datetime, timedelta outlook ...
<python><email><outlook><win32com><office-automation>
2023-03-14 19:14:52
2
605
Manz
75,737,438
1,686,628
Is there a way to pre-define the python egg name programmatically?
<pre><code>from setuptools import setup, Extension kwargs = {&quot;name&quot;: &quot;foo&quot;, &quot;author&quot;: &quot;&quot;, &quot;version&quot;: &quot;1.0&quot;, &quot;ext_modules&quot;: Extension(name='util/helper/foo', sources=[]),} setup(**kwargs) </code><...
<python><setuptools><setup.py><distutils><egg>
2023-03-14 19:13:20
0
12,532
ealeon
75,737,437
3,513,267
Python function to convert datetime object to BCD
<p>This is the best that I have come up with so far. I am not entirely happy with it because I have to use a % 100 to prevent an overflow of the year byte. As a result I have to add 2000 back to the year in the reverse function. Can anyone improve these functions?</p> <pre><code>def datetime_to_bcd(dt): &quot;&quot...
<python><datetime><bcd>
2023-03-14 19:13:12
1
512
Ryan Hope
75,737,232
8,417,363
Loss is Nan for SegFormer vision transformer trained on BDD10k
<p>I'm trying to implement a <a href="https://huggingface.co/docs/transformers/model_doc/segformer" rel="nofollow noreferrer">SegFormer</a> pretrained with a <a href="https://huggingface.co/nvidia/mit-b0" rel="nofollow noreferrer">mit-b0</a> model to perform semantic segmentation on images obtained from the <a href="ht...
<python><tensorflow><machine-learning><deep-learning><segformer>
2023-03-14 18:48:22
4
3,186
Jimenemex
75,737,187
10,292,638
How to create a column as a list of similar strings onto a new column?
<p>I've been trying to get a new row in a pandas dataframe which encapsullates as a list all the similar strings into it's original matching row.</p> <p>This is the original pandas dataframe:</p> <pre><code>import pandas as pd d = {'product_name': ['2 pack liner socks', '2 pack logo liner socks', 'b.bare Hipster', 'La...
<python><pandas><string><dataframe><nlp>
2023-03-14 18:43:48
1
1,055
AlSub
75,736,985
1,226,649
Matplotlib: resize a plot consisting of two side by side image subplots in Jupyter cell
<p>The existing solution <a href="https://stackoverflow.com/questions/14770735/how-do-i-change-the-figure-size-with-subplots">How do I change the figure size with subplots?</a> does not answer my question.</p> <pre><code>fig, axs = plt.subplots(2, 2, figsize=(15, 15)) # Does not work in my case! </code></pre> <p>Other...
<python><image><matplotlib><jupyter-notebook><subplot>
2023-03-14 18:20:50
0
3,549
dokondr
75,736,866
7,077,532
Python: Solving "Generate Parentheses" with Backtracking --> Confused About stack.pop()
<p>I am trying to understand the backtracking code below:</p> <p><a href="https://i.sstatic.net/q0Z8N.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/q0Z8N.png" alt="enter image description here" /></a></p> <pre class="lang-py prettyprint-override"><code>class Solution: def generateParenthesis(self, ...
<python><recursion><enumeration><backtracking><tree-traversal>
2023-03-14 18:07:13
2
5,244
PineNuts0
75,736,857
1,418,326
python list of lists to np.array() return ndarray of list
<p>I have a list of lists of int: list1. When I convert it to 2d np.array(), it seems like sometime it returns a 2d numpy.ndarray and sometime it returns a 1d numpy.ndarray of list. what am I missing here?</p>
<python>
2023-03-14 18:06:36
1
1,707
topcan5
75,736,742
11,452,928
Installing a new version of python3 on windows
<p>I had python 3.8.10 installed on my pc (with Windows 11 Home). I wanted python 3.10, so I download it from the official site and I installed it, but running <code>python3 --version</code> in the prompt i continued to get <code>python 3.8.10</code>. So I unistalled python 3.8 using the control panel programs and feat...
<python><python-3.x><windows><operating-system>
2023-03-14 17:53:46
2
753
fabianod
75,736,551
6,284,287
Can I assign multiple values to a proto message from a tuple?
<p>I need to create an list of proto rows from a list of tuples.</p> <p>I can only see that I can create a message by explicitly referencing the fields like</p> <pre><code>customer = customer_pb2.customer() customer.user_id = 1 customer.name = 'Mary' </code></pre> <p>But let's say I have a list of tuples like [(1, 'Mar...
<python><protocol-buffers>
2023-03-14 17:33:42
0
626
CClarke
75,736,476
4,348,400
How to make custom Hypothesis strategy to supply custom objects?
<p>Suppose I have a class <code>Thing</code></p> <pre class="lang-py prettyprint-override"><code>class Thing: def __init__(self, x, y): ... </code></pre> <p>And suppose I have a function which acts on a list of things.</p> <pre class="lang-py prettyprint-override"><code>def do_stuff(list_of_things): .....
<python><unit-testing><python-hypothesis>
2023-03-14 17:25:52
2
1,394
Galen
75,736,428
14,076,103
upload geojson file to Mapbox API
<p>I have Geopandas dataFrame, I am converting this into Geojson string and uploading it into MAPbox API.</p> <pre><code>gdf = gpd.GeoDataFrame(df, geometry=&quot;GEOMETRY&quot;) geojson_str = gdf.to_json() url = f&quot;https://api.mapbox.com/uploads/v1/{username}/credentials?access_token={my_access_token}&quot; payloa...
<python><python-requests><mapbox-gl-js>
2023-03-14 17:21:04
0
415
code_bug
75,736,181
2,065,083
What is a quick way to count the number of pairs in a list where a XOR b is greater than a AND b?
<p>I have an array of numbers, I want to count all possible combination of pairs for which the xor operation for that pair is greater than and operation.</p> <p><strong>Example:</strong></p> <pre><code>4,3,5,2 </code></pre> <p><strong>possible pairs are:</strong></p> <pre><code>(4,3) -&gt; xor=7, and = 0 (4,5) -&gt; xo...
<python><algorithm><time-complexity>
2023-03-14 16:56:00
4
21,515
Learner
75,736,140
3,826,115
Use hvplot interactive to render loop in browser, and save as html
<p>I am trying to follow this <a href="https://hvplot.holoviz.org/user_guide/Interactive.html" rel="nofollow noreferrer">example notebook</a>, specifically the plotting section where it plots the x,y grid and loops/scrolls through the time dimension.</p> <pre><code>ds.air.interactive.sel(time=pnw.DiscreteSlider).plot()...
<python><python-xarray><interactive><hvplot>
2023-03-14 16:52:22
1
1,533
hm8
75,736,111
5,852,692
ctypes character pointers with same byte string points same location
<p>I am creating two ctypes character pointers with same byte string via:</p> <pre><code>import ctypes as ct var1 = ct.c_char_p(b'.'*80) var2 = ct.c_char_p(b'.'*80) # how I check the values: api = ct.CDLL('api.dll') api.function1(var1, var2) # values of the vars are changed after running the above function print(var...
<python><string><pointers><output><ctypes>
2023-03-14 16:48:46
1
1,588
oakca
75,735,911
1,806,566
How do I load a python module before pip?
<p>I have a module that adds a metapath finder to the metapath, so it affects how modules are imported and how distributions are found. Normally, I use <code>usercustomize.py</code> to load this finder, so it happens before any other module is loaded.</p> <p>If I invoke pip with:</p> <pre><code>python3 -m pip ... </co...
<python><pip>
2023-03-14 16:27:55
0
1,241
user1806566
75,735,840
3,626,104
Python - Jira markdown preview image
<p>I'm making a PySide GUI that submits to Jira. Prior to submission, it would be ideal if I could show the user a &quot;ticket preview&quot; so they know roughly what the ticket will look like or if they made any syntax errors that would cause issues in Jira. To do that, I imagine that I would have to convert their ra...
<python><jira>
2023-03-14 16:21:47
0
1,026
ColinKennedy
75,735,744
15,959,591
List to dataframe without any indexes or NaNs
<p>I have a list of lists that I like to convert to a Pandas data frame. My list looks like this:</p> <pre><code>[1 25 2 35 3 45 4 55 5 65 Name: a, Length: 5, dtype: int 6 75 7 85 8 95 9 105 10 115 Name: b, Length: 5, dtype: int 11 125 12 135 13 145 14 155 15 165 Name: c, Length: 5, dtype: int] </code></pre> <p>My cod...
<python><pandas><dataframe><list>
2023-03-14 16:14:19
2
554
Totoro
75,735,739
5,320,122
Docker image with base image python:3.10-slim-buster apt-get update fails to fetch http://deb.debian.org/debian/dists/buster/InRelease 403 Forbidden
<p>I am trying to build the docker image from this Dockerfile.</p> <pre><code>FROM python:3.10-slim-buster # Set uid and gid for sally ARG sally_uid=2002 ARG sally_gid=2002 # Add user and group entries RUN addgroup -gid $sally_gid sally &amp;&amp; adduser --uid $sally_uid --ingroup sally --system sally # install any u...
<python><linux><docker><debian>
2023-03-14 16:14:06
1
496
Amit
75,735,672
4,502,950
Get data from specific sheets in google sheet and extract specific columns from it using gspread
<p>I am trying to get specific column data out of specific sheets in one big google sheet. For example, I have a list of sheets</p> <pre><code>Sheets = ['Sheet 1', 'Sheet 2', 'Sheet 3'] </code></pre> <p>and from these sheets, I want to retrieve specific columns like</p> <pre><code>Column_headers = ['A', 'B'] </code></p...
<python><google-sheets><gspread>
2023-03-14 16:08:16
1
693
hyeri
75,735,664
20,612,566
Getting dates for past month period Python
<p>I have to aggregate some financial data for past month period. For example, if today is March, 14, I need to get financial data from February, 01 to February, 28. If today is April, 20, I need to get financial data from March, 01 to March, 31. I have a function that takes two parameters: date_from &amp; date_to (in ...
<python><date><datetime>
2023-03-14 16:07:19
1
391
Iren E
75,735,631
1,421,907
How to use a parent classmethod that returns an instance in an overriding child method?
<p>I have a parent <code>classmethod</code> that returns an instance of the class. Later I have a child class in which I would like to use the <code>classmethod</code> of the parent and return an instance of the child class. I am using python 3.9</p> <p>An example could be the following:</p> <pre><code>class A: def...
<python><inheritance>
2023-03-14 16:04:53
0
9,870
Ger
75,735,566
15,673,412
python - remove array column if it contains at least one 0
<p>Let's suppose I have a <code>np.array</code> like:</p> <pre><code>array([[1., 1., 0., 1., 1.], [1., 1., 1., 1., 1.], [1., 1., 1., 1., 0.], [1., 1., 1., 1., 0.]]) </code></pre> <p>I would like to know if there is a pythonic way to find all the columns that contain at least one occurence of 0. In ...
<python><arrays><numpy>
2023-03-14 16:00:03
1
480
Sala
75,735,553
3,482,266
Running subprocess.call with pytest fails in GitHub Actions
<p>I have a CI pipeline in GitHub.</p> <p>In a <code>test.py</code> file, I have the following:</p> <pre class="lang-py prettyprint-override"><code>subprocess.call( args=[ &quot;python&quot;, &quot;./folder/file.py&quot;, &quot;--file_path&quot;, &quot;tests/local_tests/test_data/dat...
<python><continuous-integration><pytest><github-actions>
2023-03-14 15:59:14
1
1,608
An old man in the sea.
75,735,519
14,649,310
How are Celery queues managed?
<p>This is a bit of theoretical question and I cant find a clean cut answer in any <a href="https://docs.celeryq.dev/en/stable/getting-started/first-steps-with-celery.html#first-steps-with-celery" rel="nofollow noreferrer">celery documentation</a> I ve read. So assume we have a Flask app and also Celery with either <co...
<python><celery>
2023-03-14 15:56:03
1
4,999
KZiovas
75,735,206
12,760,550
Confirm if LOV columns in a pandas dataframe complies with another mapping dataframe
<p>I have 2 dataframes, one of them of employee information by Country, and another one with a mapping of possible values for LOV columns per country (depending on the country, the column may or may not be an LOV and accept different values and is case sensitive). Example I have this data belonging to CZ:</p> <pre><cod...
<python><pandas><list><filter><lines-of-code>
2023-03-14 15:30:26
1
619
Paulo Cortez
75,735,188
2,789,863
Django GraphQL won't create new data with foreign key
<p>I'm new to Graphene, Django, and GraphQL and am trying to wrap my head around how it would work when updating tables that use a Foreign Key. I am able successfully create a new author, which does <strong>not</strong> require populating a foreign key field, but I cannot create a new book, which <strong>does</strong> ...
<python><django><graphql><graphene-django>
2023-03-14 15:27:27
1
6,776
tblznbits
75,735,028
9,640,238
Using os.path.relpath on Windows network drive
<p>I need to get the relative path on a network drive. So, from <code>s:\path\to\file</code>, I want to get <code>path\to\file</code>.</p> <p>So, this works:</p> <pre class="lang-py prettyprint-override"><code>In [8]: path = r's:\path\to\file' In [9]: path[3:] Out[9]: 'path\\to\\file' </code></pre> <p>But I thought th...
<python><windows><path><relative-path><network-drive>
2023-03-14 15:14:12
0
2,690
mrgou
75,734,987
9,729,023
Append S3 File in Lambda, Python
<p>I understand it's not recommendable way but we need to update the same S3 file using Lambda. We'd like to write and add the count result in the same file in S3.</p> <p>Usually, it's counting and updating one by one in sequential order in the same job session. But we can't deny any possibility that the scheduled jobs...
<python><amazon-web-services><amazon-s3><aws-lambda>
2023-03-14 15:10:49
1
964
Sachiko
75,734,979
1,403,546
pandas-profiling / ydata-profiling : not able disable some basic alerts like "Zeros"
<p>I'm using ydata-profiling (pandas profiling) and I'm not able to disable some alerts (e.g. Zeros).</p> <p>Here, <a href="https://ydata-profiling.ydata.ai/docs/master/pages/advanced_usage/available_settings.html" rel="nofollow noreferrer">https://ydata-profiling.ydata.ai/docs/master/pages/advanced_usage/available_set...
<python><validation><pandas-profiling>
2023-03-14 15:10:25
1
1,759
user1403546
75,734,763
8,790,507
Ordering multi-indexed pandas dataframe on two levels, with different criteria for each level
<p>Consider the dataframe <code>df_counts</code>, constructed as follows:</p> <pre><code>df2 = pd.DataFrame({ &quot;word&quot; : [&quot;AA&quot;, &quot;AC&quot;, &quot;AC&quot;, &quot;BA&quot;, &quot;BB&quot;, &quot;BB&quot;, &quot;BB&quot;], &quot;letter1&quot;: [&quot;A&quot;, &quot;A&quot;, &quot;A&quot;, &q...
<python><pandas><dataframe>
2023-03-14 14:52:25
2
1,594
butterflyknife
75,734,602
2,790,047
Differences between forced early binding methods (In CPython) and how to access values stored in function?
<p>Using the CPython implementation of Python 3.9.16 consider the following codes</p> <pre class="lang-py prettyprint-override"><code>def foo_a(): x = 1 fun = (lambda _x: lambda: print(_x))(x) x = 2 return fun def foo_b(): x = 1 fun = lambda _x=x: print(_x) x = 2 return fun fa = foo_a(...
<python><cpython>
2023-03-14 14:39:08
1
22,544
jodag
75,734,529
7,553,746
How can I correctly parse this date string in Python using strptime?
<p>I've read previous Stack questions but I am coming unstuck with a datetime. My code looks like this and each time raises and error on just some of the transactions.</p> <pre><code> # r.createdAt = datetime.strptime(unparsed_review['createdAt'], '%Y-%m-%dT%H:%M:%S.%fZ') # ValueError: time data '2020-11-25T14:5...
<python><datetime>
2023-03-14 14:31:58
2
3,326
Johnny John Boy
75,734,478
7,702,354
Python count same keys in ordered dict
<p>I have multiple ordered dict (in this example 3, but can be more) as a result from an API, with same key value pairs and I test for the same key, then I print out another key's value:</p> <pre><code>from collections import OrderedDict d = [OrderedDict([('type', 'a1'), ('rel', 'asd1')]), OrderedDict([('type', '...
<python>
2023-03-14 14:27:37
3
359
Darwick
75,734,368
1,497,199
What is the grid_size parameter in shapely operations do?
<p>In a practical sense, what does the <code>grid_size</code> parameter do for you? When/why would you change it from the default?</p> <p>I understand from testing that it imposes a discretization on the coordinates of the resulting geometries, e.g. with <code>grid_size=0.01</code> the fractional part of the coordinat...
<python><shapely>
2023-03-14 14:17:43
1
8,229
Dave
75,734,320
19,336,534
Waiting for os command to end in python
<p>In my python program i am running:</p> <pre><code>os.popen('sh download.sh') </code></pre> <p>where <code>download.sh</code> downloads a couple of csv files using curl.<br /> Is there a way to wait until the files are downloaded before the python programm continues running?</p>
<python><python-3.x><operating-system><popen>
2023-03-14 14:13:28
2
551
Los
75,734,273
1,857,373
Error Unexpected formatting Networks edges exception. ValueError: not enough values to unpack. add_nodes_from() problem
<p><strong>Problem</strong></p> <p>Batch processing with CSV files, nodes, edges. Need to create graph data and load netowrkx.from_csv().</p> <p>Started adding nodes and edges to networkx graph using graph.add_nodes_from(_nodes) and graph.add_nodes_from(_edges). Nodes and edges are visible in sparse array. But code doe...
<python><numpy><graph><networkx>
2023-03-14 14:09:50
0
449
Data Science Analytics Manager
75,734,219
10,844,937
Why multi-thread get different output without sleep?
<p>I use <code>threading</code> to create 10 threads.</p> <pre><code>import threading import time def work(): time.sleep(1) print(f&quot;{threading.current_thread().name} - work......&quot;) if __name__ == '__main__': for i in range(10): t = threading.Thread(target=work) t.start() </code...
<python><multithreading>
2023-03-14 14:04:18
1
783
haojie
75,734,133
8,548,374
Need advice on a use case that involves maintaining several python and non-python scripts
<p>I am just learning containers and kubernetes and everything around it. There has been a use case to build a reliable setup, where we can store all our python scripts(small, usecase defined scripts that do one only job each). There are some scripts in other languages like perl too.</p> <p>Not sure if this is the corr...
<python><kubernetes><scripting><containers><podman>
2023-03-14 13:57:36
1
421
Sudhi
75,733,969
11,154,036
Splitting multiple lists in columns in multiple rows in pandas
<p>I'm looking for the best way to transform this matrix</p> <p><a href="https://i.sstatic.net/RaXM2.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/RaXM2.png" alt="enter image description here" /></a></p> <pre><code>pd.DataFrame(data=[[1, [2, 3], [4, 5], [6, 7]], ['a', ['b', 'c'], ['d', 'e'], ['f', 'g']...
<python><pandas><dataframe>
2023-03-14 13:44:22
1
302
Hestaron
75,733,920
8,176,763
jinja templates inside @task in taskflow
<p>I have a dag that does not render my jinja template:</p> <pre><code>@dag(default_args={&quot;owner&quot;: &quot;airflow&quot;}, schedule_interval=None, start_date=days_ago(1)) def my_dag(): fs_hook = LocalFilesystemHook() @task def write_output(output_name): output = &quot;This is some outpu...
<python><airflow>
2023-03-14 13:39:46
0
2,459
moth
75,733,844
18,618,577
Plot windroses subplots on the same figure
<p>there is a <a href="https://windrose.readthedocs.io/en/latest/usage.html#subplots" rel="nofollow noreferrer">beautiful example</a> of subplots display with windroses but I don't find any code of it, and for me the function windroseaxes is a blackbox.</p> <p>Here is my code, it's generate 2 plots of windrose and I tr...
<python><subplot><windrose>
2023-03-14 13:33:09
1
305
BenjiBoy
75,733,789
9,390,633
is there a way to subset a dataset when read in using pyspark
<p>I see you can use use sample to return a random sample of items but is there anyway when reading in a csv file as a dataframe for example we only read in a specified random selection of rows of a specific number?</p> <p>Is there anyway to read in the csv but pick 100 random rows from that csv.</p> <p>Do I need to re...
<python><pandas><dataframe><apache-spark><pyspark>
2023-03-14 13:29:05
1
363
lunbox
75,733,783
9,879,869
Django list display of foreign key attribute that is boolean field using check or cross icons
<p>My problem is similar to this thread: <a href="https://stackoverflow.com/questions/163823/can-list-display-in-a-django-modeladmin-display-attributes-of-foreignkey-field">Can &quot;list_display&quot; in a Django ModelAdmin display attributes of ForeignKey fields?</a>. I want to display a foreign key attribute from th...
<python><django><django-models><django-admin><django-modeladmin>
2023-03-14 13:28:40
1
1,572
Nikko
75,733,676
3,862,607
npm install --legacy-peer-deps - command failed
<p>In order to try to resolve an issue with node-sass peer dependencies, I tried running the following</p> <p><code>npm install --legacy-peer-deps</code></p> <p>However when I run this, I get the following stacktrace and I'm not sure what it means</p> <pre><code>npm ERR! code 1 npm ERR! path /Users/apple/Documents/proj...
<python><node.js><npm>
2023-03-14 13:19:36
1
1,899
Drew Gallagher
75,733,675
15,613,309
Is there an alternative to using Python eval() in this situation?
<p>I have a program that is a group of individual &quot;applets&quot;. Each of the applets has tk.Entry widgets that only require numeric entries and the decimal key (0-9 &amp; .). This program runs on a Raspberry Pi with a 10&quot; touch screen. The stock on screen keyboards (onBoard, etc.) take up way too much scre...
<python><tkinter><eval>
2023-03-14 13:19:29
1
501
Pragmatic_Lee
75,733,367
188,331
Convert Chinese numeric characters to numbers in Python
<p>I am writing a Python function to convert numbers represented in a mix of Chinese and Arabic numbers to a numerical value.</p> <pre><code>import re units = ['', '十', '百', '千', '萬', '十萬', '百萬', '千萬', '億', '十億', '百億', '千億'] # the Chinese means '', '100', '1000', '10000', etc. def chinese_numeral_replace(input_text):...
<python><regex>
2023-03-14 12:50:31
3
54,395
Raptor
75,733,294
11,932,905
Pandas: calculate time difference between different milestones in column
<p>I have a table like this:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th style="text-align: left;">id</th> <th style="text-align: left;">tm</th> <th style="text-align: left;">milestone</th> </tr> </thead> <tbody> <tr> <td style="text-align: left;">00335c06f96a21e4089c49a5da</td> <td st...
<python><pandas><group-by><pivot>
2023-03-14 12:43:40
1
608
Alex_Y
75,733,292
5,969,463
Formatting and Substituting Into Queries Fails in SQLAlchemy
<p>I am doing some wrapping of queries in <code>TextClause</code> objects by using the SQLAlchemy's <code>text()</code> function. It appears that when I try to pass values to these parameters, they do not get substituted. I am pretty sure I am passing the parameters correctly (via dictionary).</p> <p>Could there be an ...
<python><sqlalchemy><flask-sqlalchemy>
2023-03-14 12:43:33
1
5,891
MadPhysicist
75,732,892
1,937,003
Issue accessing a dictionary key in python
<p>When I execute this code:</p> <pre><code>df_settings = { &quot;headers&quot; : [ &quot;Header 1&quot;, &quot;Header 2&quot;, &quot;Header 3&quot; ], &quot;headers_type&quot; : { &quot;Header 1&quot; : &quot;int64&quot;, &quot;Header 2&quot; : &quot;object&quot;, ...
<python><list><dictionary><data-structures>
2023-03-14 12:02:11
2
424
Manuel Zompetta
75,732,797
5,623,899
Construct a cone from a set of k points given apex point i in python?
<p>Suppose you have k n-dimensional points <code>{p1, p2, ..., pk}</code> and we pick a point <code>i</code> (<code>1 &lt;= i &lt;= k</code>). How would one compute the tightest fitting cone with tip <code>pi</code>? As well as the <a href="https://link.springer.com/article/10.1007/s10107-006-0069-1" rel="nofollow nor...
<python><scipy><computational-geometry>
2023-03-14 11:52:53
0
5,218
SumNeuron
75,732,660
3,118,956
Adding missing label line
<p>I csv have a file with data lines, but it misses the label line. This label line is a string, coma separated, ready to be appended on top.</p> <pre><code>import pandas as pd data = pd.read_csv(&quot;C:\\Users\\Desktop\\Trades-List.txt&quot;, sep=',') labelLine = &quot;label1,label2,label3&quot; </code></pre> <p>How ...
<python><pandas>
2023-03-14 11:39:36
2
7,488
Robert Brax
75,732,546
12,106,577
LaTeX logo (\LaTeX)
<p>I'm trying to get the \LaTeX symbol to work in matplotlib.pyplot's mathtext or usetex (matplotlib==3.5.2).</p> <p>Other symbols display correctly with <code>text_usetex</code> both <code>True</code> and <code>False</code>:</p> <pre><code>import matplotlib.pyplot as plt plt.rcParams['text.usetex'] = False plt.plot([]...
<python><matplotlib><latex>
2023-03-14 11:30:22
1
399
John Karkas
75,732,523
1,468,797
Optimizing Django db queries for Viewset
<p>I recently was tasked to optimize db queries and performance of some of our django rest apis written in drf and was able to successfully use <code>prefetch_related()</code> to implement them.</p> <p>But there is one usecase I have been unable to resolve and looking for support on the same.</p> <p>Here goes the struc...
<python><django><django-rest-framework><django-queryset>
2023-03-14 11:26:45
1
2,175
ichthyocentaurs
75,732,371
3,063,273
How do I copy the binaries from the `python` NuGet package into my project's build output?
<p>Nothing happens when I reference <a href="https://www.nuget.org/packages/python" rel="nofollow noreferrer">the <code>python</code> NuGet package</a> in my .csproj. I would like its binaries to be copied into my build directory. What do I need to change about my .csproj for that to happen?</p> <p>My .csproj:</p> <pre...
<python><c#><msbuild><nuget>
2023-03-14 11:10:50
1
5,844
Matt Thomas
75,732,303
5,724,244
Pyspark: Compare Column Values across different dataframe
<p>we are planning to do the following, compare two dataframe, based on comparision add values into first dataframe and then groupby to have combined data.</p> <p>We are using pyspark dataframe and the following are our dataframes.</p> <p>Dataframe1:</p> <pre><code>| Manager | Department | isHospRelated | ...
<python><apache-spark><pyspark><pyspark-pandas><pyspark-schema>
2023-03-14 11:04:16
1
449
frp farhan
75,732,196
6,734,243
how to add line number in a sphinx warning?
<p>I'm writting an extention to display inline icons (<a href="https://github.com/sphinx-contrib/icon" rel="nofollow noreferrer">https://github.com/sphinx-contrib/icon</a>) in for sphinx and I realized the warnings I raise are not displaying the line number in the doc, making more difficult to debug:</p> <pre><code>WAR...
<python><python-sphinx>
2023-03-14 10:51:54
1
2,670
Pierrick Rambaud
75,732,052
1,764,089
How do I force the usual "default" formatting that pandas dataframes output to?
<p>I'm using a jupyter like platform that has truly terrible visual capabilities and one of the annoying things is that when simply seeing a dataframe by having it be the last thing in a cell all the usual pandas formatting is gone if I turn it into a styler.</p> <p>What I mean by that is:</p> <ul> <li>alternating rows...
<python><pandas><jupyter-notebook><pandas-styles>
2023-03-14 10:37:29
1
3,753
evan54
75,731,994
4,490,454
How to transform this for loop in a list comprehension?
<p>I am trying to transform a for loop in a list comprehension but I keep getting a syntax error. What am I doing wrong?</p> <p>The for loop:</p> <pre><code>for item in items: if item in default_items.keys(): total += default_items[item] </code></pre> <p>The list comprehension:</p> <pre><code>[total :=...
<python><python-3.x>
2023-03-14 10:33:04
1
445
EGS
75,731,959
12,760,550
Confirm if column in a pandas dataframe is in a sequential order starting by one
<p>Imagine I have the following column on a dataframe:</p> <pre><code>df['Col1'] = [1, 2, 3, 4, 6, 5] </code></pre> <p>What would be the best way to confirm if this column is in a sequential order having their lowest value starting with 1? In the example above, I would expect it to return &quot;True&quot;.</p>
<python><pandas><dataframe><sorting>
2023-03-14 10:30:33
2
619
Paulo Cortez
75,731,873
9,328,993
ONNX export failed on an operator with unrecognized namespace 'torch_scatter::scatter_max'
<p>I have a pytorch network like this</p> <pre class="lang-py prettyprint-override"><code>import torch.nn as nn import torch_scatter.scatter_max class DGCN(nn.Module): def __init__(self): super().__init__() def forward(self, x): ... torch_scatter.scatter_max(x, index, dim=0) .....
<python><onnx><torch-scatter>
2023-03-14 10:24:09
1
2,630
Sajjad Aemmi
75,731,770
2,754,029
run perforce sync though script after changing directory
<p>I am trying to sync the perforce code using automation script. I have a directory where /opengrok/src/&lt;project_name&gt; where .p4config is there.</p> <p>But when I run below code it fail because it takes current working directory as the script's directory:</p> <pre><code>def sync_perforce_code(project_name, p4por...
<python><subprocess><perforce><perforce-client-spec>
2023-03-14 10:16:38
1
3,642
undefined
75,731,693
13,320,357
How to add a key in a mongo document on the basis of an existing key?
<p>I have a document as follows:</p> <pre class="lang-json prettyprint-override"><code>{ &quot;_id&quot;: &quot;1234&quot;, &quot;created_at&quot;: 1678787680 } </code></pre> <p>I want to modify the document and add a new key <code>updated_at</code> which will be a datetime equivalent of the <code>created_at</c...
<python><mongodb><mongodb-query><aggregation-framework><pymongo>
2023-03-14 10:11:07
2
415
Anuj Panchal
75,731,406
8,176,763
how to use Dataset in taskflow in airflow
<p>I have a dag written in the taskflow format, and I am experimenting on how to pass files between tasks, I read some info about <code>Dataset</code>(<a href="https://airflow.apache.org/docs/apache-airflow/stable/authoring-and-scheduling/datasets.html" rel="nofollow noreferrer">https://airflow.apache.org/docs/apache-a...
<python><airflow>
2023-03-14 09:43:23
1
2,459
moth
75,731,396
865,695
OpenCV stitcher ignores additional image
<p>As a follow-up to the closed question ' <a href="https://stackoverflow.com/questions/75727432/how-to-update-a-part-of-a-panorama">How to update a part of a panorama</a> ' I have come up with an approach but OpenCV doesn't behave the way I want it to. To be more exact:</p> <ul> <li>I have a panorama of which I do not...
<python><opencv><image-manipulation><panoramas><opencv-stitching>
2023-03-14 09:42:32
0
5,290
8192K