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
⌀
77,054,028
11,578,282
Why am I missing data when I receive packets over UDP?
<p>I'm trying to receive data over a UDP connection from another app running locally but I don't seem to be receiving all the data that is being sent. I believe it's because I'm receiving the data in a while loop which sometimes doesn't run quickly enough to receive all the data but I'm not sure of an alternative I can...
<python><sockets><udp>
2023-09-06 17:12:01
0
467
Eind997
77,053,969
2,112,406
Using pyspark in a python module
<p>Can I add functionality to my Python module to use pyspark? I have to parse very large data files in a non-trivial way.</p> <p>If so, could anyone point me towards a resource? I'm a bit confused about this whole thing, because whenever I write a python script using pyspark, I have to run it with <code>spark-submit</...
<python><pyspark>
2023-09-06 17:00:56
1
3,203
sodiumnitrate
77,053,921
6,791,157
Path name with dot-colon on Windows creates a ghost file
<p>I do not understand this behavior. This is a minimal reproduction of a strange behavior I discovered while trying to write to a file whose name is an ISO format time string including <code>:</code>. The file name was truncated starting with <code>:</code>.</p> <p>The colon is an invalid path character on Windows whe...
<python><windows><cmd>
2023-09-06 16:51:18
1
789
roeen30
77,053,906
11,500,371
Can you combine pd.wide_to_long with the creation of a multiindex?
<p>I have a dataframe in a wide format that looks like this:</p> <pre><code>citydata = pd.DataFrame(columns=['Trip Date','City 1 Name','City 2 Name','City 3 Name','City 1 Cost','City 2 Cost','City 3 Cost','City 1 Hotel','City 2 Hotel','City 3 Hotel']) citydata.loc[0] = ['2023-01-15','London','Paris','Barcelona',5500,43...
<python><pandas><dataframe>
2023-09-06 16:48:33
3
337
Sean R
77,053,878
9,046,275
Row-wise aggregation based on non-zero columns
<p>I am facing a scenario where I have a sparse dataset (for each row, only 4 columns are populated at the same time, the rest will be zeros). For each variable prefix, there will be 3 variables (e.g <code>a_qty</code>, <code>a_height</code>, <code>ma_width</code>), the number of columns is completely arbitrary as new...
<python><python-polars>
2023-09-06 16:43:54
1
1,671
anddt
77,053,825
10,472,446
Sorting list of complex elements like Gray code is organized
<p>I have a list of complex elements, namely tuples containing a predefined number of numbers, here is a small example:</p> <p><code>[(2, 3, 5), (1, 5, 6), (1, 3, 4), (1, 3, 6), (2, 3, 7)]</code></p> <p>I need to sort this list in the same way than Gray code is organized, meaning that only one element of the tuple can ...
<python><python-3.x><algorithm><sorting>
2023-09-06 16:34:34
1
379
Toady
77,053,756
11,318,930
holoviews - bokeh: histogram with log axis is blank
<p>I am trying to do a log plot in Jupyter Notebook using <code>Holoviews</code> with the <code>bokeh</code> backend. If I set the y-axis to <code>log</code>, the plot shows only the axes with no data plotted and the following warning:</p> <pre><code>WARNING:param.HistogramPlot03582: Logarithmic axis range encountered...
<python><plot><jupyter-notebook><bokeh><holoviews>
2023-09-06 16:25:20
0
1,287
MikeB2019x
77,053,712
3,505,206
Pydantic 2.0: Initializing a BaseModel with a private variable to be used to create computed_fields
<p>Using the following version</p> <pre class="lang-ini prettyprint-override"><code>pydantic = &quot;^2.0.2&quot; pydantic-settings = &quot;^2.0.1&quot; </code></pre> <p>Want to create a pydantic BaseModel for AWS SQS Messages, where the input is hidden after dumping the json via <code>print(model.model_dump_json())</c...
<python><fastapi><pydantic>
2023-09-06 16:18:13
1
456
Jenobi
77,053,686
19,130,803
Save dash component or plotly express graph as json
<p>I am creating a <code>dash</code> application and plotting graphs using <code>plotly express</code>. I trying to save the <code>dash components</code> and <code>graphs</code> into a <code>json</code> file using <code>to_plotly_json()</code>. But for <code>pie chart</code> graph, getting an error as below:</p> <pre><...
<python><pandas><plotly-dash><plotly-express>
2023-09-06 16:13:59
1
962
winter
77,053,670
8,256,981
In numpy genfromtxt, missing_values, filling_values, excludelist, deletechars and replace_space are not working properly
<p>This is my test.csv file, where &quot;A 1&quot; and &quot;A+2&quot; are headers:</p> <pre><code>A 1,A+2 test&amp; ,1 skip, #, N/A,NA </code></pre> <p>This is my Jupyter code:</p> <pre><code>import numpy as np test = np.genfromtxt(&quot;test.csv&quot;, delimiter = ',', ...
<python><numpy>
2023-09-06 16:10:58
1
491
maxloo
77,053,535
13,258,525
How can I sampleBy a date column without casting it to another type in PySpark?
<p>I have a data frame which I'd like to sample by its date column. However, <code>sampleBy</code> will only accept float, int, or str types:</p> <pre class="lang-py prettyprint-override"><code>from datetime import date from pyspark.sql import Row import pyspark.sql.functions as F # create dummy data df_rows = [Row(da...
<python><dataframe><pyspark>
2023-09-06 15:50:35
0
2,183
s_pike
77,053,484
10,808,155
How to merge rows with condition on time range in PySpark Dataframe
<p>Here is my input pyspark dataframe:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>ID</th> <th>Name</th> <th>Start Date</th> <th>End Date</th> </tr> </thead> <tbody> <tr> <td>1</td> <td>John</td> <td>2022-06-29 20:00:00</td> <td>2022-07-12 20:00:00</td> </tr> <tr> <td>1</td> <td>John</t...
<python><dataframe><pyspark>
2023-09-06 15:43:21
1
305
Jie Zhang
77,053,140
2,886,640
How to make an ordered file structure in KivyMD?
<p>I watched a lot of tutorials and examples about Kivy and KivyMD, but there are only a few doing complex apps, and they use to pile all the code in almost one or two files.</p> <p>I am trying to do it properly, but I'm having errors that I can't understand very well as I'm still a newbie on this subject.</p> <p><stro...
<python><python-3.x><kivy><kivymd>
2023-09-06 14:59:58
0
10,269
forvas
77,052,972
11,832,749
How can I make transparent histograms in subplots?
<p>So far I have:</p> <pre><code>def add_alpha_to_colormap(cmap, alpha): # borrowed from https://saturncloud.io/blog/adding-alpha-to-an-existing-matplotlib-colormap-a-guide/ cmap = plt.cm.get_cmap(cmap) colors = cmap(np.arange(cmap.N)) # Add alpha to the RGB array RGBA = np.hstack([colors[:, :3], n...
<python><pandas><matplotlib><colors><histogram>
2023-09-06 14:38:52
1
371
Michael
77,052,942
6,236,430
Python (3) flask to rebuild tables fails (usually) using mysql.connector
<p>I have a few tables I wish to truncate and then repopulate (legacy and not how I'd do it but company won't pay to fix process) Code is logging the state but when it gets to truncate a table it is just hanging.</p> <p>Here's the relevant code:</p> <pre><code> print(str(datetime.utcnow()), 'Running Database Sync......
<python><mysql><flask>
2023-09-06 14:35:14
0
869
ThurstonLevi
77,052,912
1,747,834
Does pip support local plugins?
<p>I'd like to execute certain Python code each time <code>pip</code> installs (or removes) a package.</p> <p>Do I need to modify the existing pip-code for that, or can I simply register my add-on in <code>pip.conf</code>?</p>
<python><python-3.x><pip>
2023-09-06 14:31:42
0
4,246
Mikhail T.
77,052,891
22,221,987
Prevent QChart PlotArea shifting after axis labels values changes
<p>When you zoom the plot, axis values labels changes and increase their length like: <code>5.0-&gt;5.01-&gt;5.001-&gt;5.0001 etc</code>. This cause next behaviour:</p> <ol> <li>Vertical axis shifts in horizontal direction every time value label append digit in itself. This cause the whole plot area shifting. Looks kin...
<python><python-3.x><qt><pyqt><pyside>
2023-09-06 14:29:13
0
309
Mika
77,052,708
4,575,197
How to get the matched groups in regex Python and save it as a new column
<p>I have a dataframe and i want to find out, if there was any mentions of the firms that i'm looking for in <code>DocumentIdentifier</code> column. probably it should be done through Regex groups, but I'm not sure and currently i use <code>contains()</code>.</p> <p>The data looks like this:</p> <div class="s-table-con...
<python><pandas><regex><data-cleaning><string-matching>
2023-09-06 14:09:01
1
10,490
Mostafa Bouzari
77,052,659
3,387,716
python list comprehension: list of dicts to dict of lists with key intersection
<p>I have a list with a variable number of dictionaries, for ex:</p> <pre class="lang-py prettyprint-override"><code>var = [ {'a': 1, 'b': 2}, {'b': 20, 'a': 10, 'c': 30}, {'c': 300, 'a': 100} ] </code></pre> <p>I need to extract the keys that are common to all dicts, make a list of their associated values, create a ne...
<python><list-comprehension>
2023-09-06 14:02:20
2
17,608
Fravadona
77,052,482
7,862,279
Can't connect asynchronously to opcua server
<p>I'm trying to get a value of a node in my OPCUA server.</p> <p>I'm using <code>asyncua</code> on a windows 10 x64 computer. The server is on a PLC.</p> <p>When I write this in a normal task it works</p> <pre><code>client = Client(&quot;opc.tcp://192.168.1.88:4840&quot;) # client.max_chunkcount = 5000 # in case of re...
<python><async-await><opc-ua>
2023-09-06 13:41:10
1
763
Jack
77,052,324
14,073,111
Call functions using dictionaries in python
<p>Let's say that I have this pseudo code:</p> <pre><code>x11 = { &quot;exec&quot;: { &quot;test1&quot;: &quot;test1&quot; }, &quot;mount&quot;: { &quot;test2&quot;: &quot;test2&quot; }, &quot;unmount&quot;: { &quot;test3&quot;: &quot;test3&quot; }, } def get_exec(dict1)...
<python><python-3.x><function><dictionary><methods>
2023-09-06 13:20:50
3
631
user14073111
77,052,314
12,725,674
Python regex: Extract string between multiple dashes
<p>I have transcripts of speeches which have the following structure:</p> <pre><code>-------------------------------------------------------------------------------- Person 1 [1] -------------------------------------------------------------------------------- Text spoken by Person 1 -----------------------...
<python><regex>
2023-09-06 13:20:04
1
367
xxgaryxx
77,052,236
12,888,591
Pandas read_excel converting dates incorrectly
<p>I have a large number of separate .xlsx files I am trying to compile into one master list. There are dates in two of the columns of data but they are in inconsistent formats, like 01/03/2021 and 01.03.2021, among other things. The data is so large I am not sure of all the different formats. I want all data in this n...
<python><pandas><excel>
2023-09-06 13:10:15
1
415
Scott Adamson
77,052,195
241,515
Pandas: groupby by one column, select rows with the (local) minimum value in one column and the (local) maximum in another
<p>I have a <code>DataFrame</code> with this structure:</p> <pre><code> sampleid ploidy purity error 0 1962666_A1 2 0.05 0.330501 1 1962666_A1 2 0.09 0.337803 2 1962666_A1 2 0.97 0.991373 3 1962666_A1 3 0.05...
<python><pandas><dataframe>
2023-09-06 13:06:14
1
4,973
Einar
77,051,982
4,905,285
Python pandas: filter columns in dataframe BEGINNING with pattern
<p>I have 2 columns called <code>eta</code> and <code>theta</code> in a pandas data frame.</p> <p>I'm trying to select the column called <code>eta</code> only.</p> <p>So far I have tried</p> <pre><code>df.filter(like='eta') </code></pre> <p>...however this selects both <code>eta</code> and <code>theta</code>.</p> <p>I'...
<python><pandas><dataframe><filter>
2023-09-06 12:37:52
1
441
AlexLee
77,051,620
22,070,773
nanobind trampoline method name issue
<p>I have a trampoline class that I am trying to wrap in nanobind like so:</p> <pre><code>class PyT : T { public: NB_TRAMPOLINE(T, 1); void F() override { NB_OVERRIDE(F); } }; // ... nb::class_&lt;T, PyT&gt;(m, &quot;T&quot;) .def(nb::init&lt;&gt;()) .def(&quot;f&quot;, &amp;PyT::F) </code></pre...
<python><c++><nanobind>
2023-09-06 11:53:01
1
451
got here
77,051,594
424,556
Inconsistent font sizes in ticks on Y axis
<p>I use Seaborn to plot violins, though I assume the bug comes from Matplotlib. I do not do anything fancy regarding the visualization itself, and merely set the font size of tick labels on the Y axis using both</p> <pre><code>sns.set_context(&quot;notebook&quot;, font_scale=1, rc={&quot;lines.linewidth&quot;: 1.5}) ...
<python><matplotlib><seaborn>
2023-09-06 11:48:14
1
3,336
nbonneel
77,051,502
22,070,773
nanobind incompatible function argument types
<p>I have this basic example:</p> <pre><code>#include &lt;iostream&gt; #include &lt;nanobind/nanobind.h&gt; class T { public: T(std::string s) { std::cout &lt;&lt; &quot;hello world&quot; &lt;&lt; std::endl; }; } NB_MODULE(basic_example, m) { nb::class_&lt;T&gt;(m, &quot;T&quot;) .def(nb::ini...
<python><c++><nanobind>
2023-09-06 11:33:49
1
451
got here
77,051,492
6,884,119
Python: List Calendars using Google Calendar API
<p>I am trying to list my account's Google Calendars using the Calendar API, but it is returning <code>No Calendars Found</code>.</p> <p>Below is my code:</p> <p><code>models/cal_setup.py</code></p> <pre><code>import pickle import os.path from google.oauth2 import service_account from googleapiclient.discovery import b...
<python><google-calendar-api><google-workspace><google-api-python-client><service-accounts>
2023-09-06 11:32:14
1
2,243
Mervin Hemaraju
77,051,489
5,221,435
API in my main.py flask application doesn't work after dockerizing the app on Windows
<p>I dockerized my Flask application on windows. I use Docker Desktop to run docker. In windows, to join the container you can't use localhost but the ip &quot;192.168.99.100&quot;. So, after dockerizing app, I try to reach one API from this ip address, but the request goes in timeout:</p> <p><a href="https://i.sstatic...
<python><docker><flask><docker-compose><dockerfile>
2023-09-06 11:31:57
2
1,585
Giacomo Brunetta
77,051,447
6,876,422
Chunk a text based on regex expression with delimiter including
<p>I have a long text, about 10k characters that contain many sections. I need to chunk the text based on these sections. Every chunk should contain a section. The text template is represented by sections with titles start with &quot;SECTION|RUBRIQUE n&quot; where n is the number of the section.</p> <p>This is my try:<...
<python><regex><split>
2023-09-06 11:26:08
1
2,330
famas23
77,051,260
19,238,204
How to Highlight a 3D Surface Plot slice
<p>I was wondering how to highlight a 3D surface plot (done by SymPy Plotting Backends) with the help of matplotlib (because I find an example here: <a href="https://stackoverflow.com/questions/57483209/how-do-i-highlight-a-slice-on-a-matplotlib-3d-surface-plot">How do I highlight a slice on a matplotlib 3D surface plo...
<python><matplotlib><sympy><matplotlib-3d>
2023-09-06 10:56:58
1
435
Freya the Goddess
77,051,119
10,811,647
Tensorflow unable to load model
<p>I trained some models in a docker. I am trying to load the models on my host machine but I am unable to do so.</p> <p>At first I saved the models as .keras files as mentionned on the documentation. When trying to load the model using <code>tf.keras.models.load_model(&quot;model.keras&quot;)</code>, I get the followi...
<python><tensorflow><keras>
2023-09-06 10:36:38
1
397
The Governor
77,051,111
17,160,160
Linearize Pyomo model with BigM Constraint
<p>I <em>may</em> have answered my own question posted below with the following.</p> <p>I believe the construction is now appropriately linear and returns a feasible solution. Though I would appreciate any feedback as I am new to this.</p> <p>In replacement of the <code>model.bigM_cons</code> I outlined below, I have n...
<python><pyomo>
2023-09-06 10:35:59
1
609
r0bt
77,050,866
12,129,443
Why I am getting "Notebook out of memory" error upon notebook submission in Kaggle
<p>I am participating in a Kaggle competition. Over the past 7-10 days I have been facing a peculiar problem. I am trying to make my submission to the competition, but am getting &quot;Notebook out of memory&quot; error again and again as you can see in the picture.</p> <p>I have tried a variety of things to get rid of...
<python><nlp><huggingface-transformers><kaggle><large-language-model>
2023-09-06 09:55:50
1
668
Srinivas
77,050,847
1,852,526
Python trying to read XML file with Open() to string is adding invalid characters
<p>I have the following code where I am trying to read an XML file (.csproj) into string. Problem is, when I try to do so (see <code>file_content=f.read().replace('\n','')</code>), its introducing invalid characters before the '&lt;xml' tag like '' (see the screenshot) and I get an error that the XML is not well for...
<python><xml><elementtree>
2023-09-06 09:52:56
0
1,774
nikhil
77,050,824
1,928,054
Pandas stack with level parameter
<p>Consider the following DataFrame:</p> <pre><code>df1 = pd.DataFrame(np.ones((2, 2)), index=[&quot;A&quot;, &quot;B&quot;], columns=[&quot;foo&quot;, &quot;bar&quot;]) print(df1) foo bar A 1.0 1.0 B 1.0 1.0 print(df1.stack()) A foo 1.0 bar 1.0 B foo 1.0 bar 1.0 </code></pre> <p>I want to...
<python><pandas>
2023-09-06 09:49:24
1
503
BdB
77,050,751
5,510,713
Unable to decode QR code using any Python libraries but works on QR scanners app
<p>Following is a QR code captured from holography experiment with highest level of error correction. I can decode the image using my native camera app on iPhone but unable to decode using any of the Python QR code decoding libraries.</p> <p><a href="https://i.sstatic.net/P0gyV.jpg" rel="nofollow noreferrer"><img src="...
<python><opencv><qr-code><zxing><zbar>
2023-09-06 09:37:45
0
776
DhiwaTdG
77,050,748
8,510,149
Most efficient way to collect a list of values in a column Pandas - Numpy
<p>Below I have a logic that for each row in the dataframe test collects all values for id that has level lower than the current row and shares id_group.</p> <p>This code is very slow when I apply it to my real world dataset. Is it possible to do something similar using numpy?</p> <pre><code>test = pd.DataFrame({'id_gr...
<python><pandas><numpy>
2023-09-06 09:37:30
1
1,255
Henri
77,050,694
11,578,996
How to create custom heatmap annotations with a mask
<p>I want to only label the highest value on my heatmap, but only the first digit is showing. I don't know why. Shrinking the font doesn't seem to work. While writing this I guess ignoring the annotation variable and adding a text might work but I can't wrap my head around this for subplot :cryingface:</p> <p>You can ...
<python><matplotlib><seaborn><heatmap><plot-annotations>
2023-09-06 09:30:01
1
389
ciaran haines
77,050,566
11,098,908
Procedure of a recursive function
<p>I came across this code that traces the flow of a recursive function</p> <pre><code>def summation(lower, upper, margin): (1) blanks = &quot; &quot; * margin (2) print(blanks, lower, upper) (3) if lower ...
<python><recursion>
2023-09-06 09:13:48
3
1,306
Nemo
77,050,460
736,662
Python/Locust and csv-file with parameters
<p>Today I have hard-coded the values used in this Locust test into the script (TSIDs). How can I, instead, feed the values from a .csv file into the script?</p> <pre><code>from locust import HttpUser, between, task import random from datetime import datetime, timedelta server_name = &quot;https://xxx&quot; TSIDs = {...
<python><locust>
2023-09-06 09:00:37
1
1,003
Magnus Jensen
77,050,395
3,535,537
How to to burst array by timestamp dict attribute and sort by timestamp
<p>I want burst array with same <code>[&quot;content&quot;][&quot;system.id&quot;]</code> or <code>[&quot;content&quot;][&quot;target.uid&quot;]</code>. With <code>typeB</code>, this object contain a list of timestamp (key) or with <code>typeA</code>, this object contain &quot;date&quot; attribute.</p> <p>We need keep ...
<python>
2023-09-06 08:52:22
2
11,934
Stéphane GRILLON
77,050,392
774,133
plotnine: how to modify colormaps
<p>Please consider this code (it is an example in the doc):</p> <pre class="lang-py prettyprint-override"><code>import pandas as pd import numpy as np from plotnine import * df = pd.DataFrame({ 'variable': ['gender', 'gender', 'age', 'age', 'age', 'income', 'income', 'income', 'income'], 'category': ['Female'...
<python><plotnine>
2023-09-06 08:52:08
1
3,234
Antonio Sesto
77,050,065
22,466,650
How to convert a string (one single column) to a DataFrame?
<p>My input is a string :</p> <pre><code>text = '''10 February 2023 abc def 23 March 2023 ghi jkl''' </code></pre> <p>I made the code below (using regex but I'm open to any other alternative) :</p> <pre><code>data = [] for m in re.finditer(r'(\d+ \w+ \w+)\n(.*)', text, flags=re.I|re.S): data.append([m.group(1), m....
<python><pandas>
2023-09-06 08:06:35
1
1,085
VERBOSE
77,049,879
9,657,938
Send unlimited args on command line with value
<p>I am trying to build a generic file for create a table on database I want from command line send something like this <code>python create_table.py table_name=test name=TEXT city=TEXT </code></p> <p>So every time I run the file I can create a new table with new fields every field with his type</p> <p>I figure out to u...
<python><python-3.x><sqlite><command-line-arguments><argparse>
2023-09-06 07:39:19
1
369
Sideeg MoHammed
77,049,753
2,235,673
Handling overflow and underflow conditions in Python decimal conversions
<p>I'm working on a Python function that takes a <em>float</em> number as input and converts it to a <em>decimal</em>, then to a <em>string</em>. However, I need to restrict the number of digits in the exponent of the <em>decimal</em> representation to two, while allowing any exponent for the <em>float</em> number. Con...
<python><python-3.x>
2023-09-06 07:19:23
1
2,626
Medical physicist
77,049,740
3,678,257
Redis vector search does not return required number of documents for large K
<p>I have deployed a RedisSearch server to test vector similarity search. I have followed this guide pretty much exactly, <strong>using HNSW algorithm</strong>:</p> <ol> <li><a href="https://github.com/openai/openai-cookbook/blob/main/examples/vector_databases/redis/getting-started-with-redis-and-openai.ipynb" rel="nof...
<python><search><redis><vector-search>
2023-09-06 07:16:42
1
664
ruslaniv
77,049,671
3,073,612
My MongoDB server crashes with Invariant failure
<p>I have a PHP code and Python code that accesses this MongoDB server in production running on Docker. But every now and then, the MongoDB container restarts with this log, and I am unable to find what is the root cause of this random crash. This is a standalone server with no replica sets. I tried posting in MongoDB ...
<python><php><mongodb><docker>
2023-09-06 07:05:03
0
2,756
Sibidharan
77,049,610
10,994,166
Spark simple join not working, work not getting properly distributed among executors
<p>Hi I have two df like this:</p> <pre><code>df1 id items 1 [[c,b,..], [z,x,..],..] 2 [[d,t,..], [q,a,..],..] . . . . schema: [('id', 'string'), ('items', 'array&lt;array&lt;string&gt;&gt;')] Total Records: 157 Total Partition while saving: 20 Total size of data: 700mb df2 id...
<python><scala><pyspark><memory><apache-spark-sql>
2023-09-06 06:55:07
1
923
Chris_007
77,049,559
90,580
How can I generate a PBKDF2 password hash in python?
<p>I'm using some software that stores it's internal user database in a JSON file (users.json) where each user has a field called <code>password</code> where the values look like this:</p> <pre><code>pbkdf2:10000:f30dd5755d4d172d:e7b2fdda936b4ad5335c3b76c8f3568b0e3b14ce1d9b8ca1e32b7627545d0a3811aa3407a814731b1ee1c86e10...
<python><pbkdf2>
2023-09-06 06:47:30
1
25,455
RubenLaguna
77,049,365
6,032,140
yaml/ruamel string formatting and printing output isn't working as expected
<ol> <li><p>I have the following python dit string format as shown below.</p> <pre><code># With two dictionary input dit = &quot;{p_d: '{a:3, what:3.6864e-05, s:lion, vec_mode:'{2.5, -2.9, 3.4, 5.6, -8.9, -5.67, 2, 2, 2, 2, 5.4, 2, 2, 6.545, 2, 2}, sst:'{c:-20, b:6, p:panther}}}\n{mgbp: '{ifftp:'{ipdp:'{ipdncf:'{r_t:no...
<python><yaml><ruamel.yaml>
2023-09-06 06:10:43
1
1,163
Vimo
77,049,291
8,961,082
Apache Airflow running orphaned dag from days ago
<p>New to airflow, I was running a dag a few days ago on the scheduler. I want to kill it but it won't stop. I've uninstalled airflow and reinstalled, I have even created a new project just to start from scratch. Additionally, I have deleted all those files associated with the first project.</p> <p>Every time I run the...
<python><airflow><directed-acyclic-graphs><airflow-webserver>
2023-09-06 05:52:11
0
377
d789w
77,049,120
13,238,846
Structured Tool Agent Finish
<p>I have created a structured tool using Langchain and I want to output directly agent finish after using this tool. Is there any option in kwargs to pass to that when initlaizing the tool? Or I just have to remake the tool using Base Tool.</p> <pre><code> Tool( name=&quot;GetStock&quot;, func=...
<python><agent><langchain>
2023-09-06 05:05:14
3
427
Axen_Rangs
77,048,844
13,684,789
How to Copy Worksheet to an Existing Sheet with gspread?
<p>In Google Sheets one is able to manually copy a worksheet in a given sheet to another sheet; I want to do this programmatically with <code>gspread</code>. For example, if I have 2 sheets in my drive--<em>spreadsheet_1</em> and <em>spreadsheet_2</em>--I want to copy worksheet <em>ws_1</em> from <em>spreadsheet_1</em>...
<python><gspread>
2023-09-06 03:23:07
1
330
Übermensch
77,048,438
3,121,975
Modifying class decorator on class with property decorator
<p>I have a bunch of data classes that I'm trying to build from a dictionary of parsed XML. The keys in this XML have been obfuscated so I've had to go through tedious amounts of documentation, written in a language I have only passing familiarity with, to be able to construct this structure. Right, now I have somethin...
<python><decorator>
2023-09-06 00:44:37
1
8,192
Woody1193
77,048,324
1,459,079
pex built by pex doesn't run outside its virtualenv
<p><em>TL;DR</em></p> <p>I built <code>pex</code> according to the guide <a href="https://pex.readthedocs.io/en/v2.1.145/buildingpex.html" rel="nofollow noreferrer">https://pex.readthedocs.io/en/v2.1.145/buildingpex.html</a> and was expecting it to run fine outside of the virtualenv I used to build it, but alas:</p> <p...
<python><twitter><pex>
2023-09-06 00:04:19
1
3,181
Marcello Romani
77,048,121
6,395,618
How to format Ragged Tensor for Encoder-Decoder model?
<p>I'm working on building a <strong>seq2seq</strong> model using encoder-decoder architecture for which I have built a <code>tf.data.Dataset</code> pipeline that reads the text from the directories, vectorizes using them <code>tf.keras.layers.TextVectorization</code> and preprocess it to be fed for model training. I'm...
<python><tensorflow><keras><deep-learning><nlp>
2023-09-05 22:46:08
1
2,606
Krishnang K Dalal
77,048,094
9,140
How to do rolling() grouped by day by hour in Polars?
<p>Let's say you have a dataset with the following column, Node, Time, date, Hour, Amount. Time is spaced hourly. date is simply the current date corresponding to Time. You should have only one instance of a Node per hour.</p> <p>Every day, for every Hour I want the average of Amount for the past 31 days in this hour...
<python><dataframe><python-polars>
2023-09-05 22:38:22
3
5,498
EtienneT
77,048,073
1,040,915
How to iterate through paginated results in the Python SDK for Microsoft Graph?
<p>I'm getting to grips with the <a href="https://github.com/microsoftgraph/msgraph-sdk-python" rel="noreferrer">Python SDK</a>, having never used GraphQL before (but I'm familiar with the basic concept). I'm able to retrieve the <code>odata_next_link</code> value from responses, but I'm not sure how to use it. I note ...
<python><microsoft-graph-api><microsoft-graph-sdks>
2023-09-05 22:33:20
2
5,977
scubbo
77,047,987
4,921,853
ValidationError when instantiating SimpleNodeParser class from llama index
<p>Taking straight from the docs ...</p> <pre><code>from llama_index.node_parser import SimpleNodeParser from llama_index import SimpleDirectoryReader # load the blogs in using the reader docs = SimpleDirectoryReader('./data').load_data() # chunk up the blog posts into nodes parser = SimpleNodeParser() nodes = parser...
<python><parsing><large-language-model><llama-index>
2023-09-05 22:03:35
1
305
superhero
77,047,935
5,378,132
How to Create Conda Environment in AWS Lambda at Run Time?
<p>I am using an AWS lambda as part of my CI/CD pipeline. The lambda checks out some code using the provided git url and commit hash in the event. Then, it goes into the source code and does a <code>conda env create -f env.yml</code>, and then runs a python file <code>python flow.py run</code>. Unfortunately, installin...
<python><amazon-web-services><aws-lambda><anaconda><conda>
2023-09-05 21:48:09
0
2,831
Riley Hun
77,047,920
6,734,243
is there a way to create and init a dir variable in one line using pathlib?
<p>I try to stick to pathlib to create and manipulate path but generating folders is always a pain. If I want to init a &quot;toto&quot; folder in a &quot;tutu&quot; folder and store the path in a variable I'm forced to do the following:</p> <pre class="lang-py prettyprint-override"><code>from pathlib import Path tut...
<python><pathlib>
2023-09-05 21:46:03
1
2,670
Pierrick Rambaud
77,047,916
1,448,529
How to remove special character from excel header in pandas
<p>I'm trying to read an excel file in pandas which has special characters in its header. I have a column with name like this &quot;Col(≤9%)&quot;. How can I remove less than equal sign here?</p> <p>If the ingest the file as it is, it fails with below error message</p> <pre><code>pandas._libs.lib.map_infer_mask Unicode...
<python><pandas>
2023-09-05 21:45:23
1
731
hampi2017
77,047,749
1,394,763
How to keep Processes alive in python multiprocessing so that they maintain state and can be reused?
<p>I would like to divide an expensive computation among many subprocesses that can all work on part of the problem in an embarassing parallel way. However, each subprocess needs a large amount of initial data (different for each subprocess). I would like to pass in this initial data only once when the processes are cr...
<python><parallel-processing><multiprocessing><python-multiprocessing>
2023-09-05 21:07:03
2
1,502
Alex
77,047,680
6,068,731
imshow with x-axis as log scale is not equally-spaced
<p>I am using <code>pcolor</code> to generate the following plot (code below). It has a <code>colorbar</code> in log scale and the x-values are in log-scale too. The problem is that the rectangles in this plot have different widths (I've put a red grid to show the rectangles better, suggestion of Trenton). Is there any...
<python><numpy><matplotlib><imshow>
2023-09-05 20:52:30
1
728
Physics_Student
77,047,569
6,734,243
how to define a pytest plugin in a setuptools pyproject.toml?
<p>According to pytest documentation, plugins must be registered as entry points so I want ot find the pyproject.toml equivalent to:</p> <pre><code>entry_points={ &quot;pytest11&quot;: [ &quot;copie = pytest_copi.plugin&quot;, ], } </code></pre>
<python><pytest><pytest-fixtures>
2023-09-05 20:30:50
1
2,670
Pierrick Rambaud
77,047,518
3,174,124
Get the printed length of a string in terminal
<p>It seems like a fairly simple task, yet I can't find a fast and reliable solution to it.</p> <p>I have strings in bash, and I want to know the number of characters that will be printed on the terminal. The reason I need this, is to nicely align the strings in three columns of <code>n</code> characters each. For that...
<python><bash><string-length>
2023-09-05 20:19:52
4
611
Slagt
77,047,492
1,060,747
Tracking down cause of error in unittest/mock
<p>I'm using the Python Responses module (latest v0.23.3) alongside Requests (v2.31.0) in Python 3.11. It's part of a fairly large application, and I'm using Responses to simulate a device which I communicate with via Requests sending simple HTML GET strings e.g. &quot;action=instruction&amp;pin=5&quot;.</p> <p>My sta...
<python><python-requests><python-responses>
2023-09-05 20:13:37
1
561
DaveWalker
77,047,476
315,168
Pandas DataFrame.write_parquet() and setting the Zstd compression level
<p>I am writing out a compressed Parquet file from <code>DataFrame</code> as following:</p> <pre class="lang-py prettyprint-override"><code>result_df.to_parquet(&quot;my-data.parquet&quot;, compression=&quot;zstd&quot;) </code></pre> <p>How can I instruct Pandas on the compression level of zstd coding?</p>
<python><pandas><parquet><zstd>
2023-09-05 20:10:01
3
84,872
Mikko Ohtamaa
77,047,383
4,541,974
Google Speech V2 real time streaming from mic
<p>I can't seem to find anywhere in the documentation how to use google's speech V2 API. For some reason V2 seems to be cheaper than V1 (as per <a href="https://cloud.google.com/speech-to-text/pricing" rel="nofollow noreferrer">google's speech pricing table</a> -- although I have no idea why an outdated version seems t...
<python><google-speech-api><google-speech-to-text-api>
2023-09-05 19:51:37
1
1,654
Luis Cruz
77,047,372
6,484,726
FastAPI, how to block requests until specific one completes?
<p>My path operator in FastAPI making API calls. External API is protected and I have to provide Bearer token in my requests. In my application I check whether current Bearer token has expired and issue a new token, if so.</p> <p>For example:</p> <pre class="lang-py prettyprint-override"><code>from fastapi import FastA...
<python><python-asyncio><fastapi>
2023-09-05 19:49:08
1
398
hardhypochondria
77,047,030
1,903,852
Combining time and time zone columns in data frame
<p>I've got a csv file with trip data. Each row specifies where the trip started (<code>origin</code>), where the trip ended (<code>destination</code>), as well as the starting time (<code>depart_time</code>) and ending time of the trip (<code>arrival_time</code>). The <code>depart_time</code> and <code>arrival_time</c...
<python><python-3.x><dataframe>
2023-09-05 18:46:36
1
2,431
Joris Kinable
77,046,935
7,766,155
Get word frequencies from a pretrained word2vec model in gensim
<p>I am trying to get the CBOW represention (word frequencies) out of a pretrained word2vec model in gensim. I know that the word2vec model I am using was originally trained using CBOW so the word2vec object must store word frequencies somewhere but I cannot find it. I did read the documentation but did not help at all...
<python><nlp><gensim>
2023-09-05 18:29:56
0
301
AmirWG
77,046,872
8,126,390
Python asyncio how to detect unexpected exceptions
<p>I'm building a project on top of Django Channels and as such, I would like to avoid mucking with code above my sub-classed consumer.</p> <p>With asyncio, uncaught and unexpected exceptions aren't being thrown to the console even with asyncio debug enabled, and Python dev mode enabled.</p> <p>I came up with the follo...
<python><python-asyncio>
2023-09-05 18:17:33
1
740
Brian
77,046,862
12,417,488
Python pandas read file with delimiters inside the data?
<p>I regularly have to read text files as such:</p> <pre><code>Column1; Column2; Column3 data1;dat;a2;data3 </code></pre> <p>Meaning that the data in Column 2 uses the same character used as the delimiter, therefore pandas incorrectly reads this data as two columns. This is just an illustrative example, this is not th...
<python><pandas><csv><text>
2023-09-05 18:15:31
1
663
PJ_
77,046,810
7,347,774
Is it possible to use mlxtend's fpgrowth() in Snowpark without transforming data to Pandas DF?
<p>I've been trying to get the Market Basket Analysis done with FP-Growth algorithm with <code>fpgrowth</code> function from <code>mlxtend</code> library available in Snowpark.</p> <p>It works with smaller datasets but fails for the whole dataset (over 4 million rows and 6000 columns of one-hot encoding). It exits with...
<python><snowflake-cloud-data-platform><market-basket-analysis><mlxtend><fpgrowth>
2023-09-05 18:03:55
1
1,055
Piotr K
77,046,693
2,856,499
Exception in Python breaks for loop despite putting in continue/pass
<p>Im writing a python code that loops file directories and sub-directories to extract word doc file and write the content of word doc to excel/csv files. If some files are invalid (for example they have XML, the loop would skip)</p> <p>The issue now is I managed to get it more or less working, but for some reason, my ...
<python>
2023-09-05 17:44:09
1
1,315
Adam
77,046,635
4,260,095
JSON Schema referencing in array items from another file
<p>I have two JSON schemas - <code>publisher</code> and <code>article</code>, such that there could be multiple articles in a single publisher.</p> <p>This is the <code>article</code> schema (in <code>a.json</code>):</p> <pre class="lang-json prettyprint-override"><code>{ &quot;$schema&quot;: &quot;https://json-schem...
<python><json><jsonschema><python-jsonschema>
2023-09-05 17:35:01
2
955
Shod
77,046,624
7,200,745
How to filter messages from Kafka based on headers value in AWS lambda?
<p>I have a message coming from Kafka to the lambda in the format:</p> <pre><code>{ &quot;eventSource&quot;:&quot;aws:kafka&quot;, &quot;eventSourceArn&quot;:&quot;arn:aws:kafka:sa-east-1:123456789012:cluster/vpc-2priv-2pub/751d2973-a626-431c-9d4e-d7975eb44dd7-2&quot;, &quot;bootstrapServers&quot;:&quot;b-2.de...
<python><amazon-web-services><apache-kafka><aws-lambda>
2023-09-05 17:33:52
2
444
Eugene W.
77,046,591
14,141,072
Discord.py : Slash Command working but simultaneously giving and error
<p>I have just come back to coding in Discord.py and I have this error. <a href="https://i.sstatic.net/bel6Q.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/bel6Q.png" alt="enter image description here" /></a></p> <p>So basically I am unable to figure out the reason. The code is here:</p> <pre><code>@cer...
<python><discord.py>
2023-09-05 17:27:18
1
831
Bhavyadeep Yadav
77,046,536
13,757,692
Split numpy array into segments where condition is met
<p>I have an array like so:</p> <pre><code>arr = np.array([1, 2, 3, 4, -5, -6, 3, 5, 1, -2, 5, -1, -1, 10]) </code></pre> <p>I want to get rid of all negative values, and split the array at each index where there was a negative value. The result should look like this:</p> <pre><code>split_list = [[1, 2, 3, 4], [3, 5, 1...
<python><arrays><numpy>
2023-09-05 17:20:35
6
466
Alex V.
77,046,517
11,500,371
How to I create columns that are named based on the results of a groupby and matching another condition?
<p>I am trying to create three new columns (&quot;Product 1 Price&quot;, &quot;Product 2 Price&quot;, and &quot;Product 3 Price&quot;) from an existing column &quot;Product Price&quot;. The order of the product numbers is important and is based on three existing values in the dataframe (columns Product 1, Product 2, an...
<python><pandas><dataframe>
2023-09-05 17:17:37
2
337
Sean R
77,046,468
4,225,430
Where is the parameter 'request' used in view.py in django
<p>A newbie in Django web development. I've got a tiny but puzzling question about request / response in views.py.</p> <ol> <li>I self-learn Django online and here comes the http request / response section. The code is as follows:</li> </ol> <pre><code>#from django.shortcuts import render from django.http import HttpRe...
<python><django><httprequest><render><httpresponse>
2023-09-05 17:08:44
2
393
ronzenith
77,046,465
10,200,497
Add a string to a multiline string in python without creating new line
<p>I have two strings. One of them is a normal string and the other one is multiline.</p> <pre><code>a = '1' b = &quot;&quot;&quot; abc xyz &quot;&quot;&quot; </code></pre> <p>This is the output that I want:</p> <pre><code>1- abc xyz </code></pre> <p>I have tried to use a f-string:</p> <pre><code>result = f'{a}- {b}' <...
<python>
2023-09-05 17:08:10
4
2,679
AmirX
77,046,319
22,213,065
Move last lines to first line
<p>I have high number of txt files in <code>E:\Desktop\Social_media\edit8\New folder (2)</code> directory and each file have an arrangement like following:</p> <pre><code>Bolt;539,110 Classmates;263,454 PlanetAll;126,907 theGlobe;73,063 SixDegrees;64,065 JANUARY 1997 </code></pre> <p>Now I want to move last lines to fi...
<python><python-3.x>
2023-09-05 16:44:35
1
781
Pubg Mobile
77,046,307
7,169,895
PySide6 QAbstractTableView - Set table header color
<p>I saw <a href="https://stackoverflow.com/questions/12748460/qtableview-custom-table-model-set-text-color-in-header">this question</a> which is asking the same as me. However, the solution is not working for coloring my header row. Here is my code</p> <pre><code> def headerData(self, col, orientation, role): ...
<python><pyside6>
2023-09-05 16:42:22
0
786
David Frick
77,046,175
5,862,756
how to install & use numpy on macOS Ventura, ARM
<p>it's there, but computer says &quot;no&quot;...</p> <pre><code>% python --version Python 3.11.3 % find /opt -name &quot;numpy&quot; /opt/homebrew/lib/python3.11/site-packages/numpy /opt/homebrew/lib/python3.11/site-packages/numpy/core/include/numpy % export PYTHONPATH=&quot;/opt/homebrew/lib/python3.11/site-pac...
<python><macos><numpy>
2023-09-05 16:21:31
0
1,293
VorpalSword
77,046,121
15,587,184
Python regular expressions to continuously extract multiple pieces of information from text data
<p>I have a dataset that has a col named &quot;plain_text&quot; in which we have a dumped log of conversations among several user in a group chat, the servers saves the information in a format like this:</p> <pre><code>a &quot;timestamp&quot; + &quot;user name&quot; + &quot;:&quot; + &quot;text&quot; </code></pre> <p>t...
<python><regex>
2023-09-05 16:13:03
1
809
R_Student
77,046,105
22,213,065
Merge the last 3 lines of each text file with specific arrangement
<p>I have high number of txt files in <code>E:\Desktop\Social_media\edit8\New folder</code> directory and each file has an arrangement similar to the following:</p> <pre><code>Bolt 2,739,393 Classmates 1,267,092 SixDegrees 1,077,353 PlanetAll 552,488 theGlobe 437,847 OpenDiary 9,251 1998 MARCH 034+ </code></pre> <p>Now...
<python><python-3.x>
2023-09-05 16:09:57
2
781
Pubg Mobile
77,046,075
901,426
dump Protobuf class variables to a list/dict and swap keys
<p>i'm working with the lovely Protobuf (<em>cough</em>) and i'm running into an odd problem: instead of returning 'value' as a member of the 'Metric' class in the MQTT message, it is returning, through the <code>oneof</code> declaration, keys like <code>boolean_value</code>, <code>string_value</code>, &amp;c. since t...
<python><class><protocol-buffers>
2023-09-05 16:05:40
1
867
WhiteRau
77,046,010
6,231,251
Iteratively select rows in Pandas dataframes to form single df
<p>I have a dict of dataframes:</p> <pre><code>data1 = {'A': [1, 2, 3], 'B': [4, 5, 6], 'my_value': [0.1, 0.4, 0.3]} df1 = pd.DataFrame(data1) # Example DataFrame 2 data2 = {'A': [7, 8, 9], 'B': [10, 11, 12], 'my_value': [0.2, 0.5, 0.6]} df2 = pd.DataFrame(data2) # Example DataFram...
<python><pandas><dataframe>
2023-09-05 15:56:29
3
882
sato
77,045,962
5,491,260
How to use celery rdb while working with python, flask, docker and docker compose?
<p>I use python, flask, celery, docker and docker compose in my project and wanted to use <a href="https://docs.celeryq.dev/en/stable/reference/celery.contrib.rdb.html" rel="nofollow noreferrer">celery rdb</a> to debug my tasks. I could not connect to celery container using telnet from my local machine to docker contai...
<python><docker><debugging><docker-compose><celery>
2023-09-05 15:50:05
1
589
adnan kaya
77,045,947
2,258,585
Polars join with OR condition
<p>I have two dataset coming from two very different data sources.</p> <pre class="lang-py prettyprint-override"><code>import polars as pl df1 = pl.read_csv(b&quot;&quot;&quot;date,label,org_slug,org_id,org_name,issues_count 2023-08-29,label1,org-slug-name-1,org-id-1,org-name,1&quot;&quot;&quot;, try_parse_dates=True)...
<python><dataframe><python-polars>
2023-09-05 15:48:05
2
2,246
Tizianoreica
77,045,943
7,655,447
How to use logical AND operation on multiple pandas columns and change the value of column in python
<p>I have a pandas dataframe with multiple columns as below: <a href="https://i.sstatic.net/8esc0.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/8esc0.png" alt="enter image description here" /></a></p> <p>How can I create a new column named as 'result' and perform logical operation like '&amp;' on all t...
<python><pandas><dataframe>
2023-09-05 15:47:23
0
407
Nikhil Mangire
77,045,910
1,314,404
How to use higher version of sqlite3 in mac
<p>I got this error <code>&quot;RuntimeError: Your system has an unsupported version of sqlite3. Chroma requires sqlite3 &gt;= 3.35.0.&quot;</code> To check the version, I tried <code>sqlite3 --version</code> and I got <code>3.33.0 2020-08-14 13:23:32 fca8dc8b578f215a969cd899336378966156154710873e68b3d9ac5881b0alt2</co...
<python><macos><virtualenv><sqlite3-python>
2023-09-05 15:43:09
1
1,315
user1314404
77,045,877
13,559,669
Device Code Flow - Microsoft Azure Authentication
<p>What is the duration of the token we get when authenticating to Azure resources using Device Code Flow: <a href="https://learn.microsoft.com/en-us/azure/active-directory/develop/scenario-desktop-acquire-token-device-code-flow?tabs=dotnet" rel="nofollow noreferrer">https://learn.microsoft.com/en-us/azure/active-direc...
<python><azure><authentication><access-token><azure-authentication>
2023-09-05 15:38:08
1
436
el_pazzu
77,045,855
7,945,506
Python pandas: Why is concat not working?
<p>I have a list of pd.DataFrames <code>all_predictions</code> that I want to concatinate. As I am getting errors, I began to investigate:</p> <p>From two of the DataFrames in the list, I took a subset of rows and columns; and reset the index:</p> <pre><code>df1 = all_predictions[1] df2 = all_predictions[2] df1 = df1.h...
<python><pandas><concatenation>
2023-09-05 15:35:07
1
613
Julian
77,045,849
11,879,339
How to Plot GeoJSON Geometry Data in Streamlit Using Plotly Express Choropleth Mapbox?
<p>I'm trying to plot GeoJSON data of Indonesian cities and provinces using Streamlit and Plotly Express. My data comes from a DuckDB database, and I merge it with some additional data before plotting. I convert the merged data to GeoJSON format for plotting, but the map shows up empty.</p> <p>What I've Tried:</p> <ol>...
<python><plotly><geojson><streamlit><plotly-express>
2023-09-05 15:33:00
0
1,244
ebuzz168
77,045,818
1,838,726
Is it okay to use python operators for tensorflow tensors?
<p><strong>TL;DR</strong><br /> Is <code>(a and b)</code> equivalent to <code>tf.logical_and(a, b)</code> in terms of optimization and performance? (<code>a</code> and <code>b</code> are tensorflow tensors)</p> <p><strong>Details</strong>:<br /> I use python with tensorflow. My first priority is to make the code run fa...
<python><tensorflow><infix-operator><prefix-operator><xla>
2023-09-05 15:28:00
1
6,700
Daniel S.