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
74,852,873
626,664
How to use map to process column?
<p>I have a pandas dataframe like this,</p> <pre><code>import pandas as pd data = { &quot;calories&quot;: [420, 380, 390], &quot;duration&quot;: [50, 40, 45] } #load data into a DataFrame object: df = pd.DataFrame(data) calories duration 0 420 50 1 380 40 2 390 45 </co...
<python><pandas>
2022-12-19 15:52:36
2
1,559
Droid-Bird
74,852,857
8,901,144
Pyspark multiply only some Column Values when condition is met, otherwise keep the same value
<p>I have the following dataset</p> <pre><code>id col1 ... col10 quantity 0 2 3 0 1 1 4 2 2 0 4 2 3 2 2 0 </code></pre> <p>I would like to multiply the values of col1 to col10 by 2 only when quantity is equal 2, otherwise I would like to keep the pre...
<python><pyspark>
2022-12-19 15:51:35
1
1,255
Marco
74,852,817
1,028,270
Is there a way to define different pytest "profiles" in setup.cfg or pyproject.toml?
<p>I want to define two different &quot;profiles&quot; for my tests and I'm using setup.cfg. I want to know if it's possible to configure this all under <code>[tool:pytest]</code>.</p> <p>I want to do more than just change markers I want to change other settings too.</p> <p>The two different executions would look somet...
<python><python-3.x><pytest>
2022-12-19 15:49:05
0
32,280
red888
74,852,776
1,039,247
List RavenDB collections, using py-ravendb
<p>I'm trying to query or list all collections in a RavenDB database, using <a href="https://github.com/ravendb/ravendb-python-client" rel="nofollow noreferrer">RavenDB's Python Client</a>.</p> <p>So far I've come to something like:</p> <pre class="lang-py prettyprint-override"><code>URLS = ['http://localhost:8080'] DB...
<python><ravendb><ravendb5>
2022-12-19 15:44:46
1
9,632
Juliën
74,852,748
12,084,907
PYODBC Only returning values of the first query in a stored procedure
<p>I am trying to make a script that will run a stored procedure and then return the values. A simple enough script. As I run the script it is only returning the output of the first query in my stored procedure. When the call is made I have the values being appended to a list. Once the list is created I have it printin...
<python><sql><ssms><pyodbc>
2022-12-19 15:42:26
1
379
Buzzkillionair
74,852,600
10,620,003
Select the columns between two columns which we have only the name of them
<p>I have a dataframe and I want to choose the columns between two different column which I only have their name. For example, in the following df, I want to select the columns between column <code>'a1'</code> and <code>'a4'</code>. I know that I can <code>df[['a1','a2', 'a3', 'a4']]</code>. However, my df is a very la...
<python><pandas>
2022-12-19 15:32:24
1
730
Sadcow
74,852,339
3,625,770
No Module Error in Pycharm ONLY When Using A Notebook
<p>I am trying to import a method from a module outside the current module. While I can do this from a script without any issue, when I try it from inside a Jupyter notebook, it fails. How do you suggest I investigate the issue?</p> <p>Example: Imagine these be my directories.</p> <pre><code>- module_1 --- __inte__.py ...
<python><module><jupyter-notebook><pycharm><python-3.10>
2022-12-19 15:09:31
0
1,744
Azim
74,852,234
14,640,406
How to query the highest altitude within an area of interest in a DTED?
<p>I have a rectangular area of interest, and each vertex of this rectangle is defined by a pair of coordinates (latitude, longitude).</p> <p>Parsing a DTED, how could I find the highest altitude within this rectangular region? I'm using the <a href="https://github.com/bbonenfant/dted" rel="nofollow noreferrer">dted li...
<python><gis><gdal><gdal-python-bindings>
2022-12-19 15:00:03
1
309
carraro
74,852,225
11,861,874
AttributeError: module 'numpy' has no attribute 'typeDict'
<p>I am trying to install TensorFlow in Python. I am getting the following error message, I tried uninstalling NumPy and re-installing NumPy but still getting the same error message. How to resolve this issue?</p> <pre><code>AttributeError: module 'numpy' has no attribute 'typeDict' </code></pre>
<python><numpy><tensorflow>
2022-12-19 14:59:12
14
645
Add
74,852,137
8,224,266
How to read csv with multi row-column data with Pandas
<p>I have csv files with thousands of records intended for import somewhere else and the format they're in is only easy to look at but not reading for importing. Here is a sample of the record structure:</p> <p><a href="https://i.sstatic.net/eUH3H.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/eUH3H.png...
<python><pandas><csv>
2022-12-19 14:52:51
0
1,249
Redgren Grumbholdt
74,852,123
12,366,110
Duplicate rows according to a function of two columns
<p>My initial example dataframe is in the following format:</p> <pre><code>&gt;&gt;&gt; import pandas as pd &gt;&gt;&gt; d = {'n': ['one', 'two', 'three', 'four'], 'initial': [3, 4, 10, 10], 'final': [3, 7, 11, 7],} &gt;&gt;&gt; df = pd.DataFrame(d) &gt;&gt;&gt; df n initial final 0 one ...
<python><pandas><dataframe>
2022-12-19 14:51:40
2
14,636
CDJB
74,852,107
4,327,368
Pytorch Linear regression 1x1d, consistantly wrong slope
<p>I am mastering pytorch here, and decided to implement very simple 1 to 1 linear regression, from height to weight.</p> <p>Got dataset: <a href="https://www.kaggle.com/datasets/mustafaali96/weight-height" rel="nofollow noreferrer">https://www.kaggle.com/datasets/mustafaali96/weight-height</a> but any other would do n...
<python><numpy><pytorch><linear-regression>
2022-12-19 14:50:44
4
304
Timo Junolainen
74,852,058
5,562,041
Does parser type conversion happen inside django tests?
<p>I have defined a custom argument parser</p> <pre><code>from dateutil.relativedelta import relativedelta def custom_parser(value): # Do some actions with value return relativedelta(...) </code></pre> <p>I the use this in a management command as</p> <pre><code>parser.add_argument( &quot;--tes&quot...
<python><django><argparse>
2022-12-19 14:46:00
0
2,249
E_K
74,851,990
1,357,340
Windows scripting can't import ctypes module under Python 3.11.1
<p>I just ran into a snag after upgrading to Python 3.11.1. Running Python 3.10.1 the <code>ctypes</code> module imports with no problems. Same under Windows scripting using the <code>pywin32</code> package. With 3.11.1 importing <code>ctypes</code> directly still works. However, under Windows scripting using the pywin...
<python>
2022-12-19 14:40:25
1
338
Bob Kline
74,851,950
12,131,472
How to calculate month-to-date and year-to-date averages by category in a dataframe?
<p>I have a dataframe of several categories of time series of one year which looks like this:</p> <pre><code> category date price 0 A 2022-12-19 5 1 A 2022-12-16 5 2 A 2022-12-15 21 3 A 2022-12-14 21 4 A 2022-12-13 15 5 A 2022-12-12 ...
<python><pandas><time-series>
2022-12-19 14:37:20
1
447
neutralname
74,851,861
14,649,310
How to update a property for all dataclass objects in a list?
<p>I have a list of objects of the following type:</p> <pre><code>@dataclass class Feature: name: str active: bool </code></pre> <p>and my list is:</p> <pre><code>features = [Feature(&quot;name1&quot;,False), Feature(&quot;name2&quot;,False), Feature(&quot;name3&quot;,True)] </code></pre> <p>I want to get back ...
<python><python-dataclasses>
2022-12-19 14:30:01
6
4,999
KZiovas
74,851,810
1,752,251
Python Sentence Transformer - Get matching Sentence by index order
<p>I have a database table with lot of records. And I am comparing the sentence to find a best match.</p> <p>lets say the table contains 4 columns: id, sentence, info, updated_date. The data contains as below:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th style="text-align: left;">id</th>...
<python><numpy><pytorch><sentence-transformers>
2022-12-19 14:25:07
1
391
Avi
74,851,701
6,346,514
Python, Reading Zip files of a subdirectory. Windows object is not iterable
<p>I am trying to loop through my subdirectories to read in my zip files. I am getting error <code>TypeError: 'WindowsPath' object is not iterable</code></p> <p>What i am trying:</p> <pre><code>path = Path(&quot;O:/Stack/Over/Flow/&quot;) for p in path.rglob(&quot;*&quot;): print(p.name) zip_files = (str(x) f...
<python><pathlib>
2022-12-19 14:16:00
1
577
Jonnyboi
74,851,620
17,277,677
open json files in a loop - formatting problem
<p>I need to open files in my s3 bucket and those are the files:</p> <p><a href="https://i.sstatic.net/0IvkL.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/0IvkL.png" alt="enter image description here" /></a></p> <p>I want to apply some piece of code on each of them, hence I want to open them in a loop....
<python><loops><amazon-s3><amazon-sagemaker>
2022-12-19 14:08:53
1
313
Kas
74,851,500
14,579,051
How to use map function and multiprocessing to simplify this code and reduce time?
<p>Two separate queries.</p> <p>1. I have a 'm' raster files and 'n' vector files. I would like to use map function (as in R) and iterate through a list of 'n' vector files for each 'm' raster files. I got the output by writing separate for loop for each vector file.</p> <p>2.As given below, I am using for loop for eac...
<python><loops><multiprocessing><iteration>
2022-12-19 13:56:51
2
498
chris jude
74,851,448
19,336,534
Extract sentence from HTML using python
<p>I have extracted a component of interest from a HTML file using python(<a href="https://www.crummy.com/software/BeautifulSoup/bs4/doc/" rel="nofollow noreferrer">BeautifulSoup</a>) My code:</p> <pre><code>import pandas as pd import numpy as np from lxml import html from html.parser import HTMLParser from bs4 import ...
<python><python-3.x><beautifulsoup><html-parsing>
2022-12-19 13:51:44
1
551
Los
74,851,439
5,404,647
FluidSynth not available using scamp
<p>I have the following boilerplate code</p> <pre><code>from scamp import * s = Session() s.tempo = 120 clarinet = s.new_part(&quot;clarinet&quot;) </code></pre> <p>When I run it, I get the error</p> <pre><code>Traceback (most recent call last): File &quot;/home/norhther/Descargas/music.py&quot;, line 6, in &lt;mod...
<python><python-3.x>
2022-12-19 13:51:30
2
622
Norhther
74,851,410
4,418,481
Python was not found when running pyspark in VSC
<p>I'm learning <code>Spark</code> now and have installed it on a Windows PC.</p> <p>I used the following guide and to be honest, it all seems right.</p> <p>Also, when I type in my cmd <code>spark-shell</code> it opens <code>scala</code>, and when I type <code>pyspark</code> in opens the python shell as I would expect....
<python><apache-spark><visual-studio-code><pyspark>
2022-12-19 13:48:29
0
1,859
Ben
74,851,090
18,504,344
Is it possible to set activeforeground/activebackground using customtkinter?
<p>I am able to use activeforeground and activebackground to change color in background/text when button is clicked in tkinter.</p> <p>Is it possible to do the same thing in customtkinter as well? I have checked the website if similar context is available, however, could not see any.</p> <p>Thanks in advance.</p>
<python><tkinter><button><frontend><customtkinter>
2022-12-19 13:18:04
1
483
Baris Ozensel
74,850,922
10,748,412
Django serializer returns empty list
<p>I have a class-based view that returns all the data in the table. But while accessing the URL all I get is an empty list.</p> <p>models.py</p> <pre><code>from django.db import models class EmployeeModel(models.Model): EmpID = models.IntegerField(primary_key=True) EmpName = models.CharField(max_length=100) ...
<python><django><serialization><django-rest-framework><orm>
2022-12-19 13:03:14
1
365
ReaL_HyDRA
74,850,816
12,730,406
Do we One Hot Encode (create Dummy Variables) before or after Train/Test Split?
<p>I've seen quite a lot of conflicting views on if one-hot encoding (dummy variable creation) should be done before/after the training/test split.</p> <p>Responses seem to state that one-hot encoding before leads to &quot;data leakage&quot;.</p> <p>This example states it's industry norm to do one-hot encoding on the e...
<python><pandas><machine-learning><statistics>
2022-12-19 12:53:50
0
1,121
Beans On Toast
74,850,738
16,727,671
How to edit a file with multiple YAML documents in Python
<p>I have the following YAML file:</p> <pre><code>apiVersion: apps/v1 kind: Deployment metadata: name: nodejs namespace: test labels: app: hello-world spec: selector: matchLabels: app: hello-world replicas: 100 template: metadata: labels: app: hello-world spec: cont...
<python><kubernetes><yaml><ruamel.yaml><multi-document>
2022-12-19 12:46:45
2
448
microset
74,850,673
5,638,904
FastAPI: form-data name with a dot
<p>I have documentation. Form-data names have dots.</p> <p><a href="https://i.sstatic.net/0Xb1H.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/0Xb1H.png" alt="enter image description here" /></a></p> <p><a href="https://i.sstatic.net/IUh4i.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/I...
<python><multipartform-data><fastapi><hikvision>
2022-12-19 12:40:18
1
812
Alexey Golyshev
74,850,650
17,158,703
Error in replacing 'hour' and 'minute' of pandas TimeStamp
<p>I'm creating a datetime variable with pandas using <code>pd.to_datetime()</code> The referenced dataframe only has the date (e.g. 31/12/2023) so the function returns it with time 00:00:00 (e.g. 31/12/2023 00:00:00) and now I want to set the time value individually with the <code>replace()</code> function following t...
<python><pandas><datetime>
2022-12-19 12:38:15
1
823
Dattel Klauber
74,850,561
7,437,143
Python 3.10.8 TypeError: TypedDict does not support instance and class checks
<p>After having created the a typeddict, I am experiencing the following error:</p> <blockquote> <p>TypeError: TypedDict does not support instance and class checks</p> </blockquote> <p>Below is a MWE</p> <pre class="lang-py prettyprint-override"><code>from typeguard import typechecked import sys from typing import Dict...
<python><typeddict>
2022-12-19 12:30:09
0
2,887
a.t.
74,850,553
17,903,744
Is there a way to refresh a matplotlib cursor on click?
<p>I'm plotting around 250k points with matplotlib so naturally when I'm moving my mouse to use/refresh a cursor widget, it lags a lot. Therefore, I was looking for one way to optimize the use of this widget and I thought of refreshing the cursor on click to reduce the number of freezes. I saw <a href="https://matplotl...
<python><matplotlib>
2022-12-19 12:29:17
2
345
Guillaume G
74,850,526
5,786,023
pandas read_json from s3 with chunksize option returns single row multiple columns dataframe
<p>I have a json file in s3 (with &gt;100 records), this is sample json file format:</p> <pre><code>[{ &quot;data&quot;: { &quot;a&quot;: &quot;hello&quot; }, &quot;details&quot;: { &quot;b&quot;: &quot;hello1&quot; }, &quot;dtype&quot;: &quot;SP&quot; }, { &quot;data&quot;: { ...
<python><json><pandas><dataframe><amazon-s3>
2022-12-19 12:27:17
0
753
arevur
74,850,461
10,428,677
Incremental group by from a specific year onwards in Pandas
<p>I have a dataframe that looks like this:</p> <pre><code>df_dict = {'country': ['Japan','Japan','Japan','Japan','Japan','Japan','Japan', 'Greece','Greece','Greece','Greece','Greece','Greece','Greece'], 'year': [1970, 1982, 1999, 2014, 2017, 2018, 2021,1981, 1987, 2002, 2015, 2018, 2019, 2021], '...
<python><pandas>
2022-12-19 12:21:56
2
590
A.N.
74,850,440
19,155,645
pandas add a value to new column to each row in a group
<p>I have a pandas dataframe with several columns. for examlpe:</p> <pre><code> # name abbr country 0 454 Liverpool UCL England 1 454 Bayern Munich UCL Germany 2 223 Manchester United UEL England 3 454 Manchester City UCL England </code></pre> <p>and I run a function using .gropuby() - but ...
<python><pandas><group-by>
2022-12-19 12:19:35
1
512
ArieAI
74,850,387
19,339,998
execute a specific method into sgx using gramine
<p>I have an application which is using gRPC, client.py and server.py , I want to use gramine in order to execute the service inside SGX. how can I run a specific method not the whole script inside sgx using gramine? client.py:</p> <pre><code>&quot;&quot;&quot;The Python implementation of the GRPC helloworld.Greeter cl...
<python><sgx>
2022-12-19 12:15:14
1
341
sama
74,850,324
12,263,543
Deserializing Prometheus `remote_write` Protobuf output in Python
<p>I'm experimenting (for the first time) with Prometheus. I've setup Prometheus to send messages to a local flask server:</p> <pre><code>remote_write: - url: &quot;http://localhost:5000/metric&quot; </code></pre> <p>I'm able to read the incoming bytes, however, I'm not able to convert the incoming messages to any me...
<python><protocol-buffers><prometheus>
2022-12-19 12:09:45
1
1,655
picklepick
74,850,236
12,366,110
How can I make NaN values sum to NaN rather than 0 when using df.resample?
<p>I have the following example dataframe:</p> <pre><code>&gt;&gt;&gt; import pandas as pd &gt;&gt;&gt; import numpy as np &gt;&gt;&gt; d = {'date': pd.date_range(start='2022-12-09 00:00:00', end='2022-12-09 02:50:00', freq='10min'), 'amount': [np.n...
<python><pandas><pandas-resample>
2022-12-19 12:00:16
1
14,636
CDJB
74,850,167
1,745,291
Popen.wait never returning with docker-compose
<p>I am developing a wrapper around docker compose with python. However, I struggle with Popen.</p> <p>Here is how I launch launch it :</p> <pre><code>import subprocess as sp argList=['docker-compose', 'up'] env={'HOME': '/home/me/somewhere'} p = sp.Popen(argList, env=env) def handler(signum, frame): p.send_signal(si...
<python><subprocess>
2022-12-19 11:54:11
1
3,937
hl037_
74,850,128
13,066,054
macros are not recognised in dbt
<pre><code>{{ config ( pre_hook = before_begin(&quot;{{audit_tbl_insert(1,'stg_news_sentiment_analysis_incr') }}&quot;), post_hook = after_commit(&quot;{{audit_tbl_update(1,'stg_news_sentiment_analysis_incr','dbt_development','news_sentiment_analysis') }}&quot;) ) }} select rd.news_id ,rd....
<python><etl><dbt>
2022-12-19 11:50:45
2
351
naga satish
74,850,101
4,248,850
Disable "live log setup" and "live log teardown" in pytest
<p>Is there an option (or combination of options) in <code>pytest</code> to view only &quot;live log call&quot; ?</p> <p>I have to establish a handful of sessions in setup and close them in teardown, so a lot of noise from those logs, (changing them to debug is not going to help me as these logs are printed from anothe...
<python><python-3.x><pytest>
2022-12-19 11:48:23
0
1,922
Sam Daniel
74,850,029
7,800,760
Pyplot suptitle: can it word wrap a long title
<p>I am generating a networkx word graph and displaying it with pyplot as follows:</p> <pre><code>import networkx as nx import matplotlib.pyplot as plt IN_TXT = &quot;&quot;&quot; Giorgia Meloni festeggia i 10 anni di FdI e oggi arriverà la ciliegina sulla torta: l’accordo con gli alleati su una manovra che colpisce i ...
<python><matplotlib><networkx>
2022-12-19 11:42:45
1
1,231
Robert Alexander
74,849,965
16,708,111
Add values from a dictionary to a ManytoMany field
<pre><code>class GuestOrder(models.Model): comment = models.CharField(max_length=400, blank=True, null=True) guest = models.ForeignKey(Guest, on_delete=models.SET_NULL, null=True) dish = models.ManyToManyField(Dish) ingredient = models.ManyToManyField(Ingredient) table = models.ForeignKey(Table, on_...
<python><django><django-rest-framework>
2022-12-19 11:37:53
2
444
Mike D Hovhannisyan
74,849,588
12,366,110
Simple expression parsing throws a TypeError referencing 'AssumptionKeys'
<p>I'm trying to get sympy to calculate the result of what should be a simple expression with three substitutions, but I'm coming up against an error I've not encountered before.</p> <pre><code>&gt;&gt;&gt; from sympy import sympify, symbols &gt;&gt;&gt; input_str = '100*Q+10*R+5*S+0.6*T' &gt;&gt;&gt; Q,R,S,T = symbol...
<python><sympy>
2022-12-19 11:03:01
3
14,636
CDJB
74,849,543
544,542
Python ldap3 authenticate using mail or user id
<p>I am using the ldap3 library (<a href="https://ldap3.readthedocs.io/en/latest/" rel="nofollow noreferrer">https://ldap3.readthedocs.io/en/latest/</a>) with Python and authenticating against LDAP</p> <pre><code>conn = Connection(server, user='CN=person,OU=Service Accounts,DC=mydc,DC=mydomain,DC=co,DC=uk', password='P...
<python><ldap>
2022-12-19 10:57:29
2
3,797
pee2pee
74,849,387
12,058,154
Is it secure to store credentials protected with dotenv on public repos on Github?
<p>I am using GitHub and upload Jupyter notebooks. My goal is to showcase use cases of Cloud service providers like AWS, IBM or Heroku.</p> <p>Therefore, I store user credentials on public repos on GitHub. This allows me to execute the code on the Cloud platforms.</p> <p>(Reacting to comments: I am not storing the cred...
<python><github><jupyter-notebook><dotenv>
2022-12-19 10:43:41
1
335
Ormetrom2354
74,849,357
1,783,398
Python: bin a dictionary's values and then create another dictionary of bin membership
<p>I have a dictionary that has key as string and value a number, like this</p> <pre><code>d = {'key1': 0.5, 'key2': 0.2, 'key3': 0.3, 'key4': 0.9, 'key5': 0.94, ...} </code></pre> <p>What I would like to do is</p> <ol> <li>bin the values (0.5, 0.2, ....) based on a fixed interval, say every 0.2 increment</li> <li>prod...
<python><dictionary>
2022-12-19 10:40:41
1
2,570
Ziqi
74,849,356
1,928,054
Change deepest level of MultiIndex and append level
<p>Consider the following DataFrame:</p> <pre><code>import numpy as np import pandas as pd arrays1 = [ [&quot;A&quot;, &quot;A&quot;, &quot;A&quot;, &quot;B&quot;, &quot;B&quot;, &quot;B&quot;], [&quot;foo&quot;, &quot;bar&quot;, &quot;baz&quot;, &quot;foo&quot;, &quot;bar&quot;, &quot;baz&quot;], ] tuples1 = ...
<python><pandas>
2022-12-19 10:40:38
1
503
BdB
74,849,292
3,962,748
PyCharm Error when setting remote interpreter -> Run Error: Jupyter server process failed to start due to path mismatch issue
<p>I am trying to setup remote development on PyCharm. For this, I want to make changes locally and execute the code on remote Amazon EC2 instance with a remote interpreter. I had done the following configuration of the project, but I am getting run error when I try to execute a ipython file created locally.</p> <block...
<python><intellij-idea><amazon-ec2><pycharm>
2022-12-19 10:34:52
1
1,363
Abhinav Aggarwal
74,849,133
4,970,679
How to handle one-to-many relationship during HATEOAS serialization in Marshmallow?
<p>Trying to implement a rather simple REST API in Python (SQLAlchemy + Marshmallow) using HATEOAS resource linking, I am stuck when attempting to create &quot;smart hyperlinks&quot; for one-to-many relationships.</p> <p>Let's consider the classic book example: One book has exactly one publisher, but 1 to n authors. To...
<python><flask-sqlalchemy><flask-restful><hateoas><marshmallow-sqlalchemy>
2022-12-19 10:21:40
1
2,117
ahuemmer
74,849,129
19,155,645
function does not work correctly with pandas.apply(lambda)
<p>I have a function that takes two strings and give an output.</p> <p>I would like to apply it on my pandas dataframe using panads' apply funciton (with Lambda).</p> <p>The function runs correctly for certain inputs, but then fails in one of my checks. I double checked that the class of this example inputs is still st...
<python><pandas><dataframe>
2022-12-19 10:21:20
1
512
ArieAI
74,849,095
10,829,044
Iterate int variable to do in operator check
<p>I already referred the post <a href="https://stackoverflow.com/questions/57579095/argument-of-type-int-is-not-iterable">here</a> and <a href="https://stackoverflow.com/questions/23851723/pythongetting-argument-of-type-int-not-iterable-error">here</a>. Please don't mark as duplicate. My python version is 3.8.8</p> <p...
<python><pandas><dataframe><loops><for-loop>
2022-12-19 10:19:00
1
7,793
The Great
74,849,029
625,408
How to filter/search for emails with a custom header field using Python imaplib?
<p>I want to <strong>filter emails</strong> for the presence of a <strong>specific custom header</strong> field, e.g. <code>&quot;X-my-header-field: my-header-value&quot;</code>. I am using <strong>Python's imaplib</strong>. I unsuccessfully tried the <strong>search method</strong>: <code>rv, data = mailbox.search(None...
<python><imaplib><header-fields>
2022-12-19 10:12:42
2
3,224
Jonas
74,848,892
1,236,858
Databricks: Uploading a file to another location from Azure Blob Storage without copying it locally
<p>I have a file in Azure Blob Storage, and I would like to upload it to another location without copying it to Databricks' local storage.</p> <p>Currently my code needs to copy it locally before uploading:</p> <pre><code># Set up connection to Azure Blob Storage spark.conf.set(&quot;fs.azure.account.key.[some location...
<python><azure-blob-storage><databricks>
2022-12-19 10:01:51
1
7,307
rcs
74,848,876
18,248,287
Updating a list of dictionaries inside a loop
<p>I find that when I attempt to update values in a dictionary for items from another list, then only the last item in that last will be used to update the value. For example:</p> <pre><code>a=[{'a':1},{'a':2},{'a':3},{'a':4},{'a':5}] b=[9, 8, 7, 6, 5] changed = [] for items in a: for values in b: items.upd...
<python>
2022-12-19 10:00:02
0
350
tesla john
74,848,707
6,849,045
How do I group by depending on the previous value in spark
<p>I have some data on a machine. When it runs, it creates at least one entry every 5 seconds, which contains a timestamp field. I want to know how long that machine is on. So I want to know the stretch between the first entry and the last entry.</p> <p>I was thinking to order the data set by the timestamp, and then ag...
<python><pyspark><time>
2022-12-19 09:43:40
1
1,072
Typhaon
74,848,562
11,178,936
How to change to datetime format date with dashes?
<p>I have a date in format <code>2022-12-16T16-48-47&quot;</code> and I would like to change it to <code>datetime</code> using function <code>pd.to_datetime</code>.</p> <p>My first idea was to create split the string to have it in more readable way:</p> <pre><code>string = &quot;2022-12-16T16-48-47&quot; date, hour = s...
<python><pandas><string><datetime>
2022-12-19 09:32:19
1
1,947
John
74,848,531
1,516,331
In pandas, how to groupby and apply/transform on each whole group (NOT aggregation)?
<p>I've looked into agg/apply/transform after groupby, but none of them seem to meet my need. Here is an example DF:</p> <pre><code>df_seq = pd.DataFrame({ 'person':['Tom', 'Tom', 'Tom', 'Lucy', 'Lucy', 'Lucy'], 'day':[1,2,3,1,4,6], 'food':['beef', 'lamb', 'chicken', 'fish', 'pork', 'venison'] }) person,da...
<python><pandas>
2022-12-19 09:28:49
2
3,190
CyberPlayerOne
74,848,278
11,883,900
Calculate percentage of interview participants who had education background
<p>I am really sorry if this question was already asked. I have tried to search different answers but havent found one related to mine.</p> <p>I have a large dataframe with data looking like this :</p> <pre><code>import pandas as pd # intialise data of lists. data = {'interview_key':['00-60-62-69', '00-80-63-65', '0...
<python><pandas>
2022-12-19 09:06:44
2
1,098
LivingstoneM
74,848,203
1,415,826
python dict recursion returns empty list
<p>I have this dictionary that I am trying to iterate through recursively. When I hit a matching node <code>match</code> I want to return that node which is a <code>list</code>. Currently with my code I keep on getting an empty <code>list</code>. I have stepped through the code and I see my check condition being hit, b...
<python><dictionary><recursion>
2022-12-19 09:00:04
2
945
iambdot
74,848,199
2,975,438
Getting "TypeError: type of out argument not recognized: <class 'str'>" when using class function with Pandera decorator
<p>I am trying to get to use decorators from Python package &quot;Pandera&quot; and I am having trouble to get them work with classes.</p> <p>First I create schemas for Pandera:</p> <pre><code>from pandera import Column, Check import yaml in_ = pa.DataFrameSchema( { &quot;Name&quot;: Column(object, nullable...
<python><pandas><pandera>
2022-12-19 08:59:53
2
1,298
illuminato
74,848,126
2,173,320
PyQt6 - custom widget - get default widget colors for text, background etc
<p>I'm developing custom components using PyQt6. I now like to adapt my widgets' colors to the default Palette colors so that they look like the default widgets of PyQt6. I think I found a way to get the default colors of a global palette:</p> <pre><code>default_palette = self.palette() self.textColor = default_palette...
<python><user-interface><pyqt6>
2022-12-19 08:53:52
1
1,507
padmalcom
74,847,873
20,051,041
HDBSCAN dendrogram with Plotly, Python
<p>Creating a dendrogram using <code>plotly.figure_factory.create_dendrogram</code> <a href="https://stackoverflow.com/questions/38452379/plotting-a-dendrogram-using-plotly-python">has been discussed</a>. I decided to use HDBSCAN as custering algorithm and would like to visualize the clusters with Plotly.</p> <pre><cod...
<python><cluster-analysis><plotly-dash><hierarchical-clustering>
2022-12-19 08:29:17
1
580
Mr.Slow
74,847,696
9,939,634
The coordinates of the reconstructed 3D points are different after the virtual camera intrinsic K has also changed proportionally after image resize?
<p>As far as I know, after image resize, the corresponding intrinsic parameter K also changes proportionally, but why the coordinates of the 3D reconstruction of the same point are not the same?</p> <p>The following python program is a simple experiment, the original image size is <img src="https://latex.codecogs.com/s...
<python><numpy><image-resizing><3d-reconstruction><camera-intrinsics>
2022-12-19 08:06:52
1
311
cui xingxing
74,847,642
15,724,084
need to re-write my code in less than O(n2) complexity
<p>I have an algorithm written which gives result. Given an array of integers nums and an integer target, return indices of the two numbers such that they add up to target.</p> <p>You may assume that each input would have exactly one solution, and you may not use the same element twice.</p> <p>You can return the answer...
<python><hashmap>
2022-12-19 08:00:02
2
741
xlmaster
74,847,472
1,934,212
pop rows from dataframe based on conditions
<p>From the dataframe</p> <pre><code>import pandas as pd df1 = pd.DataFrame({'A':[1,1,1,1,2,2,2,2],'B':[1,2,3,4,5,6,7,8]}) print(df1) A B 0 1 1 1 1 2 2 1 3 3 1 4 4 2 5 5 2 6 6 2 7 7 2 8 </code></pre> <p>I want to pop 2 rows where 'A' == 2, preferably in a single statement like</p> <blockquote> <p>df...
<python><pandas>
2022-12-19 07:39:46
2
9,735
Oblomov
74,847,424
1,144,868
ModuleNotFoundError: No module named 'testing' While trying to execute unittest case in Python
<p>I have written a test case for my Python-airflow project, but while executing the command it is throwing <code>ModuleNotFoundError: No module named 'testing'</code></p> <p>Complete error stack is -</p> <pre><code>ERROR: testing (unittest.loader._FailedTest) -----------------------------------------------------------...
<python><python-3.x><unit-testing><airflow><python-unittest>
2022-12-19 07:35:08
1
3,355
sandeep
74,847,418
8,874,837
python regex transpose capture group into another regex
<p>I have:</p> <pre><code>regex1 = 'CCbl([a-z]{2})la-12([0-9])4' inputstring = 'CCblabla-1234' regex2_to_get_substituted = 'fof([a-z]{2})in(.)ha' desired output = 'fofabin3ha' </code></pre> <p>Basically I want to get result of the capture groups from <code>regex1</code> and transpose them into the same positions of nt...
<python><regex><python-re>
2022-12-19 07:34:39
1
350
tooptoop4
74,847,225
3,004,472
how to check different version of same file using python
<p>I have list of files two lists (A and B). I am comparing the file names in list A with B. I want to know whether the latest version of the files is available in List B when doing comparison.</p> <p>For example:</p> <p>List A contains - <strong>id_prot_number_f1_v1_p1</strong> and List B contains <strong>id_prot_num...
<python><regex><string>
2022-12-19 07:10:55
0
880
BigD
74,847,167
9,861,647
Get all File from Subfolder Boto3
<p>I have this code to download all the files from a buckets AWS S3</p> <pre><code>import os import boto3 #initiate s3 resource s3 = boto3.resource('s3') s3 = boto3.resource( 's3', aws_access_key_id = '__________', aws_secret_access_key = '________', region_name = '______' ) # select bucket my_bucke...
<python><amazon-s3><boto3>
2022-12-19 07:03:19
1
1,065
Simon GIS
74,847,154
7,947,316
How to using sum function with encrypted column in SQLAlchemy?
<p>I have used <code>EncryptedType</code> from <code>sqlalchemy_utils</code> to encrypt data of the specific column which will make when inserting data into the table or selecting data, the data of encrypted column will be encrypted.</p> <p>This is the ORM structure of my database which have encrypted in <code>value</c...
<python><postgresql><sqlalchemy>
2022-12-19 07:01:54
1
563
Kaow
74,846,933
9,257,578
How to pick up data from json objects in python?
<p>I am trying to pick <code>Instances</code> in the json objects data which looks like this</p> <p><code>[{'Groups': [], 'Instances': [{'AmiLaunchIndex': 0, 'ImageId': 'ami-0ceecbb0f30a902a6', 'InstanceId': 'i-xxxxx', 'InstanceType': 't2.micro', 'KeyName': 'xxxx', 'LaunchTime': {'$date': '2022-12-17T13:07:54Z'}, 'Moni...
<python><json>
2022-12-19 06:32:09
2
533
Neetesshhr
74,846,760
11,332,693
Python String Matching Using Loops and Iterations and Score Calculation using two dataframes
<p>df1</p> <pre><code>Place Location Delhi,Punjab,Jaipur Delhi,Punjab,Noida,Lucknow Delhi,Punjab,Jaipur Delhi,Bhopal,Jaipur,Rajkot Delhi,Punjab,Kerala Delhi,Jaipur,Madras </code></pre> <p>df2</p> <pre><code>Target1 Target2 Strength Jaipur Rajkot 0.94 Jaipur ...
<python><pandas><string><dataframe><string-matching>
2022-12-19 06:04:22
1
417
AB14
74,846,659
29,573
Python typing dict of dicts
<p>How do I correctly type hint this python structure:</p> <pre class="lang-py prettyprint-override"><code>people={ &quot;john&quot; : {&quot;likes&quot;: &quot;apples&quot;, &quot;dislikes&quot;: &quot;organges&quot;}, &quot;aisha&quot;: {&quot;likes&quot;: &quot;kittens&quot;, &quot;dislikes&quot;: &quot;raven...
<python><python-typing>
2022-12-19 05:45:49
2
2,306
Konrads
74,846,653
9,668,481
How to define a column as an Array of any type in POSTGRESQL FlaskSQLAlchemy?
<p>I am using <code>flask_sqlalchemy</code> and I want to define column <strong>prompts</strong> to be an array which accepts values of any data type, particularly <strong>string</strong> or <strong>json</strong>.</p> <pre class="lang-py prettyprint-override"><code>from flask_sqlalchemy import SQLAlchemy db = SQLAlchem...
<python><postgresql><sqlalchemy>
2022-12-19 05:44:23
2
846
Saurav Pathak
74,846,487
1,251,099
running shell command in python under git-bash not working well
<p>I am using python3 under git-bash environment, and sometimes it does not run shell command well.</p> <pre><code>#!/usr/bin/env python3 import subprocess as sp print(&quot;hello&quot;) print(sp.getoutput(&quot;ls -l&quot;)) # This works. print(sp.getoutput(&quot;date&quot;)) # This hangs and cannot terminate ...
<python><python-3.x><bash><git-bash>
2022-12-19 05:11:59
1
6,206
user180574
74,846,450
16,124,033
How to aggregate unique substrings in a column of strings in Python?
<p>I have a <code>.csv</code> file as follows:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th>Alphabet</th> <th>Sub alphabet</th> <th>Value</th> <th>Strings</th> </tr> </thead> <tbody> <tr> <td>A</td> <td>B</td> <td>1</td> <td>AA, AB</td> </tr> <tr> <td>A</td> <td>C</td> <td>1</td> <td>AA,...
<python><pandas><dataframe>
2022-12-19 05:03:32
1
4,650
My Car
74,846,281
4,479,864
Mocking Azure BlobServiceClient in Python
<p>I am trying to write a unit test that will test <code>azure.storage.blob.BlobServiceClient</code> class and its methods. Below is my code</p> <p>A fixture in the <code>conftest.py</code></p> <pre class="lang-py prettyprint-override"><code>@pytest.fixture def mock_BlobServiceClient(mocker): azure_ContainerClient...
<python><unit-testing><pytest><pytest-mock>
2022-12-19 04:26:20
0
432
gh0st
74,846,253
11,124,121
Is there any function to check the location of the last date element in pandas dataframe?
<p>The sample data is like:</p> <div class="s-table-container"> <table class="s-table"> <thead> <tr> <th style="text-align: left;">Empty header</th> </tr> </thead> <tbody> <tr> <td style="text-align: left;">'2/01/2011'</td> </tr> <tr> <td style="text-align: left;">'3/01/2011'</td> </tr> <tr> <td style="text-align: left...
<python><pandas><date>
2022-12-19 04:17:56
1
853
doraemon
74,846,241
1,528,840
Rename a column if there is duplicate based on value in another column
<p>I have a dataframe like the following:</p> <pre><code>df = pd.DataFrame({&quot;Col1&quot;: [&quot;AA&quot;, &quot;AB&quot;, &quot;AA&quot;, &quot;CC&quot;, &quot;FF&quot;], &quot;Col2&quot;: [18, 23, 13, 33, 48], &quot;Col3&quot;: [17, 27, 22, 37, 52]}) </code></pre> <p>My goal ...
<python><pandas><dataframe><valueerror><shift>
2022-12-19 04:15:43
2
1,342
AZhu
74,846,222
8,422,170
How can I implement python AutoML libraries (like Pycaret, auto-sklearn) etc, on pyspark dataframe?
<p>I am trying to implement AutoML over a Pyspark DataFrame but didn't found any particular documentation or library specific for this? Can we implement Pycaret, MLJar or any automl library for pyspark dataframes using pandas_udfs?</p>
<python><pandas><dataframe><pyspark><automl>
2022-12-19 04:11:17
1
1,939
Mehul Gupta
74,846,182
2,091,585
Replace characters that repeats more than 20 times with 10 with a regex
<p>This is basically more complicated version of this question.</p> <p><a href="https://stackoverflow.com/questions/7172378/replace-repeating-characters-with-one-with-a-regex">Replace repeating characters with one with a regex</a></p> <p>If there is a character that repeats more than 20 times, then replace with just te...
<python><regex><backreference>
2022-12-19 04:01:57
1
2,238
user67275
74,846,075
5,398,127
How do I predict the future closing price of stock after training and testing?
<p>I am trying to do multivariate time series forecasting using linear regression model.</p> <p>In the below code I first split the data in 80-20 ratio for training and testing.</p> <p>Then I train the model and use the model to predict using test and compute the relevant performance metrics of the model.</p> <pre><cod...
<python><scikit-learn><linear-regression>
2022-12-19 03:34:51
1
3,480
Stupid_Intern
74,846,048
1,779,091
Does list slicing create shallow or deep copy?
<pre><code>Lst1 = [1,2,3,4] Lst2 = Lst1 Lst3 = Lst1[0:2] Lst4 = Lst1[:] </code></pre> <p>So Lst1 and Lst2 point to same list.</p> <p>And Lst3 points to slice of Lst1.</p> <p>And Lst4 point to slice of Lst1.</p> <p>Whether Lst3 &amp; Lst4 (output of slicing) are deep or shallow copy?</p>
<python>
2022-12-19 03:30:00
2
9,866
variable
74,846,020
4,755,567
How to check array contains string by using pyspark with this structure
<p>The curly brackets are odd. Tried with different approaches, but none of them works</p> <pre><code># root # |-- L: array (nullable = true) # | |-- element: struct (containsNull = true) # | | |-- S: string (nullable = true) # +------------------+ # | L| # +------------------+ # |[{string1...
<python><apache-spark><pyspark>
2022-12-19 03:24:50
1
549
TommyQu
74,845,697
7,211,014
python selenium refuses to scroll down page, how to force / fix?
<p>I need selenium using the firefox driver to scroll down the page to the very bottom, but my code no longer works. Its like the page recognizes I am trying to scroll with selenium and forces the scroll back to the top of the screen...</p> <pre><code>def scroll_to_bottom(): ''' Scroll down the page the whole ...
<python><selenium><web-scraping><scroll><height>
2022-12-19 01:55:41
0
1,338
Dave
74,845,330
3,277,133
How to display row as dictionary from pyspark dataframe?
<p>Very new to pyspark.</p> <p>I have 2 datasets, <code>Events</code> &amp; <code>Gadget</code>. They look like so:</p> <pre><code>Events </code></pre> <p>[![enter image description here][1]][1]</p> <p><code>Gadgets</code></p> <p>[![enter image description here][2]][2]</p> <p>I can read and join the 2 dataframes by usi...
<python><pyspark>
2022-12-19 00:27:41
1
3,707
RustyShackleford
74,845,263
2,374,964
'Internal space embedding need ...' error when attemping to use spaCy text_categorizer
<p>Hello sirs and madams,</p> <p>I very much need your help to understand this error:</p> <pre><code>Exception has occurred: NotImplementedError internal spacy embeddings need to be derived from md/lg spacy models not from sm/trf models. File &quot;/Users/Rune/Sites/smartez-backend/analytics/pipeline.py&quot;, line 517...
<python><spacy>
2022-12-19 00:11:59
0
409
BispensGipsGebis
74,845,219
587,021
SQLalchemy keyword argument equivalent of `Column('id', String, Enum(("foo", "bar")))`
<p>I'm looking at <a href="https://docs.sqlalchemy.org/en/14/core/defaults.html#sqlalchemy.schema.Identity" rel="nofollow noreferrer">https://docs.sqlalchemy.org/en/14/core/type_basics.html#sqlalchemy.types.Enum</a> and <a href="https://docs.sqlalchemy.org/en/14/core/metadata.html#sqlalchemy.schema.Column.__init__" rel...
<python><sqlalchemy>
2022-12-19 00:04:35
1
13,982
A T
74,845,051
436,721
Every other celery task fails; it seems to be "unregistered"
<p>I'm using <code>celery</code> to run a task called <code>'filter'</code>.</p> <p>I'm having a weird error whereby <strong>every other</strong> task call seems to result in a <code>celery.exceptions.NotRegistered</code> exception.</p> <p>By <em>every other call</em>, I mean:</p> <ul> <li>I call it once, it works</li>...
<python><queue><celery>
2022-12-18 23:15:40
1
11,937
Felipe
74,845,039
6,346,514
Python, KeyError: "There is no item named '{filename}' in the archive
<p>I am running a code to try to extract the length of each file in a directory. I cannot figure out why I am getting error : <code>KeyError: &quot;There is no item named 'Test1' in the archive&quot;</code></p> <p>Code:</p> <pre><code>from io import BytesIO from pathlib import Path from zipfile import ZipFile import p...
<python><pandas>
2022-12-18 23:12:15
1
577
Jonnyboi
74,844,847
1,245,262
Why would a Python call to an sqllite3 database crash with only 'Killed' as an output
<p>I'm trying to run some 3rd party code that attempts to read a database it has created. However, when I run this code, it crashes and only gives me the word <code>Killed</code> as output.</p> <p>I inserted</p> <pre><code>import pdb pdb_set_trace() </code></pre> <p>Before the relevant section of the code:</p> <pre><c...
<python><python-3.x><sqlite>
2022-12-18 22:32:50
0
7,555
user1245262
74,844,790
2,272,824
What is the most efficient way to handle conversion from full to symmetric second order tensors using numpy?
<p>I am processing symmetric second order tensors (of stress) using numpy. In order to transform the tensors I have to generate a fully populated tensor, do the transformation and then recover the symmetric tensor in the rotated frame.</p> <p>My input is a 2D numpy array of symmetric tensors (nx6). The code below works...
<python><numpy><numpy-ndarray><array-broadcasting><numpy-slicing>
2022-12-18 22:21:57
2
391
scotsman60
74,844,554
8,359,217
Applying Black formatter on symlink directory
<p>I have the following folder structure:</p> <pre><code>- etl - raw - raw.py - etl (symlink) - raw - raw.py - etl (symlink) ... (infinite paths) - config.py </code></pre> <p>I've created a <a href="https://linuxize.com/post/how-to-crea...
<python><black-code-formatter>
2022-12-18 21:30:38
0
303
Matheus Schaly
74,844,481
1,976,597
How do I control how a Python class is printed (NOT a class instance)
<p>I have a Python class with <em>class attributes</em>, and I would like it to show the values of the attributes when printed.</p> <p>But instead, it just shows the name of the class.</p> <pre class="lang-py prettyprint-override"><code>class CONFIG: ONE = 1 TWO = 2 print(CONFIG) # &lt;class '__main__.CONFIG...
<python>
2022-12-18 21:17:22
0
4,914
David Gilbertson
74,844,432
587,021
SQLalchemy keyword argument equivalent of `Column('id', Integer, Identity())`
<p>Attempt: <code>Column(name='id', type_=Integer, default=Identity())</code></p> <p>I'm looking at <a href="https://docs.sqlalchemy.org/en/14/core/defaults.html#sqlalchemy.schema.Identity" rel="nofollow noreferrer">https://docs.sqlalchemy.org/en/14/core/defaults.html#sqlalchemy.schema.Identity</a> and <a href="https:/...
<python><sql><sqlalchemy>
2022-12-18 21:08:47
1
13,982
A T
74,844,395
7,422,352
matplotlib's ion() does not make any difference
<p>To test the matplotlib's interactive mode, I used the following two code snippets:</p> <p><strong>Snippet 1:</strong> Has <code>plt.ion()</code> with no call to <code>fig.canvas.draw()</code>:</p> <pre><code>import numpy as np import matplotlib.pyplot as plt x = np.array([]) y_1 = np.array([]) y_2 = np.array([]) p...
<python><matplotlib><data-science><matplotlib-animation><matplotlib-ion>
2022-12-18 21:01:20
0
5,381
Deepak Tatyaji Ahire
74,844,309
1,243,255
Downloading all zip files from url
<p>I need to download all the zip files from the url: <a href="https://www.ercot.com" rel="nofollow noreferrer">https://www.ercot.com</a></p>
<python><web-scraping><beautifulsoup>
2022-12-18 20:49:28
1
4,837
Zanam
74,844,262
9,481,479
How can I solve error "module 'numpy' has no attribute 'float'" in Python?
<p>I am using NumPy 1.24.0.</p> <p>On running this sample code line,</p> <pre class="lang-py prettyprint-override"><code>import numpy as np num = np.float(3) </code></pre> <p>I am getting this error:</p> <pre class="lang-none prettyprint-override"><code>Traceback (most recent call last): File &quot;&lt;stdin&gt;&quot...
<python><numpy>
2022-12-18 20:42:16
9
1,004
Nawin K Sharma
74,844,237
7,168,244
How to include both percent and N as bar labels in grouped bar chart
<p>I recently asked a question and on how to include both % and N as bar labels and received assistance <a href="https://stackoverflow.com/questions/74832746/include-both-and-n-as-bar-labels/74833282#74833282">Include both % and N as bar labels</a> I am trying to use that example in a bar plot over a variable as per th...
<python><pandas><matplotlib><seaborn><grouped-bar-chart>
2022-12-18 20:39:08
1
481
Stephen Okiya
74,844,201
6,205,382
Processing and validating JSON containing duplicate keys
<p>I'm trying to validate &quot;json&quot; files that we receive because the source code that generates these files has some issues that cannot be corrected without a major overhaul. There are many objects in the &quot;json&quot; that are invalid. An example below, which reuses keys for port naming.</p> <p>example inva...
<python><json>
2022-12-18 20:33:09
1
2,239
CandleWax