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
answer67
viewsIdentify matching in dataframes
Dataframe D1. Ano/Mês Referência Ano/Mês Competência UF Código Município SIAFI Nome Município SIAFI NIS Beneficiário Nome Beneficiário Valor Benefício 0 201301 201202 AL 2785 MACEIO 16035155015…
-
1
votes3
answers127
viewsCode does not work as expected
My code should read name and weight using an auxiliary list and throwing the data to a main list. In the end, it generates a result of the highest and lowest weight with the name of the people who…
-
1
votes1
answer46
viewsHow do I print a table with all iterations in Python?
With the code below I get only the final answers, how do I print each step? def funcao_volume(x : float): return 4*(x**3) - 1014*(x**2) + 62370*x def calculate_alpha(delta: float): numerador =…
-
1
votes1
answer244
viewsSort lists without Sort
I’m trying to solve an exercise, but I’m not getting any results yet. I’m new to language. '''Define a merge function that does the following: Given two ordered lists L1 and L2, returns an ordered…
-
1
votes1
answer144
viewsHow to do this kind of relationship in Django?
I have the models "Subscriber": class Assinante(models.Model): name = models.CharField("Nome", max_length=32, null=False, blank=True) phone = models.CharField("Telefone", max_length=11, null=True,…
-
1
votes0
answers51
viewsProblem with the xticks - matplotlib
I’m a beginner in the Science data area and I’m developing my solution to the Kaggle Titanic problem (https://www.kaggle.com/c/titanic). At the moment I am creating a visualization to verify the…
-
1
votes3
answers132
viewsMerge 2 Programs - Python (3)
I created 2 programs separately to convert Real to Dollars and another to convert Dollars into Real, what I would like to do is create a kind of menu or input, where it would be written: "Type 1 to…
-
1
votes1
answer108
viewsFor nested only works in first iteration (Python)
I’m trying to get one nested to compare lines in two different csv files, but after the first interaction of the first file is searched inside the second file and skip to the second iteration, the…
-
1
votes5
answers2318
views -
1
votes1
answer442
viewsAdding a column of numbers 1 to a numpy array
Let X be the numpy array below: array([ 6.1101, 5.5277, 8.5186, 7.0032, 5.8598, 8.3829, 7.4764, 8.5781, 6.4862, 5.0546, 5.7107, 14.164 , 5.734 , 8.4084, 5.6407, 5.3794, 6.3654, 5.1301, 6.4296,…
-
1
votes1
answer158
viewsWhy use double clasps in Pandas?
Given the following Dataframes: df = pd.DataFrame([[1, 2, 1], [4, 5, 2], [1, 2 , 3]], columns=['coluna1', 'coluna2','id']) df2 = pd.DataFrame([[1, 7, 1], [4, 'a', 2], [1, 'abc', 3]],…
-
1
votes2
answers113
viewsEncapsulation of functions
Below is an example of using a function passed as a parameter to another function: def gera_nums(): lista = [] for c in range(0, randint(1, 15)): lista.append(randint(0, 100)) return lista def…
-
1
votes1
answer139
viewsTurning binary into a Python chart
Good evening I have a message that I turned into binary and wanted to make a graph from the following patterns ami pseudoternary, where if the binary digit 1 the frequency is 0 and if the binary…
-
1
votes0
answers43
viewsProblems with Memcached + Django + Celery(Rabbitmq)
I’m having trouble using the memcached + Celery(Django). My program makes a query in a database, through a cursor, creates chuncks with the return of the bank and sends these Chunks to be processed…
-
1
votes2
answers294
viewsRegex does not take all span tag strings
I know there are HTML parsers, but since my HTML is not well structured, I also need to use regular expressions. The HTML is like this: <tr bgcolor="#CCCCCC"> <td colspan="2"><font…
-
1
votes1
answer715
viewsDoubt about the __dict__ method in Python
Well, I’m a beginner in Python programming and started studying object orientation. I came across the following code, which is very simple. class Pessoa: def __init__(self, nome, idade, altura):…
-
1
votes1
answer218
viewsError passing numpy.core. _exceptions.Ufunctypeerror: ufunc 'subtract' Did not contain a loop Signature matching types (dtype('<U21')
Basically I have the following code: import numpy as np def localize(aux1, aux2, aux3, aux4, aux5, aux6): search = np.array([(aux1,aux2,aux3,aux4,aux5,aux6)]) B1A =…
-
1
votes1
answer141
viewsHow to update Forms in Django
Hello, everybody. Here’s the thing: I have two presses that integrate with a model in Django, being them: Forms.py from datetime import datetime from django import forms from .models import…
-
1
votes1
answer282
viewsdraw rectangle with hastags and ask again
Hello, I’m trying to make this code work as follows: you say the width and height and then it completes with the proper "#" and then it would ask again and continue like this until the person closes…
pythonasked 4 years, 8 months ago Kal Arruda 21 -
1
votes1
answer31
viewsImport a file that starts with numbers in Python
I have the following problem: I am trying to import a module into Python. I have the following code: # -*- coding: utf-8 -*- import 01_Jogo print("----------------------------------------")…
-
1
votes2
answers5692
viewsHow to print all the contents of a list in Python
How do I print contents from a list? I want the output to look like this: Indice: 0 1 2 ... likes: 0 0 0 ... A post is represented as an element of a list. The list index indicates the post number.…
-
1
votes1
answer235
viewsHow to sort a python dictionary in descending order?
How can I order this dictionary so that it is in descending order: dict= {'1': array([44, 32, 56, 57, 43, 21, 36, 35, 39, 27, 23, 24, 25, 26, 31, 28, 29, 30, 20, 22, 18, 19, 8, 1, 33, 2, 3, 4, 0, 6,…
-
1
votes1
answer66
viewsI cannot change the verbose_name of a field
I am programming an agenda, and for that, I created the model "Commitment", which has the following code: class Compromisso(models.Model): nome = models.CharField(max_length=100,…
-
1
votes0
answers75
viewsOpencv in kivy image detector ERROR camera hangs
Guys, I’m trying to run this code and it locks the camera and does nothing else. The idea of the code is to run the face detector inside the widgets + kivy using this library from kivy.uix.image…
-
1
votes1
answer173
viewsBucket Sort in Python: The array is only partially ordered!
I’m trying to implement the algorithm Bucket Sort. The code below implemented only "1 round" (considering the numbers from right to left) of the algorithm, in which the array [97,3,100] turned into…
-
1
votes1
answer74
viewsSuggested improvement of code, for opening of several csv files in different directories
Good evening friends, a friend passed me a code that he was developing so that I could study, however I would like to see a better alternative to the opening of various files . csv, only they’re in…
-
1
votes1
answer1363
viewsSites with authentication - Web Scraping - Python
BR: I’m trying to automate a web data acquisition process using Python. In my case, I need to pull the information from the page https://sistema.justwebtelecom.com.br/adm.php. However, before going…
-
1
votes1
answer81
viewsOcaml vs Python - Function return value
I have the following function written in ocaml let rec pow((x:int), (y:int)) : int = if y=0 then 1 else x * pow(x,y-1) ;; let pr = 13;; let bs = 31;; let getvalor num ch1 ch2 tam = (num * bs +…
-
1
votes1
answer370
viewsCreate sublists in python
I created the following code: self.buckets = [[], []] for i in self.keys: for ii in self.lista: if i % len(lista) == ii: self.buckets[ii].append(i) That adds the elements of a list in the case…
-
1
votes3
answers348
viewsArithmetic operations where some Dataframe data is not int in Python (pandas)
I am working with some data from IBGE and I meet with two spreadsheets that I need to take their percentage. The formula for this is very simple, ie: percentage = (dividend / divisor) * 100…
-
1
votes1
answer365
viewsAutomate web scraping in Python
I’m trying to get the speeches of the deputies, which can be found here. The site has several pages (1 to 300 +/-) and on each page has a table with a "summary" of the information, with 50 lines.…
-
1
votes1
answer1167
viewsCreation of python Dict
Time, has a class that creates dicts and stores them in a list slot: class Pagina: def __init__(self, keys, palavras, tamanhoP): aux = list(zip(keys, palavras)) self.paginas = list() for i in…
-
1
votes2
answers173
viewsTurn a sentence into a list of letters of each word and then calculate the sum of the alphabetic numbers of those letters
I need to turn a sentence into a list of letters of each word and then calculate the sum of the alphabetic numbers of those letters. Ex: "Joao da silva pinto" nome=input('Digite seu nome completo:…
pythonasked 4 years, 7 months ago Renan De Castro Reis 23 -
1
votes1
answer80
viewsHow to pass values from one function to another?
I made the code below, in order to receive and display data, as if they were related to a tax bill. The code displays the following error when running: File "main.py", line 49, in <module>…
-
1
votes1
answer180
viewsHow to add an array inside a python Matrix
Hello I’m having a problem in python I’m taking an excel a Matrix of 15 columns and 3 rows, so I’m reading excel with pandas and did that while below to read all columns and all rows: import pandas…
-
1
votes3
answers124
viewsif and Else in Python
Hello, I have a question about the command order. My script went like this: if salario <= 1250: aumento = (salario * 15 / 100) + salario print('Seu salário com reajuste é…
-
1
votes2
answers884
viewsPython - how to create a two-dimensional matrix with for loops
Hello The code below gives the following error message: Traceback (Most recent call last): File "C:/Users/Usuario/Documents/tests python/várias.py", line 12, in mult[i][j] = (i*j) Indexerror: list…
-
1
votes0
answers56
viewsSELECT Asynchronous with PYTHON
Hello everyone, thank you!! I am trying to make some connections to a Mysql database in asynchronous mode where there is dispute and print on the screen the result that arrives first... but I am not…
-
1
votes0
answers54
viewsHessian update in BFGS method
I’m developing the nonlinear optimization method BFGS (Broyden-Fletcher-Goldfarb-Shanno) and I’m having a hard time updating the value of Hessian to minimize function. The input variables for…
-
1
votes2
answers82
viewsList ordering returns "None"
I’m doing a program that renders keys to the euro millions, but the keys are None, what is my mistake? import random print('Chave do Euromilhões') num=…
-
1
votes1
answer348
viewsHow to calculate polynomial roots with a list?
I’m having a hard time with a university job and I’ve come to ask for your help here. I have two lists of candidate values to be roots of a polynomial. listaDivisoresP = [] for i in…
-
1
votes1
answer101
viewsHow to stop reading from sys.stdin in Python 3 after reaching a bounded number of lines?
I am trying to receive command from sys.stdin until it reaches a limit n lines, and then finish the execution automatically. My code is as follows: import sys A = [] n = int(input("number of nodes:…
-
1
votes1
answer129
viewsFiltrar Foreign Key
Good afternoon...I’m trying to make a filter through Foreignkey, return only items that are not included in the registry of allocations, I’m using Select2...but I can’t filter... I have 3 models:…
-
1
votes1
answer27
viewsWhy should this repeating structure that should turn a word upside down not come back at all?
phrase = str(input("Type your phrase: ")).upper().strip() words_phrase = phrase.split() words_together = ''.join(words_phrase) phrase_inverse = "" for letra in range(len(words_together) - 1, -1,…
-
1
votes2
answers87
viewsHow to define which inputs will be accepted by the code?
I have a code where as the user enters data, I want to create a list that will be used for operations later. Output input would be the key "f" interrupting the repeat structure and initiating…
-
1
votes1
answer513
viewsCount number of occurrences of a number
Program that has only one function, besides the main program, that will receive as parameters an integer number x, a sequence of integers L and a natural n, representing an item x that must have…
-
1
votes1
answer1271
viewsHow to make a dynamic table in a Pandas dataframe?
Good afternoon. I’m migrating some activities from excel to python (an environment I’m still a layman), and came across a problem in making a dynamic table. I tried using pivot_table but could not…
-
1
votes2
answers159
viewsDecoding a conversation
Problem: A code has been created between friends to encode conversations. There is a code relationship between letters and numbers as shown below. It is necessary to create a function called…
-
1
votes1
answer224
viewsDelete duplicate files
I am creating a script to scan my system and delete all duplicate files. To not have problems in the test phase I changed the function of delete to copy and I am testing in a specific folder, to…
-
1
votes2
answers2626
viewsHow to make a "procv" in Python using the Pandas library
good afternoon! I got csv down: Nome Vendas Produto Data Carlos 83,40 cod2 15/04/2020 Andre 70,50 cod5 10/04/2020 Cristina 100 cod7 25/04/2020 Carlos 20,80 cod1 03/04/2020 Gisele 10,50 cod9…