QuestionId
int64
74.8M
79.8M
UserId
int64
56
29.4M
QuestionTitle
stringlengths
15
150
QuestionBody
stringlengths
40
40.3k
Tags
stringlengths
8
101
CreationDate
stringdate
2022-12-10 09:42:47
2025-11-01 19:08:18
AnswerCount
int64
0
44
UserExpertiseLevel
int64
301
888k
UserDisplayName
stringlengths
3
30
75,306,735
5,024,631
How to quickly convert groups in a pandas df to a list of separate arrays?
<p>I made this function which converts the groups within a pandas dataframe into a separate list of arrays:</p> <pre><code>def convertPandaGroupstoArrays(df): # convert each group to arrays in a list. groups = df['grouping_var'].unique() mySeries = [] namesofmyseries = [] for group in groups: ...
<python><arrays><pandas>
2023-02-01 07:13:13
1
2,783
pd441
75,306,453
13,359,498
Explaining Resnet50/Densenet121 outputs with LIME
<p>I am trying to explain the outputs of my Transfer learning models in Keras with LIME. I am following this <a href="https://towardsdatascience.com/interpreting-image-classification-model-with-lime-1e7064a2f2e5" rel="nofollow noreferrer">blog</a>.</p> <p>My model is a multi-class image classifier. I am implementing LI...
<python><tensorflow><keras><deep-learning><visualization>
2023-02-01 06:36:49
1
578
Rezuana Haque
75,306,441
3,247,006
How to use "Prefetch()" with "filter()" to reduce `SELECT` queries to iterate 3 or more models?
<p>I have <code>Country</code>, <code>State</code> and <code>City</code> models which are chained by foreign keys as shown below:</p> <pre class="lang-py prettyprint-override"><code>class Country(models.Model): name = models.CharField(max_length=20) class State(models.Model): country = models.ForeignKey(Countr...
<python><django><postgresql><django-models><django-prefetch>
2023-02-01 06:35:49
1
42,516
Super Kai - Kazuya Ito
75,306,200
4,095,108
Add the word "cant" to Spacy stopwords
<p>How to I get <code>SpaCy</code> to set words such as &quot;cant&quot; and &quot;wont&quot; as stopwords?<br /> For example, even with tokenisation it will identify &quot;can't&quot; as a stop word, but not &quot;cant&quot;.<br /> When it sees &quot;cant&quot;, it removes &quot;ca&quot; but leaves &quot;nt&quot;. Is ...
<python><spacy>
2023-02-01 06:00:57
2
1,685
jmich738
75,306,132
866,082
WARNING:tensorflow:Inconsistent references when loading the checkpoint into this object graph
<p>I'm saving and loading a Keras model with some custom layers (even though I'm not sure if custom layers have anything to do with the issue). For the record, I'm not saving the model myself but it's done through TFX's Pusher component. At the time of loading, I get a few warnings:</p> <pre><code>WARNING:tensorflow:In...
<python><tensorflow><machine-learning><keras><deep-learning>
2023-02-01 05:50:42
0
17,161
Mehran
75,306,070
15,233,108
How do I match the file name from different directories and replace the partial filename with the actual filename?
<p>So I have a slightly complicated issue that I need some help with :(</p> <p>In Directory 1, I have the filenames as follows:</p> <blockquote> <p>00HFP.mp4<br /> 0AMBV.mp4<br /> 2D5GN.mp4<br /> 3HVKR.mp4<br /> 3IJGQ.mp4</p> </blockquote> <p>In Directory 2, I did some processing to the mp4s and got some output files:<...
<python><file><io>
2023-02-01 05:38:57
1
582
Megan Darcy
75,305,784
10,339,757
Replace value in mutiple columns based on dictionary map
<p>I have a dataframe that looks similar to -</p> <pre><code>df = DataFrame(data={'ID': ['a','b','c','d'], 'col1':[1,2,3,4], 'col2':[5,6,7,8], 'col3':[9,10,11,12]}) </code></pre> <p>I have a dictionary like this</p> <pre><code>mapper = {'a':100,'d':3} </code></pre> <p>Where the key in the dictionary matches the ID in t...
<python><python-3.x><pandas><dataframe>
2023-02-01 04:49:04
3
371
thefrollickingnerd
75,305,671
16,169,533
Seperate duplicate in string into list
<p>I have a following string</p> <pre><code>&quot;TAUXXTAUXXTAUXX&quot; </code></pre> <p>i want to make a list contains the following</p> <pre><code>lst = [&quot;TAUXX&quot;, &quot;TAUXX&quot;, &quot;TAUXX&quot;] </code></pre> <p>How i make it and is there is a string library in python to do it ?</p> <p>Thanks in advan...
<python><arrays><string><list>
2023-02-01 04:31:01
2
424
Yussef Raouf Abdelmisih
75,305,603
9,092,563
How do you divide up a list into chunks which vary according to a normal distribution
<p>I want to take a list of thousands of items and group them into 12 chunks, where the number of items found in each chunk correspond to a normal distribution (bell curve) and <strong>no duplicates across chunks - the list must exhaust itself</strong>.</p> <h2>Input data looks like this</h2> <pre><code>['6355ab76f70c5...
<python><list><numpy><sorting><normal-distribution>
2023-02-01 04:17:40
2
692
rom
75,305,569
12,319,746
Getting all build logs from Jenkins API
<p>I need to get logs for all builds from a Jenkins instance.</p> <pre><code>def get_builds(): builds_api_res = session.get('https://build.org.com/api/json?depth=3',stream=True,auth=(username,access_token),).json() for chunk in builds_api_res.iter_content(chunk_size=1024*1024): # Do something with the c...
<python><jenkins><jenkins-api>
2023-02-01 04:10:54
1
2,247
Abhishek Rai
75,305,478
9,919,423
Can tf.gradienttape() calculate gradient of other library's function
<p>If I include inside the <code>tf.GradientTape()</code> some functions from other Python libraries, like `sklearn.decomposition.PCA.inverse_transform()', can TensorFlow calculate gradients from that function?</p> <p>Specifically, can tf automatically differetiate <code>pca_inverse_tranform = pca.inverse_transform(h2)...
<python><tensorflow><keras><automatic-differentiation><gradienttape>
2023-02-01 03:53:11
1
412
David H. J.
75,305,341
2,579,031
How to add pause in Google Text to Speech?
<p>I am trying to use Google Cloud text to speech module, and I can convert a text to audio using below code. But I am unable to add breaks in the code, like a pause of 5 sec. I have added tags for break in my <strong>synthesis_input variable</strong>. Can anyone help me with that?</p> <pre><code>import os from google....
<python><google-cloud-platform><google-text-to-speech>
2023-02-01 03:26:19
2
939
Abhishek dot py
75,305,242
1,828,539
How to read a list of h5 objects in a dictionary and assign them to the names said dictionary?
<p>If I have the following dictionary:</p> <pre><code>input_dict = {'Sample': ['org_1', 'org_2', 'org_3'], 'Location': ['../cellbender/SAM24425933_cellbender_out_filtered.h5', '../cellbender/SAM24425932_cellbender_out_filtered.h5', '../cellbender/SAM...
<python><dictionary>
2023-02-01 03:04:03
1
2,376
Carmen Sandoval
75,305,169
3,843,659
Decoding hidden layer embeddings in T5
<p>I'm new to NLP (pardon the very noob question!), and am looking for a way to perform vector operations on sentence embeddings (e.g., randomization in embedding-space in a uniform ball around a given sentence) and then decode them. I'm currently attempting to use the following strategy with T5 and Huggingface Transfo...
<python><machine-learning><nlp><huggingface-transformers><transformer-model>
2023-02-01 02:49:47
1
565
jmindel
75,305,001
10,844,937
How to add Pandas dataframe to an existing xlsx file using to_excel
<p>I have write some content to a xlsx file by using <code>xlsxwriter</code></p> <pre><code>workbook = xlsxwriter.Workbook(file_name) worksheet = workbook.add_worksheet() worksheet.write(row, col, value) worksheet.close() </code></pre> <p>I'd like to add a dataframe after the existing rows to this file by <code>to_exce...
<python><pandas><xlsxwriter>
2023-02-01 02:12:11
2
783
haojie
75,304,991
1,256,757
How to deploy Apache superset using mod_wsgi that is installed in python3-venv?
<p>I have installed apache superset and i need to run this through wsgi server using mod_wsgi of apache. Im new to python and configuring apache. I need help on what exactly my superset.wsgi would look like and my superset.conf would look like.</p> <p>This is my conf</p> <pre><code>&lt;VirtualHost *:80&gt; WSGIDaem...
<python><mod-wsgi><python-venv><apache-superset>
2023-02-01 02:09:33
1
342
butching
75,304,942
15,843,133
xlrd assertion error when opening a .xls file (converted from .xlsx): assert _unused_i == nstrings - 1
<p>I have a script that uses the xlrd library to read and write .xls files. The program works for most .xls', but I found that after I converted an .xlsx to .xls and try to open the workbook, I get the following assertion error:</p> <pre><code>Traceback (most recent call last): File &quot;/home/troublebucket/Projects...
<python><excel><xlrd>
2023-02-01 01:57:38
1
353
Trouble Bucket
75,304,882
678,188
Terminal on brand new macbook 2023 with Mac OSX Ventura 13.2 gives error "zsh: command not found: python"
<p>Terminal on brand new macbook 2023 with M2 chip and Mac OSX Ventura 13.2 gives error &quot;zsh: command not found: python&quot;.</p> <p>Haven't been able to find answer on google.</p>
<python><macos-ventura>
2023-02-01 01:46:21
0
529
esd100
75,304,836
10,049,514
FastAPI Pagination with Redis
<p>Currently I have some cached data in a Redis cluster and the data is being served over an endpoint developed by FastAPI.</p> <p>Below is an example:</p> <pre><code>key_001: [value_1, value_2, value_3, value_4] </code></pre> <p>There is another service that updates this data in real-time. For example this service and...
<python><redis><pagination><fastapi>
2023-02-01 01:36:03
0
1,071
knl
75,304,698
772,649
How to add typing hints of **kwargs?
<p>Here is an example:</p> <pre class="lang-py prettyprint-override"><code>class A: def __init__(self, a=1, b=2, c=3): self.a = a self.b = b self.c = c class B(A): def __init__(self, d=4, **kwargs): super().__init__(**kwargs) self.d = d </code></pre> <p><code>B</code> ad...
<python><typing><keyword-argument><pylance>
2023-02-01 01:08:41
1
97,797
HYRY
75,304,693
2,175,783
how to set env variable in conda and use it in ansible
<p>I am debugging this ansible call in a shell script (I am a complete beginner in ansible)</p> <pre><code>source /path/.conda/etc/profile.d/conda.sh &amp;&amp; \ conda activate my_ansible &amp;&amp; \ AWS_REGION=us-east-1 \ AWS_SHARED_CREDENTIALS_FILE=acredsfile \ ansible-playbook /path/ansible...
<python><amazon-web-services><ansible><conda>
2023-02-01 01:07:55
0
1,496
user2175783
75,304,615
4,926,165
How do I programmatically create class methods in Python?
<p>Suppose I want to define a Python class whose instances have several members of similar form:</p> <pre><code>class Bar: def __init__(self): self.baz=3 self.x=1 self.name=4 </code></pre> <p>I can instead create all members at once using explicit manipulation of <code>__dict__</code>:</p> <...
<python><class><namespaces>
2023-02-01 00:51:17
1
730
Jacob Manaker
75,304,567
18,758,062
Get the current step number in a gym.Env
<p>Is there a way to access the current step number of a <code>gym.Env</code> from inside its <code>step</code> method?</p> <p>I'm using a model from <code>stable_baselines3</code> and want to terminate the env when N steps have been taken.</p>
<python><openai-gym><stable-baselines>
2023-02-01 00:42:48
2
1,623
gameveloster
75,304,566
9,194,965
remove commas/quotation marks in column name in pandas or sql
<p>I am trying to pull some columns from a snowflake table using python/sqlalchemy into a pandas dataframe and subsequently do additional operations using Python/Pandas.</p> <p>However, it appears that the resulting dataframe has some quotation marks/commas in the column names.</p> <p>Code follows below:</p> <pre><code...
<python><sql><pandas><dataframe><sqlalchemy>
2023-02-01 00:42:38
1
1,030
veg2020
75,304,550
19,831,782
Python byte decode for JPEG EXIF data fails
<p>I am trying to decode JPEG EXIF data using Pillow. When I decode, I either get a parsing error or the decode results in hex instead of actually decoding the bytes.</p> <p>Here is my code based on work by Abdou Rockikz <a href="https://www.thepythoncode.com/article/extracting-image-metadata-in-python" rel="nofollow n...
<python><jpeg><decode>
2023-02-01 00:39:11
0
395
usagibear
75,304,530
13,114,791
importlib.metadata.PackageNotFoundError: No package metadata was found for djoser pyinstaller
<h2>Context</h2> <p>I made a Django react app. Now I want to make it a desktop application so that the user does not have type <code>python manage.py runserver</code> and also activate the environment every time. I used pyinstaller. I did all the steps mentioned for <a href="https://github.com/pyinstaller/pyinstaller/w...
<python><pyinstaller><djoser><python-exec><django-react>
2023-02-01 00:32:59
2
521
Hasnain Sikander
75,304,404
14,293,020
Python index selection in a 3D list
<p>I have the following 3D list:</p> <pre><code>test = [[[(x,y,z) for x in range(0,5)] for y in range(5,8)] for z in range(0,4)] test[0].append([(0,5),(5,0)]) </code></pre> <p>I want to select all the indices of the first dimension, the 0th index of the 2nd dimension and all the indices of the 3rd dimension. If it was ...
<python><list><list-comprehension><indices>
2023-02-01 00:09:07
1
721
Nihilum
75,304,252
6,467,512
Object detection using fastai
<p>Object detection using fastai Hello,</p> <p>I am looking to create a fast ai object detection model on the deep fashion dataset but do not know how make it predict. How can I make my model output prediction on images. Here is the code:</p> <p>The data is loaded using the COCO format as a json. Then I create the mode...
<python><model><python-imaging-library><object-detection><fast-ai>
2023-01-31 23:40:44
0
323
AynonT
75,304,110
14,914,517
Keras model predicts different results using the same input
<p>I built a Keras sequential model on the simple dataset. I am able to train the model, however every time I try to get a prediction on the same input I get different values. Anyone knows why? I read through different Stackoverflow here (<a href="https://stackoverflow.com/questions/64321976/why-the-exactly-identical-k...
<python><tensorflow><keras><prediction>
2023-01-31 23:16:58
3
439
Shahin Shirazi
75,304,086
16,978,074
Read all fields of a CSV file in Python
<p>I have a problem reading a csv file. Each line of the csv file is separated by , My edge.csv file looks like this:</p> <pre><code>source,target,genre apple,banana,28 strawberry,mango,30 so on..... </code></pre> <p>So this is my code for read edge.csv file:</p> <pre><code>def read_net(filename): g = nx.Graph() ...
<python><csv>
2023-01-31 23:12:17
1
337
Elly
75,304,048
9,100,431
How to randomly split grouped dataframe in python
<p>I have the next dataframe:</p> <pre><code>df = pd.DataFrame({ &quot;player_id&quot;:[1,1,2,2,3,3,4,4,5,5,6,6], &quot;year&quot; :[1,2,1,2,1,2,1,2,1,2,1,2], &quot;overall&quot; :[20,16,7,3,8,80,20,12,9,3,2,1]}) </code></pre> <p>what is the easiest way to randomly sort...
<python><pandas><dataframe>
2023-01-31 23:03:11
1
660
Diego
75,303,937
7,376,511
Access subtype of type hint
<pre><code>class MyClass: prop: list[str] MyClass.__annotations__ # {'prop': list[str]} </code></pre> <p>How do I access &quot;str&quot;?</p> <p>As a more generic question, given an obnoxiously complex and long type hint, like <code>prop: list[set[list[list[str] | set[int]]]]</code>, how do I access the internal v...
<python><type-hinting>
2023-01-31 22:46:42
1
797
Some Guy
75,303,877
2,152,371
Fetch Request in Jinjia Include getting CORS Error
<p>So I have a site that is using Flask for the Front and Backend with Jinja templates. Currently testing with localhost (5000 is the backend and 8000 is for the frontend)</p> <p>the page in question</p> <p>main.html</p> <pre><code>&lt;!DOCTYPE html&gt; &lt;html lang=&quot;en&quot;&gt; &lt;head&gt; &lt;meta charse...
<javascript><python><flask><cors><flask-cors>
2023-01-31 22:38:22
2
470
Miko
75,303,726
8,537,770
AWS CDK EC2 Instance SSH with Keypair Timing out
<p>I've created an ec2 instance with AWS CDK in python. I've added a security group and allowed ingress rules for ipv4 and ipv6 on port 22. The keypair that I specified, with the help of <a href="https://stackoverflow.com/questions/60041500/create-associate-ssh-keypair-to-an-ec2-instance-with-the-cdk/60043612#60043612"...
<python><amazon-web-services><amazon-ec2><aws-cdk>
2023-01-31 22:17:01
1
663
A Simple Programmer
75,303,621
153,612
Set range and label for axis
<p>I'm ploting data from an array A of size 10*10, each element <code>A[x,y]</code> is calculated by a function <code>f(x,y)</code> where x and y are in the range <code>(-3, 3)</code></p> <pre><code>import numpy as np import matplotlib.pyplot as plt def f(x,y): return ... s = 10 a = np.linspace(-3, 3, s) fxy = np...
<python><matplotlib><imshow>
2023-01-31 22:03:55
1
671
Ta Thanh Dinh
75,303,360
2,542,194
PyPdf2 interactive form elements missing after Adobe sign
<p>I have an Acroform pdf that contains a combination of text and interactive fields like dropdowns and checkboxes. I am using PyPDF2 to successfully retrieve all the field values (using get_Fields() and decrypting it with the default '' password), however once the pdf is signed using Acrobat Sign, I cannot access the ...
<python><python-3.x><itext><pypdf><adobe-sign>
2023-01-31 21:32:15
0
737
javapyscript
75,303,328
860,991
Accessing dockerized neo4j using neo4j vs py2neo
<p>I have setup neo4j to run in docker and exposed the http and bolt ports (7474, 7687).</p> <p>This is the setup I used :</p> <pre><code>docker run \ --name testneo4j \ -p7474:7474 -p7687:7687 \ -d \ -v `pwd`/neo4j/data:/data \ -v `pwd`/neo4j/logs:/logs \ -v `pwd`/import:/var/lib/neo4j/import \...
<python><python-3.x><neo4j><cypher>
2023-01-31 21:28:20
1
3,517
femibyte
75,303,230
14,908,234
How to delete line of large CSV file in place for upload to Postgres
<p>I have a 102gb CSV file exported from MongoDB that I'm trying to upload to Postgres. The file contains ~55 million rows. I'm using <code>\copy</code> to upload. However, I get a carriage return error on line 47,867,184:</p> <pre><code>ERROR: unquoted carriage return found in data HINT: Use quoted CSV field to repres...
<python><python-3.x><postgresql><csv><bigdata>
2023-01-31 21:15:48
0
1,151
mmz
75,303,213
10,194,070
python3 + how to open files while file that opened created with owner and group on the fly
<p>here is simple example when I wrote the list - some_list in file test.txt</p> <pre><code> with open('/home/moon/test.txt', 'w') as f: print(some_list, file=f) f.close() </code></pre> <p>the file above created with owner and group <code>root:root</code></p> <p>is it possible to create the same file...
<python><python-3.x><linux>
2023-01-31 21:14:28
1
1,927
Judy
75,303,020
11,281,877
Label specific points in seaborn based on x-values
<p>I have a dataframe where idividuals have some scores. The idea is to highlight the reference indididual (check) in red and the individuals with a lower score in green. Following similar problem on StackOverflow (<a href="https://stackoverflow.com/questions/46027653/adding-labels-in-x-y-scatter-plot-with-seaborn">Add...
<python><matplotlib><text><seaborn>
2023-01-31 20:53:43
1
519
Amilovsky
75,302,846
7,984,318
Python move file to folder based on both partial of file name and value of another partial of file name
<p>There are 3 files in folder:</p> <pre><code>my_floder: Review Report - 2020-3.20230110151743889.xlsx Review Report - 2020-3.20230110151753535.xlsx Review Report - 2019-4.20230110151744423.xlsx </code></pre> <p>Each of the file name has 3 parts,take the first file as an example:</p> <pre><code>First Part:&quot;Rev...
<python><python-3.x>
2023-01-31 20:34:25
2
4,094
William
75,302,795
9,391,359
How to get text and corresponding tag with BeautifulSoup?
<p>I have a text, contains HTML tags something like:</p> <pre><code>text = &lt;p&gt;Some text&lt;/p&gt; &lt;h1&gt;Some text&lt;/h1&gt; .... soup = BeautifulSoup(text) </code></pre> <p>I parsed this text using <code>BeautifulSoup</code>. I would like to extract every sentence with corresponding text and tag. I tried:</...
<python><html><web-scraping><beautifulsoup>
2023-01-31 20:30:04
1
941
Alex Nikitin
75,302,631
1,464,160
Installing ssdeep package from PyPi on M1 Macbook
<h1>The Goal</h1> <p>Install <a href="https://pypi.org/project/ssdeep/" rel="nofollow noreferrer">ssdeep</a> PyPi package on a M1 Macbook Pro.</p> <h1>The Problem</h1> <p>When I run <code>pip install ssdeep</code> I get 2 errors</p> <p>The first error is caused because <code>fuzzy.h</code> cannot be found.</p> <pre><co...
<python><pip><apple-m1><pypi>
2023-01-31 20:12:28
3
1,483
HopAlongPolly
75,302,370
7,228,093
Create Flask Restx endpoints without namespaces
<p>I'm working on the redesign of an API with Flask using Flask-restx, but I've a problem: We need a legacy version of the API that accepts the old URLs, for compatibility reasons, but I'm not understanding how to do this since Flask-restx requires a namespace to be declared.</p> <p>Urls should be something like this:<...
<python><flask><flask-restx>
2023-01-31 19:43:58
1
515
Efraín
75,302,280
12,695,210
Pytest fixture scope and @pytest.mark.parametrize
<p>I am a little confused about fixture scope in pytest. Say I have a fixture</p> <pre><code>@pytest.fixture(scope=&quot;function&quot;) def data(): data = generate_some_data() yeild data teardown() </code></pre> <p>and a test function</p> <pre><code>@pytest.mark.parametrize(&quot;runs&quot;, [&quot;one&quo...
<python><pytest>
2023-01-31 19:34:13
1
695
Joseph
75,302,259
9,648,665
Sort the products based on the frequency of changes in customer demand
<p>Imagine following dataframe is given.</p> <pre><code>import pandas as pd products = ['Apple', 'Apple', 'Carrot', 'Eggplant', 'Eggplant'] customer_demand_date = ['2023-01-01', '2023-01-07', '2023-01-01', '2023-01-01', '2023-01-07', '2023-01-14'] col_02_2023 = [0, 20, 0, 0, 0, 10] col_03_2023 = [20, 30, 10, 0, 10, 0]...
<python><pandas><sorting><group-by><accumulate>
2023-01-31 19:32:22
2
687
Sascha
75,302,200
1,484,601
python types: Literal of logging level as type?
<p>the following code:</p> <pre class="lang-py prettyprint-override"><code>import logging print(type(1)) print(type(logging.WARNING)) </code></pre> <p>prints:</p> <pre><code>&lt;class 'int'&gt; &lt;class 'int'&gt; </code></pre> <p>yet, according to mypy, the first line of this code snippet is legal, but the second is ...
<python><types><mypy><literals>
2023-01-31 19:25:12
1
4,521
Vince
75,302,161
1,028,237
ECS Fargate shutdown and decrement desired count in task
<p>I would like to shut down a task once I've detected there is no more work. The task is part of fargate target group with autoscaling rules so simply doing an <code>ecs.stop_task(cluster=cluster_arn, task=task_id)</code> won't work as the group will add another task to meet the desired task count. I want something li...
<python><amazon-web-services><boto3><amazon-ecs>
2023-01-31 19:21:47
0
1,426
Verbal_Kint
75,302,111
2,185,248
using python to load docker image zip file without python docker module
<p>Using python3.10.6 and docker 20.10.23, build 7155243 on Ubuntu 22.04. And trying not to use the <code>docker</code> module but just <code>subprocess</code> to load a docker image</p> <pre><code>def run(params): output = subprocess.run(params, stdout=subprocess.PIPE, stderr=subprocess.PIPE) if output.returnc...
<python><docker>
2023-01-31 19:15:57
1
2,809
r0n9
75,302,082
1,028,237
Pandas: Group by contiguous time blocks
<p>I have API access logs with a timestamp user ID and request payload. I want to group by user and contiguous requests within 1 minute of each other and aggregate a count within each block. So if I had:</p> <pre><code>@timestamp @data @id ...
<python><pandas>
2023-01-31 19:13:12
1
1,426
Verbal_Kint
75,301,743
2,623,317
How to list, concatenate, and evaluate polars expressions?
<p>I would like to store in an object (a list, a dictionary or whatever) many different filters, and then be able to select the ones I want and evaluate them in the <code>.filter()</code> method. Below is an example:</p> <pre><code># Sample DataFrame df = pl.DataFrame( {&quot;col_a&quot;: [1, 2, 3, 4, 5, 6, 7, 8, 9...
<python><python-polars>
2023-01-31 18:39:50
2
477
Guz
75,301,630
5,675,325
Pass data from the pipeline to views in Django Python Social Auth
<p>I was reading the documentation of Python Social Auth and got curious about the section of <a href="https://github.com/python-social-auth/social-docs/blob/master/docs/developer_intro.rst#interrupting-the-pipeline-and-communicating-with-views" rel="nofollow noreferrer">Interrupting the Pipeline (and communicating wit...
<python><django><authentication><django-views><python-social-auth>
2023-01-31 18:30:30
1
15,859
Tiago Peres
75,301,389
5,993,616
How to properly plot graph using matplotlib?
<p>I have these two lists:</p> <pre><code>**l1** = ['100.00', '120.33', '140.21', '159.81', '179.25', '183.13', '202.49', '202.89', '204.18', '205.35', '206.44', '207.45', '208.40', '209.30', '210.15', '210.96', '211.73', '212.47', '213.18', '213.87', '214.53', '215.17', '215.79', '216.39', '216.98', '217.54', '218.10'...
<python><matplotlib>
2023-01-31 18:10:25
3
317
drSlump
75,301,374
5,510,540
python: cumulative density plot
<p>I have the following dataframe:</p> <pre><code>df = Time_to_event event 0 0 days 443 1 1 days 226 2 2 days 162 3 3 days 72 4 4 days 55 5 5 days 30 6 6 days 36 7 7 days 18 8 8 days 15 9 9 days 14 ...
<python><cumulative-sum>
2023-01-31 18:08:54
2
1,642
Economist_Ayahuasca
75,301,344
7,895,542
Install python package for python2.7 with pip
<p>I am trying to install pre-commit for python2.7 with pip 8.1.2.</p> <p>If i do <code>pip install --user pre-commit</code> or ´python -m pip install --user pre-commit´ it keeps trying to load pre-commit3.0.2 and failing.</p> <p>So i tried to find the most recent version that still supports python2.7 (by manually goin...
<python><python-2.7><pip>
2023-01-31 18:06:25
1
360
J.N.
75,301,282
17,696,880
How to send each of the strings within a list of strings to a function, and then replace that list element with the list that the function generates?
<pre class="lang-py prettyprint-override"><code>import re, spacy def evaluates_if_substring_is_a_verb_func(input_element): #---------------------------------- #nlp = spacy.load('en_core_web_sm') nlp = spacy.load('es_core_news_sm') doc = nlp(input_element) # Your text here list_verbs_in_element = ...
<python><python-3.x><string><list><spacy>
2023-01-31 18:01:45
1
875
Matt095
75,301,216
777,593
Pandas convert a column containing strings into new columns
<p>I have a dataframe with columns that contains comma separated strings. I would like to create new columns similar to what one hot encoding does.</p> <p>Below is a very simplistic example. In my use case, I have thousands of rows with more columns, and two columns containing comma separated many strings. I could have...
<python><pandas><dataframe><one-hot-encoding>
2023-01-31 17:57:06
2
2,411
Khurram Majeed
75,301,196
2,013,056
Getting list of all the URLs in a Closed Issue page in GitHub using Selenium
<p>I am trying to store the links of all the closed issues from a GitHub (<a href="https://github.com/mlpack/mlpack/issues?q=is%3Aissue+is%3Aclosed" rel="nofollow noreferrer">https://github.com/mlpack/mlpack/issues?q=is%3Aissue+is%3Aclosed</a>) project using Selenium. I use the code below:</p> <pre><code>repo_closed_u...
<python><selenium><selenium-webdriver><xpath><selenium-chromedriver>
2023-01-31 17:55:07
3
649
Mano Haran
75,301,185
11,462,274
Center align all dataframe headers except two that one of them must align left and the other right
<p>The code below creates a table with the values of all columns centered and the column titles also centered. I align the values in the <code>local_team</code> column to the right and the values in the <code>visitor_team</code> column to the left:</p> <pre class="lang-python prettyprint-override"><code>ef dfi_image(li...
<python><pandas>
2023-01-31 17:54:19
1
2,222
Digital Farmer
75,300,936
11,092,636
%%timeit magic command and variable set to global in function
<p>Here is a MRE:</p> <pre class="lang-py prettyprint-override"><code>%%timeit variable = 0 def func(): global variable variable += 1 func() assert (variable == 1) </code></pre> <p>It works perfectly without the magic command <code>%%timeit</code>.</p> <p>I'm not sure I understand why it doesn't work when I...
<python><visual-studio-code><timeit>
2023-01-31 17:33:26
1
720
FluidMechanics Potential Flows
75,300,900
11,887,287
conda python 3.8 ffmpeg【ffprobe: symbol lookup error: /anaconda3/envs/bin/../lib/./libgnutls.so.30: undefined symbol: mpn_add_1, version HOGWEED_4】
<p><strong>Dependencies:</strong></p> <ul> <li>Ubuntu: 20.04</li> <li>conda: 4.12.0</li> <li>Python: 3.8</li> <li>Pytorch: 1.7.1</li> <li>ffmpjpe: 4.2.3 (conda-forge)</li> </ul> <p>I am facing a problem after installing <strong>FFmpeg</strong> from the conda-forge channel as follows command:</p> <pre><code>$ conda conf...
<python><ffmpeg><conda><ffprobe>
2023-01-31 17:31:02
3
985
wen
75,300,844
2,186,785
Executing python script with pdflatex using PHP on Ubuntu webserver?
<p>I am trying to execute a python script which uses pdflatex using php. Running the python script via command line works well.</p> <p>But if I try to call it with php, it throws this error:</p> <blockquote> <p>I can't write on file mylatex.log'. (Press Enter to retry, or Control-D to exit; default file extension is `....
<python><php><webserver><pdflatex>
2023-01-31 17:25:59
1
1,179
JavaForAndroid
75,300,635
6,218,501
Version control with DataFrames
<p>I'm trying to compare two dataframes in order to check what have changed between both of them. This is part of a version control script so I've made a simplified version trying to find a solution:</p> <pre><code>data = {'ID': ['1', '2', '3', '4'], 'Date': ['23-01-2023', '01-12-1995', '03-07-2013', '05-09-2...
<python><pandas>
2023-01-31 17:07:29
2
461
Ralk
75,300,605
7,920,004
Return data from Python's Redshift procedure call
<p><code>redshift_connector</code> is defined to be aligned with <a href="https://peps.python.org/pep-0249/#id24" rel="nofollow noreferrer">https://peps.python.org/pep-0249/#id24</a> but I can't, after calling procedure, retrieve data into a dataframe.</p> <p>Instead I'm getting <code>'mycursor'</code> value. How to ov...
<python><amazon-web-services><amazon-redshift>
2023-01-31 17:05:05
2
1,509
marcin2x4
75,300,476
14,912,118
PySpark GroupBy agg collect_list multiple columns
<p>I have working with following code.</p> <pre><code>df = spark.createDataFrame(data=[[&quot;john&quot;, &quot;tomato&quot;, 1.99, 1],[&quot;john&quot;, &quot;carrot&quot;, 0.45, 1],[&quot;bill&quot;, &quot;apple&quot;, 0.99, 1],[&quot;john&quot;, &quot;banana&quot;, 1.29, 1], [&quot;bill&quot;, &quot;taco&quot;, 2.59...
<python><apache-spark><pyspark>
2023-01-31 16:53:38
1
427
Sharma
75,300,188
2,371,684
python dictionary update without overwriting
<p>I am learning python, and I have two json files. The data structure in these two json files are different structures.</p> <p>I start by importing both of the json files. I want to choose a course from the courses dict, and then add it to a specific education in the educations dict. What I want to solve is via user i...
<python><dictionary>
2023-01-31 16:30:54
2
1,575
user2371684
75,300,029
5,833,797
Python SQLAlchemy 2.0 non required field types using dataclass_transform
<p>I have just installed SQLAlchemy 2.0 on a new project and I am trying to make my models as type-safe as possible.</p> <p>By using <code>@typing_extensions.dataclass_transform</code>, I have been able to achieve most of what I want to achieve in terms of type checking, however all fields are currently being marked as...
<python><sqlalchemy><python-typing><python-dataclasses>
2023-01-31 16:17:07
1
727
Dave Cook
75,299,996
1,446,710
Importing multiple CSV into one DataFrame?
<p>I tried many answers but none of them working for me:</p> <p>For example this: <a href="https://stackoverflow.com/questions/20906474/import-multiple-csv-files-into-pandas-and-concatenate-into-one-dataframe">Import multiple CSV files into pandas and concatenate into one DataFrame</a></p> <pre><code>import pandas as p...
<python><pandas><csv>
2023-01-31 16:14:31
3
2,725
Daniel
75,299,972
1,552,080
Flask + Jinja2: how to replace the occurrence of a value in a table by a icon
<p>I am working on a simple web page showing the content of a pandas <code>DataFrame</code> by using the Flask framework:</p> <pre><code>from flask import Flask, render_template import DatabaseConnector from jinja2 import Environment app = Flask(__name__) app.jinja_options = {'lstrip_blocks': True, 'trim_blocks': True...
<javascript><python><html><css><pandas>
2023-01-31 16:12:36
1
1,193
WolfiG
75,299,946
14,802,285
How to access the gradients of intermediate outputs during the training loop?
<p>Let's say I have following (relatively) small lstm model:</p> <p>First, let's create some pseudo input/target data:</p> <pre><code>import torch # create pseudo input data (features) features = torch.rand(size = (64, 24, 3)) # of shape (batch_size, num_time_steps, num_features) # create pseudo target data targets =...
<python><deep-learning><pytorch><lstm><recurrent-neural-network>
2023-01-31 16:10:25
1
3,364
bird
75,299,891
6,930,340
Type hint for numpy.ndarray containing unsignedinteger
<p>I have a numpy array that contains unsignedinteger, something like this:</p> <pre><code>arr = np.uint16([5, 100, 2000]) array([ 5, 100, 2000], dtype=uint16) </code></pre> <p>This <code>arr</code> will be input to a function. I am wondering how the type hint of the function argument should look like?</p> <pre><co...
<python><numpy><mypy>
2023-01-31 16:06:04
2
5,167
Andi
75,299,817
9,458,342
Plotly px.Scatter or go.Scatter Graph Unique Color/Symbol for specific points (Simple Map)
<p>I am attempting to create a simple site map using Plotly. I can't use scatter_geo because I am using known X, Y coordinates relative the site - not lat/long. px.Scatter or go.Scatter seem to be a viable option for a mostly simple map. So, I have a dataframe from that essentially looks like:</p> <pre><code>Location ...
<python><pandas><plotly><nan>
2023-01-31 16:01:32
1
399
Sam Dean
75,299,808
1,681,409
Finding the Plot Coordinates from the Scatter Plot Data
<p>So I want to annotate a plot of points in an ellipse by embedding a graph on top of each of the points. I have done this manually with the first few points via the inset axes function.</p> <p><a href="https://i.sstatic.net/8Fojk.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/8Fojk.png" alt="enter ima...
<python><matplotlib><overlay>
2023-01-31 16:00:42
0
681
The Dude
75,299,770
14,790,056
I want to groupby, and then, create a new column which takes a value from a different column if a condition is met
<p>I have the following dataframe. I want to create a new column <code>col2</code> which takes a value from the column <code>value</code> after groupby ID, if the value from <code>col1</code> is BX.</p> <p>and another new column <code>col3</code> which takes the value from <code>value</code> if the value from `col1 is ...
<python><pandas><dataframe>
2023-01-31 15:58:25
2
654
Olive
75,299,734
4,498,050
Using gymnasium play on CartPole makes the cart go left all the time
<p>I'm trying to play CartPole on Jupyter Notebook using my keyboard. I'm using the following code from Farama documentation</p> <pre><code>import gymnasium as gym from gymnasium.utils.play import play env = gym.make(&quot;CartPole-v1&quot;, render_mode=&quot;rgb_array&quot;) play(env, keys_to_action={&quot;a&quot;: 0...
<python><reinforcement-learning><openai-gym>
2023-01-31 15:55:08
2
610
Moltres
75,299,671
825,489
How can I count # of occurences of more than one column (eg city & country)?
<p>Given the following data ...</p> <pre><code> city country 0 London UK 1 Paris FR 2 Paris US 3 London UK </code></pre> <p>... I'd like a count of each city-country pair</p> <pre><code> city country n 0 London UK 2 1 Paris FR 1 2 Paris US 1 </code></pre> <p>The...
<python><pandas><dataframe>
2023-01-31 15:50:58
1
1,269
Bean Taxi
75,299,652
6,694,814
Conditional-based geolocator in Python
<p>I am working on the Nominatim geolocator in Python. Unfortunately, some addresses are missing, therefore I tried to make some condition-based workaround, which would allow executing something based at least on postcode, which works well in any case. Unfortunately, I failed for now. With the following code:</p> <pre>...
<python><geocoding><nominatim>
2023-01-31 15:49:44
1
1,556
Geographos
75,299,587
6,766,408
How to add code change to multiple scripts in pycharm
<p>I have develop around 85 automation scripts using python-selenium-robot framework in pycharm. I need to add one piece of code in all the 85 scripts. Is there way to do it without opening every script and adding? Thanks!</p>
<python><selenium-webdriver><pycharm><automated-tests><robotframework>
2023-01-31 15:44:37
2
312
ADS KUL
75,299,524
50,065
Missing type parameters for generic type "Callable"
<p>What is the correct way to add type hints to the following function?</p> <pre class="lang-py prettyprint-override"><code>from typing import Callable def format_callback(f: Callable) -&gt; Callable: &quot;&quot;&quot;Function to wrap a function to use as a click callback. Taken from https://stackoverflow.co...
<python><mypy><python-typing><python-click>
2023-01-31 15:39:13
1
23,037
BioGeek
75,299,298
6,628,988
writing json record from dataframe column to S3 in spark streaming
<p>I have a drataframe shown in below format with records as json data (which is in string format) read from kafka topic</p> <p><a href="https://i.sstatic.net/9mYWp.png" rel="nofollow noreferrer"><img src="https://i.sstatic.net/9mYWp.png" alt="enter image description here" /></a></p> <p>I need to write just the json re...
<python><pyspark><apache-kafka><user-defined-functions><spark-structured-streaming>
2023-01-31 15:20:53
1
430
Saranraj K
75,299,245
11,001,493
How to split time series in clusters by different patterns?
<p>This is an example of a larger data with many dataframes similar to this one below (df_final):</p> <pre><code>df1 = pd.DataFrame({&quot;DEPTH (m)&quot;:np.arange(0, 2000, 2), &quot;SIGNAL&quot;:np.random.uniform(low=-6, high=10, size=(1000,))}) df2 = pd.DataFrame({&quot;DEPTH (m)&quot;:n...
<python><pandas><time-series><cluster-analysis><signal-processing>
2023-01-31 15:17:00
2
702
user026
75,299,204
2,163,392
Error in applying Butterworth lowpass filter in Scipy - advice for a good Wn parameter
<p>I am brand new to Digital Signal Processing and I would like to understand how to choose the parameter Wn (or the critical frequency) when aplying Butterworth lowpass filter with scipy.signal. To apply the butterworth lowpassfilter, the following Python/scipy source code can do it.</p> <pre><code> from scipy.sign...
<python><scipy><signal-processing><fft><lowpass-filter>
2023-01-31 15:13:18
0
2,799
mad
75,299,191
12,274,651
Global minimum versus local minima solution with Python Gekko
<p>A simple optimization example has 2 local minima at <code>(0,0,8)</code> with objective <code>936.0</code> and <code>(7,0,0)</code> with objective <code>951.0</code>. What are techniques to use local optimizers in Python Gekko (<code>APOPT</code>,<code>BPOPT</code>,<code>IPOPT</code>) to find a global solution?</p> ...
<python><mathematical-optimization><nonlinear-optimization><gekko>
2023-01-31 15:12:39
2
744
TexasEngineer
75,299,182
13,219,123
Writing to delta table using spark sql
<p>In python I am trying to create and write to the table <code>TBL</code> in the database <code>DB</code> in Databricks. But I get an exception: <em>A schema mismatch detected when writing to the Delta table</em>. My code is as follows, here <code>df</code> is a pandas dataframe.</p> <pre><code>from pyspark.sql import...
<python><pyspark><apache-spark-sql><azure-databricks>
2023-01-31 15:11:20
1
353
andKaae
75,299,153
732,629
Problems when running python using new environment in spyder/anaconda
<p>I installed new packages using anaconda3 navigator into a new environment called <code>newconda</code>, then I changed the conda environment in spyder to <code>newconda</code>. When I run the code it displays errors such as &quot;module not found&quot;, despite that the module exist in <code>newconda</code>. I resta...
<python><conda><spyder><anaconda3>
2023-01-31 15:09:13
0
333
jojo
75,299,135
8,262,535
Screen freeze when training deep learning model from terminal but not Pycharm
<p>I have an extremely weird issue where if I run pytorch model training from Pycharm, it works fine but when I run the same code on the same environment from terminal, it freezes the screen. All windows become non-interactable. The freeze affects only me, not other users and for them &gt;&gt;top shows that the model i...
<python><pytorch><pycharm><conda><virtualenv>
2023-01-31 15:07:52
1
385
illan
75,299,066
1,132,175
Pyflink kafka topic consumption not working
<p>I have this code consuming from confluent's kafka platform (pageviews) but for some reason, execution just hangs up and I can't get it to work. I am new to flink, my experience is mainly with spark streaming, so this is my learning process with flink.</p> <p>Below you can find the python code and then the exception ...
<python><apache-kafka><apache-flink>
2023-01-31 15:02:21
0
597
Jorge Cespedes
75,298,972
4,075,169
ModuleNotFoundError: No module named '_curses' on Ubuntu 22.04
<p>I want to use <code>curses</code> for a personnal Python project. However, when I try to import it, I get the following error :</p> <pre class="lang-bash prettyprint-override"><code>&gt;&gt;&gt; import curses Traceback (most recent call last): File &quot;&lt;stdin&gt;&quot;, line 1, in &lt;module&gt; File &quot;...
<python><ubuntu><ncurses><curses><python-curses>
2023-01-31 14:54:38
1
847
Kahsius
75,298,911
8,848,630
AttributeError when using wrds library
<p>Doing the following:</p> <pre><code>import wrds db = wrds.Connection() </code></pre> <p>does throw this error:</p> <pre><code>--------------------------------------------------------------------------- AttributeError Traceback (most recent call last) File ~\anaconda3\envs\playground\lib\si...
<python><wrds-compusat>
2023-01-31 14:49:58
1
335
shenflow
75,298,904
9,262,339
How to determine the status after a celery task has been completed inside code?
<p>Sample logic</p> <p><strong>logic.py</strong></p> <pre><code>@shared_task def run_create_or_update_google_creative(): return create_or_update_google_creative() def create_or_update_google_creative() : # do some logic def run_db_sinc(): result = run_create_or_update_google_creative.delay() job = ...
<python><celery>
2023-01-31 14:48:55
1
3,322
Jekson
75,298,738
4,125,774
Problem in using conftest.py from a packaged pytest framework
<p>I am working on a pytest-framework that will be packed as a package. The setup file i am using for this is as this:</p> <pre><code>setup( name='MyTestFrameWork', version=&quot;2&quot;, author='my name', author_email='name@gmail.com', description='My test framework', long_description=open('README.md', 'rb').read().de...
<python><python-3.x><pytest>
2023-01-31 14:35:26
1
307
KapaA
75,298,725
12,065,403
How to populate an AWS Timestream DB?
<p>I am trying to use <a href="https://docs.aws.amazon.com/timestream/latest/developerguide/what-is-timestream.html" rel="nofollow noreferrer">AWS Timestream</a> to store data with timesteamp (in python using <a href="https://boto3.amazonaws.com/v1/documentation/api/latest/index.html" rel="nofollow noreferrer">boto3</a...
<python><amazon-web-services><amazon-timestream>
2023-01-31 14:34:21
1
1,288
Vince M
75,298,536
12,125,777
Uploading files using design pattern with python
<p>I used to upload csv, excel, json or geojson files in my a postegreSQL using Python/Django. I noticed that the scripts is redundant and sometimes difficult to maintain when we need to update key or columns. Is there a way to use design pattern? I have never used it before. Any suggestion or links could be hep!</p>
<python><django><design-patterns>
2023-01-31 14:19:10
0
542
aba2s
75,298,403
1,314,503
Highlight inserted,deleted elements/text - Python Docx
<p>I want to <strong>highlight</strong> the text or elements which are inserted or deleted, after combine the two version of the Docx file.</p> <p><a href="https://stackoverflow.com/questions/51361538/python-docx-get-inserted-deteled-revised-paragraphs-elements">Here</a> there are just returning the the values. I tried...
<python><python-3.x><ms-word><docx><python-docx>
2023-01-31 14:09:26
1
5,746
KarSho
75,298,356
13,174,189
What does [1,2] means in .mean([1,2]) for tensor?
<p>I have a tensor with shape <code>torch.Size([3, 224, 225])</code>. when I do <code>tensor.mean([1,2])</code> I get tensor([0.6893, 0.5840, 0.4741]). What does [1,2] mean here?</p>
<python><python-3.x><pytorch>
2023-01-31 14:05:28
2
1,199
french_fries
75,298,308
3,130,747
Plot line segments between two dates in matplotlib
<p>Given the following data:</p> <pre class="lang-py prettyprint-override"><code>dt = pd.DataFrame.from_dict( { &quot;thing&quot;: {0: &quot;A&quot;, 1: &quot;B&quot;, 2: &quot;C&quot;}, &quot;min&quot;: { 0: &quot;2021-11-01 00:00:00+00:00&quot;, 1: &quot;2021-11-01 00:00:00...
<python><matplotlib><datetime><plot>
2023-01-31 14:02:01
1
4,944
baxx
75,298,299
5,722,716
Python requests stream reads more data than chunk size
<p>I am using python requests library to stream the data from a streaming API.</p> <pre class="lang-py prettyprint-override"><code>response = requests.get('http://server/stream-forever', stream=True) for chunk in response.iter_content(chunk_size=1024): print len(chunk) # prints 1905, 1850, 1909 </code></pre> <p>I ...
<python><python-requests>
2023-01-31 14:01:29
1
683
Prajwal
75,298,179
14,843,068
Convert pandas column with featurecollection to GeoJSON
<p>I downloaded a CSV that contains a column which has a GeoJSON format, and imported it as a pandas dataframe. How can I convert this to a GeoJSON (.geojson)? I have about 10,000 rows, each with information as shown below:</p> <p>This is an example of a cell in the column: {&quot;type&quot;:&quot;FeatureCollection&quo...
<python><json><pandas><geojson><geopandas>
2023-01-31 13:52:03
1
622
CrossLord
75,298,089
3,768,053
Calculate averages over subgroups of data in extremely large (100GB+) CSV file
<p>I have a large semicolon-delimited text file that weighs in at a little over 100GB. It comprises ~18,000,000 rows of data and 772 columns.</p> <p>The columns are: 'sc16' (int), 'cpid' (int), 'type' (str), 'pubyr' (int) and then 767 columns labeled 'dim_0', 'dim_1', 'dim_2' ... 'dim_767', that are all ints.</p> <p>Th...
<python><pandas><python-itertools>
2023-01-31 13:44:46
1
423
Obed
75,298,035
7,026,806
Narrower types for pytest fixtures that perform actions without returning objects?
<p>Consider a fixture like</p> <pre class="lang-py prettyprint-override"><code>@pytest.fixture def mock_database(monkeypatch: MonkeyPatch) -&gt; None: ... </code></pre> <p>And it's use in a test</p> <pre class="lang-py prettyprint-override"><code>def test_with_mock_database(mock_database: None) -&gt; None: ... ...
<python><types><pytest><mypy>
2023-01-31 13:40:35
1
2,020
komodovaran_