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,013,095
929,732
convert_tz is taking on GMT at the end of the date although I'm converting to East Coast Time
<p>So here the the time in the database...</p> <pre><code>2023-01-02 21:00:00 </code></pre> <p>Here is the select that I use to get the information out of the database...</p> <pre><code>SELECT job_id,job_desc, CONVERT_TZ(job_date, 'GMT', 'US/Eastern') &quot;job_date&quot;, cust_auto_id, cost, paid, ...
<python><mariadb><convert-tz>
2023-01-05 01:48:03
0
1,489
BostonAreaHuman
75,013,084
3,137,388
gzip python module is giving empty bytes
<p>I copied one .gz file to a remote machine using fabric. When I tried to read the same remote file, empty bytes are getting displayed.</p> <p>Below is the python code I used to read the zip file from remote machine.</p> <pre><code>try: fabric_connection = Connection(host = host_name, connect_kwargs = {'key_file...
<python><gzip><fabric>
2023-01-05 01:45:39
1
5,396
kadina
75,012,933
8,616,751
Confusion matrix plot one decimal but exact zeros
<p>I'm trying to plot a confusion matrix that has one decimal for all values but if the value is exact zero, I would like to keep it as an exact zero rather than 0.0. How can I achieve this? In this minimal example for example I would like to keep <code>4.0</code> but instead of <code>0.0</code> I would like a <code>0<...
<python><matplotlib><scikit-learn><confusion-matrix>
2023-01-05 01:11:20
1
303
scriptgirl_3000
75,012,853
875,295
How do python pipe still work through spawning processes?
<p>I'm trying to understand why the following code <strong>works</strong>:</p> <pre><code>import multiprocessing def send_message(conn): # Send a message through the pipe conn.send(&quot;Hello, world!&quot;) if __name__ == '__main__': multiprocessing.set_start_method('spawn') # Create a pipe pare...
<python><multiprocessing>
2023-01-05 00:56:51
1
8,114
lezebulon
75,012,806
7,766,024
Python logger is not creating log file despite a FileHandler being specified
<p>I've been using a logger to log messages to a file and also output them to the console. I don't believe I did anything wrong, but the log file hasn't been being created for a few of the runs that I did.</p> <p>The code I have is:</p> <pre><code>log_msg_format = '[%(asctime)s - %(levelname)s - %(filename)s: %(lineno)...
<python><logging>
2023-01-05 00:47:08
0
3,460
Sean
75,012,613
1,278,365
Python how to programmatically print the first two lines the REPL prints everytime is started
<pre class="lang-none prettyprint-override"><code>$ python Python 3.11.1 (main, Jan 4 2023, 23:41:08) [GCC 11.3.0] on linux Type &quot;help&quot;, &quot;copyright&quot;, &quot;credits&quot; or &quot;license&quot; for more information. &gt;&gt;&gt; </code></pre> <p>Is there a programmatic way of printing those two line...
<python>
2023-01-05 00:08:23
4
2,058
gmagno
75,012,582
236,594
Generating an interval set in hypothesis
<p>I have some code that works with intervals, which are really just python dicts with the following structure:</p> <pre class="lang-py prettyprint-override"><code>{ &quot;name&quot;: &quot;some utf8 string&quot;, &quot;start&quot;: 0.0, # 0.0 &lt;= start &lt; 1.0 &quot;end&quot;: 1.0, # start &lt; end ...
<python><python-hypothesis>
2023-01-05 00:03:21
1
2,098
breadjesus
75,012,514
12,242,085
How to make dummy coding (pd.get_dummies()) only for categories which share in nominal variables is at least 40% in Python Pandas?
<p>I have DataFrame like below:</p> <pre><code>COL1 | COL2 | COL3 | ... | COLn -----|------|------|------|---- 111 | A | Y | ... | ... 222 | A | Y | ... | ... 333 | B | Z | ... | ... 444 | C | Z | ... | ... 555 | D | P | ... | ... </code></pre> <p>And I need to do dummy coding ...
<python><pandas><categories><one-hot-encoding><dummy-variable>
2023-01-04 23:46:13
1
2,350
dingaro
75,012,497
14,729,820
How to split big compressed text file to small text files
<p>I want to convert this corpus <a href="https://data.statmt.org/cc-100/hu.txt.xz" rel="nofollow noreferrer">hu.txt.xz</a> <strong>15GB</strong> which becomes around <strong>60GB</strong> after unpacking to small versions of text files, each file with less than <strong>1GB</strong> or <strong>100000</strong> lines</...
<python><file><deep-learning><pytorch><nlp>
2023-01-04 23:41:17
2
366
Mohammed
75,012,234
968,273
how to send message to azure bot in python via direct line service
<p>We recently deployed a Bot to Azure with type User assigned managed identity, so I only have app id, but not app password. I am trying to send messages via the Direct Line service from a python app. Following are my code:</p> <pre><code>from botframework.connector.auth import MicrosoftAppCredentials from botframewor...
<python><botframework>
2023-01-04 22:56:55
1
3,703
GLP
75,012,197
9,537,439
Why eval_set is not used in cross_validate with XGBClassifier?
<p>I'm trying to plot a graph where I can see the evolution in learning of the model as the number of estimators increases. I can do this with <code>eval_set</code> in <code>xgboost.XGBClassifier</code>, giving this plot:</p> <p><a href="https://i.sstatic.net/iqHMm.png" rel="nofollow noreferrer"><img src="https://i.sst...
<python><xgboost><cross-validation>
2023-01-04 22:52:37
1
2,081
Chris
75,012,181
17,047,177
Impossible to retrieve data form pyattck module
<p>I am using the <code>pyattck</code> module to retrieve information from mitre att&amp;ck.</p> <p>Versions:</p> <pre class="lang-bash prettyprint-override"><code> - pyattck==7.0.0 - pyattck-data==2.5.2 </code></pre> <p>Then, I just created a simple <code>main.py</code> file to test the module.</p> <pre cla...
<python><python-3.10><mitre-attck>
2023-01-04 22:51:36
1
1,069
A.Casanova
75,012,176
20,851,944
Call of class in python with attributes
<p>I made a typo with the <code>__init__()</code> in line 23, but my program runs only with this failure and shows the right result. Could some experienced OOP expert help me please.</p> <p>If I correct this tripple underscore <code>___init__()</code> to the correct on <code>__init__(file_path)</code> I get this ERROR ...
<python><init><class-variables>
2023-01-04 22:50:29
1
316
Paul-ET
75,011,719
3,133,027
Connect to Oracle on an encrypted port using sqlalchemy
<p>we have been using sqlalchemy successfully to connect to Oracle. Just now our organization is moving to encrypted Oracle database and we have been asked to switch to the encrypted database.</p> <p>The sample code given to me by the database engineering team is which uses cx_Oracle directly is:</p> <pre><code>import ...
<python><oracle-database><encryption><sqlalchemy>
2023-01-04 21:49:11
2
578
Krish Srinivasan
75,011,620
8,942,319
Adding USER to Dockerfile results in /bin/sh: 1: poetry: not found
<p>Dockerfile:</p> <pre><code>FROM python:3.10 WORKDIR /home/app/my_script COPY pyproject.toml /home/app/my_script COPY poetry.lock /home/app/my_script RUN groupadd -g 9999 app; \ useradd -ms /bin/bash -u 9999 -g app app; \ mkdir /home/app/.ssh; \ ssh-keyscan github.com &gt;&gt; /home/app/.ssh/known_host...
<python><docker><python-poetry>
2023-01-04 21:39:22
1
913
sam
75,011,487
10,792,871
Use ast.literal_eval on all columns of a Pandas Dataframe
<p>I have a data frame that looks like the following:</p> <pre><code>Category Class ========================== ['org1', 'org2'] A ['org2', 'org3'] B org1 C ['org3', 'org4'] A org2 A ['org2', 'org4'] B ... </code></pre> <p>When I read in this data using Pandas, the li...
<python><python-3.x><pandas><lambda><eval>
2023-01-04 21:22:52
2
724
324
75,011,459
2,011,041
How to create set (as value to dict) or add element in case set exists?
<p>I'm iterating over a list of objects that have three int attributes: <code>start</code>, <code>end</code>, <code>data</code>. And I'm trying to add all numbers from <code>start</code> up until <code>end</code> as keys to a dictionary, with the value being a set containing <code>data</code>. So, for example, if objec...
<python><dictionary>
2023-01-04 21:20:30
1
1,397
Floella
75,011,337
7,287,543
In-line substring exchange in a Python string
<p>I have a string that says <code>&quot;Peter has a boat, but Steve has a car.&quot; </code>. I need to change that to <code>&quot;Steve has a boat, but Peter has a car.&quot; </code> The only way I can think of doing this is an ugly three-step <code>replace()</code> with a placeholder:</p> <pre><code>&quot;Peter has ...
<python><string><replace>
2023-01-04 21:07:32
1
1,893
Yehuda
75,011,288
6,612,915
Python List calculation this is not about slicing
<pre><code>list=[3, 1, -1] list [-1]=list [-2] print(list) </code></pre> <p>ok my last post was closed, even though this is not about slicing. There are no semicolons. The question is an exam question from the Python Institute course. I do not understand why the result of this calculation is [3, 1, 1]</p> <p>Can someo...
<python><list>
2023-01-04 21:03:06
2
464
Anna
75,011,155
740,553
How to get the time in ms between two calls in Python
<p>How does one properly get the number of millis between two successive calls? There's a bunch of different ways to get or profile time, and all of them seem to have problems:</p> <ul> <li><code>time.clock()</code> is deprecated</li> <li><code>time.time()</code> is based on the system's clock to determine seconds sinc...
<python><precision><timing>
2023-01-04 20:52:15
1
54,287
Mike 'Pomax' Kamermans
75,011,084
18,205,996
Generating new HTML rows for each Document from firestore in python Django
<p>I have a collection of documents in a Firestore database. I want to create a web form to display all the documents and their fields. I started by streaming all the documents using:</p> <pre><code> docs = db.collection(u'users').stream() </code></pre> <p>and then appending all the docs IDs to a list and pass it t...
<python><html><django><google-cloud-firestore>
2023-01-04 20:44:48
1
597
taha khamis
75,011,003
12,350,966
How to get value_counts normalize=True with pandas agg?
<p>This gives me counts of the # <code>my_other_var</code> that are contained in 'my_var'</p> <p><code>df.groupby('my_var').agg({'my_other_var' : 'value_counts')</code></p> <p>What I want is the percentage of 'my_var' that is comprised of 'my_other_var'</p> <p>I tried this, but does not seem to give me what I expect</p...
<python><pandas>
2023-01-04 20:35:16
1
740
curious
75,010,992
833,208
Why is poetry not updating git+ssh dependency from private repo versioned using git tag?
<p>I have two python projects, lib and app, managed through poetry. Lib is on github in a private repo and the version in its pyproject.toml is 0.2.0. This is tagged in github with git tag v0.2.0.</p> <p>Access to the gh private repo is enabled by adding my ssh public key to my gh account <a href="https://docs.github.c...
<python><git><ssh><python-poetry>
2023-01-04 20:33:56
1
5,039
Robino
75,010,986
18,758,062
Avoid distortring squares/circles in Matplotlib figure with fixed figsize
<p>In a Matplotlib figure with aspect ratio <code>12:5</code>, a square is drawn on <code>ax</code> and 4 circles on <code>ax2</code>. The 4 circles are then redrawn with different colors.</p> <p>However, the square looks like a rectangle, and the circles look like ellipses.</p> <p><a href="https://i.sstatic.net/QMEZ7...
<python><matplotlib>
2023-01-04 20:33:23
1
1,623
gameveloster
75,010,789
803,801
How to typecheck a property with a class decorator
<p>I'm struggling to get this code to properly type check with <code>mypy</code>:</p> <pre><code>from typing import Any class Decorator: def __init__(self, func) -&gt; None: self.func = func def __call__(self, *args: Any, **kwargs: Any) -&gt; Any: return self.func(*args, **kwargs) class Foo: ...
<python><python-decorators><mypy><python-typing>
2023-01-04 20:12:50
2
12,299
gsgx
75,010,637
3,525,780
Replace and += is abismally slow
<p>I've made following code that deciphers some byte-arrays into &quot;Readable&quot; text for a translation project.</p> <pre><code>with open(Path(cur_file), mode=&quot;rb&quot;) as file: contents = file.read() file.close() text = &quot;&quot; for i in range(0, len(contents), 2): # Since it's encoded in UTF16...
<python><string><replace>
2023-01-04 19:55:46
3
1,382
Fusseldieb
75,010,474
11,370,582
KMeans Clustering - Getting "malloc" error
<p>I'm trying to run kmeans clustering on a dataset with ~120,000 datapoints but I am getting a 'malloc' error:</p> <pre><code>python3(2830,0x70000d545000) malloc: *** error for object 0xc0: pointer being freed was not allocated python3(2830,0x70000e54b000) malloc: *** error for object 0xc0: pointer being freed was not...
<python><machine-learning><scikit-learn><malloc><k-means>
2023-01-04 19:37:45
0
904
John Conor
75,010,391
880,783
Why do imports behind `if False` generate local variables?
<p>The following code works as expected:</p> <pre class="lang-py prettyprint-override"><code>from os import name def function(): # if False: # from os import name print(name) function() </code></pre> <p>However, when uncommenting the <code>if False</code> block, the code stops working:</p> <blockquote...
<python><import><scope>
2023-01-04 19:31:43
1
6,279
bers
75,010,371
20,266,647
An error occurred while calling o91.parquet. : java.lang.IllegalStateException: Cannot call methods on a stopped SparkContext
<p>I used this simple python code with focus on spark.sql:</p> <pre><code>from pyspark.sql import SparkSession spark = SparkSession.builder.appName('jist-test').getOrCreate() myDF = spark.read.parquet(&quot;v3io://projects/fs-demo-example/FeatureStore/vct_all_other_basic&quot;) myDF.show(3) </code></pre> <p>and I got ...
<python><apache-spark><pyspark><apache-spark-sql>
2023-01-04 19:29:34
1
1,390
JIST
75,010,343
12,242,085
How to make dummy columns only on variables witch appropriate number of categories and suffisant share category in column?
<p>I have DataFrame in Python Pandas like below (both types of columns: numeric and object):</p> <p>data types:</p> <ul> <li>COL1 - numeric</li> <li>COL2 - object</li> <li>COL3 - object</li> </ul> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>COL1</th> <th>COL2</th> <th>COL3</th> <th>...</th>...
<python><pandas><categories><one-hot-encoding><dummy-variable>
2023-01-04 19:27:06
1
2,350
dingaro
75,010,319
11,644,523
Python extract values in JSON array to form a new key-value pair
<p>Given an array of JSON objects as:</p> <pre><code>arr=[{&quot;id&quot;: &quot;abc&quot;, &quot;value&quot;: &quot;123&quot;}, {&quot;id&quot;: &quot;xyz&quot;, &quot;value&quot;: &quot;456&quot;}] </code></pre> <p>I would like to output a single JSON object like:</p> <pre><code>new_arr={&quot;abc&quot;:123,&quot;xyz...
<python><json>
2023-01-04 19:24:34
4
735
Dametime
75,010,297
1,410,829
Accessing txt file while using module function
<p>I'm attempting to access a .txt file while accessing a module function I made. Problem is I don't think the function can access the text file. The file has data in it. It goes through the motions of trying to populate it. Do I need a <em>init</em>.py? I'm getting now output in my data.csv file that I'm attempti...
<python><text><module>
2023-01-04 19:22:06
2
745
John Verber
75,010,219
1,601,580
how do I pip install something in editable mode using a requirements.txt file?
<p>I tried:</p> <pre><code>pip install -er meta-dataset/requirements.txt </code></pre> <p>doesn't work:</p> <pre><code>(meta_learning) brandomiranda~/diversity-for-predictive-success-of-meta-learning ❯ pip install -er meta-dataset/requirements.txt ERROR: Invalid requirement: 'meta-dataset/requirements.txt' Hint: It loo...
<python><pip>
2023-01-04 19:14:54
1
6,126
Charlie Parker
75,009,890
11,956,484
Round each column in df1 based on corresponding column in df2
<p>df1:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Li</th> <th>Be</th> <th>Sc</th> <th>V</th> <th>Cr</th> <th>Mn</th> </tr> </thead> <tbody> <tr> <td>20.1564</td> <td>-0.0011</td> <td>-0.1921</td> <td>0.0343</td> <td>0.5729</td> <td>0.1121</td> </tr> <tr> <td>19.2871</td> <td>-0.0027</...
<python><pandas>
2023-01-04 18:45:18
2
716
Gingerhaze
75,009,815
4,418,481
Displaying Dash plot without using Web
<p>I have a large dataset of around 500 parquet files with about 42 million samples.</p> <p>In order to read those files I'm using <code>Dask</code> which does a great job.</p> <p>In order to display them, I downsampled the Dask DataFrame in the most basic way (something like dd[::200]) and plotted it using <code>Plotl...
<python><plotly-dash><plotly>
2023-01-04 18:38:30
1
1,859
Ben
75,009,761
10,480,181
Do we need to run load_dotenv() in every module?
<p>I have a <code>.env</code> defined with the following content:</p> <pre><code>env=loc </code></pre> <p>I have three python module that make use of this variable.</p> <pre><code>├── __init__.py ├── cli.py |── settings.py ├── commands │ ├── __init__.py │ └── output.py </code></pre> <p><code>settings.py:</code></p>...
<python><python-3.x><dotenv>
2023-01-04 18:32:20
1
883
Vandit Goel
75,009,474
19,633,374
How to write if condition in when condition - PySpark
<p>I am trying to add an if condition in F. when in a pyspark column my code:</p> <pre><code>df = df.withColumn(&quot;column_fruits&quot;,F.when(F.col('column_fruits') == &quot;Berries&quot; if(&quot;fruit_color&quot;)== &quot;red&quot;: return &quot;cherries&quot; elif(&quot;fruit_color&quot;) == &quot;pink&quot...
<python><dataframe><apache-spark><pyspark>
2023-01-04 18:01:27
1
642
Bella_18
75,009,431
11,462,274
Maintain a default of True/False for each date
<p>During the day, new investment possibilities are registered, but the results (<code>lay</code> column) are only registered at midnight each day.</p> <p>So let's assume this <code>CSV</code>:</p> <pre class="lang-none prettyprint-override"><code>clock_now,competition,market_name,lay 2022/12/30,A,B,-1 2022/12/31,A,B,1...
<python><pandas><dataframe><group-by><cumsum>
2023-01-04 17:57:23
1
2,222
Digital Farmer
75,009,352
9,783,831
Build python package using swig and setuptools
<p>I have a dll file that I am wrapping using swig. Then I want to create a package to distribute the python extension.</p> <p>The folder structure looks like:</p> <pre><code>- myPackage - __init__.py - my_interface.i - my_header.hpp - my_dll.dll - my_lib.lib - setup.py - pyproject.toml - MANIFEST.in </c...
<python><setuptools><swig>
2023-01-04 17:49:23
0
407
Thombou
75,009,287
2,410,605
Selenium Python Am I selecting a drop down item the best way?
<p>I'm working on my first-ever Selenium Python project and am baby stepping through it. I have an inconsistent issue and want to see if there's a better way to code it.</p> <p>I need to select &quot;Active&quot; from a drop-down menu. I'm selecting the drop down input element and clicking on it. This will open a child...
<python><selenium-webdriver><selenium-chromedriver>
2023-01-04 17:44:42
1
657
JimmyG
75,008,898
5,088,513
Count python dataclass instances
<p>what is the best way to achieve class counter implementation with dataclass</p> <pre><code>class geeks:          # this is used to print the number     # of instances of a class     counter = 0        # constructor of geeks class     def __init__(self,name):         self.name = name         # increment         gee...
<python><python-dataclasses>
2023-01-04 17:10:18
0
633
Sylvain Page
75,008,868
8,864,226
Python: Improve this by making the algorithm less complex
<p>I have a working block of code, but it seems there should be a more efficient algorithm, presumably with less loops or using a library/module.</p> <p>This example version of the code takes a list of strings, reverse sort by <code>len()</code>, then build a new list:</p> <pre class="lang-py prettyprint-override"><cod...
<python><algorithm><sorting>
2023-01-04 17:07:28
1
6,097
James Risner
75,008,833
893,866
How to transfer TRC20 token using tronpy?
<p>I want to send USDT TRC20 tokens using <a href="https://tronpy.readthedocs.io/" rel="nofollow noreferrer">tronpy</a>, while i succeded to transfer TRX, same approach failed for the TRC20 tokens, here's my code:</p> <pre><code>import codecs from tronpy.keys import PrivateKey from hexbytes import HexBytes def transfe...
<python><smartcontracts><tron><tronpy>
2023-01-04 17:04:15
2
921
zfou
75,008,676
5,041,045
why does python allows me to access elements not specified in __all__ within a module?
<p>I have the following directory structure:</p> <pre><code>. ├── main.py └── myproj ├── __init__.py └── mymodule.py </code></pre> <p>This is <strong>mymodule.py</strong>:</p> <pre><code>hello = &quot;hello&quot; byebye = &quot;byebye&quot; class sayHello(): def __init__(self): print(&quot;Hello Wor...
<python><import><module>
2023-01-04 16:51:33
0
3,022
Simon Ernesto Cardenas Zarate
75,008,445
4,364,157
Why CLOB slower than VARCHAR2 in Oracle?
<p>Currently, we have a table containing a varchar2 column with 4000 characters, however, it became a limitation as the size of the 'text' being inserted can grow bigger than 4000 characters, therefore we decided to use CLOB as the data type for this specific column, what happens now is that both the insertions and sel...
<python><oracle-database>
2023-01-04 16:31:17
3
1,026
Bruno Assis
75,008,347
11,370,582
Installed 2 Versions of Anaconda - libraries don't work
<p>I have mistakenly installed 2 versions of Anaconda on my 2019 Mac Pro and now I cannot access python libraries.</p> <p>In an attempt to update anaconda I installed another version using homebrew instead of the GUI installer and it seems to have changed the path to my libraries. Now when I try to run a python script ...
<python><macos><visual-studio-code><path><anaconda>
2023-01-04 16:23:49
1
904
John Conor
75,008,222
10,886,283
Assign specific colors to array columns without explicit iteration when plotting in matplotlib
<p>It is helpful sometimes to do <code>plt.plot(x, y)</code> when <code>y</code> is a 2D array due to every column of <code>y</code> will be plotted against <code>x</code> automatically in the same subplot. In such a case, line colors are set by default. But is it possible to customize colors with something similar to ...
<python><numpy><matplotlib>
2023-01-04 16:14:12
1
509
alpelito7
75,007,950
4,051,219
Pandas Group by column and concatenate rows to form a string separated by spaces
<p>I have a dataset that looks like:</p> <pre class="lang-py prettyprint-override"><code>my_df = pd.DataFrame({&quot;id&quot;: [1, 1, 1], &quot;word&quot;: [&quot;hello&quot;, &quot;my&quot;, &quot;friend&quot;]}) </code></pre> <p>And I would like to group by id and concatenate the word (without changing the order), th...
<python><pandas><dataframe>
2023-01-04 15:50:04
2
510
dpalma
75,007,763
10,891,675
Why unit tests fil whereas the program runs?
<p>I'm asked to develop unit tests for a program which is such badly developed that the tests don't run... but the program does. Thus, I need to explain the reason why and I actually don't know!</p> <p>Here is a piece of code that intends to represent the code I need to test:</p> <pre><code>from services import myModul...
<python><unit-testing>
2023-01-04 15:33:22
1
696
Christophe
75,007,630
12,084,907
UnicodeEncodeError: 'charmap' codec can't encode characters in position 202-203: character maps to <undefined>
<p>I am trying to write a data stored in a dataframe to a csv and am running into the following error:</p> <pre><code>UnicodeEncodeError: 'charmap' codec can't encode characters in position 202-203: character maps to &lt;undefined&gt; </code></pre> <p>I looked at <a href="https://stackoverflow.com/questions/27092833/un...
<python><python-3.x><pandas><csv>
2023-01-04 15:23:18
1
379
Buzzkillionair
75,007,603
14,882,883
Combining dictionaries with a particular key: Python
<p>I have the following dictionaries generated using for loop and I would to combine and dump them into one <code>YAML</code> file.</p> <p>dict1</p> <pre><code>{'name': 'test', 'version': '0011 * *? *', 'datasets': [{ 'dataset': 'dataset_a', 'match_on': ['code'], 'columns': {'include': ['aa', 'bb', ...
<python><dictionary><yaml><pyyaml>
2023-01-04 15:20:45
1
608
Hiwot
75,007,568
329,829
How to specify the parameter for FeatureUnion to let it pass to underlying transformer
<p>In my code, I am trying to access the <code>sample_weight</code> of the <code>StandardScaler</code>. However, this <code>StandardScaler</code> is within a <code>Pipeline</code> which again is within a <code>FeatureUnion</code>. I can't seem to get this parameter name correct: <code>scaler_pipeline__scaler__sample_we...
<python><pandas><scikit-learn><pipeline>
2023-01-04 15:18:26
1
5,232
Olivier_s_j
75,007,444
10,687,615
Extract Date/time from string
<p>I have a dataframe that looks like this:</p> <pre><code>ID RESULT 1 Pivot (Triage) Form Entered On: 12/30/2022 23:20 EST Performed On: 12/30/2022 23:16 EST </code></pre> <p>I would like to extract both datetime variables so the new dataframe looks like this:</p> <pre><code>ID END_TIME ...
<python><pandas>
2023-01-04 15:10:09
2
859
Raven
75,007,435
8,864,226
Replace None in list with average of last 3 non-None entries when the average is above the same entry in another list
<p>I have two lists:</p> <pre class="lang-py prettyprint-override"><code>dataa = [11, 18, 84, 51, 82, 1, 19, 45, 83, 22] datab = [1, None, 40, 45, None, None, 23, 24, None, None] </code></pre> <p>I need to replace all None in datab for any instance where the prior 3 entries are &gt; than the data entry (see walk-throug...
<python><list><loops><average>
2023-01-04 15:09:35
1
6,097
James Risner
75,007,399
13,543,225
Multiple pip locations and versions, and pip not updating - Ubuntu on WSL
<h1>Why are there so many versions and locations of pip?</h1> <p>When I run <code>pip install -U pip</code> it says it's updating to a newer version, then when I run <code>pip --version</code> it's the un-updated version. I am on WSL.</p> <p><a href="https://i.sstatic.net/z47qa.png" rel="nofollow noreferrer"><img src="...
<python><pip>
2023-01-04 15:07:08
2
650
j7skov
75,006,928
1,128,632
Sagemaker training job fails ""FileNotFoundError: [Errno 2] No such file or directory: '/opt/ml/input/data/training/annotations.json'"
<p>When trying to use a Quick Start model in AWS Sagemaker, specifically for Object Detection, all fine tune models fail to train.</p> <p>I'm attempting to fine tune a <code>SSD Mobilenet V1 FPN 640x640 COCO '17</code> model.</p> <p>The annotations and images are accepted, but after initializing the training session, t...
<python><tensorflow><machine-learning><amazon-sagemaker><amazon-sagemaker-studio>
2023-01-04 14:30:46
1
4,678
Dylan Pierce
75,006,911
1,200,914
How can I dynamically observe/change limits of a Autoscale group?
<p>I want to modify the number of minimum/maximum/target instances of an autoscale group and see if there's any instance on from this autoscale group, all dynamically using the AWS SDK for Python. How can I do it?</p> <p>I'm unable to find it from literature.</p>
<python><amazon-web-services><aws-auto-scaling>
2023-01-04 14:29:53
2
3,052
Learning from masters
75,006,868
12,886,858
Adding multiple foreign keys from same model (FastAPI and SqlAlechemy)
<p>I am trying to have two foreign keys from User table inside Ban table. Here is how I did it:</p> <pre><code>class Ban(Base): __tablename__ = &quot;ban&quot; ban_id = Column(Integer, primary_key=True, index=True) poll_owner_id = Column(Integer) banned_by = Column(String , ForeignKey('user.username',...
<python><sqlalchemy>
2023-01-04 14:26:30
1
633
Vedo
75,006,842
7,848,740
Reduce dimension of Docker Python Image
<p>I'm building a Python Image in Docker and I need it to be the smaller possible.</p> <p>I'm using venv on my PC and the app is basically a unqiue file .py of 3.2kb. I'm using Python 3.10 and the following libraries</p> <pre><code>import feedparser import sched import time import dbm import paho.mqtt.client as mqtt im...
<python><python-3.x><docker><dockerfile><alpine-linux>
2023-01-04 14:23:57
2
1,679
NicoCaldo
75,006,821
4,380,853
What's the best way to create flink table for time series data
<p>I have aws kinesis data format as follows:</p> <pre><code>[ { 'customer_id': UUID, 'sensor_id': UUID, 'timestamps': [ ... ], 'values': [ ...] }, ... ] </code></pre> <p>I later want to apply a Sliding Window on the data based on event time (which is included in time stamps....
<python><apache-flink><pyflink>
2023-01-04 14:22:48
1
2,827
Amir Afianian
75,006,769
1,128,648
NaN values when new column is added to pandas DataFrame based on an existing column data
<p>I am trying to create a new column in pandas DataFrame which is based on another existing column. I am extracting characters <code>10:19</code> from column <code>Name</code> and adding it as a new column <code>expiry</code> . But most of the datas in <code>expiry</code> are showing as <code>nan</code>. I am new to ...
<python><pandas>
2023-01-04 14:18:19
1
1,746
acr
75,006,733
3,657,967
Python Random Module sample method with setstate notworking
<p>I am wondering if I am doing it wrong when setting the random seed and state. The random number generated from the random.sample seems not predictable. Does anyone know why? Thanks.</p> <pre><code>&gt;&gt;&gt; state = random.getstate() &gt;&gt;&gt; random.seed(7) &gt;&gt;&gt; x = list(range(10)) &gt;&gt;&...
<python><random>
2023-01-04 14:15:34
2
479
acai
75,006,683
12,760,550
Create column that identify first date of another column pandas dataframe
<p>Imagine I have a dataframe with employee IDs, their Hire Dates, the contract type (can be Employee or Contractor) and the company they where hired. Each employee may have as many rows for the same, or different companies and the same or different contract types.</p> <pre><code>ID Hire Date Contract Type Com...
<python><pandas><lambda><merge>
2023-01-04 14:11:22
1
619
Paulo Cortez
75,006,666
6,187,009
In python, how to transfer file in bytes with GRPC in a right way?
<p>For some reason, I want to transfer file (not in stream) with grpc in python. The protobuf and python code are as follows</p> <ul> <li>protobuf</li> </ul> <pre><code>syntax = &quot;proto3&quot;; import &quot;google/protobuf/empty.proto&quot;; package xxxx; service gRPCComServeFunc { rpc sendToClient(FileRequest)...
<python><grpc><grpc-python>
2023-01-04 14:10:06
0
974
david
75,006,356
7,583,084
How to find the whole word with re.findall?
<p>this is my code:</p> <pre><code>str_list = 'Hallo Welt Halloer' conversations_counter = len(re.findall(&quot;Hallo&quot;, str_list)) print(conversations_counter) </code></pre> <p>The result is 2! But I just want to have a match for the whole word 'Hallo'. The word 'Hallo' in the word 'Halloer' should not be counted...
<python><findall>
2023-01-04 13:42:18
1
301
HansMuff
75,006,287
11,462,274
How to make a cumulative sum in blocks with results according to until the day before instead of each line?
<p>Example of my CSV:</p> <pre class="lang-none prettyprint-override"><code>clock_now,competition,market_name,back,lay 2022/08/09,South African Premier Division,Over/Under 0.5 Goals,0.28985,-1.0 2022/08/12,South African Premier Division,Over/Under 0.5 Goals,-1.0,1.28 2022/09/07,South African Premier Division,Over/Under...
<python><pandas><group-by><cumsum>
2023-01-04 13:36:30
1
2,222
Digital Farmer
75,006,181
10,963,018
How can I tell if wx.media.MediaCtrl was included in my installation of wxPython?
<p><strong>What's the problem:</strong> I am trying to get wxPython, specifically wx.media.MediaCtrl, working on my Raspberry Pi running Raspbian bullseye. I'm trying to play an mp4 video when a button is pushed and I keep getting errors like this:</p> <pre><code>Traceback (most recent call last): File &quot;/home/[U...
<python><linux><raspberry-pi><wxpython><wxwidgets>
2023-01-04 13:28:35
1
422
Jkkarr
75,006,095
8,510,149
Subclass EarlyStopper in scikit-optimize
<p>I can't figure out how to subclass EarlyStopper to use it as callback in scikit-optimize (gp_minimize). Based on the documentation. How should I think when subclassinging?</p> <p>Documentation: <a href="https://scikit-optimize.github.io/stable/modules/generated/skopt.callbacks.EarlyStopper.html#skopt.callbacks.Early...
<python><callback><subclassing><python-class><scikit-optimize>
2023-01-04 13:21:56
0
1,255
Henri
75,005,916
5,114,495
How to run only a part of the DAG in Airflow?
<p>Is it possible to run <strong>only a part of the DAG</strong> in Airflow?</p> <p>I know one can run a single task. But is it possible to run a set of linked tasks within the DAG?</p>
<python><python-3.x><airflow><airflow-2.x>
2023-01-04 13:07:42
1
1,394
cavalcantelucas
75,005,699
12,760,550
Create "Yes" column according to another column value pandas dataframe
<p>Imagine I have a dataframe with employee IDs, their Contract Number, and the Company they work for. Each employee can have as many contracts as they want for the same company or even for different companies:</p> <pre><code>ID Contract Number Company 10000 1 Abc 10000 2 Zxc 10000 3 ...
<python><pandas><dataframe><multiple-columns>
2023-01-04 12:51:00
2
619
Paulo Cortez
75,005,594
10,658,339
merge pandas dataframe from two columns
<p>I have two dataframes with a composite primary key, that is, two columns identify each element, and I would like to merge these dataframes into one. How can I do that ? My example is:</p> <pre><code>import random import pandas as pd import numpy as np A = ['DF-PI-05', 'DF-PI-09', 'DF-PI-10', 'DF-PI-15', 'DF-PI-16', ...
<python><dataframe><join><merge><concatenation>
2023-01-04 12:41:45
1
527
JCV
75,005,560
8,757,033
How to clear a terminal in pyscript (py-terminal)
<p>The idea is to clear the output of the python REPL provided by pyscript, embedded in a website.</p> <p>I have tried the <a href="https://stackoverflow.com/questions/517970/how-to-clear-the-interpreter-console">regular ways</a> used in the OS console (<code>os.system(&quot;clear&quot;)</code>, <code>print(&quot;\033c...
<python><web-frontend><pyscript>
2023-01-04 12:38:26
1
2,229
Miguel
75,005,513
6,400,443
Does Pandas "cross" merge keep order of both left and right?
<p>I would like to know if the merge operation using <code>how=&quot;cross&quot;</code> will keep my lines order on the left and right side, to be more clear, I except something like that :</p> <pre><code>df1 = pd.DataFrame([&quot;a&quot;, &quot;b&quot;, &quot;c&quot;]) df2 = pd.DataFrame([&quot;1&quot;, &quot;2&quot;,...
<python><pandas>
2023-01-04 12:33:58
1
737
FairPluto
75,005,451
925,179
flask --help displays Error: Could not import 'server'
<p>I cloned project <a href="https://github.com/sayler8182/MockServer" rel="nofollow noreferrer">https://github.com/sayler8182/MockServer</a>, go to project directory and run ./scripts/init.sh</p> <p>Init.sh code:</p> <pre class="lang-py prettyprint-override"><code>pip3 install virtualenv python3 -m venv venv . venv/b...
<python><macos><flask><iterm2>
2023-01-04 12:28:33
1
341
granan
75,005,416
5,114,495
Multiple inheritance using `BaseBranchOperator` in Airflow
<p>Can one use multiple inheritance using <code>BaseBranchOperator</code> in Airflow?</p> <p>I want to define an operator like:</p> <pre><code>from airflow.models import BaseOperator from airflow.operators.branch import BaseBranchOperator class MyOperator(BaseOperator, BaseBranchOperator): def execute(self, cont...
<python><python-3.x><airflow><airflow-2.x>
2023-01-04 12:24:57
2
1,394
cavalcantelucas
75,005,351
7,462,275
Problem to solve sympy symbolic equation with tanh
<p>I write the following equation <code>my_Eq</code>. <code>a</code> and <code>b</code> are reals.</p> <pre><code>a,b=sp.symbols('a,b',real=True) my_Eq=sp.Eq(sp.tanh(a),b) </code></pre> <p>When I tried to solve it : <code>sp.solve(my_Eq,a)</code>, two solutions are found : <code>[log(-sqrt(-(b + 1)/(b - 1))), log(sqrt(...
<python><sympy><hyperbolic-function>
2023-01-04 12:19:36
1
2,515
Stef1611
75,005,300
801,618
How can I fix my DSL grammar to parse a problem statement?
<p>I've been tasked with creating a grammar for a legacy DSL that's been in use for over 20 years. The original parser was written using a mess of regular expressions, so I've been told.</p> <p>The syntax is generally of the &quot;if this variable is n then set that variable to m&quot; style.</p> <p>My grammar works fo...
<python><parsing><dsl><lark-parser>
2023-01-04 12:15:42
1
436
MerseyViking
75,005,072
2,601,357
Flask Route: pattern matching to exclude certain routes
<p>I have the following routes already set up:</p> <pre><code> @app.route(&quot;/&quot;) @app.route(&quot;/index&quot;) def index(): ... @app.route(&quot;/projects/&lt;projname&gt;&quot;) def projects(projname): ... @app.route(&quot;/extras/&quot;) def extras(): ... @app.route(&quot;/extras/&lt;topic&gt...
<python><flask>
2023-01-04 11:54:26
1
564
asuprem
75,005,044
1,114,453
Add version to pipeline
<p>Is there any standard or recommended way to add a version number to a pipeline (written in snakemake in my case)?</p> <p>For example, I have this <a href="https://github.com/glaParaBio/genomeAnnotationPipeline" rel="nofollow noreferrer">pipeline</a> and just now I added a <code>CHANGELOG.md</code> file with the curr...
<python><python-3.x><version><pipeline><snakemake>
2023-01-04 11:52:26
1
9,102
dariober
75,004,957
15,406,157
Python virtual environment does not recognize its own site packages
<p>I created a virtual environment <code>myenv1</code> on machine #1.</p> <p>I installed some packages in this virtual environment.</p> <p><code>pip3 freeze</code> shows me this list of packages:</p> <pre class="lang-none prettyprint-override"><code>cffi==1.15.1 chardet==5.0.0 click==8.0.4 cryptography==39.0.0 dataclas...
<python><python-3.x><virtualenv>
2023-01-04 11:44:42
1
338
Igor_M
75,004,683
14,720,380
How do I override the precedence of a header file when using pybind11 and cmake?
<p>I have a header file called <code>node.h</code> within my C++ project, where I am now writing python bindings. Within python, there is also a header file called <a href="https://github.com/python/typed_ast/blob/master/ast27/Include/node.h" rel="nofollow noreferrer"><code>node.h</code></a>. I am creating my Python bi...
<python><c++><header-files><pybind11>
2023-01-04 11:21:51
0
6,623
Tom McLean
75,004,607
12,040,751
Type annotation for non iterables
<p>I want to write an annotation for variables that are not iterables.</p> <pre><code>def f(x: NonIterable): if not isinstance(x, Iterable): pass else: raise TypeError </code></pre> <p>As you can see in the function the definition of a <code>NonIterable</code> is clear, but I am struggling to tu...
<python><python-typing>
2023-01-04 11:14:54
0
1,569
edd313
75,004,599
1,315,472
Monitor the progress of pyspark's `applyInPandas()`
<p>In Databricks, we use the Python command</p> <pre><code>spark_df.groupBy(&quot;variable1&quot;).applyInPandas(python_function, schema=schema) </code></pre> <p>to run the <code>python_function</code> on subsets of the <code>spark_df</code>. The command works fine and the computation also scales to 100+ CPUs. However,...
<python><pyspark><parallel-processing><databricks><hpc>
2023-01-04 11:14:18
1
2,566
Nairolf
75,004,590
8,610,286
How to put data in a PyPi python package and retrieve via pip?
<p>I am trying to package some data alongside the scripts within a package of mine: <a href="https://pypi.org/project/taxon2wikipedia/0.0.4/" rel="nofollow noreferrer">https://pypi.org/project/taxon2wikipedia/0.0.4/</a></p> <p>The source distribution seems to contain the files that I need, but when trying to use the p...
<python><pypi>
2023-01-04 11:13:19
2
349
Tiago Lubiana
75,004,494
159,072
TypeError: Object of type Response is not JSON serializable (2)
<p>I have been trying to serialize an SQLAlchemy model so that I can pass a number of data from flask server to an html socketio client.</p> <p>I am trying the following <a href="https://medium.com/@mhd0416/flask-sqlalchemy-object-to-json-84c515d3c11c" rel="nofollow noreferrer">where an object is frirst converted into ...
<python><flask><flask-socketio>
2023-01-04 11:05:25
2
17,446
user366312
75,004,379
5,058,026
Python assign tuple to set() without unpacking
<p>How can I assign a <code>tuple</code> to a <code>set</code> without the members being unpacked and added separately?</p> <p>For example (python 3.9.11):</p> <pre><code>from collections import namedtuple Point = namedtuple('Point', 'x y') p = Point(5, 5) set(p) </code></pre> <p>produces <code>{5}</code>, whereas I wo...
<python><set><iterable-unpacking>
2023-01-04 10:55:35
3
1,439
Martin CR
75,004,270
10,737,778
Is it possible to show __init_subclass__ docstring on the subclass?
<p>Let's say I have a class that implement __init_subclass__ with two parameters:</p> <pre><code>class Foo: def __init_subclass__(name: str, surname: str): &quot;&quot;&quot; name: The name of the user surname: The surname of the user &quot;&quot;&quot; ... </code></pre> <p>...
<python><python-3.x><docstring>
2023-01-04 10:45:11
1
441
CyDevos
75,004,129
3,381,215
Snakemake/miniforge: Nothing provides libgcc-ng >=12 needed by freebayes-1.3.6-hbfe0e7f_2
<p>I am running a Snakemake NGS data analysis pipeline, one rule uses Freebayes, it's env looks like this:</p> <pre class="lang-yaml prettyprint-override"><code>name: freebayes channels: - bioconda dependencies: - freebayes=1.3.6 </code></pre> <p>While creating the env this error occurs:</p> <pre class="lang-bash pr...
<python><conda><bioinformatics><snakemake><mini-forge>
2023-01-04 10:32:33
2
1,199
Freek
75,004,108
1,029,902
Constructing GET url to retrieve JSON from JS button click function
<p>I am trying to scrape this page using requests and BeautifulSoup in Python but the page is in Javascript so I am including both tags for the question. The page is</p> <p><a href="https://untappd.com/v/southern-cross-kitchen/469603" rel="nofollow noreferrer">https://untappd.com/v/southern-cross-kitchen/469603</a></p>...
<javascript><python><web-scraping><get>
2023-01-04 10:30:29
1
557
Tendekai Muchenje
75,004,065
12,934,163
Receiving TypeError, when PandasCursor is imported from pyathena.pandas.cursor
<p>I want to read an excel file into <code>pandas</code> from an AWS S3 bucket. Everything worked fine But when I import <code>PandasCursor</code>, which I need for another part of the code, I receive the following error message:</p> <pre><code>import pandas as pd import s3fs from pyathena import connect from pyathena....
<python><pandas><amazon-web-services><amazon-s3><pyathena>
2023-01-04 10:26:03
0
885
TiTo
75,003,903
9,262,339
Failed to connect to postgre database inside docker container
<p><strong>docker-compose.yaml</strong></p> <pre><code>version: '3.9' services: web: env_file: .env build: . command: sh -c &quot;alembic upgrade head &amp;&amp; uvicorn main:app --host 0.0.0.0 --port 8000&quot; volumes: - .:/app ports: - 8000:8000 depends_on: - db - r...
<python><docker><docker-compose>
2023-01-04 10:11:03
1
3,322
Jekson
75,003,869
970,872
how to handle timestamps from summer and winter when converting strings in polars
<p>I'm trying to convert string timestamps to polars datetime from the timestamps my camera puts in it RAW file metadata, but polars throws this error when I have timestamps from both summer time and winter time.</p> <pre><code>ComputeError: Different timezones found during 'strptime' operation. </code></pre> <p>How do...
<python><datetime><timestamp><strftime><python-polars>
2023-01-04 10:07:32
2
557
pootle
75,003,854
19,580,067
Split the single alphanumeric string column to two columns as numbers and alphabets
<p>I have a single alphanumeric string column that has to be split into two different columns: numbers and alphabet. But the thing is we just need to split the first part of numbers from string and the remaining alphanumeric should remain same in 2nd column</p> <p>For example:</p> <div class="s-table-container"> <table...
<python><dataframe><python-re>
2023-01-04 10:06:15
2
359
Pravin
75,003,817
20,051,041
How to remove unexpected hover value in Plotly Express bar plot, Python
<p>I am using plotly express for creating a horizontal bar plot. After adding <code>hovertamplate</code>, an ugly zero appeared in hover box (always a zero for each element). What is it and how can I get rid of it? Thanks.</p> <pre><code>fig = px.bar(df, orientation = 'h') fig.update_traces(hovertemplate = &quot;%{lab...
<python><plotly><hover>
2023-01-04 10:03:05
1
580
Mr.Slow
75,003,385
8,788,960
What is equivalent Protocol of Python Callable?
<p>I always though that Callable is equivalent to having the dunder <code>__call__</code> but apparently there is also <code>__name__</code>, because the following code is correct for <code>mypy --strict</code>:</p> <pre class="lang-py prettyprint-override"><code>def print_name(f: Callable[..., Any]) -&gt; None: pr...
<python><mypy><python-typing>
2023-01-04 09:25:04
1
1,171
hans
75,003,376
1,773,702
How to capture the error logs from Airflow and send it in mail?
<p>We are trying to report the failures that occur during Airflow job execution and capture the exceptions from logs and send it in email .</p> <p>Currently we display following things in the failure email written in pyt.</p> <pre><code>failure_msg = &quot;&quot;&quot; :red_circle: Task Failed. ...
<python><airflow>
2023-01-04 09:24:42
1
949
azaveri7
75,003,271
10,950,656
Iterate over rows while targeting columns two at a time
<p><code>cols_df</code> represents the chunk of the DataFrame in which I want to be able to perform multiple operations but, each time, target two columns along with the first one. I sort the selected columns from small to large in each round (ex. '0', '2', '3' columns in first round, and '0', '4', '5' columns in secon...
<python><pandas>
2023-01-04 09:16:05
1
481
Maya_Cent
75,003,123
5,138,888
How to make a figure of a keyboard where each key has its own color
<p>I would like to prepare images of keyboards where each key can be assigned a different color. I have seen the Python <a href="https://pypi.org/project/keyboardlayout/" rel="nofollow noreferrer">keyboardlayout</a> package but it is not clear how to control the color of the keys. I would prefer to use existing Pytho...
<python><matplotlib><keyboard-layout><color-mapping>
2023-01-04 09:03:34
1
656
ranlot
75,002,560
5,805,893
Install Local Python Package with pip
<p>I'm building a python package to use for 'global' functions (i.e. stuff that I will use in multiple other projects). I have built the package using <code>py -m build</code> and it then puts the <code>MyPackage-0.1.0.tar.gz</code> into the <code>dist</code> directory in my folder.</p> <p>My goal is to be able to run ...
<python><pip>
2023-01-04 08:10:52
4
1,261
Michael Barrowman
75,002,460
6,213,883
How to pip install from a private artifactory?
<p>A private artifactory is available. We pushed a Python lib into it using <code>Twine</code>:</p> <pre><code>/python-XYZ/mylib/version/mylib-version.tar.gz </code></pre> <p>However, I do not understand how we can get this library using <code>pip install</code>.</p> <p>I have tried the following (based on <a href="htt...
<python><pip><artifactory>
2023-01-04 08:00:30
1
3,040
Itération 122442