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
-
1
votes1
answer88
viewsPython - Compare Lists, using conditions to determine Start and End of Search
Introducing: Program has 1 Lists and 1 Set: List = Data Entry; Ensemble: Comparative Data lista_entrada = ['BBB','AAA','CCC','DDD','EEE'] print() for item in lista_entrada: print("item") lista_bd =…
pythonasked 6 years ago Guilherme Henrique 61 -
1
votes1
answer297
viewsFilter python list
I need to remove elements from a list whose item reference for removal is in another list: # Esta lista foi gerada por combinação lista original=[ (182361, 243148, 360624, 364188), (182361, 243148,…
-
1
votes2
answers2471
viewsHow to select JSON elements with Python?
I’m using a news API, it returns me a JSON file: import json import requests url = ('https://newsapi.org/v2/top-headlines?' 'country=us&''apiKey=be7b904493554491afde83281651f05a') response =…
-
1
votes0
answers2358
viewsDjango - CPF or CNPJ
Good afternoon Personal. As a way of learning I am creating a system in Django with Client Registration. Could someone help me in logic so that in the register I can choose CPF or CNPJ. My Models…
-
1
votes1
answer193
viewsRandom Forest with very high accuracy
I’m working with this dataset And I applied Forest Random to create a price forecast model, but the accuracy of the model is getting too high, so I’m suspicious if something is wrong. Apparently…
-
1
votes1
answer602
viewsTry & Except, correct way
The right way to use the try and except in the Python it’s like? try: variavel = funcao() except: return 'error' Or do I: variavel = funcao() and then I’ll deal with it that way variavel = funcao()…
-
1
votes1
answer639
viewsThe Pytesseract does not recognize only one letter
I need to recognize only one letter through the Pytesseract library in python but OCR is not able to recognize when it is only one letter. In this case, I’m trying to recognize the letter H, but…
-
1
votes1
answer33
viewsBs4 returning only version
Opa, I’m creating a tool that searches the wordpress version and prints on screen (requests + bs4). Excerpt from the code: def versao(): r = requests.get('https://'+f'{site}') html = r.text sopinha…
pythonasked 5 years, 4 months ago Richard Marcelo 25 -
1
votes1
answer551
viewsMeasure CPU or Memory usage of a windows program in Python
Good afternoon! Guys, I’m new around here. And I’m new with programming too. My doubt is the following, it is possible to measure the use of CPU or Memory for a program in specific windows using…
pythonasked 5 years, 4 months ago Thiago Dias 27 -
1
votes1
answer624
viewsProblem with Python Graph
Through calculations and mathematical expressions, starting from the information of three data informed by the user (Launch distance - Duration time - Maximum height reached), calculate the speeds…
-
1
votes1
answer748
viewsHow to make a program run inside a pygame window?
I made a window using pygame, and I have a code that I wanted to run inside it, but I don’t know how to do that, if anyone can help I’m very grateful. Here the window code: pygame.init() tela =…
-
1
votes1
answer61
viewsreturn a list of numbers that are in sequence
I’m trying to make some list go through and make another one come back with the numbers that are in sequence. My list is returning empty. Ex: lista=[1,2,3,5,9,10] returns nova_lista=[1,2,3,9,10]…
-
1
votes1
answer825
viewsCopy part of Dataframe where column is Null or Nan
I have the following doubt. I have the following sample dataframe: import pandas as pd df = pd.DataFrame({'A' : [4,5,13,18], 'B' : [10,np.nan,np.nan,40], 'C' : [np.nan,50,25,np.nan], 'D' :…
-
1
votes1
answer133
viewsAPÍ Django-storages Dropbox url error Pattern
I am using the following API: https://django-storages.readthedocs.io/en/latest/backends/dropbox.html I have exactly everything configured, from the lib installed to the settings of Settings.py. A…
-
1
votes1
answer36
viewsScript to Save the Page and Change the URL, and Save the Next Page
Well, I have a problem that in my view is simple, but in practice is complex, I need a Script in which it Save several URL pages and change to the next URL, Example: www.exemplo.com/1 Save 1 Next…
-
1
votes2
answers717
viewsRead a.dat file and assign names to its columns using Pandas
How do I assign names in columns using pandas? For example, consider a arquivo.dat in the following format: 3.141592543 3.141592543 3.141592543 3.141592543 3.141592543 3.141592543 3.141592543…
-
1
votes0
answers56
viewsI found the Attributeerror error: 'Dataframe' Object has no attribute 'media_url' how can I adjust it? thanks
import pandas as pd import numpy as np from datetime import datetime, date, timedelta import time from google.cloud import storage import io import re import requests import gcsfs def bq_date(x): if…
-
1
votes1
answer463
viewsNameerror: name 'Window' is not defined
I’m following this PDF, I’m on page 10, the code is wrong and I don’t know why. from tkinter import * class Janela: def __init__(self,toplevel): self.fr1 = Frame(toplevel) self.fr1.pack()…
-
1
votes0
answers92
viewsPass input numbers to Python array
I’m doing an exercise on bipartite graphs, in which the input is given in the following form: 6 2 4 5 1 3 2 3 5 1 0 2 2 1 1 1 Being 6 (the number of the first line) the number of lines to be read,…
-
1
votes1
answer375
viewsError in Python function ("is not defined")
This was the simplest code I found in a demonstration of a chained list in python, I just couldn’t understand why it’s not working class NodoLista: #Esta classe representa um nodo de uma lista…
-
1
votes2
answers138
viewsRead input data and write read lines to a file
I’m trying to create a program that when I give an entry it will create a list within a file, but when I try to do this it adds my entries in a single line and not one under the other. There must be…
-
1
votes2
answers53
viewsHow do I insert information into the page that is in Excell
Good afternoon guys, I wonder if anyone can help me ... I am automating a page and would like to know if it is possible to use an Excell spreadsheet to popular the fields ... for example: Today I am…
-
1
votes1
answer374
viewsHow to logout in Django?
I managed to create and log a user into the system, but the logout does not work and I do not understand the reason. View: def logout_view(request): logout(request) return redirect('home') html file…
-
1
votes1
answer99
viewsDoubt python model creation machine Learning
I have a question in the creation of my machine model Learning. I want to create a model that provides me the PSS_Stress columns =…
-
1
votes0
answers83
viewsIntermediate Code Generation - Recursion in Verification
Good afternoon, guys. I’m at a stage in the matter of compilers which is the intermediate code generation of my grammar. After the steps of lexical, syntactic, semantic analysis. Basically I have…
-
1
votes3
answers562
viewsMath library
You guys have a question. I’m giving a study in the library Math. What’s the difference between: Ceil, floor and trunc?? The idea is to take the floating part of the number. Hug!
-
1
votes1
answer198
viewsWarning looping Python Pandas, How to make the looping differently?
Guys I’m doing this looping here: for i in range(1, len(candles)): if candles['askclose'][i]> candles['askopen'][i]: candles['Fechamento'][i]= 'alta' But the jupyternotebook always returns me…
-
1
votes2
answers741
viewsHow do I put the value of a variable in a statement of another variable?
NomeDoProduto1 = str(input("Qual o seu primeiro produto? ")) NomeDoProduto2 = str(input("Qual o seu segundo produto? ")) NomeDoProduto3 = str(input("Qual o seu terceiro produto? ")) PrecoProduto1 =…
-
1
votes1
answer73
viewsI cannot perform color conversion after image rotation
I’m developing an algorithm that rotates images every 10 degrees. For this, I am identifying the center of my region of interest, not the center of the image, because it has region of interest that…
-
1
votes1
answer1643
viewsTurning a table column into a list in Python
importances_DT = pd.DataFrame({'feature':x.columns,'importance':np.round(decision_tree.feature_importances_,3)}) importances_DT =…
-
1
votes1
answer4550
viewsHow to make a Console menu in Python
I need to make a menu in the console in Python, but the same should be triggered by letters and not numbers, for example: def menu(): print(''' MENU: [C] - Cadastrar novo voto [R] - Ver Resultado…
pythonasked 5 years, 11 months ago Évertom Araújo 11 -
1
votes3
answers629
viewsPython: Indexerror: list index out of range
Does anyone know why you’re returning "list index out of range"? def balanceada(string): pilha = [] for i in string: if i != '(' or i != '[' or i != '{' or i != '<' or i != ')' or i != ']' or i…
pythonasked 5 years, 2 months ago tatiane berrocal 61 -
1
votes2
answers493
viewsTypeerror: 'datetime.datetime' Object is not callable
Python code to send sms only when the difference date of the query is equal to 7 days of the date of the current day. # -*- coding: utf-8 -*- import MySQLdb import pycurl import base64 import json…
-
1
votes1
answer75
viewsHow to obtain items that multiple lists have in common
How to do for when there is no common item, launch warnings? List 1, 2 and 3 have different index numbers. def compabilitySorter (lista1, lista2, lista3): listCompatible=[lista1, lista2, lista3]…
-
1
votes1
answer126
viewsSelect with LIKE operator using an array
I am trying to select with LIKE operator using an array, but it is returning error when forming the string. SCRIPT placeholder= '?' placeholders= ', '.join(placeholder for unused in NAMES) query=…
-
1
votes1
answer347
viewsScraping data using Robobrowser
I’m trying to scrape a form, to insert an attachment and submit, using Robobrowser. To open the page I do: browser.open('url') To get the form I make: form = browser.get_form(id='id_form') To enter…
-
1
votes1
answer562
viewsStacked dice. How to work this on pandas?
I have a table that is structured with "stacked" data, that is, all the information of a customer occupies a few first lines. Once the customer’s information is complete, the next client takes the…
-
1
votes0
answers162
viewsDjango project deploy on Heroku with errors
When trying to deploy my Python project using Django on Heroku, I am getting the following error. Counting objects: 3, done. Delta compression using up to 4 threads. Compressing objects: 100% (2/2),…
-
1
votes1
answer112
viewsWhy do lists (arrays) behave differently than common variables in Python?
Two examples that I think defines my question well, the first is the function: a = [1, 2, 3, 4, 5] def soma(l_item): l_item[0] += 10 soma(a) print(a) >>> [11, 2, 3, 4, 5] It is changed by…
-
1
votes1
answer123
viewsDifference between algorithms that read numbers until receiving the number 999
What is the difference of these codes? First code: cont = 0 n = 0 total = 0 n = int(input("Digite 999 para parar")) while n != 999: n = int(input("Digite 999 para parar")) cont += 1 total += n…
-
1
votes1
answer36
viewsHow to single lines a Dataframe Pandas that vary in just a few fields?
I have a Dataframe with the following format: And I would like to have the following result: How do I get it? Thank you.…
-
1
votes1
answer127
viewsDjango Application Deploy with Apache
I made a Django application and am doing some deployment tests on a virtual machine with Ubuntu Server 18.04, before deploying it in a VPS. I made the settings correctly, but I’m having a problem…
-
1
votes1
answer38
viewsReturn only the file name in the view
How do I display only the file name, example RET_PREF_ANAPOLIS..., removing the path arquivos/? py.models: def user_directory_path(instance, filename): if instance.tipo_arquivo.id == 1: tipo = 'RET'…
-
1
votes1
answer114
viewsUse of map() in python
Searching on this site https://pythonhelp.wordpress.com/2012/05/13/map-reduce-filter-e-lambda/ vi o uso do map(). But in the terminal the first example is not printing a list. import math lista1 =…
pythonasked 5 years, 2 months ago Jorge Borges 63 -
1
votes1
answer360
views[How to check if my list has letters or words in Pyton]
I have a list in Python and I need to know if it has any words or letters, because I need it to only have numbers def sum_of_products(lista): if type(lista) != int: print("Possui letras") else:…
-
1
votes2
answers115
viewsRemove only strings from a list
I have the following code: Lista_1 = [10, 3, 6, 27, 'Maria'] Lista_2 = [37, 8, 45, 80, 'Jose'] Lista_3 = [43, 67, 99, 3.456, 'Pipoca'] Lista_4 = [432, 456, 333, 538, 'Bala'] Concatenating lists…
-
1
votes1
answer2061
viewsDjango: Modulenotfounderror: No module named
I have the following problem between two apps, in which I call a model from an app (app1) in a view from another app (app2) Projeto ├ APP1 └ APP2 View from APP2: from projeto.app1.models import…
-
1
votes1
answer110
viewsHow to keep the window created by Pyqt5 open?
After studying the object orientation part for a long time I started to study Pyqt5. I was doubtful in the following code: class App(QWidget): def __init__(self): super().__init__()…
-
1
votes1
answer36
viewsI don’t know how to move from one option to another
I tried to make in the first lines a menu that would direct to an action if a certain number was typed , but an error appears that I do not know how to solve def menupricip(): print ('#### Lucy_Main…
-
1
votes1
answer143
viewsVariable changes value when calling function
I created a variable v, who receives n random numbers. when create another variable by calling a function and passing v by parameter, the v mute. n = int(input("Entre com o tamanho de vetor: ")) v =…