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
-
0
votes1
answer36
viewsEllipsis in numpy array
What the object means ... in a numpy array. I am working with a database and when I use the Unique method in one of the columns, between the objects it returns this ... What these reservations…
-
0
votes1
answer344
viewshow to do total in list elements Python Django
Enter primary data (raw data)where it has values . Flot and I am already calculating the total in function "totalv2" ta run class Funcionario(models.Model): Custocoleta = models.Decimalfield(…
-
0
votes1
answer209
viewsReduce Runtime Python3
I’m solving a challenge here, which is to basically see how many elements of a list fit into ALL ranges of an array. And my solution was this: def countSignals(frequencies, filterRanges): corretos =…
-
0
votes0
answers38
viewsAccessing data in CSV
The code is to separate the values of each state in different lists, so the variable 'o' changes all once the state acronym changes and tells which list the values will be. It works until the…
-
0
votes1
answer43
viewsHow can I write the generated data in different lines?
Example: I want a number in one line, then in another line. But all within the same generated text file. from tkinter import* janela = Tk() #################Cria o arquivo##########################…
-
0
votes1
answer90
viewsExercise - Calculation of bhaskará
a=int(input("Digite o valor de A: ")) b=int(input("Digite o valor de B: ")) c=int(input("Digite o valor de C: ")) delta=float(((b**2)-4*a*c)) r1=float((-b +(delta ** (1/2))/2) r2=float((-b -(delta…
-
0
votes1
answer336
viewsPassing error (loops) - play stone paper scissors lizard and Spock
I’m making a game Stone, paper, scissors, lizard and Spock. The intention of the game is to create a function that asks me which option I will choose, while the computer randomly chooses one of…
-
0
votes1
answer478
viewsAdding and sorting row of matrices in python
The program below generates a random matrix, according to the amount of lines desired. def gerar(nLins, nCols, min, max): from random import randint vals = [None] * nLins for i in range(nLins):…
-
0
votes1
answer40
viewsproblem with None
I’m doing an exercise here and the desired output would be Yes in this case but it’s returning me None. Could anyone help me? vlw def alphabet (s,t,k): for i in range(0,len(s)): if s[i] != t[i] or s…
-
0
votes1
answer69
viewsReturn value based on date criteria within start and end date range and ID in another data frame? (pandas and python)
I have two dataframes, where the df1 contains the column Data and Praca_ID, where I need to look in the df2, who owns DataInicial DataFinal Praca_ID and Tarifa (column to be returned.) The example…
-
0
votes1
answer351
viewsCompression and Reading of CSV file with large-scale rows x columns via Pandas
I am stuck looking for a precise and intuitive way to read a file of 70.000KB formed by the concatenation of several files being them with varied sizes. Initially possessing several files in the…
-
0
votes0
answers77
viewsHow to run scripts in F12 by Selenium
I wanted to know how to run a script by F12 ( Developer Tools ) by Selenium, I wanted him to open F12, then I would go to the Console and put the script there, I tried…
-
0
votes1
answer637
viewsError running python script via python 2 terminal: "Ioerror: [Errno 2] No such file or directory:"
The program should create a mes/dia.dat file, but nothing is created and this error is returned to me, where we can see that the file is not being created with the file.open() command. Follow the…
-
0
votes1
answer1445
viewsDraw an item from the List, and then draw another item from a list with the name that was drawn from the first list
Good morning, everyone. I have a master list called "Livros". I need to draw a name from that list Livros. After choosing one of the names, I need to draw again, but now I need to choose from…
-
0
votes1
answer44
viewsUnintentionally changing the value of the object
Project link: https://github.com/ThomasCaio/RPG2 self.enemy.Damage returns : {'Physical': 45, 'fire': 25} self.Defense returns : {'Physical': 50} def receive_damage(self): damage = self.enemy.damage…
-
0
votes1
answer177
viewsFunction to print directory on a Python Label
I created a function that opens a file with Tkinter + filedialog, so far so good. But I need to print the directory of the selected file on a label. Follows function: from tkinter import * from…
-
0
votes1
answer26
viewsInstallation of Tensorflow by Pip
When trying to install tensorflow by Pip always gives error, version indepentendete python, Pip or tensorflow. When trying the command via cmd: Pip install tensorflow The answer is: ERROR: Could not…
-
0
votes1
answer107
viewsProcessing Complexity in a Pandas Dataframe
I need to deal with a base junction problem in the Python language. I have three layers of folders that I need to enter, find the file and merge into a dataframe. The layers being: year, month and…
-
0
votes2
answers183
viewsPrint which (ais) words repeat in Python
Hello, how could I know which or which words repeated? For example, I have a.txt file, in which when I open it as . read() and it returns it to me... Alface, Alecrim, Capim, Limão, Alface, Azeitona,…
-
0
votes2
answers49
viewsLen and Max Float together Python
I’m trying to figure out the index of the highest number in the list and add the index number to a variable, but it’s giving an error of float, which list cannot be executed with float. How can I…
pythonasked 3 years, 12 months ago Rhuan Burle 11 -
0
votes1
answer635
viewsHow to get n working day of the month?
I’m creating a data model for Machine Learning to get a transaction amount forecast per year/month/day/hour. But I am needing to map the 5th and 10th working day of the month so that my algorithm…
-
0
votes1
answer34
viewsPython+HTML+Sqlalchemy error
Hello I am trying to do a simple procedure, but I stopped at the problem below. I have the simple goal of passing a parameter and filtering a list of associates. I have the following codes: Python…
-
0
votes0
answers71
viewsHow to make a function with Python data validation? type Try
When I do this code outside a function it works, now when I do with function it returns me 0. ``` def validacao(x): try: x = int(input()) band = 1 except ValueError: band = 0 while band==0:…
pythonasked 3 years, 11 months ago Victor Hugo 1 -
0
votes1
answer37
viewsHow do you move the first two characters of a word to the end of it?
How can I move the first two characters of a word to the end of it? For example: LUCAS --> CASLU casa --> saca I’ve tried using the replace transforming into list and read the first two…
-
0
votes2
answers53
viewsHow to keep the window open in Python Kivy?
I am learning the Python Kivy library. The code is not making mistakes, but the window opens and closes immediately. How can I make the window stay open? import kivy from kivy.app import App from…
-
0
votes1
answer45
viewsError outside the list range
I have a problem, I have 3 files that I need to open and get information from them, move to a list within the list (matrix?!) and compare information from 2 lists with another list to validate…
-
0
votes0
answers36
viewsHow to update a key slice (key) of a Python dictionary?
How do I update just a slice of a key in a Python dictionary? I am scraping a page and would like to format the result so that my key is on the same line as my value, for example: Air Conditioners:…
-
0
votes1
answer48
viewsHow to know how many times the highest value was read (without list)?
I am doing an exercise where I must print the highest value of the numbers typed and how many times this higher value was typed. I tried to put the qnt += 1 but it’s not working. qnt = 0 num_lidos =…
-
0
votes1
answer390
viewsDisplay number that most repeated and its quantity
I have the following code: def repetido(numeros, count): for i in range(len(numeros)): count.append(float(numeros[i])) for x in range(len(count)): aux = count.count(count[x]) if aux > count:…
-
0
votes1
answer103
viewsImport JSON data between Python files
I’m having a hard time. i have a code in Selenium(test.py) and I have another python queue code (Queue.py) my goal is to pass the error message [ error = {'Status': 'Error'} ] to the…
-
0
votes1
answer95
viewsDjango ORM to select with group by
I have a very simple model in Django: class TrackService(models.Model): ip = models.CharField(max_length=150, db_column='nm_grupo') creation_date =…
-
0
votes0
answers12
viewsWhat does __class__mean?
I was reading a code in Python when I came across this excerpt: def __init__(self, conexao): __class__.conexao = conexao __class__.centro_espacial = conexao.space_center self.iniciar_decolagem()…
-
0
votes1
answer761
viewsPython module import Import ('cannot import name rr',))
I have two python codes, one that is called [receiving.py] another that is called [sending.py] I have a problem importing my codes. I’m just gonna send a little piece of my code that I’m in trouble.…
-
0
votes1
answer123
viewsHow to remove background using python and cv2?
I’m a beginner in programming and have some problems trying to remove the background of the image using cv2. The program below runs, however the result is not as expected. I would like to help…
-
0
votes2
answers288
viewsPrint repeated strings inside the List in Python
I have a file that has several words like: apple, grape, dog, etc. I made a random to get 1 random word. The intention is to play the hangman, the user type a letter, for example: 'r'. Then the…
pythonasked 5 years, 3 months ago heitor_deep 81 -
0
votes0
answers35
viewsProblem deleting Discord.py positions
I was taking a test and the next thing I knew, I was creating a lot of positions to do tests, only I tried to do it to erase and I couldn’t. Does anyone have any idea how to help me? @client.event…
-
0
votes1
answer51
viewsHow to name multiple dataframes automatically in Python?
I need help automating a dataframe naming process that I’m applying. I imported 3 csv files and applied the code below, which worked smoothly: Loja_1, Loja_2, Loja_3 = (pd.read_csv(cont) for cont in…
-
0
votes1
answer72
viewsInheritance in classes
I have a challenge to create a small system in Python that manages associations in a club. For this, I created the following class: class Carteira: def __init__(self,numero,atividade,bilhete):…
pythonasked 5 years, 3 months ago Diovana Valim 203 -
0
votes1
answer30
viewsArray saving only the last inserted value (PYTHON)
I have a script that captures all processes from the machine, using the library PSUTIL, But when you put it inside an array it is only saving the last value in memory, not all values. OBS: I need…
pythonasked 5 years, 3 months ago Luis Henrique 697 -
0
votes0
answers19
viewsmy display does not open in pygame by vs code
i made an initial script of my game in pygame and the code is as follows: import pygame pygame.init() display = pygame.display.set_mode([840, 480]) running = True while running: for event in…
-
0
votes2
answers47
viewsCompare the values of two lists
So, I just started learning Python and I’d like to know how to compare the values of two lists, more specifically, know the values that match them, example a = [30, 35, 40, 50] b = [25, 35, 40, 55]…
-
0
votes0
answers57
viewsBisection Method with Python
I am developing a program to calculate numerical methods. Start by confinement methods, in this case one of them is the bisection. I’m not being able to print the iterations that the method…
pythonasked 5 years, 3 months ago Felipe Roque 57 -
0
votes2
answers507
viewsChange List with a python function
I’m developing some book exercises "Intensive Course of Python" but I stopped in the proposed 8.10 exercise: EX: 8.10 - Great magicians: Start with a copy of your program from Exercise 8.9. Write a…
-
0
votes1
answer37
viewsHow to initialize N random vectors, where N is provided by the user?
import random x = int(input("Digite o tamando do cromossoma: ")) n = int(input("Digite a quantidade de vetores: ")) saida = [] for _ in range(x): …
pythonasked 3 years, 11 months ago Anderson Nicolau 17 -
0
votes1
answer420
viewsHow to use pandas.read_sql_query within a class
I created a class to facilitate the use of the library psycopg2 responsible for connection to the Postgresql database. import psycopg2 as pg class Postsql: def __init__(self, Phst, Pusr, Ppwd,…
-
0
votes0
answers214
viewsSelenium Python Input on a virtual keyboard
I am facing a problem with Selenium, which is to log in to a page, but the problem is that when I get the element (name) or the element (ID) of the field it returns error telling me that that…
-
0
votes2
answers49
viewsHow do you sum all the values of the vector in Python?
How can I sum all the values? Should I use an array (list) to store the values. valores = [] for i in range(1,11): valores.append(input('Informe o {}º valor: '.format(i)))…
-
0
votes3
answers105
viewsDoubt about Python list
The problem is to make a function that receives a list, and returns True if any of the elements are repeated, or False otherwise, without modifying the original list. I made an algorithm, but it is…
-
0
votes0
answers43
viewsI have a simple class and it doesn’t answer when I call the methods
Can someone help me? class sorvete(): def __init__(self,sabor, recipiente): self.sabor= sabor self.recipiente= recipiente self.ml= 0 def sabor(self): print("O sabor que pediu é: ", (self.sabor)) def…
-
0
votes1
answer102
viewsPython/Selenium - Webscrapping, click
Hello, I started to study Python a little bit and I’m doing some tests with Lenium and I came across an error in which I am not able to solve. I’m trying to click a button on a website but the…