Most voted "python" questions
Python is a dynamic and heavily typed programming language whose design philosophy emphasizes usability. Two similar but incompatible versions of Python are in use (2 and 3). Please mention the version you are using when asking a question about Python.
Learn more…8,642 questions
Sort by count of
-
2
votes1
answer172
viewsLoop Replace all string characters by python list character
What I want to do is take a string and for each character of the string walk type 3 positions back in the alphabet and replace in the string or create a new string Ex string = 'abcd' walking 3…
-
2
votes1
answer165
viewsHow to know the direction of the mouse?
I would like to make a program that indicates to which position the mouse is moving (right, left, high, low, right and high, right and low...), but I can’t get a logic that gives me this result.…
-
2
votes1
answer146
viewsANSI in Visual Studio Code with Python
How do I make vs code understand this command line: print('\033[1mNome: ') Where " 033[1m" is the part responsible for leaving in bold, but instead it is responding with this: ?[1mNome:…
-
2
votes2
answers1424
viewsProblems with python libraries, Chatbot
I’m having trouble with the Python library, specifically the Chatbot, the error is as follows: from chatterbot import Chatbot ImportError: cannot import name 'Chatbot' " Here is my code: from…
-
2
votes2
answers3831
viewsDataframe Pandas - Calculate column based on other
I have a dataframe in the following format: colunas = [ 'COMEDY', 'CRIME', 'Classe Prevista' ] precisao_df = pd.DataFrame(columns=colunas) precisao_df['COMEDY'] = y_pred_proba[:,0]…
-
2
votes1
answer125
viewsEasy counting between columns - Python
I’m starting in python and have trouble automating some calculations. I have a Dataframe with 8 columns [A, B, C, D, E, F, G, H] and 150 rows. I need to count how many times 2 columns are equal to…
-
2
votes1
answer253
viewspass input data to mysql database table
People help me there, I’m creating a user manager with level system. however I am not able to pass a value of the variable defined by input() to the INSERT. please help me. code: def…
-
2
votes2
answers867
viewsReplace string with regex in python 3
I have a code that replaces certain string with whitespace dados =…
-
2
votes1
answer153
viewsHow to pass the return of a function that is a tuple as arguments to another one in Python?
I’m trying to return multiple values from one function to another with multiple parameters: def chamar_ab(): a = 1 b = 2 return a, b #tupla def soma(x, y): return x + y But using it doesn’t seem…
-
2
votes2
answers1544
viewsScript . sh to run a python script from within Cron
Good morning. I’m having a problem with a python program I did. What happens is that when I run my program from the command line with this command it works normal : python3…
-
2
votes1
answer46
viewsDifficulty removing Child, Python
Good morning friends. I’m having trouble removing a Child. I wrote a code to collect all the prices of the products of a site (this is a list of products, not a page for each one). As for this…
pythonasked 6 years ago Jordan Garcia 35 -
2
votes1
answer63
viewsRemove tags generated at the end of a string from a Text Editor
I am using a text editor and like others I have used, it always generates some useless tags that I would like to remove. I can remove the last, but sometimes it generates more than once. My code:…
-
2
votes2
answers123
viewsPython functions + lists
When I try to create the function below I always get the first list value, it seems that it is not iterated. Someone could explain me why? Follows the code: novalista = [] def find_it(seq):…
-
2
votes1
answer196
viewsClass within class, is it possible? (Python)
I can include a class within another class (Father and daughter rsrs)? Reason for the question? Simple, in Django I saw something like this class Form(...): class Meta: (code) Okay, I looked it…
-
2
votes0
answers22
viewsHow to use AWS Glue to obtain 'batch' data in semi-structured BD?
Is it possible to use AWS Glue to retrieve data incrementally in a semi-structured SQL database? The data on-premise that I intend to export to the AWS cloud are in a single table, with primary key,…
-
2
votes1
answer52
viewsHow to make this class usable?
In the code below, I would like to return an instance of the class itself with the data filled through a text file. The lines are stored this way in the file: Yug…
-
2
votes2
answers1003
viewsHow to do a regex to capture a sequence in numbers with dots and strings
Examples are: 1.1. FLESH 1.1.2. BRAIN I want to make sure I get sequences number.number. ... space and a high-box string (can’t be low box). I tried this: reg = r'[1-9][.]+\s\b[A-Z]*' However, the…
-
2
votes3
answers78
viewsDifficulty with first code
This is my first code that doesn’t involve my class. My goal is to assemble a code that asks you to insert any chemical symbol and this will tell your group. Pretty simple concept, but I’m having a…
-
2
votes1
answer134
viewsFind number with smaller number of decimals between two other numbers
The final part for data arithmetic compression is to find a number, which is among other 2 numbers, and which has the smallest number/decimal places! Example: Number between 0.1234 and 0.1245. The…
-
2
votes1
answer242
viewsOmdb API sorting python dictionary items
I need to make a program that given a given name, return the name of the film and the year it was released using the Omdb api, and sort by year of release. I managed to list the movies but I’m not…
-
2
votes1
answer396
viewsRemove image background with Tkinter
I’m trying to make two layers with two images in which the background is whole in the application, and the second overlaps. The second is transparent, however, when the display occurs, it puts gray…
-
2
votes1
answer100
viewsHow to replace a float element with a string in a zeroed array?
I generated a zero matrix through the code: import numpy as np lista = np.zeros([4,4]) Later, I tried to replace an element of the matrix with some string (for example "a"). However, I made an…
-
2
votes2
answers962
viewsSearch Only the numbers of a String using Regex in python
I’m trying to clear a column of a process dataset and the number of processes come in various forms: 5080847-62.2018.4.04.7100 033/2.17.0001000-7 I want to leave only numbers and remove the other…
-
2
votes1
answer1852
viewsDefine matrix in python
I need to create a matrix and fill it with random values (randint(0,9)), except in equal rows and columns. For example, in this way: A| B| C| D| E A x| 2| 1| 4| 2 B 1| x| 1| 1| 2 C 5| 1| x| 4| 3 D…
-
2
votes2
answers113
viewsisinstance() does not produce the expected result after a data entry
I made the following example of factorial using function isinstance(). def factory(n): if not isinstance(n,int) or n<0: print('NAO E NUMERO INTEIRO VALIDO:\n') return None if n==0: return 1 else:…
-
2
votes1
answer68
viewsSearching for a field contained in several models
I have a manager in my project, which is to make TAGS, and on the front of my system the user will search a tag, and it will return everything related to that tag. Follow the models.py: from…
-
2
votes2
answers763
viewsAccess related table columns through ORM DJANGO
How to access the object user and its attributes after a join? This is my consultation Idea.objects.select_related("user").values("author_id").annotate( qtd=Count('author_id')) Example of a result:…
-
2
votes3
answers2034
viewsHandle cmd files using python
Hello! I need to create an application in python to decrease the labor where I work, we use files . bat to execute several commands in cmd, but some of these commands manipulate IP’s and as it comes…
-
2
votes1
answer338
viewsSignal change of values in Pandas Dataframe
Hello, good night. I have a set of vectors whose components (px, py and Pz) are stored in a Dataframe Pandas. I wrote a function whose goal is to change the signal of the components of the vectors…
-
2
votes2
answers1097
viewsHow to search for a word in a file and pull the phrase where it is together with the result?
I need to search for words in a book archive (vidas secas.txt). But I want her to bring the phrase where she is. There’s a way to do that? Here is my program: arquivo =open('Vidas Secas.txt','r')…
pythonasked 5 years, 11 months ago Arthur Vidal 33 -
2
votes2
answers270
viewsRun multiple processes on Linux with Python
I receive some Urls as parameter via MQTT, after extracting them I can execute the command for FFMPEG to record them with os.system. But it works for only one process, and I need to run N…
-
2
votes1
answer376
viewsHow to eliminate noise in an image?
In relation to the image presented, I want to leave only visible the main trunk and the (secondary) branches of the plant (tomato). Depending on my attempts, what seems to me to give more…
-
2
votes2
answers78
viewsCondition does not enter as entered
No matter what I type is falling on the first if, if I type m, M or even 10 will fall in the first if. I want that if the user type f or F appears feminine and the same goes for M or m. Letra =…
-
2
votes1
answer1999
viewsSyntaxerror: invalid syntax, what happened?
I am using Python 3.7.4, I tried to write several different ways and nothing worked. character_name = "Johnny" character_age = "64" print(+character_name "is cool.") print("And he is " character_age…
-
2
votes1
answer98
viewsProblem with the conditional IF structure
I’m trying to learn Python (and programming in general). At the moment, I’m studying if and Else and conditions, or and not. I’m training doing a quiz on star Wars, but I’m having a hard time. Score…
pythonasked 5 years, 11 months ago Eduardo Mergener 21 -
2
votes1
answer61
viewsInsert SQL with 3 arrays in the same table - PYTHON
I have the following structure of INSERT to the database POSTGRES: for first in nomes: for second in quantidades: for third in produtos: cursor.execute(first,second,third,str(timestampInitial))…
pythonasked 5 years, 3 months ago Luis Henrique 697 -
2
votes1
answer348
viewsPandas: Subtract dates into grouped indexes in a dataframe
I am conducting a research using pandas and need to infer the time between two buses based on their start times (start_time). For this I have grouped in my dataframe a field for itinerary and…
-
2
votes1
answer221
viewsProblems using Selenium module with Firefox
I’m using: Debian version 9.6 Python 2.7 Selenium 3.141.0 Firefox 60.3.0 I’m trying to learn how to use Selenium with Python but I haven’t been able to do anything yet. There is always some error, I…
-
2
votes3
answers122
viewsIteration using "while"
I have a little trouble understanding while and I came across an exercise that asked me to do the following: Read N sequences and find out how many f has in each sequence. I cannot use for in that…
-
2
votes2
answers1740
viewsComparing datetime with minutes interval
I need to compare 2 dates, these dates are in format %d/%m/%Y %H:%M:%S and one is obtained through the internet, and the other locally, however I am not able to compare the two with an interval of 2…
-
2
votes1
answer192
viewsSort dictionary and add python values
I have this text file that is processed to capitalize and this part does correctly. olá meu nome é meu nome pois eu olá é meu nome walt não disney olá Then I have this function which should be able…
-
2
votes1
answer166
viewsHow to use pandas styling properly?
Python code From the examples of documentation the following code has been created: import pandas as pd import os import webbrowser import io def highlight_max(s): ''' highlight the maximum in a…
-
2
votes2
answers902
viewsFunction Encode() and hash creation
I’m using Python 3.6 to make a program in which the person types an MD5 hash, then the program saves the hash in a variable, reads a txt file and plays the content inside a list, where each name…
-
2
votes1
answer213
viewsCode adaptation Fortran for python [Runtimewarning: overflow encountered in double_scalars]
I tried to adapt the following code in Fortran to python: PROGRAM Escape_tent IMPLICIT NONE ! Declare local variables INTEGER :: i,j,tfinal,P,k,rede Real,dimension(0:2800) :: x,xn real, external ::…
-
2
votes1
answer993
viewsCopy the value of a list variable to a python variable
I’m declaring a variable X with the value of another Y using =, but when having do a append in the variable X, to Y also changes. Code: ''' Resultado obtido: ['casaRJ', 'casaSP', 'casaDF', 'apRJ',…
-
2
votes2
answers143
viewsConditional structure does not work
Several times, especially when the second price is higher than the others, the program accuses that it is the cheapest. #Faça um programa que pergunte o preço de três produtos e informe qual produto…
-
2
votes1
answer109
viewsPrint specified JSON value
I am creating an application whose one of the returns comes from an API (return in JSON), and I need to collect the value of the key 'text' but when I return this way: data = json.dumps(response)…
-
2
votes1
answer912
viewsFormatting a python stored text
I made a random number generator that generates and saves in.txt file I made generate 3 combinations, it happens that when I open the txt the combinations are on the side of the other, as I do to be…
-
2
votes4
answers931
viewsPython columns excel csv
I made this number generator that gets saved in a csv file that I open in excel, the combinations are generated in column A but n want it to appear in A. as I do for her to appear in column B and C?…
-
2
votes1
answer400
viewsHow to count the elements of a list
I have a list that stores data: [(pizzas, 'COMIDA'), (1, 'QUANTIDADE'), (chocolate, 'SABOR'), (1, 'QUANTIDADE'), (catupiry, 'SABOR'), (1, 'QUANTIDADE'), (morango, 'SABOR')] I’d like to check what’s…