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,678,741
4,450,090
polars aggregate list[str] column into set[str]
<p>I have polars dataframe:</p> <pre><code>df = pl.DataFrame({ 'col1': [[&quot;aaa&quot;, &quot;aaa&quot;], [&quot;bbb&quot;, &quot;ccc&quot;], [&quot;ccc&quot;, &quot;ddd&quot;, &quot;ddd&quot;], [&quot;ddd&quot;, &quot;ddd&quot;, &quot;ddd&quot;]], 'col2': [&quot;a&quot;, &quot;a&quot;, &quot;a&quot;, &quot;a...
<python><set><aggregate><flatten><python-polars>
2023-03-08 22:17:07
2
2,728
Dariusz Krynicki
75,678,693
2,981,639
Polars custom function returning multiple features
<p>I'm evaluating <code>polars</code> for timeseries feature extraction - replicating for example the functionality of libraries such as <code>tsfresh</code>.</p> <p>I have the basics working really well, i.e. using <code>dynamic grouping</code> to create windows and most of the basic <code>tsfel</code> features can be...
<python><python-polars>
2023-03-08 22:09:07
1
2,963
David Waterworth
75,678,678
817,659
Parse GET parameters
<p>I have an <code>REST API</code> where the url looks like this:</p> <pre><code>class RRervice(pyrestful.rest.RestHandler): @get('/Indicator/{rparms}') def RR(self, rparms): print(rparms) ... </code></pre> <p>So when this codes executes on this URL:</p> <pre><code>http://ip...
<python><rest><urllib><argparse><url-parameters>
2023-03-08 22:06:23
1
7,836
Ivan
75,678,657
1,968,829
How to merge two dataframes on list of columns and then deduplicate?
<p>I have two dataframes that I would like to do a merge on <code>cols = ['male', 'age_cat', 'inpatient']</code>, and once merged then I would like to dedupulicate these on the left and right column <code>index</code> from each dataframe.</p> <p>a:</p> <pre><code> index male age_cat inpatient 6885 34273 0....
<python><pandas><merge><duplicates>
2023-03-08 22:02:57
1
2,191
horcle_buzz
75,678,575
5,924,264
Passing a series into a dict
<p>I have a <code>dict</code>, <code>ht</code>, where the key is an <code>int</code>, and the value is a conversion factor.</p> <p>I also have a dataframe <code>df</code>, with a column <code>id</code> that stores <code>int</code> variables, and another column, <code>vals</code>, that I need to multiply to relevant con...
<python><pandas><dictionary>
2023-03-08 21:52:17
2
2,502
roulette01
75,678,404
9,669,142
Python - change the layout of a decision tree
<p>I have a decision tree classifier from Scikit-Learn in Python and I want to visualize (plot) a tree. I'm looking at two options: using Graphviz (by exporting the data to a text file) or to use tree.tree_plot(clf). I find both options however not very readable and I want to be able to change the visualization. R prod...
<python><scikit-learn>
2023-03-08 21:28:50
0
567
Fish1996
75,678,261
15,803,668
Pdfs in QWebEngineView: How to select letters inside linked phrase
<p>I use <code>pyqt5 QWebEngineView</code> to display pdfs. In the pdfs there are phrases that are linked. When I want to select individual words or letters, it doesn't work with the links. Is there a possibility in <code>QWebEngineView</code> to &quot;turn off&quot; the links without changing the pdf itself?</p> <p>Th...
<python><pyqt5><qwebengineview>
2023-03-08 21:11:17
0
453
Mazze
75,678,100
2,006,921
OpenGL gluPerspective and shader question
<p>I am trying to learn OpenGL, and I have copied and pasted a few things from various sources. Things are starting to come together, but not quite. Here's my code that is doing something:</p> <pre><code>from OpenGL.GLUT import * from OpenGL.GL import * from OpenGL.GL import shaders import numpy as np from PyQt6 impor...
<python><opengl><pyopengl><pyqt6>
2023-03-08 20:50:44
1
1,105
zeus300
75,678,004
3,885,794
How to deal with module name collisions in Python?
<p>Say in my code, I need to use a 3rd-party package from Pypi which has a module <code>somemodule</code>. On the other hand, I have a user-defined module <code>somemodule</code> from which I need to import some functions. Is it possible to import from both modules in a single file?</p> <p>Below is the sample code that...
<python>
2023-03-08 20:39:28
0
1,313
fhcat
75,677,991
4,450,090
polars datetime 5 minutes floor
<p>I have polars dataframe with timestamp folumn of type datetime[ns] which value is <code>2023-03-08 11:13:07.831</code> I want to use polars efficiency to round timestamp to 5 minutes floor.</p> <p>Right now I do:</p> <pre><code>import arrow def timestamp_5minutes_floor(ts: int) -&gt; int: return int(arrow.get(t...
<python><timestamp><python-polars><floor>
2023-03-08 20:37:07
1
2,728
Dariusz Krynicki
75,677,936
970,121
How to transform a dataset to basic metrics dataset on various date based rollup in a big dataset using pyspark
<p>I have a dataset that looks like this.</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Date</th> <th>Time</th> <th>Stock-a</th> <th>Stock-b</th> <th>Stock-c</th> </tr> </thead> <tbody> <tr> <td>2023-01-01</td> <td>10:30</td> <td>10</td> <td>20</td> <td>30</td> </tr> <tr> <td>2023-01-01</...
<python><apache-spark><pyspark>
2023-03-08 20:31:08
1
1,329
pramodh
75,677,825
523,612
Why is copying a list of simple objects slower, when the list contains multiple repeats?
<p>This is my environment:</p> <pre><code>$ python Python 3.8.10 (default, Nov 14 2022, 12:59:47) [GCC 9.4.0] on linux Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information. &gt;&gt;&gt; quit() $ lscpu | grep &quot;Model name&quot; Model name: ...
<python><list><performance>
2023-03-08 20:14:51
1
61,352
Karl Knechtel
75,677,672
2,261,553
Select specific items from generator
<p>Given a generator object, I want to be able to iterate only over the elements with defined indices. However, I have experienced that when the generator yields &quot;heavy&quot; items (memory-wise), the loading of each item takes a considerable time compared to the case when iteration is performed on every element in...
<python><generator>
2023-03-08 19:58:50
2
411
Zarathustra
75,677,665
8,229,534
How to display year-month accurately on X-axis for plotly chart?
<p>I am trying to find a solution to accurately display the X-axis for my plotly chart.</p> <p>Here is my code -</p> <pre><code>import pandas as pd print(pd.__version__) # 1.2.4 import plotly print(plotly.__version__) # 5.5.0 </code></pre> <p>I create a data frame with <code>year_month</code> as object type and <code...
<python><pandas><plotly>
2023-03-08 19:57:58
1
1,973
Regressor
75,677,643
10,922,372
Django - Query on overridden save() method cached or something
<p>I am overriding the default save() method of my model in Django 4. The problem is that I am making queries related to an instance of the model with the overridden save() method, but the queries seem not to be updated during the method execution.</p> <p>Example:</p> <pre><code>class Routine(models.Model): exerci...
<python><django>
2023-03-08 19:55:57
0
1,010
Gonzalo Dambra
75,677,603
17,620,209
Checking if subprocess was terminated by user
<pre><code># Create a new terminal window and run the ffmpeg command in it cmd = ' '.join(ffmpeg.compile(output_stream, overwrite_output=True)) compressing = subprocess.Popen('start cmd /k {}'.format(cmd), shell=True) while compressing.poll() is None: #check if the process is still running print('Processing video....
<python><shell><subprocess><subshell>
2023-03-08 19:51:49
0
714
Mohamed Darwesh
75,677,446
1,424,395
Qt for python not working: Spyder not launching and matplotlib unable to plot
<p>I am running Windows. I have Anaconda and several environments there, I use Spyder, and also Visual studio Code. After updating packages (many, I cannot really tell which ones), spyder cannot be launched anymore. I get a window error with the following message.</p> <blockquote> <p>qt.qpa.plugin: Could not load the Q...
<python><windows><qt><spyder>
2023-03-08 19:33:28
1
1,827
myradio
75,677,442
4,809,113
how to find rows in numpy array thatare in another array
<p>I have two numpy arrays:</p> <pre><code>import numpy as np arrlist = np.array([[1,0,0,1] , [0,1,1,0]]) rng = np.random.default_rng() rand_arr = rng.choice([0, 1], size=(5, 4))) </code></pre> <p>How do I find the indices <code>i</code> of every row in <code>rand_arr</code> where <code>rand_arr[i]</code> is in <code>...
<python><numpy>
2023-03-08 19:33:21
1
441
proton
75,677,435
12,076,197
Create a row in a in a multiindex dataframe
<p>original DF</p> <pre><code> 2022 2023 In Out In Out ABC DOG 7 3 1 10 DEF DOG 3 14 8 3 GHI CAT 12 5 2 3 JKL CAT 2 3 3 1 </code></pre> <p>This is a multi index DF. Both the index and c...
<python><dataframe>
2023-03-08 19:32:08
1
641
dmd7
75,677,363
277,504
Does pip provide a TOML parser for python 3.9?
<p>I want to parse TOML files in python 3.9, and I am wondering if I can do so without installing another package.</p> <p>Since <code>pip</code> knows how to work with <code>pyproject.toml</code> files, and I already have <code>pip</code> installed, does <code>pip</code> provide a parser that I can import and use in my...
<python><pip><python-import><toml>
2023-03-08 19:23:32
3
1,872
Arthur Hebert-Ryan
75,677,038
4,801,066
Get a list of all Discord.Member(s) that are currently looking at a given Discord.TextChannel
<p>In Discord.py, TextChannel provides the property 'members' to &quot;returns all members that can see this channel.&quot; (<a href="https://discordpy.readthedocs.io/en/stable/api.html?highlight=member#discord.TextChannel.members" rel="nofollow noreferrer">https://discordpy.readthedocs.io/en/stable/api.html?highlight=...
<python><discord><discord.py>
2023-03-08 18:45:35
0
693
Morgan
75,676,939
8,508
Celery error when a chord that starts a chain has an error in the group
<p>I have a Chord. After the chord, we chain another task. If one of the tasks in that group of that chord raises an exception, I get a mess of an exception that looks like a bug in celery or django_celery_results.</p> <p>I am using amqp as my task queue and django_celery_results as my results backend.</p> <p>My Tasks:...
<python><django><celery><amqp><django-celery-results>
2023-03-08 18:35:11
0
15,639
Matthew Scouten
75,676,928
6,290,062
Fortran subroutine returning None in python c.f. working in R
<p>Im trying to implement some probability work that utilises the bivariate normal cdf. In R I can use <a href="https://github.com/brentonk/pbivnorm" rel="nofollow noreferrer">the pbivnorm package</a> (line <a href="https://github.com/brentonk/pbivnorm/blob/master/R/pbivnorm.r#L90" rel="nofollow noreferrer">90</a> spec...
<python><fortran><f2py>
2023-03-08 18:34:13
1
917
Robert Hickman
75,676,807
8,512,262
Preventing middle-clicking on selected text from copying and pasting in tkinter
<p>I've noticed a &quot;feature&quot; of the <code>Entry</code> and <code>Text</code> widgets wherein any selected text will be duplicated (essentially copied and pasted) when middle-clicked. I'm trying to prevent this behavior, since I don't want or need it for my use case.</p> <pre><code>import tkinter as tk from tki...
<python><tkinter><text><event-handling><mouseevent>
2023-03-08 18:20:38
1
7,190
JRiggles
75,676,642
6,077,239
How to perform conditional join more efficiently in Polars?
<p>I have a reasonably large dataframe on hand. Joining it with itself takes some time. But I want to join them with some conditions, which could make the resulting dataframe much smaller. My question is how can I take advantage of such conditions to make the conditional join faster to plain full join?</p> <p>Code belo...
<python><python-polars>
2023-03-08 18:01:53
1
1,153
lebesgue
75,676,575
10,375,073
Typing warning: pylance "str" is incompatible with "list[Literal]"
<p>Why pylance can't reconnize that I am assigning a literal in this case</p> <pre class="lang-py prettyprint-override"><code>Color = Literal[&quot;blue&quot;, &quot;green&quot;, &quot;white&quot;] @dataclass class TestColor: my_color: Color | list[Color] color = TestColor(my_color=[&quot;blue&quot;]) color.my_...
<python><python-3.x><typing><python-dataclasses><pylance>
2023-03-08 17:54:20
1
405
RaphWork
75,676,509
5,378,132
Python Docker - bind source path does not exist
<p>I basically want to run an external docker container within another docker container using the python docker client. Basically the python script, which will be run inside the docker container will pull in an image and then run the container. I tried running the standalone python script locally first, and didn't have...
<python><docker><volume><mount>
2023-03-08 17:47:33
1
2,831
Riley Hun
75,676,268
562,697
Remove excessive top and left margin from matplotlib 3D subplot
<p>I have a bunch of plots, one is a 3D projection. All the plots look good, except the 3D plot has a ton of empty space above and to the left (see the example). The bottom and right margins look fine, just not the top and left margins. Is there any way to remove this extra white space?</p> <p>I have tried manually cha...
<python><matplotlib>
2023-03-08 17:24:48
0
11,961
steveo225
75,676,246
6,676,101
How would we create a class constructor which does nothing if the input is already an instance of that class?
<p>How would we create a class constructor which does nothing if the input is already an instance of that class?</p> <p>The following code does not work, but it does partially show you what I am trying to accomplish:</p> <pre class="lang-python prettyprint-override"><code>class Apple: def __init__(self, *args): ...
<python><python-3.x><constructor>
2023-03-08 17:22:48
1
4,700
Toothpick Anemone
75,676,231
2,912,859
How to prevent filling up memory when hashing large files with xxhash?
<p>I'm trying to calculate xxhash of video files using the following code:</p> <pre><code>def get_hash(file): with open(file, 'rb') as input_file: return xxhash.xxh3_64(input_file.read()).hexdigest() </code></pre> <p>Some of the files are larger than the amount of RAM on the machine. When hashing those file...
<python>
2023-03-08 17:19:56
2
344
equinoxe5
75,676,099
10,714,156
PyTorch: `forward()` works but `backward()` fails for the same batch data
<p>Even though I provide a (rather convoluted but) concrete example below, I have a conceptual question that I haven't been able to solve reading the documentation on the <code>torch.tensor.backward()</code> function:</p> <p>My question is: <strong>How could it be possible that, for a given batch, I can correctly compu...
<python><arrays><pandas><deep-learning><pytorch>
2023-03-08 17:07:06
0
1,966
Álvaro A. Gutiérrez-Vargas
75,676,023
7,949,129
Python ftplib fails with FTPS but WinSCP works
<p>I have following code:</p> <pre><code>import pysftp user = ... password = ... host = ... port = 21 class FtpDirectory: def __init__(self): self.ftp = None def __enter__(self): self.ftp = FTP_TLS() self.ftp.debugging = 1 self.ftp.connect(host, port) self.ftp.login( ...
<python><ftp><winscp><ftplib><ftps>
2023-03-08 16:59:37
1
359
A. L
75,676,017
1,975,199
FastAPI websocket not receiving all the data
<p>This is my first experience with websockets, and I'm not completely sure I am doing everything correctly. However, when reloading the web browser, the reconnects to the websocket. When this happens I have a list of messages from previous sessions and I send them back. At the moment, there are only 3, but the brow...
<python><websocket><fastapi>
2023-03-08 16:58:27
0
432
jgauthier
75,676,016
2,789,788
How to handle memory problems when using python multiprocessing
<p>I have 10 long arrays, <code>arr1, arr2, ..., arr10</code>, and each gets pass to a function <code>foo</code>. Each <code>arr</code> is list of around 100 million floats. I'd like to use multiprocessing. Something like</p> <pre><code>import multiprocessing as mp def foo(arr): # ...call external module to proces...
<python><multiprocessing>
2023-03-08 16:58:24
2
1,810
theQman
75,675,892
1,804,896
Pandas styleframe styling applies differently to first sheet than all subsequent sheets
<p>I am writing multiple sheets to an excel workbook with some formatting. In general everything works, just the formatting is a little off. The formatting works exactly as I want on the first sheet, but I am looping through multiple data sets and writing to a sheet for each one and the subsequent sheets have the for...
<python><excel><pandas><dataframe><styleframe>
2023-03-08 16:47:07
0
854
ssbsts
75,675,839
16,319,191
Make new column based on values in other columns pandas
<p>I want to introduce a new col in df based on other col values. If c1-c3 cols have only 1 unique value then that unique value will go into c4 col. If c1-c3 cols have two different values then &quot;both&quot; will go into c4 col. NaN should not be considered as a valid value. Only c2 and c3 have a few NaNs.</p> <p>Mi...
<python><pandas><dataframe>
2023-03-08 16:42:06
3
392
AAA
75,675,752
12,320,370
DataFrame string exact match
<p>I am using the <code>str.contains</code> method to look for a specific row in a data frame. I however want to find an exact string match, and even if I add <code>regex = False</code>, it seems to pick up the partial matches.</p> <p><code>str.find</code> doesn't work either, is there another function I should be usin...
<python><pandas><string><numpy><find>
2023-03-08 16:34:45
2
333
Nairda123
75,675,743
8,899,386
How can I have a row-wise rank in a pyspark dataframe
<p>I have a dataset for which I am going to find the rank per row. This is a toy example in <code>pandas</code>.</p> <pre class="lang-python prettyprint-override"><code>import pandas as pd df = pd.DataFrame({&quot;ID&quot;:[1,2,3,4], &quot;a&quot;:[2,7,9,10], &quot;b&quot;:[6,7,4,2], &quot;c&quot;:[...
<python><sql><pandas><dataframe><pyspark>
2023-03-08 16:34:13
1
4,890
Hadij
75,675,674
7,984,318
python pyodbc pass parameters issue
<p>Code:</p> <pre><code>import pyodbc as pyodbc cnxn = pyodbc.connect(DB_STR) cursor = cnxn.cursor() def insert_table(insert_query,date_para): result = cursor.execute(insert_query,date_para) cnxn.commit() </code></pre> <p>The code is used to pass a parameter in sql.</p> <p>My issue is ,when there is no paramet...
<python><sql><postgresql><pyodbc>
2023-03-08 16:27:45
1
4,094
William
75,675,592
5,371,582
headless authentification of an app to google api
<p>I have a python app which needs (among many other things) to read a googlesheet. The line</p> <pre><code>flow = InstalledAppFlow.from_client_secrets_file(cred_file, SCOPES) </code></pre> <p>requires me to visit <code>https://accounts.google.com/o/oauth2/auth?response_type=code&amp;client_id=...</code> I go there, gi...
<python><google-api><headless>
2023-03-08 16:20:46
1
705
Laurent Claessens
75,675,556
8,847,609
How to get Aruco pose estimation in OpenCV Python?
<p>I'm following <a href="https://betterprogramming.pub/getting-started-with-aruco-markers-b4823a43973c" rel="nofollow noreferrer">this</a> tutorial on getting started with aruco markers.</p> <p>I want to get the pose estimation frame axis and display it ontop of the aruco marker like so:</p> <p><a href="https://i.ssta...
<python><opencv><aruco>
2023-03-08 16:18:08
2
1,176
Brandon Pillay
75,675,368
5,758,423
How to include conditional installs in python packages -- namely for backports?
<p>My question is about conditional installs in general, but the usage I have in mind is for python backports specifically. Let's do this with a concrete example.</p> <p>It often happens that I want to use <code>from importlib.resources import files</code>, but that only exists in 3.9+.</p> <p>In my code, I end up doin...
<python><python-import><setuptools><python-packaging><python-importlib>
2023-03-08 16:01:36
1
2,432
thorwhalen
75,675,364
2,537,394
Why does tkinter block when ending this thread?
<p>I'm trying to create a worker thread that manages further threads/processes and communicates with my tkinter GUI thread.</p> <p>For this I have a GUI class that inherits from <code>tkinter.Frame</code> with a simple start button, a progressbar and a variable label. When pressing the start button the worker thread ge...
<python><python-3.x><multithreading><tkinter><python-multithreading>
2023-03-08 16:01:23
1
731
YPOC
75,674,970
2,836,172
Matplotlib Subplots: Subplot gets scaled down so axes do not match
<p>I got two numpy arrays which I want to plot above each other. It works, but the top image gets scaled down, so the axis do not match anymore. I can &quot;fix&quot; it by setting the Figsize to (8, 8), but then there is a big whitespace below the plots.</p> <p>So my code:</p> <pre><code>fig, (ax1, ax2) = plt.subplots...
<python><matplotlib>
2023-03-08 15:24:38
1
1,522
Standard
75,674,794
12,845,199
Interacting through dicts, grabbing their values and transitioning to a panda df
<p>I have a list of dicts</p> <pre><code>[{a:'jeffrey',b:'pineapple',c:'apple'},{a:'epstein',c:'banana'},{a:'didnt kill'},{a:'himself',b:'jebus'}] </code></pre> <p>What I want to do is transition those values to a pandas df. But as you can see a few dicts are lacking a few keys and therefore lacking values. So I took a...
<python><pandas><collections>
2023-03-08 15:08:00
3
1,628
INGl0R1AM0R1
75,674,779
3,343,378
Dash plotly figures jumping around in predefined grid
<p>In Dash, the layout of a page can be designed using bootstrap components (see for instance <a href="https://stackoverflow.com/questions/63592900/plotly-dash-how-to-design-the-layout-using-dash-bootstrap-components">Plotly-Dash: How to design the layout using dash bootstrap components?</a>). We can make a 12x12 grid ...
<python><layout><plotly-dash>
2023-03-08 15:06:58
1
444
blah_crusader
75,674,633
11,918,269
Explicit line ranges when parsing YAML in Python
<p>I have the following YAML file contents (a single block for example):</p> <pre class="lang-yaml prettyprint-override"><code>.deploy_container: tags: - gcp image: google/cloud-sdk services: - docker:find variables: PORT: &quot;$APP_PORT&quot; script: - cp $GCP_SERVICE_KEY gcloud-service-key....
<python><pyyaml>
2023-03-08 14:54:24
1
1,686
Eliran Turgeman
75,674,380
274,460
How to relate Python threads to POSIX threads in Python 3.6?
<p>Is there a way to relate the Python thread name and thread ID to the POSIX thread ID in Python 3.6? Any of the following would do:</p> <ul> <li>Get the POSIX thread ID from a <code>threading.Thread</code> object</li> <li>Get the Python thread ID from a <code>psutil._common.pthread</code> object</li> <li>Set the pro...
<python><multithreading><python-3.6><psutil>
2023-03-08 14:31:05
0
8,161
Tom
75,674,260
4,408,818
Shapely removing disconnected geometries after a unary_union of two MultiPolygons
<p><strong>edit: The geometries were not dissapearing, they were in the interiors property of the Polygon.</strong></p> <p>I have two MultiPolygons, both of which are made up of disconnected polygons. I need to join them such that they &quot;cut&quot; each other out. The two shapes are these; <a href="https://i.sstatic...
<python><pandas><geopandas><shapely>
2023-03-08 14:20:23
1
959
Ozymandias
75,674,206
16,389,095
KivyMD AttributeError: Content/TwoLineIconListItem object has no attribute '_disabled_count'
<p>Starting from an <a href="https://github.com/kivymd/KivyMD/wiki/Components-Expansion-Panel" rel="nofollow noreferrer">example</a> of the Kivy MD Expansion Panel, I would like to customize the content of the panel. The example shows the same content for each expansion panel. I would like to set values of the fields '...
<python><kivy><kivy-language><kivymd>
2023-03-08 14:16:14
2
421
eljamba
75,674,169
12,501,684
How to assign text class based on line height (quantize height to discrete H1, H2, H3, p)?
<p><strong>TLDR:</strong> I am converting a PDF to MarkDown and I need a heuristic that will allow me to assign styles (H1, H2, H3, regular, caption) to lines, based on their heights. Essentially, I have a <code>list[tuple(str, float)]</code> of lines and their heights that I need to covert into a <code>list[tuple(str,...
<python><pdf><markdown><classification><histogram>
2023-03-08 14:12:52
1
5,075
janekb04
75,674,114
8,176,763
airflow cannot find module from imported file
<p>I have a directory structure like this:</p> <pre><code>dags/ β”œβ”€β”€ airflow_sched.py β”œβ”€β”€ backend β”‚ β”œβ”€β”€ README.md β”‚ β”œβ”€β”€ requirements.txt β”‚ └── src β”‚ β”œβ”€β”€ buffer.py β”‚ β”œβ”€β”€ config β”‚ β”‚ β”œβ”€β”€ config.py |-- stage.py </code></pre> <p><code>airflow_sched.py</code> is where my dag definition file i...
<python><airflow>
2023-03-08 14:07:09
1
2,459
moth
75,674,082
8,869,570
How to find the name of the class that defined a method?
<p>I'm trying to get the name of the class that defined a method. The method is passed into a function. Within that function, I printed the type of the method, and it shows</p> <pre><code>&lt;class 'method'&gt; </code></pre> <p>but it doesn't tell me what class it belongs to. How can I get the name of the class?</p>
<python><types>
2023-03-08 14:04:05
1
2,328
24n8
75,674,032
10,485,625
Concat two dataframe with different timedeltas
<p>Hello I am trying to concat two dataframes based on this logic : I have a first df <code>df_minutes</code> that contains data for each minute and a second <code>df_hourly</code> that contains data with an hour delay.</p> <p>I need to add the column RSI-1H of my 2nd dataframe to the first and get the same value 56 fo...
<python><dataframe><merge><concatenation>
2023-03-08 13:59:23
3
589
userHG
75,673,818
2,532,296
parsing words from a specific line
<p>Following is python implementation to extract specific fields from the following input file. For the line starting with <code>MEMRANGE</code>, I would like to extract the values corresponding to keys <code>BASEVALUE</code>, <code>INSTANCE</code> and <code>SLAVEBUSINTERFACE</code> and print the result in the followin...
<python><parsing><awk><sed><grep>
2023-03-08 13:40:45
3
848
user2532296
75,673,794
13,039,962
How to transpose a table keeping their columns headers?
<p>I have a df like this:</p> <pre><code>+----+----+----+----+ | December| January| +----+----+----+----+ 1 1 2 2 . . 31 31 </code></pre> <p>You can build it with this code:</p> <pre><code>numbers = [] for i in range(1, 32): numbers.append(i) df = pd.DataFrame({...
<python><pandas>
2023-03-08 13:38:48
1
523
Javier
75,673,679
9,225,671
python signxml - InvalidDigest if there is a "xmlns" namespace declaration in the root element
<p>I need to sign a XML file. The signature process works in both cases (with and without the namespace declared in the root element), but the signature verification fails when there is the specific <code>xmlns</code> namespace declared.</p> <p>Also, when I have less nested levels, then there is no error in both cases,...
<python>
2023-03-08 13:29:39
1
16,605
Ralf
75,673,613
1,939,730
Sklearn's TargetEncoder not dealing properly with category with 1 observation
<p>Given this piece of code</p> <pre><code>from category_encoders import TargetEncoder X = [&quot;a&quot;, &quot;a&quot;, &quot;a&quot;, &quot;b&quot;, &quot;b&quot;, &quot;c&quot;] y = [5, 5, 5, 6, 7, 4] encoder = TargetEncoder(smoothing = 0, min_samples_leaf = 0) print(encoder.fit_transform(X, y)) </code></pre> <p>I...
<python><scikit-learn>
2023-03-08 13:23:21
1
567
Carlos Navarro AstiasarΓ‘n
75,673,609
1,946,052
Equivalent of xsum for pySCIPOpt
<p>What is the equivalent of <code>xsum</code> from python Mip in pySCIPOpt to summarize arrays of variables in constraints?</p>
<python><optimization><scip>
2023-03-08 13:22:34
1
2,283
Michael Hecht
75,673,581
11,167,163
How to use ROLLING in Python ? Error : ValueError: window must be an integer 0 or greater
<p>I have the following code :</p> <pre><code>DF['AA'].rolling('90D').apply(calc_performance) </code></pre> <p>Where <code>calc_performance</code></p> <pre><code>def calc_performance(x): if len(x) &lt; 3: return np.nan else: return (x[-1] / x[0]) - 1 </code></pre> <p>But it does throw an error :...
<python><pandas>
2023-03-08 13:19:44
1
4,464
TourEiffel
75,673,570
3,437,787
How to expand the number of dataframe rows based on column titles?
<p>I've got a dataframe of the form:</p> <pre><code> name 0 1 2 0 A 4 2 1 1 B 2 3 4 2 C 1 3 2 </code></pre> <p>This is the result of grouping and summarizing data earlier in my real world data process. What I would like to do now, is to expand (explode?) each row so that each element in that row f...
<python><pandas>
2023-03-08 13:19:05
2
62,064
vestland
75,673,363
4,210,662
Typescript Uint8Array, Uint16Array Python equivalent
<pre><code>new Uint8Array(new Uint16Array([64]).buffer) </code></pre> <p>How can I achieve same result structure with pure Python? What is an equivalent of Uint8Array/Uint16Array?</p> <p>I'm getting buffer from Uint16Array type here and cast to Uint8Array, however I'm not sure how can I achieve similar behavior in Pyth...
<python><typescript><uint32>
2023-03-08 13:00:20
1
794
Tatarinho
75,673,304
12,924,562
How to get Mastodon direct messages using Mastodon.py
<p>I am trying to get direct messages from my Mastodon account using Mastodon.py. I am able to get everything on the timeline, but can't seem to return direct messages. Since direct messages are separate from the timeline (on the web interface), I am assuming there is some function other than <code>timeline()</code> I ...
<python><dm><mastodon>
2023-03-08 12:53:50
1
386
Rick Dearman
75,673,294
5,295,778
How to run command with docker that saves data on local machine
<p>My intention is to dump data from Django app (running inside docker container) directly on the disk and not inside the container. Any ideas how to do it? I tried this:</p> <pre><code>docker exec -it app bash -c &quot;python manage.py dumpdata &gt; data.json&quot; </code></pre> <p>but the data is saved inside contain...
<python><django><linux><docker>
2023-03-08 12:52:41
4
526
cristian
75,673,278
1,652,954
OSError: [Errno 24] Too many open files when using With....as: expression
<p>despite i am using <code>with....as:</code> expression to gaurantee that the pool and consequently all of its processes are closed, however, when i run the code, i receive the error posted below. to solve this issue, i referred to some posts in stackoverflow and referred to a tutorial called &quot;superFast python&q...
<python><multiprocessing><python-multiprocessing>
2023-03-08 12:51:14
0
11,564
Amrmsmb
75,673,074
3,099,733
A pythonic way to iterate combination of items in different categories?
<p>Suppose there are 2 categories if items: <code>cat_1 = [1, 2], cat_2 = ['a', 'b']</code>, then I should get <code>(1, 'a'), ('1', 'b'), (2, 'a'), (2, 'b')</code>. And if there is one more categories of items <code>cat_3 = ['x', 'y']</code>, then the result should be <code>(1, 'a', 'x'), (1, 'a', 'y'), ... (2, 'b', ...
<python>
2023-03-08 12:32:16
1
1,959
link89
75,672,901
13,158,157
Algorithm for insight into string pattern matching
<p>My question is general but I struggle to find proper articles for that so any reading leads will be much appreciated!</p> <p>I have two dataframes to join by Id that should be formed from multiple different columns. For example:</p> <pre><code>df.Id = df.A + df.B + df.C df2.Id= df2.A2 + df2.D2 + df2.E2 +df2.F2 </co...
<python><algorithm><cluster-analysis>
2023-03-08 12:14:07
0
525
euh
75,672,527
492,034
Apply excel formulas with xlsxwriter (or another engine)
<p>I create with pandas and xlsxwiter an excel file with some formulas and, from that file, I have to create another one. Thus I need the formulas to be applied and the right values being set on load. On windows the best solution I've found is the following:</p> <pre><code>def __applyExcelFormulasOrPromptToDoItManually...
<python><excel><pandas><xlsxwriter>
2023-03-08 11:37:21
0
1,776
marco
75,672,490
3,478,288
Display data by date, when data comes from multiple models in Django
<p>I'm currently working on an app with Django 4.1. I try to display a resume of some data comming from the database. Here is a simplified example of my models:</p> <pre class="lang-py prettyprint-override"><code>class Signal(models.Model): data1 = models.CharField() data2 = models.CharField() date = models.Da...
<python><django><django-models>
2023-03-08 11:34:11
2
632
Tartempion34
75,672,488
7,214,714
Efficient way for ordering values within group in Pandas
<p>I'm working with time series data, which is packaged in a time long dataframe, something like this:</p> <pre><code>ACCOUNT | VAR1 | VAR2 | DAY </code></pre> <p>I'm interested in creating a new column <code>DAY_ORD</code>, which would give the ordinal rank of the <code>DAY</code> variable to each row within a group o...
<python><pandas><dataframe>
2023-03-08 11:33:56
1
302
Vid Stropnik
75,672,420
4,658,633
How to send HTTP request with trailers?
<p>MDN Web Docs stated that the trailer could be included in the request phase: <a href="https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Trailer" rel="nofollow noreferrer">https://developer.mozilla.org/en-US/docs/Web/HTTP/Headers/Trailer</a></p> <p>I saw some trailers in the response examples. How could I sen...
<python><go><http><curl>
2023-03-08 11:27:09
0
556
Blaise Wang
75,672,263
3,348,264
SQLAlchemy & postgres - add days to date, get date diff and compare. Coerce error
<p>No matter what I try I keep getting an error <code>cannot coerce the integer to in interval.</code></p> <pre><code>@get_due_date.expression def get_due_date(cls): return func.add(cls.date_last_service, cast(cls.get_service_schedule, INTERVAL), func.now()) &lt;= 3.5 </code></pre> <p>The equivalent python code for...
<python><postgresql><sqlalchemy>
2023-03-08 11:11:59
1
2,204
Lewis Morris
75,672,080
2,626,865
Map (1:1) N input sentences to N given sentences by similarity
<p>I want to map <code>N_a</code> input sentences to <code>N_b</code> given sentences so that the mapping is one-to-one. That is,</p> <ul> <li>Every <code>N_a</code> is assigned</li> <li>No <code>N_a</code> appears more than once</li> </ul> <p>Unfortunately the inputs vary slightly over time. Here is a representative m...
<python><deep-learning><nlp><similarity>
2023-03-08 10:51:24
1
2,131
user19087
75,671,996
330,867
Python SSLError "SSLV3_ALERT_CERTIFICATE_EXPIRED". How to get the expired certificate name from the exception?
<p>I'm running <code>aiosmtpd</code> on my server, and from time to time, I have the following error and stack:</p> <pre><code>SSL handshake failed protocol: &lt;asyncio.sslproto.SSLProtocol object at 0x7f90f77c59e8&gt; transport: &lt;_SelectorSocketTransport fd=11 read=polling write=&lt;idle, bufsize=0&gt;&gt; Traceba...
<python><ssl>
2023-03-08 10:43:30
0
40,087
Cyril N.
75,671,713
9,859,642
Using filename to initialize new DataFrame without exec
<p>I have a series of files to process and I need DataFrames that will have the same names as the files. The number of files is large so I wanted to make the processing parallel with joblib. Unfortunately joblib is not accepting <code>exec</code> as an element of a function to execute. Is there a better solution to thi...
<python><pandas><dataframe><exec><joblib>
2023-03-08 10:12:05
1
632
Anavae
75,671,573
746,777
Win32 in Python - LoadImage gets handle of icon but InsertMenuItem throws error
<p>I'm trying to add an icon to every menu option in a systray library in Python, <a href="https://pypi.org/project/pystray/" rel="nofollow noreferrer">pystray</a>. For that I'm using win32 functions, I can sucessfully load an icon with extension .ico using the <a href="https://learn.microsoft.com/en-us/windows/win32/a...
<python><winapi><pystray>
2023-03-08 09:56:35
0
317
digfish
75,671,499
9,439,097
DuckDB Binder Error: Referenced column not found in FROM clause
<p>I am working in DuckDB in a database that I read from json.</p> <p>Here is the json:</p> <pre class="lang-json prettyprint-override"><code>[{ &quot;account&quot;: &quot;abcde&quot;, &quot;data&quot;: [ { &quot;name&quot;: &quot;hey&quot;, &quot;amount&quot;:1, &quo...
<python><sql><duckdb>
2023-03-08 09:49:07
2
3,893
charelf
75,671,456
10,989,584
Error installing pyqt5 under aarch64 architecture
<p>I'm trying to install <strong>pyqt5 V5.15.2</strong> on an emulate qemu <strong>aarch64 debian</strong> distro, but it fails with the following trace:</p> <pre class="lang-bash prettyprint-override"><code>root@debian-arm64:~# pip install pyqt5==5.15.2 --config-settings --confirm-license= --verbose Using pip 23.0.1 f...
<python><pyqt5><arm64>
2023-03-08 09:44:24
3
413
Hele
75,671,277
230,270
python set windows environment parameters persistent
<p>I would like to set environment parameters using python in windows 11. Using commands like:</p> <pre><code>import os os.environ['USER'] = 'username' print(os.environ['USER']) </code></pre> <p>will print <em>username</em>. Nether the less, once I close the window. The set environment parameters dissipated. It seems I...
<python><windows>
2023-03-08 09:22:07
1
3,496
Eagle
75,671,167
3,657,417
Pandas update previous records because future peaking is not possible
<p>This is what I have so far:</p> <pre><code>import numpy as np import pandas_ta as ta from pandas import DataFrame, pandas df = pandas.DataFrame({&quot;color&quot;: [None, None, 'blue', None, None, None, 'orange', None, None, None, None], 'bottom': [1, 2, 7, 5, 9, 9, 5, 4, 5, 5, 3], ...
<python><pandas><dataframe>
2023-03-08 09:10:32
1
773
Florian
75,671,125
2,926,271
Autoencoder for dimensionality reduction of binary dataset for clustering
<p>Given a binary dataset (derived from yes/no questionnaire responses) aimed to use for subsequent unsupervised cluster analysis, with significant multicolinearity and a total of 31 features by ~50,000 observations (subjects), it appeared sensible to reduce the dimensionality of the input data before performing cluste...
<python><tensorflow><keras><artificial-intelligence><cluster-analysis>
2023-03-08 09:06:14
2
4,405
display-name-is-missing
75,671,070
7,483,211
How to make Snakemake run a rule once for all matching outputs, not once for each wildcard match
<p>In a Snakemake workflow, for efficiency reasons, I want to run a rule once for the <em>list</em> of wildcard matches - rather than once for each match.</p> <p>What's the idiomatic way of doing this in Snakemake?</p> <p>This is a minimal starter code that does <em>not</em> what I want, as it would call <code>rule pro...
<python><wildcard><bioinformatics><snakemake>
2023-03-08 09:00:24
1
10,272
Cornelius Roemer
75,671,038
7,376,511
pytest: manually add test to discovered tests
<pre><code># tests/test_assert.py @pytest.mark.mymark def custom_assert(): assert True </code></pre> <p>How do I force pytest to discover this test?</p> <p>In general, how do I dynamically add any test to pytest's list of discovered tests, even if they don't fit in the naming convention?</p>
<python><pytest>
2023-03-08 08:56:52
2
797
Some Guy
75,670,969
2,793,602
Hugging Face transformer - object not callable
<p>I am trying to make a text summarizer using the T5 transformer from Hugging Face.</p> <p>From the Hugging Face site I am running this:</p> <pre><code>from transformers import T5Tokenizer, T5Model tokenizer = T5Tokenizer.from_pretrained(&quot;t5-small&quot;) model = T5Model.from_pretrained(&quot;t5-small&quot;) </co...
<python><huggingface-transformers>
2023-03-08 08:49:55
1
457
opperman.eric
75,670,692
5,159,404
Why does Pandas fail to open excel file?
<p>I am having troubles opening excel files (xlsx) in pandas. I had a small application that used to work, but then another application with the same code was failing miserably when opening the same files.</p> <p>The files have not changed since and I cannot change them (they are provided externally)</p> <p>After some ...
<python><pandas><openpyxl>
2023-03-08 08:18:27
0
1,002
Wing
75,670,679
7,376,511
Dynamically reuse integration testing scenarios in pytest
<p>I have a set of classes for which each property and method must be tested.</p> <p>Something like</p> <pre><code>datasets = [{ &quot;klass&quot;: MyClass1, &quot;a&quot;: 1, &quot;c&quot;: 3, }, { &quot;klass&quot;: MyClass2, &quot;a&quot;: 12, &quot;b&quot;: 13, }] </code></pre> <p>Note that ...
<python><testing><pytest><integration-testing>
2023-03-08 08:17:20
1
797
Some Guy
75,670,657
4,212,875
For each group in Pandas dataframe, return the most common value if it shows up more than `x%` of the time
<p>Given a pandas dataframe, I would like to return a column's (string datatype) most common value for each groupby if this value shows up in more than <code>n%</code> of the rows, otherwise return 'NA'.</p>
<python><pandas><dataframe><group-by>
2023-03-08 08:15:07
2
411
Yandle
75,670,106
20,762,114
Is there a way to perform validations/assertions within method chaining in Polars?
<p>Is there any way to perform validations/assertions as part of method chaining?</p> <p>This is very useful for long queries where we want to stop execution early on if a certain condition is not met.</p> <p>Some possible examples:</p> <pre class="lang-py prettyprint-override"><code>df = pl.DataFrame({ 'A': ['X', ...
<python><python-polars>
2023-03-08 06:53:41
0
317
T.H Rice
75,669,517
1,289,479
How to send text from Python to DeepL desktop app
<p>I know DeepL has a library to send text to their servers for translation, but I want to use their desktop app which has no internet dependency.</p> <p>The Desktop app has this feature where if you press Ctrl+C+C, it will put that highlighted text into the DeepL app and it works from there.</p> <p>I was wondering if ...
<python><desktop-application><deepl>
2023-03-08 04:46:52
0
311
user1289479
75,669,373
7,780,577
How do you avoid memory leaks in Spark/Pyspark for multiple dataframe edits and loops?
<p>There are 2 scenarios that I feel cause memory leaks that I struggle to know how to avoid.</p> <p><strong>Scenario 1:</strong></p> <p>There is a need to perform multiple edits to a df like below:</p> <pre><code>df = method1() df = method2(df) df = method3(df) </code></pre> <p>If I'm not mistaken, this approach is di...
<python><apache-spark><pyspark><memory-management><memory-leaks>
2023-03-08 04:07:46
1
301
cauthon
75,669,344
7,021,137
`import matplotlib.pyplot` or `import pylab`?
<p>Excuse the blunt question, but what's the difference between <code>import pylab</code> and <code>import matplotlib.pyplot</code>? I realized my coworker and I have been using different imports and, to the best of our knowledge, there is no difference between the two imports.</p> <p>Does anyone choose one over the ot...
<python><matplotlib>
2023-03-08 04:01:34
2
377
NoVa
75,669,330
2,073,640
Getting data from streamlit instance
<p>I made a streamlit app that locally writes to a CSV on the instance, and just realized now i have no way to get that data. I am pretty sure if I push up a change via github it'll overwrite the DB (can I use a gitignore maybe?)</p> <p>Pretty dumb problem, open to any suggestions how to recover the data :)</p>
<python><streamlit>
2023-03-08 03:56:44
1
358
SimonStern
75,669,316
7,021,137
Connecting Lowest Datapoints in Plot
<p>I'm needing to make a fancy plot that draws a line through the lowest x-valued data points. The code below is a working example of similar-looking data to what I'm working with. Please only use <code>numpy</code> and <code>matplotlib</code>, and please continue using the <code>plt.subplots()</code> method.</p> <pre...
<python><pandas><numpy><matplotlib>
2023-03-08 03:53:16
2
377
NoVa
75,669,198
7,475,225
Odd behavior with !help command in discord.py?
<p>So I am trying to define the brief description for the generic <code>!help</code> command and that works fine but I am also trying to define the extended help for the <code>!help command_name</code> command so I get get further details on how a command works.</p> <p>In my command I have defined the details like so:<...
<python><python-3.x><discord><discord.py>
2023-03-08 03:27:46
1
15,266
Mike - SMT
75,669,165
7,993,977
Find time difference of first instance of a value and first instance of another value in dataframe
<p>I have an already sorted dataframe of panel data below, where a certain <code>diagnosisCode</code> is mapped to a positive or false value in <code>hasDisease</code>. I have 2 arrays which indicate whether a code is positive or negative</p> <pre><code>positiveDiagnosisCodes = [A] # corresponds to hasDisease = 1 negat...
<python><pandas><dataframe><algorithm><panel-data>
2023-03-08 03:20:04
1
375
MrSoLoDoLo
75,669,150
11,016,395
Retrieve relative position of multilevel list in docx file using Python
<p>I need to read docx files in Python and retrieve the relative positions of multilevel list. See below example:</p> <p><a href="https://i.sstatic.net/Kbpnw.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/Kbpnw.png" alt="enter image description here" /></a></p> <p>I want to read the text within the mult...
<python><python-docx>
2023-03-08 03:17:25
1
483
crx91
75,669,055
4,420,797
Python: Read a .txt file and change the name of files in directory with .txt index
<p>I have a directory that contains lots of images and meanwhile, I have a <code>.txt</code> file that contains names like in the below format. I would like to change the name of images based on text file titles. There are 100 names and 100 images in a folder.</p> <p><strong>Inside Text Files</strong></p> <pre><code>Fl...
<python><python-3.x><list>
2023-03-08 02:56:21
2
2,984
Khawar Islam
75,669,048
16,922,748
Randomly changing letters in list of string based on probability
<p>Given the following</p> <p><code>data = ['AAACGGGATT\n','CTGTGTCAGT\n','AATCTCTACT\n']</code></p> <p>For every letter in a string not including (\n), if its probability is greater than 5 (i.e. there is a 50% chance for a change), I'd like to replace the letter with a randomly selected letter from options (A,G,T,C), ...
<python><string><list><replace><probability>
2023-03-08 02:54:25
2
315
newbzzs
75,668,928
14,608,529
How to export played audio that is merged and looped through via Python?
<p>I have code in Python that loops through and merges a series of audio files to play a customized sound as follows:</p> <pre><code>from pydub import AudioSegment from pydub.playback import play sounds = [] sounds.append(AudioSegment.from_file(&quot;Downloads/my_file.mp3&quot;)) for i in range(4): sounds.append(s...
<python><python-3.x><file><audio><pydub>
2023-03-08 02:24:20
2
792
Ricardo Francois
75,668,916
8,751,871
Overriding dynamically created dag's attributes (start_date)
<p>Say I had a <code>dag1.py</code> file:</p> <pre class="lang-py prettyprint-override"><code>@dag( dag_id=&quot;my_dag&quot;, start_date=pendulum.datetime(2022, 9, 28, tz=&quot;UTC&quot;), catchup=True # ... ) def some_dag_code(name=&quot;bob&quot;, age=21): @task() def print_name(name): print(...
<python><airflow>
2023-03-08 02:22:56
1
2,670
A H