Questions tagged [python]
Python is a multi-paradigm, dynamically typed, multi-purpose programming language. It is designed to be quick to learn, understand, and use, and enforces a clean and uniform syntax. Please note that Python 2 is officially out of support as of 2020-01-01. For version-specific Python questions, add the [python-2.7] or [python-3.x] tag. When using a Python variant (e.g. Jython, PyPy) or library (e.g. Pandas, NumPy), please include it in the tags.
2,008,815
questions
0
votes
0
answers
3
views
Tetris blocks collapse when touching the border(Python TKinter)
The program isn't finished yet, but i found a bug. If you move a block to one side of the screen and then quickly move it to another so it touches the border, the block will collapse. Can anyone help ...
0
votes
0
answers
10
views
Groupby: displaying data in groups in a worksheet (PANDAS)
I am working with a data analysis where I have some metrics related to an individual in one specific year, specific place, specific level, etc. These information (year, place, level) repeat itself, ...
0
votes
0
answers
8
views
remove a portion of string values in column
START=20220605104039.163068
START=20220605104045.818461
START=20220605104051.500539
START=20220605104053.444575
sep='='
df['START'].str.split(sep,[1])
result
0 NaN
1 NaN
2 NaN
3 ...
-1
votes
3
answers
35
views
List comprehension instead of extend in loop
Can I write this code in one line? I tried use chain in list comprehension.
def divisors(n):
result = []
for div in range(1, int(sqrt(n)) + 1):
if n % div == 0:
result....
0
votes
0
answers
14
views
How to return a response if pagination does not exist on a page
This appears to be a rather simple one but I can't tell exactly why I am not getting it right.
I have website pages with similar content but the difference is that some of these pages contain ...
-1
votes
0
answers
23
views
Regex Python for on JSON FILE [closed]
I have this json file below, I would like to extract the bold data, how could I do that properly ? I have this result after extracting a pdf to txt then to json
[
"Indicator:",
"...
0
votes
0
answers
19
views
What is the correct way to import this class?
I have the following repository structure:
directoryA
- moduleA.py (it contains MyClass class)
directoryB
- moduleB.py
In moduleB.py I need to import MyClass, I use the following command:
...
0
votes
0
answers
13
views
Python3 string conversion failure using html.unescape
I'm having trouble decoding a string.
Here's my code:
from html import unescape
s = "css?family=\u0026quot;+e,id:i"
print(s)
print(repr(s))
print(type(s))
print(...
0
votes
0
answers
13
views
Django Signals Python
In this piece of code i want to get text from reacently created data in model
models.py:
from django.db import models
class Tokenize(models.Model):
text = models.TextField()
class Pos(models....
-1
votes
0
answers
19
views
Assign a subset of values from a list returned by an iterable to a variable (Python)
I have an iterable that returns multiple values as a list. In this case, I only care about one of the values in each iteration.
As a concrete example:
class Triples:
def __init__(self):
self.x = 0
...
1
vote
0
answers
14
views
Why doesn't Python mocker resolve to a immutable value?
How do you make Python's unittest.mock.patch return an object that lets you assign a callable return value?
For example, I have a custom class in myclass.py defined as:
class MyClass:
@property
...
0
votes
0
answers
18
views
How do I make each image have the corresponding tag?
with the following code, I augmented some images and I would like to know how I can make each generated image have the corresponding label
I try with save_prefix = +label but it just prints the same ...
0
votes
0
answers
20
views
Reading a .xls file into a DataFrame using read_html creating a list, not a df
At first I tried reading the .xls file like this:
df = pd.read_excel('/Users/KLG/regionlist1.xls')
Which led to this error: ValueError: Excel file format cannot be determined, you must specify an ...
0
votes
0
answers
9
views
python chatterbot call function instead of providing a text response back
I am trying to create a chatbot in python that depending on the user questions and confirmations, I execute a specific python function, adding data to a database, for example. From what I have seen, ...
0
votes
1
answer
13
views
Python - Panel data create indicator with if statement
I am trying to create an indicator equal to 1 if my meeting_date variable matches my date variable, and zero otherwise. I am getting an error in my code that consists of the following:
ValueError: The ...