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,834,337
14,823,310
Why as type('category') is not saving memory in my data frame?
<p>I have a data frame with a column with strings that I want to optimize using 'category'. I am obvisouly doing something wrong as I thought the memory usage is far less with category rather than string.</p> <pre><code>In [28]: df1.memory_usage() Out[28]: Index 15218784 DATE_CALCUL 15218784 ABN_CONTRAT ...
<python><pandas><dataframe><memory>
2022-12-17 13:09:18
1
591
pacdev
74,834,293
3,728,901
Windows 11 uninstall Python 3.9, install 3.11.1: Fatal error in launcher: Unable to create process using .. The system cannot find the file specified
<p>Windows 11 uninstall Python 3.9, then install Python 3.11.1: Fatal error in launcher: Unable to create process using</p> <pre class="lang-py prettyprint-override"><code>D:\temp20221103&gt;jupyter lab Fatal error in launcher: Unable to create process using '&quot;C:\Users\donhu\AppData\Local\Programs\Python\Python39\...
<python><jupyter-lab>
2022-12-17 13:03:24
1
53,313
Vy Do
74,834,145
1,485,853
let sublimetext run last used build command
<p>As an example, there are two files, <code>main.py</code> and <code>module.py</code>, I could only run the project when <code>main.py</code> is in the current active tab window by <code>Ctrl + B</code>. However, a big amount of my code work is in <code>module.py</code>, after some modification of <code>module.py</co...
<python><sublimetext3><sublimetext><sublime-text-plugin>
2022-12-17 12:41:21
1
2,478
iMath
74,833,958
324,315
How to convert None values in Json to null using Pyspark?
<p>Currently I am parsing my Json feeds with:</p> <pre><code>rdd = self.spark.sparkContext.parallelize([(json_feed)]) df = self.spark.read.json(rdd) </code></pre> <p>That works fine as long as values are all there, but if I have a Json (as Python dict) like:</p> <pre><code>json_feed = { 'name': 'John', 'surname': 'Smit...
<python><pyspark>
2022-12-17 12:10:26
2
9,153
Randomize
74,833,942
1,290,055
Efficient way to get the minimal tuple from a set of columns in polars
<p>What is the most efficient way in polars to do this:</p> <pre class="lang-py prettyprint-override"><code>import polars as pl import numpy as np rng = np.random.default_rng() df = pl.DataFrame([ pl.Series('a', rng.normal(size=10_000_000)), pl.Series('b', rng.normal(size=10_000_000)), ]) df.sort('a', 'b').he...
<python><sorting><python-polars>
2022-12-17 12:08:30
1
1,823
Martin Wiebusch
74,833,794
5,362,515
Python threading code giving different thread counts in Notebook and in shell
<p>I just started learning Python <code>asyncio</code> and ran a script containing following basic code in Jupyter Notebook -</p> <pre><code>import threading def hello_from_thread(): print(f'Hello from thread {threading.current_thread()}!') hello_thread = threading.Thread(target=hello_from_thread) hello_thread.s...
<python><python-multithreading>
2022-12-17 11:43:33
1
327
mayankkaizen
74,833,769
3,515,313
Scapy proxy HTTP packet
<p>I want to send an HTTP packet to port 31112, but I want to change the IP identification header to 0xabcd.</p> <p>What I am doing is using iptables for, whatever packet with destination port 31112, redirect it to a queue:</p> <pre><code>iptables -A OUTPUT -p tcp --dport 31112-j NFQUEUE --queue-num 1 </code></pre> <p>...
<python><network-programming><tcp><scapy><netfilter>
2022-12-17 11:40:23
1
1,949
aDoN
74,833,553
11,291,663
How to plot my own logistic regression decision boundaries and SKlearn's ones on the same figure
<p>I have an assignment in which I need to compare my own multi-class logistic regression and the built-in SKlearn one.</p> <p>As part of it, I need to plot the decision boundaries of each, on the same figure (for 2,3, and 4 classes separately).</p> <p>This is my model's decision boundaries for 3 classes:</p> <p><a hre...
<python><plot><scikit-learn><logistic-regression>
2022-12-17 10:59:21
1
313
RedYoel
74,833,499
13,230,147
Type hints for Python 3 dictionary containing required and un-determined optional keys
<p>If I have a dictionary which contains required and but also arbitrary optional keys, how should I type this dictionary?</p> <p>Example:</p> <pre><code>Dictionary family: father: str, mother: str, # optional key start son1: str, daughter1: str, son2: str, daughter2: str, # arbitrary many more sons, d...
<python><python-typing><typeddict>
2022-12-17 10:49:33
1
343
obelisk0114
74,833,164
7,451,580
using exec how to save variable equal to a string
<p>I am using exec to save a variable equal to a string. I am getting a SyntaxError. I'm assuming exec is getting confused with the value as string. Is this assumption accurate? Would appreciate the learnings! If I changed each question to an str(int), the code will work. Any help is much appreciated.</p> <pre><code>j...
<python><python-exec>
2022-12-17 09:54:34
1
441
BrianBeing
74,833,139
12,000,021
Outlier detection in time-series
<p>I have a dataset in the following form:</p> <pre><code> timestamp consumption 2017-01-01 00:00:00 14.3 2017-01-01 01:00:00 29.1 2017-01-01 02:00:00 28.7 2017-01-01 03:00:00 21.3 2017-01-01 04:00:00 18.4 ... ... ... 2017-12-31 19:00:00 53.2 2017-12-31 20:00:00 43.5 2017-12-31 21:00:00 37.1 2017-12-31 22:00:00 ...
<python><machine-learning><outliers><anomaly-detection><isolation-forest>
2022-12-17 09:49:58
1
428
Kosmylo
74,832,746
7,168,244
Include both % and N as bar labels
<p>I have created a bar plot with percentages. However, since there's possibility of attrition I would like to include N, the number of observations or sample size (in brackets) as part of the bar labels. In other words, N should be the count of baseline and endline values.</p> <pre><code>import matplotlib.pyplot as pl...
<python><pandas><matplotlib><seaborn>
2022-12-17 08:29:47
1
481
Stephen Okiya
74,832,586
688,208
Python: muliple projects in the same package
<p>I want to have multiple Python projects in the same package. For example: <code>mycompany.parser</code>, <code>mycompany.database</code>. These projects have to be able to be installed separately. So a user can have only <code>mycompany.parser</code> or only <code>mycompany.database</code>, or both.</p> <p>Is it pos...
<python><python-packaging>
2022-12-17 07:55:42
1
493
Number47
74,832,296
17,582,019
"TypeError: string indices must be integers" when getting data of a stock from Yahoo Finance using Pandas Datareader
<pre><code>import pandas_datareader end = &quot;2022-12-15&quot; start = &quot;2022-12-15&quot; stock_list = [&quot;TATAELXSI.NS&quot;] data = pandas_datareader.get_data_yahoo(symbols=stock_list, start=start, end=end) print(data) </code></pre> <p>When I run this code, I get error <code>&quot;TypeError: string indice...
<python><yahoo-finance><pandas-datareader>
2022-12-17 06:53:00
5
790
Deepak
74,831,956
13,079,519
How to extract value from specific P-tag with BeautifulSoup?
<p>Is there a way to only extract the value for Acid(<code>5.9 g/L</code>) and Alcohol(<code>14.5%</code>)?</p> <p>I thought of using <code>find_all('p')</code>, but it is giving me all the p tag while I only need two of them.</p> <p><a href="https://i.sstatic.net/vpQ3P.png" rel="nofollow noreferrer"><img src="https://...
<python><html><web-scraping><beautifulsoup>
2022-12-17 05:17:30
1
323
DJ-coding
74,831,714
874,380
Why does spaCy run slower in a difference conda environment?
<p>I used JupyterLab to preprocess a larger set of text documents with spaCy. While there's overall no problem, I've noticed that there's a huge speed difference when I use different conda kernels / virtual environments. The difference is about 10x.</p> <p>Both environments have the same version of spaCy and NumPy inst...
<python><anaconda><conda><spacy>
2022-12-17 04:03:37
1
3,423
Christian
74,831,706
364,197
zlib error code -3 while using zlib to decompress PDF Flatedecode stream
<p>I am trying to extract some information from a PDF file. There is a 12 character stream that is compressed with Flatedecode that I've been unable to decompress although other streams in the document are readily decompressed with the same python 3.9 program.</p> <p>This is extracted from a US Government - FAA Instru...
<python><pdf><zlib><itext7>
2022-12-17 04:01:43
1
1,133
DarwinIcesurfer
74,831,663
1,497,199
How to create unit tests for a FastAPI endpoint that makes request to another endpoint?
<p>I have a FastAPI app that makes requests to other endpoint within a function that handles a particular request.</p> <p>How can I build unit tests for this endpoint using <code>fastapi.testclient.TestClient</code>?</p> <pre><code>import fastapi import requests import os app = fastapi.FastAPI() # in production this ...
<python><unit-testing><fastapi>
2022-12-17 03:47:43
1
8,229
Dave
74,831,603
9,983,652
yahoo_fin get_balance_sheet() doesn't return any data
<p>I am using yahoo_fin to get some fundamental data and it is working fine for PE, PS ratio etc. but when using get_balance_sheet(), it return no data. Any suggestion? Thanks</p> <pre><code>import yahoo_fin.stock_info as si sheet = si.get_balance_sheet(&quot;AAPL&quot;) </code></pre> <p>Get PE ratio is fine</p> <pre><...
<python><yfinance>
2022-12-17 03:30:11
0
4,338
roudan
74,831,583
640,558
for python string how can I print each line as a new line?
<p>I have a weird problem. I call a API and get this result:</p> <pre><code>1. Increase the use of alternative fuels: The aviation industry can reduce its carbon emissions by increasing the use of alternative fuels such as biofuels, hydrogen, and synthetic fuels. 2. Improve aircraft efficiency: The aviation industry ca...
<python>
2022-12-17 03:24:45
3
26,167
Lostsoul
74,831,471
4,451,521
Filtering dataframes based on one column with a different type of other column
<p>I have the following problem</p> <pre><code>import pandas as pd data = { &quot;ID&quot;: [420, 380, 390, 540, 520, 50, 22], &quot;duration&quot;: [50, 40, 45,33,19,1,3], &quot;next&quot;:[&quot;390;50&quot;,&quot;880;222&quot; ,&quot;520;50&quot; ,&quot;380;111&quot; ,&quot;810;111&quot; ,&quot;22;888&quo...
<python><pandas><dataframe>
2022-12-17 02:48:09
2
10,576
KansaiRobot
74,831,439
2,416,097
Subprocess.call appears to modify (rsync) command inputs causing failure
<p>I am attempting to write a python script that calls rsync to synchronize code between my vm and my local machine. I had done this successfully using subprocess.call to write from my local machine to my vm, but when I tried to write a command that would sync from my vm to my local machine, subprocess.call seems to er...
<python><subprocess><rsync>
2022-12-17 02:36:49
0
4,079
bgenchel
74,831,339
5,508,736
flask-HTTPTokenAuth Fails to Verify Token
<p>I'm working my way through Miguel Grinberg's book Flask Web Development, and I've run into a snag in Chapter 14 (Application Programming Interfaces) with the authentication routine. I'm attempting to update the code to use the current version of flask-HTTPAuth according to the example code in the github repo. I can ...
<python><flask><httpie><flask-httpauth>
2022-12-17 02:07:41
1
5,266
Darwin von Corax
74,831,338
1,698,736
How do you import a nested package via string?
<p>I'm trying to dynamically import a package which is a subdirectory of another package.</p> <p>Though there is no <a href="https://docs.python.org/3/library/importlib.html" rel="nofollow noreferrer">documentation</a> about it, this doesn't seem to be possible with <code>importlib</code>.</p> <p>Example: Start with</p...
<python><import><python-module><python-importlib>
2022-12-17 02:07:17
1
9,202
cowlinator
74,831,253
1,893,234
Rethinking Python for loop to pySpark to create dataframes
<p>I have a list of accounts which I iterate in a loop calling the details from an API function <code>get_accounts</code>. The JSON response for each call includes details for one account with one or more contacts which I add to dataframes <code>df_accounts</code> and <code>df_contacts</code> respectively.</p> <p>The A...
<python><pyspark><apache-spark-sql><azure-synapse>
2022-12-17 01:47:54
0
2,154
Alen Giliana
74,831,244
3,247,006
How to run "SELECT FOR UPDATE" instead of "SELECT" when adding data in Django Admin?
<p>In <code>PersonAdmin():</code> below, I overrode <a href="https://docs.djangoproject.com/en/4.1/ref/contrib/admin/#django.contrib.admin.ModelAdmin.response_add" rel="nofollow noreferrer"><strong>response_add()</strong></a> with <a href="https://docs.djangoproject.com/en/4.1/ref/models/querysets/#select-for-update" r...
<python><python-3.x><django><django-admin><select-for-update>
2022-12-17 01:45:44
1
42,516
Super Kai - Kazuya Ito
74,831,243
14,159,985
Getting empty dataframe after foreachPartition execution in Pyspark
<p>I'm kinda new in PySpark and I'm trying to perform a foreachPartition function in my dataframe and then I want to perform another function with the same dataframe. The problem is that after using the foreachPartition function, my dataframe gets empty, so I cannot do anything else with it. My code looks like the foll...
<python><apache-spark><pyspark>
2022-12-17 01:45:38
1
338
fernando fincatti
74,831,234
15,171,387
Get a list from numpy ndarray in Python?
<p>I have a numpy.ndarray here which I am trying to convert it to a list.</p> <pre><code>&gt;&gt;&gt; a=np.array([[[0.7]], [[0.3]], [[0.5]]]) </code></pre> <p>I am using hstack for it. However, I am getting a list of a list. How can I get a list instead? I am expecting to get <code>[0.7, 0.3, 0.5]</code>.</p> <pre><cod...
<python><numpy>
2022-12-17 01:43:30
2
651
armin
74,831,044
497,132
How to get ImageField url when using QuerySet.values?
<pre><code>qs = self.items.values( ..., product_preview_image=F('product_option_value__product__preview_image'), ).annotate( item_count=Count('product_option_value'), total_amount=Sum('amount'), ) </code></pre> <p><code>product_option_value__product__previ...
<python><django><django-queryset>
2022-12-17 00:43:12
1
16,835
artem
74,831,038
15,542,245
File Opening - Script still finds file in cwd even when absolute path specified
<p>I have looked at <a href="https://stackoverflow.com/questions/22282760/filenotfounderror-errno-2-no-such-file-or-directory">How to open a list of files in Python</a> This problem similar but not covered.</p> <pre><code>path = &quot;C:\\test\\test5\\&quot; files = os.listdir(path) fileNames = [] for f in files: ...
<python><file>
2022-12-17 00:40:12
0
903
Dave
74,830,869
14,729,041
Delete only first occurrence of element in list Recursively
<p>I am trying to remove only the first occurrence of an element from a file-like structure. I have the following code:</p> <pre><code>d2 = (&quot;home&quot;, [(&quot;Documents&quot;, [(&quot;FP&quot;, [&quot;lists.txt&quot;, &quot;recursion.pdf&quot;, &quot;functions.ipynb&quot;, &quot;lists...
<python><recursion>
2022-12-16 23:59:27
1
443
AfonsoSalgadoSousa
74,830,790
13,079,519
Why is the html content I got from inspector different from what I got from Request?
<p>Here is the site I am trying to scrap data from: <a href="https://i.sstatic.net/QQjEh.png" rel="nofollow noreferrer">https://www.onestopwineshop.com/collection/type/red-wines</a></p> <pre><code>import requests from bs4 import BeautifulSoup url = &quot;https://www.onestopwineshop.com/collection/type/red-wines&quot; r...
<python><web-scraping><beautifulsoup>
2022-12-16 23:41:43
2
323
DJ-coding
74,830,591
18,248,287
Inverse of double colon indexing
<p>I'm in want of figuring out the inverse of double indexing. For example, If I index my data <code>[::3]</code> at every three steps, then I want the negation of all those that were selected, so all those not in three steps. How can I achieve this?</p> <p>For example:</p> <pre><code>df = { 'OR': [0, 1, 0, 0, 1, 0...
<python><pandas>
2022-12-16 23:04:58
0
350
tesla john
74,830,550
17,639,970
Why having this error just for test_data?
<p>I'm trying to build a simple dtaset to work with, however, pytorch gives an error that I can't understand. Why?</p> <pre><code>import numpy as np import torch import torch.nn as nn import torch.nn.functional as F from torch.utils.data import DataLoader, TensorDataset from sklearn.model_selection import train_test_s...
<python><pytorch><dataloader>
2022-12-16 22:58:25
1
301
Rainbow
74,830,375
10,713,420
How do I create new columns based on the first occurrence in the previous group?
<p>I have a dataframe that looks like below</p> <pre><code>id reg version 1 54 1 2 54 1 3 54 1 4 54 2 5 54 3 6 54 3 7 55 1 </code></pre> <p>The goal is to assign two new columns previous_version and next_version that takes the values from id's and popul...
<python><pandas><dataframe>
2022-12-16 22:31:29
2
471
NAB0815
74,830,329
10,853,071
Pandas Crosstab dos not support Float (with capital F) number formats
<p>I am working on a sample data transaction dataframe. Such base contains cliente ID, transaction gross value (GMV) and revenue. Take this example as DF :</p> <pre><code>num_variables = 100 rng = np.random.default_rng() df = pd.DataFrame({ 'id' : np.random.randint(1,999999999,num_variables), 'date' : [np.rand...
<python><pandas>
2022-12-16 22:24:20
1
457
FábioRB
74,830,287
6,346,514
Pandas, making a dataframe based on the length of another dataframe
<p>I am trying to convert <code>df</code> to just get the length of it in a new dataframe. Which is what I do, but then this dataframe does not have a header. How do I add a header to this length?</p> <pre><code> df = df.append(df_temp, ignore_index=True, sort=True) df = len(df) </code></pre> <p>...
<python><pandas>
2022-12-16 22:19:05
1
577
Jonnyboi
74,830,278
1,562,772
python Environment Variables not changed for object of imported module
<p>I am puzzled with this behavior where environment variable is not updated correctly for class of a module I import on second or later calls.</p> <p>I have a module which have some class I initialize to get a function (and totally works fine). To control and <strong>Test</strong> some behaviors on an automated manner...
<python><python-3.x><object><environment-variables><python-3.8>
2022-12-16 22:18:18
1
991
Gorkem
74,830,150
8,816,642
Aggregate data with given bins by dates in Python
<p>I have two dataframes, one is the score with a given date,</p> <pre><code>date score 2022-12-01 0.28 2022-12-01 0.12 2022-12-01 0.36 2022-12-01 0.42 2022-12-01 0.33 2022-12-02 0.15 2022-12-03 0.23 2022-12-03 0.25 </code></pre> <p>Another dateframe is score bins,</p> <pre><code>breakpoints 0.1 0.2 0...
<python><pandas><dataframe><numpy><group-by>
2022-12-16 21:59:21
1
719
Jiayu Zhang
74,829,976
5,942,100
Separate values from date datatype using Pandas
<p>I wish to separate values from date datatype</p> <h2>Data</h2> <pre><code>time ID 2021-04-16T00:00:00.000-0800 AA 2021-04-23T00:00:00.000-0800 AA 2021-04-30T00:00:00.000-0800 BB </code></pre> <h2>Desired</h2> <pre><code>time ID 2021-04-16 AA 2021-04-23 AA 2021-04-30 ...
<python><pandas><numpy>
2022-12-16 21:35:14
2
4,428
Lynn
74,829,912
5,356,096
Splitting a list of strings into list of tuples rapidly
<p>I'm trying to figure out how to squeeze as much performance out of my code as possible, and I am facing with the issue of losing a lot of performance on tuple conversion.</p> <pre class="lang-py prettyprint-override"><code>with open(&quot;input.txt&quot;, 'r') as f: lines = f.readlines() lines = [tuple(line.str...
<python><python-3.x><list><performance><tuples>
2022-12-16 21:25:53
2
1,665
Jack Avante
74,829,721
7,211,014
Parse xml for text of every specific tag not working
<p>I am trying to gather every element <code>&lt;sequence-number&gt;</code> text into a list. Here is my code</p> <pre><code>#!/usr/bin/env python from lxml import etree response = ''' &lt;rpc-reply xmlns:nc=&quot;urn:ietf:params:xml:ns:netconf:base:1.0&quot; xmlns=&quot;urn:ietf:params:xml:ns:netconf:base:1.0&quot;...
<python><xml><parsing><element>
2022-12-16 21:01:25
1
1,338
Dave
74,829,713
4,343,563
Try-except with if conditions?
<p>I have created if-else statements within my functions to check if certain conditions are met. However, I need to convert it try-except statement since the app I am working on is set up so that when a condition is met, it creates log info statements and when it is not met it creates log error statements. Currently my...
<python><if-statement><try-except>
2022-12-16 20:59:47
1
700
mjoy
74,829,709
3,727,975
Receiving Error: 'apxs' command appears not to be installed
<p>This is the error I am receiving: <code>RuntimeError: The 'apxs' command appears not to be installed or is not executable. Please check the list of prerequisites in the documentation for this package and install any missing Apache httpd server packages.</code></p> <p>How can I get around this? I have received this w...
<python><django>
2022-12-16 20:59:27
1
720
qbush
74,829,659
5,881,882
Can't fix torch autograd runtime error: UNet inplace operation
<p>I can't fix the runtime error &quot;one of the variables needed for gradient computation has been modified by an inplace operation.</p> <p>I know, that if I comment out <code>loss.backward()</code> the code will run, but I don't get in which order should I call the functions to avoid this error</p> <p>When I call it...
<python><pytorch><autograd><unet-neural-network>
2022-12-16 20:53:32
1
388
Alex
74,829,618
4,361,020
Split string into segments according to the alphabet
<p>I want to split the given string into alphabet segments that the string contains. So for example, if the following string is given:</p> <pre><code>Los eventos automovilísticos comenzaron poco después de la construcción exitosa de los primeros automóviles a gasolina. El veloz zorro marrón saltó sobre el perezoso perr...
<python><string><text><nlp><cld2>
2022-12-16 20:48:30
1
791
Sirojiddin Komolov
74,829,544
2,803,488
How to use record separator as delimiter in Pandas
<p>I am trying to use the record separator (<code>0x1E</code>) as the separator in the Pandas read_table() function, but it is instead it seems to be splitting on <code>\n</code> (<code>0x0A</code>).</p> <p>This is my code:</p> <pre><code>df = pandas.read_table( &quot;separator.log&quot;, sep = &quot;[\x1E]&quot;, engi...
<python><pandas>
2022-12-16 20:37:52
1
455
Adam Howell
74,829,476
3,521,180
why the return statement inside main function is terminating unexpectedly?
<p>I have a requirement wherein I have to perform multiple pyspark transformations and write it to a parquet file. But below are the conditions:</p> <ul> <li><p>there are in total 2 files, but at a time either one of them or both could be supplied by the user.</p> </li> <li><p>when x_path file is given then <code>if i ...
<python><python-3.x><pyspark><pytest>
2022-12-16 20:30:07
0
1,150
user3521180
74,829,469
18,392,410
polars native way to convert unix timestamp to date
<p>I'm working with some data frames that contain Unix epochs in ms, and <strong>would like to display the entire timestamp series as a date.</strong> Unfortunately, the docs did not help me find a polars native way to do this, and I'm reaching out here. <strong>Solutions on how to do this in Python and also in Rust</s...
<python><pandas><datetime><python-polars><rust-polars>
2022-12-16 20:29:14
1
563
tenxsoydev
74,829,420
18,086,775
How to drop rows based on multiple condition?
<p>I have the following <strong>datframe setup</strong>:</p> <pre><code>dic = {'customer_id': [102, 102, 105, 105, 110, 110, 111], 'product':['skateboard', 'skateboard', 'skateboard', 'skateboard', 'shoes', 'skateboard', 'skateboard'], 'brand': ['Vans', 'Converse', 'Vans', 'Converse', 'Converse','Convers...
<python><pandas><dataframe><data-wrangling>
2022-12-16 20:23:14
3
379
M J
74,829,335
10,037,461
Convert PySpark DataFrame column with list in StringType to ArrayType
<p>So I got an input pysaprk dataframe that looks like the following:</p> <pre><code>df = spark.createDataFrame( [(&quot;1111&quot;, &quot;[clark, john, silvie]&quot;), (&quot;2222&quot;, &quot;[bob, charles, seth]&quot;), (&quot;3333&quot;, &quot;[jane, luke, adam]&quot;), ], [&quot;column1&quo...
<python><python-3.x><pyspark>
2022-12-16 20:12:13
1
415
Lucas Mengual
74,829,297
5,106,834
Can a QAbstractItemModel trigger a layout change whenever underyling data is changed?
<p>The following is a slightly modified version of the <a href="https://www.pythonguis.com/tutorials/modelview-architecture/" rel="nofollow noreferrer">Model/View To-Do List tutorial</a>.</p> <p>I have a class <code>Heard</code> that is composed of a list of <code>Animal</code>. The <code>Heard</code> serves as the und...
<python><architecture><pyqt><pyqt5>
2022-12-16 20:06:39
1
607
Andrew Plowright
74,829,288
17,277,677
predict_proba on pyspark testing dataframe
<p>I am very new to pyspark and need to perform prediction. I've already done everything but in python, because the data I have to apply the logic is huge - I need to transform everything to pyspark.</p> <p>The problem is: I have 2 dataframes, first dataframe is for training purposes with Y column and the second one is...
<python><pyspark><classification>
2022-12-16 20:05:53
1
313
Kas
74,829,264
6,535,324
PyCharm, open new window for each "View as DataFrame"
<p>In Debug mode, I would like PyCharm to open a new window (<em>not</em> a new tab!) for every &quot;View as DataFrame&quot; click I do.</p> <p><a href="https://i.sstatic.net/kSNdA.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/kSNdA.png" alt="enter image description here" /></a></p> <p>Right now, they...
<python><pycharm>
2022-12-16 20:02:49
0
2,544
safex
74,829,237
392,923
populating elements of dict using pandas.read_pickle() results in killed python process
<p>On an Ubuntu 18.04.5 image running on AWS, I've noticed that attempting to populate a dict with multiple (7, in my case) dataframes loaded via pandas.read_pickle(), e.g., using something like</p> <pre><code>import pathlib import pandas as pd df_dict = {} base_dir = pathlib.Path('some_path') for i, f in base_dir.glob...
<python><pandas><dataframe><pickle><feather>
2022-12-16 20:00:17
0
1,391
lebedov
74,829,095
7,802,183
Which Seasonal Adjustment Program should I use with Statsmodels X-13-ARIMA
<p>I have downloaded Win X-13 <a href="https://www.census.gov/data/software/x13as.Win_X-13.html#list-tab-635278563" rel="nofollow noreferrer">from Census</a>, and unpacked it on my drive.</p> <p>My code looks like this:</p> <pre><code>import pandas as pd from pandas import Timestamp import os import statsmodels.api as ...
<python><statsmodels><arima>
2022-12-16 19:43:37
1
507
NRVA
74,829,045
5,319,229
subsetting by two conditions (True & False) evaluating to (True)
<pre><code>import pandas as pd d = {'col1':[1, 2, 3, 4, 5], 'col2':[5, 4, 3, 2, 1]} df = pd.DataFrame(data=d) df[(df['col1'] == 1) | (df['col1'] == df['col1'].max()) &amp; (df['col1'] &gt; 2)] </code></pre> <p>Why doesn't this filter out the first row? Where col1 is less than 2?</p> <p>I'm getting this:</p> <pre><code...
<python><pandas>
2022-12-16 19:39:07
1
3,226
Rafael
74,829,028
5,213,521
detect socket timeout when using "with" instead of "try"
<p>Using python 3.6.8, I have the following code</p> <pre><code>with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.settimeout(20) s.connect(host, port) </code></pre> <p>As I understand it, using <code>with</code> as shown instead of a <code>try</code> <code>except</code> block better handles the er...
<python>
2022-12-16 19:37:13
0
382
Consumer of Cat Content
74,829,002
327,038
Is there a way to use pytest.raises in pytest-bdd "When" steps?
<p>I would like to define a scenario as follows:</p> <pre class="lang-gherkin prettyprint-override"><code>Scenario: An erroneous operation Given some data And some more data When I perform an operation Then an exception is raised </code></pre> <p>Is there a good way to do this so that the <code>when</code> step...
<python><pytest><pytest-bdd>
2022-12-16 19:34:16
1
9,487
asthasr
74,828,993
15,781,591
how to build multiple dropdown prompt function using IPyWidget?
<p>I am trying to build a simple tool in python here that simply asks the user to select a fruit type and then a color type from two drop down options and then, based on the user input, print a string that reads: &quot;I would love to try a <em>color</em> <em>fruit</em>!&quot;. I am using IPyWidget for the dropdown fun...
<python><jupyter-notebook><ipywidgets>
2022-12-16 19:32:11
1
641
LostinSpatialAnalysis
74,828,731
1,411,376
When kuberentes terminates a pod, it kills any ongoing pyodbc calls, even when the parent python process is handling SIGTERM etc
<p>I have a python docker container running in kuberetes. The code's general workflow is that it receives messages and then kicks off a series of long-running SQL Server statements via pyodbc.</p> <p>My goal is to increase the kubernetes timeout and intercept the shutdown signal so that we can finish our SQL statements...
<python><sql-server><docker><kubernetes><pyodbc>
2022-12-16 19:00:50
0
795
Max
74,828,698
143,684
Python type checking: cannot assign to a dict
<p>I get the following error message in my Python code when assigning something to a dict:</p> <pre><code>Argument of type &quot;dict[Unknown, Unknown]&quot; cannot be assigned to parameter &quot;__value&quot; of type &quot;str&quot; in function &quot;__setitem__&quot; &quot;dict[Unknown, Unknown]&quot; is incompatib...
<python><python-typing><pyright>
2022-12-16 18:56:36
0
20,704
ygoe
74,828,666
5,237,560
Why doesn't spawned process start
<p>I'm having issues using Python's multiprocessing module. Here is a (Very) simplified version of the issue i'm having trying to use a multiprocessing queue to communicate between the spawned process and the main process:</p> <pre><code>from time import sleep import multiprocessing as mp # add number to queue Q ever...
<python><multiprocessing>
2022-12-16 18:52:16
2
42,197
Alain T.
74,828,640
4,863,700
Stable Diffusion issue on intel mac: connecting the weights/model and connecting to the model.ckpt file
<p>I'm trying to get a command line version of Stable Diffusion up and running on Mac Intel from the following repo: <a href="https://github.com/cruller0704/stable-diffusion-intel-mac" rel="nofollow noreferrer">https://github.com/cruller0704/stable-diffusion-intel-mac</a></p> <p>I'm getting the error: <code>Too many le...
<python><artificial-intelligence><stable-diffusion>
2022-12-16 18:49:03
1
4,550
Agent Zebra
74,828,633
10,819,464
Selenium Python: Hidden Input Field Not Interactable
<p>I'm working on selenium python (modifying zap auth repo) trying to pass login page that has hidden field for the password. So the login flow would be, <strong>Insert Email</strong> &gt; <strong>Click Button &quot;Continue&quot;</strong> &gt; <strong>(password field comes up)</strong> <strong>Insert Password</strong>...
<python><selenium><selenium-webdriver>
2022-12-16 18:47:43
0
467
Dhody Rahmad Hidayat
74,828,478
10,681,595
Convert Row values of a column into multiple columns by value count with Dask Dataframe
<p>Using the pandas library, this operation is very quick to be performed.</p> <pre class="lang-py prettyprint-override"><code>import pandas as pd import dask.dataframe as dd df = pd.DataFrame(columns=['name','contry','pet'], data=[['paul', 'eua', 'cat'], ['pedro', 'brazil', ...
<python><pandas><dataframe><group-by><dask>
2022-12-16 18:30:32
1
442
the_RR
74,827,982
1,394,697
Using a buffer to write a psycopg3 copy result through pandas
<p>Using <code>psycopg2</code>, I could write large results as CSV using <code>copy_expert</code> and a <code>BytesIO</code> buffer like this with <code>pandas</code>:</p> <pre class="lang-py prettyprint-override"><code>copy_sql = &quot;COPY (SELECT * FROM big_table) TO STDOUT CSV&quot; buffer = BytesIO() cursor.copy_...
<python><pandas><postgresql><psycopg2><psycopg3>
2022-12-16 17:39:55
2
14,401
FlipperPA
74,827,763
14,594,208
How to create all combinations of one column's items and choose one of the other columns each time?
<p>For instance, let's consider the following DataFrame:</p> <pre><code> id metric_a metric_b 0 a 1 2 1 b 10 20 2 c 30 40 </code></pre> <p>The resulting dataframe would consist of all the combinations of <code>id</code>, that is n<sup>2</sup> rows (square matrix).</p> <p>In ...
<python><pandas>
2022-12-16 17:20:15
1
1,066
theodosis
74,827,534
7,134,235
How can I create a new dataframe out of a json column in a pyspark dataframe?
<p>I have a pyspark dataframe where some of the columns are nested json objects, because I created it from a jsonl file. The schema looks like this:</p> <pre><code>root |-- _corrupt_record: string (nullable = true) |-- meeting: struct (nullable = true) | |-- meeting_id: string (nullable = true) | |-- meeting_...
<python><json><pyspark>
2022-12-16 16:56:23
0
906
Boris
74,827,473
9,212,995
What are other options available to generate DOIs without using extensions in CKAN?
<p>Well, I would like to know if there is any other options that I can use to generate <strong>DOI</strong>s for all or newly created datasets in <strong>CKAN</strong> if I am not using <strong>ckanext-doi</strong> extension. Can someone try to explain how this is possible.</p> <p>As far as I know, <strong>DataCite</st...
<python><metadata><ckan><metadata-extractor><doi>
2022-12-16 16:50:39
1
372
Namwanza Ronald
74,827,466
7,800,760
Stanford Stanza NLP to networkx: superimpose NER entities onto graph of words
<p>Here is a sample program which will take a text (example is in italian but Stanza supports many languages) and builds and displays a graph of the words (only certain Parts of Speech) and their syntactic relationships:</p> <pre><code>&quot;&quot;&quot; Sample program to analyze a phrase with Stanfords STANZA and buil...
<python><nlp><networkx><stanford-nlp>
2022-12-16 16:49:39
0
1,231
Robert Alexander
74,827,380
3,450,163
Convert 1-D array to upper triangular square matrix (anti-diagonal) in numpy
<p>I have an array as below:</p> <pre><code>arr = np.numpy([1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21]) </code></pre> <p>What I would like to do is to convert this array to an upper triangular square matrix anti-diagonally. The expected output is like below:</p> <pre><code>output = [ [1, 2, 3, 4, 5,...
<python><arrays><numpy>
2022-12-16 16:42:29
2
3,097
GoGo
74,827,320
4,171,008
AtributeError: can't set attribute for python list property
<p>I'm working with the <code>python-docx</code> library from a forked <a href="https://pypi.org/project/bayoo-docx/" rel="nofollow noreferrer">version</a>, and I'm having an issue with editing the elements list as it is defined as a property.</p> <pre class="lang-py prettyprint-override"><code># docx.document.Document...
<python><python-3.x><list><python-decorators><python-docx>
2022-12-16 16:36:41
2
1,884
Ahmad
74,827,286
10,190,191
How to read bytes type from bigquery in Java?
<p>We have a legacy dataflow job in Scala which basically reads from Bigquery and then dumps it into Postgres. <br> In Scala we read from bigquery, map it onto a case class and then dump it into Postgres, and it works perfectly for bigquery's <code>Bytes</code> type as well.<br> The Schema we read from BQ into has an <...
<python><java><google-bigquery><pickle>
2022-12-16 16:33:27
1
714
saadi
74,827,243
1,862,861
Cython numpy array view off by one when wraparound is False
<p>I have some Cython code where I fill in the last value in each row of a memory view of a NumPy array with a number. If I compile the code with <code>wraparound = False</code>, the last value in the final row of the array does not get filled in. However, if I set <code>wraparound = True</code> it does get filled in a...
<python><numpy><cython>
2022-12-16 16:29:06
1
7,300
Matt Pitkin
74,827,216
10,934,417
ThreadPoolExecutor or multi-processing for Pandas DataFrame
<p>Asuume there will be a mega size dataframe, which has &gt; <strong>1M</strong> columns. Based on the following toy dataframe.</p> <pre><code>import pandas as pd import numpy as np from concurrent.futures import * import multiprocessing num_processes = multiprocessing.cpu_count() print(f'num_precesses: {num_processe...
<python><pandas>
2022-12-16 16:26:51
0
641
DaCard
74,827,212
13,839,945
Python add path of data directory
<p>I want to add a path to my data directory in python, so that I can read/write files from that directory without including the path to it all the time.</p> <p>For example I have my working directory at <code>/user/working</code> where I am currently working in the file <code>/user/working/foo.py</code>. I also have a...
<python><file><path>
2022-12-16 16:26:36
2
341
JD.
74,827,200
11,197,796
Groupby and assign operation result to each group
<pre><code>df = pd.DataFrame({'ID': ['A','A','A','A','A'], 'target': ['B','B','B','B','C'], 'length':[208,315,1987,3775,200], 'start':[139403,140668,141726,143705,108], 'end':[139609,140982,143711,147467,208]}) ID target length star...
<python><pandas><dataframe>
2022-12-16 16:25:26
1
440
skiventist
74,827,163
9,394,364
Parsing a log file and ignoring text between two targets
<p>This question is a follow-up to my previous question here: <a href="https://stackoverflow.com/q/74818311/9394364">Parsing text and JSON from a log file and keeping them together</a></p> <p>I have a log file, <code>your_file.txt</code> with the following structure and I would like to extract the timestamp, run, user,...
<python><regex>
2022-12-16 16:22:30
1
1,651
DJC
74,827,127
8,901,144
Pyspark Rolling Sum based on ID, timestamp and condition
<p>I have the following pyspark dataframe</p> <pre><code>id timestamp col1 1 2022-01-01 0 1 2022-01-02 1 1 2022-01-03 1 1 2022-01-04 0 2 2022-01-01 1 2 2022-01-02 0 2 2022-01-03 1 </code></pre> <p>I would like to get the cumulative sum of col1 for each ID and based on timestamp as an addi...
<python><pyspark><group-by><window-functions>
2022-12-16 16:19:01
1
1,255
Marco
74,827,051
16,988,223
How I can get the value of this json key called 'sentence'
<p>I want to extract the values of the key called 'sentence' of this json:</p> <pre><code>{&quot;title&quot;: &quot;llamar | Definici\u00f3n | Diccionario de la lengua espa\u00f1ola | RAE - ASALE&quot;, &quot;articles&quot;: [{&quot;id&quot;: &quot;NTReP1j&quot;, &quot;lema&quot;: {&quot;lema&quot;: &quot;llamar&quot;,...
<python><json>
2022-12-16 16:12:10
4
429
FreddicMatters
74,827,011
930,122
Python: reconstruct image from difference
<p>Using the following code I calculated the difference matrix between two images:</p> <pre><code>import time import cv2 from imutils.video import VideoStream from skimage.metrics import structural_similarity from skimage.color import rgb2gray cap = VideoStream(src=0, framerate=30).start() cap.stream.set(cv2.CAP_PROP_...
<python><opencv><difference><scikit-image>
2022-12-16 16:09:00
0
1,695
Lorenzo Sciuto
74,826,979
8,117,999
How to tag previous months with sequence
<p>Given a datframe:</p> <pre><code>df = pd.DataFrame({'c':[0,1,1,2,2,2],'date':pd.to_datetime(['2016-01-01','2016-02-01','2016-03-01','2016-04-01','2016-05-01','2016-06-05'])}) </code></pre> <p>How can I tag the latest month as M1, 2nd latest as M2 and then so on.</p> <p>so for and example out looks like this:</p> <pr...
<python><pandas><dataframe>
2022-12-16 16:06:27
1
2,806
M_S_N
74,826,828
7,168,098
Python Pandas: using slice to build a multiindex slicing in pandas
<p>I have a double Multiindex dataframe as follows. I slice the rows with idx = pd.IndexSlice but I don't know how to do the same with the columns so provided this data:</p> <pre><code>df = pd.DataFrame(data=pd.DataFrame(data=np.random.randint(0, 10, size=(9, 5)))) # rows list1 = ['2021-01-01','2022-02-01','2022-03-01'...
<python><pandas><slice><multi-index>
2022-12-16 15:54:02
1
3,553
JFerro
74,826,411
5,224,236
Listing blobs inside container in Azure
<p>I am able to download a single file from azure blob storage using python:</p> <pre><code>from azure.storage.blob import BlobClient, ContainerClient import pandas as pd from io import StringIO sas_url = 'https://tenant_datalake.blob.core.windows.net/filename.xml?sp=racwdymeop&amp;st=2022-12-16T14:24:34Z&amp;se=2022-1...
<python><azure><azure-blob-storage>
2022-12-16 15:19:50
1
6,028
gaut
74,826,333
2,707,864
Install Quantum Development Kit (QDK) in Ubuntu, without conda
<p>I mean to use QDK in Ubuntu 22.04LTS. I have a virtualenv, but no conda. I installed qsharp in my venv with</p> <pre><code>$ pip3 install qsharp </code></pre> <p>but then</p> <pre><code>$ python -c &quot;import qsharp&quot; IQ# is not installed. Please follow the instructions at https://aka.ms/qdk-install/python. Tr...
<python><q#><qdk>
2022-12-16 15:13:20
1
15,820
sancho.s ReinstateMonicaCellio
74,826,238
8,761,554
Assigning functional relu to a variable while inplace parameter is True
<p>If I want to do ReLU operation after my convolution on x, and in my code I do:</p> <pre><code>x = F.leaky_relu(x, negative_slope=0.2, inplace=True) </code></pre> <p>Is this code wrong since I assign the relu to x variable while <code>inplace</code> is <code>True</code>? Ie. does it mean the ReLU function ran twice a...
<python><machine-learning><pytorch><in-place><relu>
2022-12-16 15:06:12
1
341
Sam333
74,826,213
17,654,424
Inserting items in a list with python while looping
<p>I'am trying to change the following code to get the following return :</p> <p>&quot;1 2 3 ... 31 32 33 34 35 36 37 ... 63 64 65&quot;</p> <pre><code>def createFooter2(current_page, total_pages, boundaries, around) -&gt; str: footer = [] page = 1 #Append lower boundaries while page &lt;= boundaries: ...
<python><list><insert>
2022-12-16 15:04:22
2
651
Simao
74,825,983
1,169,091
It looks like a List but I can't index into it: ValueError: Length of values (2) does not match length of index (279999)
<p>I am importing the CSV file from here: <a href="https://raw.githubusercontent.com/kwartler/Harvard_DataMining_Business_Student/master/BookDataSets/LaptopSales.csv" rel="nofollow noreferrer">https://raw.githubusercontent.com/kwartler/Harvard_DataMining_Business_Student/master/BookDataSets/LaptopSales.csv</a></p> <p>T...
<python><pandas><dataframe><dfply>
2022-12-16 14:44:15
2
4,741
nicomp
74,825,855
12,752,172
How to format list data and write to csv file in selenium python?
<p>I'm getting data from a website and storing them inside a list of variables. Now I need to send these data to a CSV file. The website data is printed and shown below.</p> <p><strong>The data getting from the Website</strong></p> <pre><code>['Company Name: PATRY PLC', 'Contact Name: Jony Deff', 'Company ID: 234567', ...
<python><selenium><csv>
2022-12-16 14:32:58
1
469
Sidath
74,825,685
7,168,098
python pandas: using pd.IndexSlice for both rows and columns in a double multiindex dataframe
<p>I have a double Multiindex dataframe as follows. I slice the rows with idx = pd.IndexSlice but I dont know how to do the same with the columns so provided this data:</p> <pre><code>df = pd.DataFrame(data=pd.DataFrame(data=np.random.randint(0, 10, size=(9, 5)))) # rows list1 = ['2021-01-01','2022-02-01','2022-03-01']...
<python><pandas><slice><multi-index>
2022-12-16 14:17:02
1
3,553
JFerro
74,825,616
4,557,493
Multiple Django Projects using IIS but Getting Blank Page on Second Site
<p>I'm running two django projects in IIS with wfastcgi enabled. The first django project is running without an issue but the second project displays a blank page (code 200) returned.</p> <p>Second Project Info:</p> <p>A virtual folder, within it's own application pool in IIS, is created to host the second project. T...
<python><django><iis><wfastcgi>
2022-12-16 14:11:07
1
723
Shoother
74,825,613
453,767
Element is found but not clickable
<p>I'm trying to find an element by it's id, click on it and download a file.</p> <pre><code>driver.get(url); driver.implicitly_wait(60); time.sleep(3) element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, &quot;ContentPlaceHolder1_a1&quot;))) href = element.get_attribute('href') value = href.spl...
<python><selenium><webdriverwait><web-scripting>
2022-12-16 14:10:56
1
7,409
Amit Kumar Gupta
74,825,507
14,030,805
why unpickling functions is not possible using pickle?
<p>when i use pickle package to serialize a dict object for example, i can load it in another context without problem. but it's not the case for functions unless i import it again as explained <a href="https://stackoverflow.com/questions/27732354/unable-to-load-files-using-pickle-and-multiple-modules#:%7E:text=111,clas...
<python><function><pickle>
2022-12-16 14:02:56
0
365
Kaoutar
74,824,944
3,474,956
How to optimize the zoom parameter in zoomed_inset_axes?
<p>I am creating plots that include zoom inserts. The data is diverse it is impossoble for me to know what the data will be like before the program starts. I want to make the zoom insert zoom in as much as possible, without overlapping with any other element of my plot. Here is an example, where I use a zoom of 2. Idea...
<python><matplotlib>
2022-12-16 13:13:54
1
10,243
kilojoules
74,824,935
5,945,369
Transform a 3D numpy array to 1D based on column value
<p>Maybe this is a very simple task, but I have a numpy.ndarray with shape (1988,3).</p> <pre class="lang-python prettyprint-override"><code>preds = [[1 0 0] [0 1 0] [0 0 0] ... [0 1 0] [1 0 0] [0 0 1]] </code></pre> <p>I want to create a 1D array with shape=(1988,) that ...
<python><arrays><numpy>
2022-12-16 13:13:09
1
976
joasa
74,824,911
2,095,521
Python split string retaining the bracket
<p>I would like to split the string and eliminate the whitespaces such as</p> <pre><code>double a[3] = {0.0, 0.0, 0.0}; </code></pre> <p>The expected output is</p> <pre><code>['double', 'a', '[', '3', ']', '=', '{', '0.0', ',', '0.0', ',', '0.0', '}', ';'] </code></pre> <p>How could I do that with re module in Python?<...
<python><string><split>
2022-12-16 13:10:11
3
570
kstn
74,824,819
13,285,583
selenium-standalone-chrome throws error when driver is trying to connect
<p>My goal is to run Selenium in a docker. The problem is that it refused to connect although selenium-standalone-chrome works fine and I can hit <a href="http://127.0.0.1:4444" rel="nofollow noreferrer">http://127.0.0.1:4444</a> in my own browser.</p> <p>The culrpit:</p> <pre><code>chrome_options = webdriver.ChromeOpt...
<python><selenium><selenium-webdriver>
2022-12-16 13:01:29
0
2,173
Jason Rich Darmawan
74,824,477
20,793,070
Multi-columns filter VAEX dataframe, apply expression and save result
<p>I want to use VAEX for lazy work wih my dataframe. After quick start with export big csv and some simple filters and extract() I have initial df for my work with 3 main columns: cid1, cid2, cval1. Each combitations of cid1 and cid2 is a workset with some rows where is cval1 is different. My df contents only valid ci...
<python><dataframe><vaex>
2022-12-16 12:29:38
1
433
Jahspear
74,824,353
12,231,454
Patch Django EmailMultiAlternatives send() in a Celery Task so that an exception is raised
<p>I want to test a Celery Task by raising an SMTPException when sending an email.</p> <p>With the following code, located in:</p> <p><strong>my_app.mailer.tasks</strong></p> <pre><code>from django.core.mail import EmailMultiAlternatives @app.task(bind=True ) def send_mail(self): subject, from_email, to = 'hello',...
<python><django><mocking><celery><django-celery>
2022-12-16 12:17:49
2
383
Radial