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
answer805
viewsSending e-mail with excel attachment - Python
import smtplib from email.mime.multipart import MIMEMultipart from email.mime.text import MIMEText from email.mime.base import MIMEBase from email import encoders email_user = '[email protected]'…
-
0
votes2
answers415
viewsRename a graph label in Python Matplotlib
I have a dataframe filter: F 3257703 M 2256044 with the code below I was able to display the graphic in pizza: porcentagemSexo = sexo.value_counts(normalize=True) rotulo = sexo.unique()…
-
0
votes1
answer86
viewsHow to sort elements from a list using Selection Sort?
I implemented Selection Sort to sort the text of a . txt that I made into a list. The problem is that it only orders field 1 and field 3, field 2 it did not order, as seen in the output: 10, 100, 2,…
-
0
votes1
answer80
viewsError when using Getoldtweets3 filter for a certain period
Hello, I am improving in Python studies and came across the error: Indexerror: list index out of range the Code I’m running is this: import GetOldTweets3 as got max_tweets = 3 tweets=[]…
pythonasked 5 years, 7 months ago MarciaNakayama 3 -
0
votes1
answer14334
viewsDataframe - Pandas. Creating new column after comparison between columns
I have the following df I need to add the code of the CODIGO column in the cod_city column in cases where the value of the ds_city column equals the LOCALITY column. I’ve tried that way, but it…
-
0
votes1
answer76
viewsGuessing minigame telling wrong
Total hits and kicks do not appear correct, if I change "hits" and "totalguess" to 0 the first hit or kick counts as 0 and wanted as 1 from random import randint acertos = 1 totalguess = 1 while…
-
0
votes2
answers153
viewsWithout the if explanation
As far as I know, else should be below the if, corresponding it, but in the code below, Else is not next to the if , because it is outside the repeating structure, to be more exact, the else is not…
-
0
votes1
answer53
viewsgetter-Setter error #python
I wonder where is the error in this supposedly simple code class Nome: def __init__(self,nome,sobrenome): self.__nome = nome # variável privada self.__sobrenome = sobrenome # variável privada…
-
0
votes0
answers29
viewstime() function is returning the same value every time
I have the following code snippet: from time import time class Transaction: def __init__(self, value, timestamp=time()): self.value = value self.created_at = timestamp Creating an instance and…
pythonasked 5 years, 7 months ago Thiago Krempser 1,878 -
0
votes1
answer280
viewsCount number of comparisons and exchange in a python sorting algorithm
I need to count the number of comparisons and exchange in the following sorting algorithm: def selecao(lista): c1 = c2 = 0 for i in range(0, (len(lista)-1)): mini = i c1 += 1 for j in range(i+1,…
-
0
votes2
answers48
viewsString sub-stituir per variable
i have the following text inside a.txt file [ExpertSingle] { 1050 = N X 0 1260 = N X 0 1470 = N X 0 1680 = N X 0 1890 = N X 0 2100 = N X 0 I want to turn "X" into numbers using Choice Ring to look…
-
0
votes1
answer126
viewsValues are not converted to np.Nan
I have the function: def zero_to_null(x): if x == 0: x = np.nan return x Uso series.apply: Series.apply(zero_to_null) However, the values 0 are not converted to np.Nan: Series.value_counts() 0 35 2…
-
0
votes1
answer120
viewsDoubt in lines
So guys, I’m doubtful about two queue algorithms, and I’d like a little help. The first doubt, From collections import Deque class Fila: def __init__(self): self.fila = deque() # atributo fila é um…
pythonasked 5 years, 7 months ago Thiago Andrade HoocKPeeR 29 -
0
votes2
answers1060
viewsMake a program that inverts an integer number with two digits
You must print the inverted number followed by a final line. No need to print the 0 further left. For example, if the number typed is 30, just print 3 and not 03. num=int(input()) if num > 0: a =…
-
0
votes3
answers69
viewsSQL syntax error in a Flask application
I am developing a game display system, with user login necessary to add games to this list, but when I try to run the query, I get a syntax error. It follows the code that prepares the database (has…
-
0
votes2
answers693
viewsHow to generate a range from A to B-1 in Python?
Here is my code to print if a number is prime or not, but it is necessary that the number printed by the user is not included in the block if, how could I do to establish an interval in the for in…
-
0
votes1
answer92
viewsHow to replace by following a pre-determined python pattern
within txt have 12480 = B X 43200 = B X 47040 = B X 50880 = B X 54720 = B X 58560 = B X 62400 = B X 66240 = B X 70080 = B X 73920 = B X 77760 = B X 85440 = B X 89280 = B X 93130 = B X 96960 = B X I…
-
0
votes2
answers106
viewsHow to discover relevant properties of a basis for a Python classification algorithm?
I have a database (excel spreadsheet) about the health of the elderly with about 112 columns and I would like to know the best algorithm to extract some of these columns, maintaining the variability…
-
0
votes1
answer148
viewsIs it good practice to use n to skip lines or to use a print() alone?
Hello, I already know that adding n to a string will cause a new line to start, but when I want to skip a line I should use n at the end/beginning of a string or should put a print() alone? For…
-
0
votes1
answer169
viewsTake the probability of belonging to each class
I have a theoretical problem where a store owner wants to know the chance of a particular phrase generating a sale, I have in hand a dictionary with 20 random words and 10 phrases formed by exactly…
-
0
votes1
answer1666
views -
0
votes1
answer251
viewsAdditional filter for groupby
The following code groups my DF by some columns f0219.groupby(['Matricula', 'Nome', 'Rubrica', 'Valor', 'CodigoRendimentoDesconto', 'Tiporubrica']).Rubrica.count() and counts how many times the…
-
0
votes1
answer67
viewsHow to create conditions in read and write text files (python3)?
So how could I pick up a text like this for example: "testo<br>de<br>exemplo<br>" and create a conditional (after giving the .open('file.txt', 'r')) for each time the program finds…
-
0
votes1
answer396
viewsHow to calculate the factorial of a list of integers using thread?
Given an A vector of size N with only positive integers, calculate the factorial of each of them and store the result in a vector B. To calculate the factorial, use the following function: def…
-
0
votes1
answer19
viewsError importing SKLEARN 32b into 64b server
all right? I’m really desperate for a question: I have a Python 3.7 environment mounted on a machine, Windows 10 64b, and I need to migrate it (which has been working for some time) to another…
-
0
votes1
answer130
viewsHow to create a PDF from a list
want to create a PDF from a list but this resulting the following error: C:\Users\nicperei\Desktop\pyCodes>py web.py Traceback (most recent call last): File "web.py", line 22, in <module>…
-
0
votes1
answer401
views -
0
votes1
answer94
viewsInput of various inputs
I do not know how to solve this problem, the problem asks me between several inputs at once. example: 10 12 10 14 100 200 And after that give the difference between them line by line, I was trying…
-
0
votes1
answer236
viewsRepetition for command exercise in python
The exercise is this one: Marcílio and Aurélio are disputing the election for president of the Academic Center. To be the candidate must have more votes than his opponent, and also a number of votes…
-
0
votes0
answers23
viewsMake python file into a library file
I have a python file that I want to transform into a library so I can call it in another file through the import subprocess, for files with extension . c the command I know is cc -o nomeficheiro…
pythonasked 5 years, 7 months ago Sergio Nunes 351 -
0
votes2
answers82
viewsPython - is it possible to use lambda in print with format (f or .format)?
I searched for lambda and print and I didn’t find anything I imagined, I mean, it’s possible to do something like this: mil = num//1000 print(f'O número tem {mil} {lambda milhar if (mil == 1) else…
-
0
votes2
answers165
viewsPython how to repeat my code
I would like to repeat this code not to iterate it 300 times , is a robot to click on the screen,I wanted it to repeat , the code is this ,I am new here and in programming I did not put the format…
-
0
votes1
answer363
viewsError initializing PYGAME
I’m creating a simple replica of the game Space Invaders in Python3.7, at first I was creating the screen all with Turtle, but the game entered in a kind of infinite loop and did not execute the…
-
0
votes1
answer1037
viewsCreate successive sum multiplication program in Python
The requirements are: solve positive and negative numbers; Do twice the one million, never a million times the 2, ie always the fewest sums; use the Try and ask for new execution. Like I’m trying to…
-
0
votes1
answer42
viewsHow do I resolve a problem of renaming ENCODED URL files?
How to troubleshoot this problem of renaming ENCODED URL files? When converting a list of URL ENCODED files through the following code from urllib.parse import unquote import os, shutil cwd =…
-
0
votes1
answer110
viewsHow to add to each value of a list, a number that depends on another random?
I have a list of 21 terms and a value that goes from 0 to a random number that varies from zero to the number typed by the user. I need to divide this random number into smaller numbers that add up…
-
0
votes1
answer1361
viewsError "Valueerror: Length of value does not match length of index"
I’m trying to find the address of stores "5aSec" in Brazil, but I keep getting error when I run this code import requests import json import pandas as pd dMun =…
-
0
votes1
answer1068
viewsList and Access Python subdirectories
Good afternoon guys, I’m trying to create a very simple text file management system, but in some of the difficulties I am found is accessing and manipulating files in subdirectories. Below I have…
-
0
votes1
answer69
viewsKeyboard condition
I am wanting to make a condition through the keys that the user press. For example, if it press 'ENTER' the script continues and press 'ESC' the script to. I searched the internet but found nothing…
-
0
votes1
answer74
viewsHow can I make the print text present more slowly?(python)
The idea is to delay the text, not like Sleep, but to make the characters of the sentence appear at a certain speed, instead of presenting everything at once. print('E lá vamos nós') There is a…
-
0
votes2
answers172
viewsDelete a row and column range in python?
Hello. I want to delete rows and columns from a csv file, and just keep the lines in the 15212 to 21777 range, from a file with more than 23,000 lines. The columns I managed to delete in the way I…
-
0
votes1
answer269
viewsSelect from and Insert into another database with Python
I’m trying to select a DB from Azure and after that insert the data into a postgresql DB. I tested the separate connections and both are working, but when running the full code nothing happens until…
-
0
votes0
answers52
viewsCalculate the weight of each class of an unbalanced multi-label dataset
I would like to calculate the weight of each class of a dataset multi-label to pass to fit_generator of Keras the parameter class_weight. In the case of a dataset single label, as my output is…
-
0
votes1
answer388
viewsRemoving duplicate lines
I’m developing my TCC, My TCC, it searches emails in google collection, makes bulk sending etc, I’m having a problem, In this search for emails he collects repeated emails and invalid emails, then…
python python-3.x python-2.7 python-requests python-kivyasked 5 years, 7 months ago Allan Petersen 3 -
0
votes1
answer132
viewsTkinter Entry always captures empty string
I am trying to create an application with graphical interface using the Tkinter. The graphical interface consists of a button, one text and of a entry, as in the image below. The idea is to type a…
-
0
votes1
answer531
views'<' not supported between instances of 'str' and 'int' >>> Not an input problem!
The idea is to create a matrix of confusion. yhat_tr has a hundred values(float), positive and negative. d_tr is a column inside an excel file with the same amount of items as yhat_tr. d_tr values…
-
0
votes1
answer33
viewsClass mock without methods
I need to mock a class that has no methods and returns nothing, how could I do that in Python? I’m mocking this class because it acts as a typing converter. My class is very similar to the one…
-
0
votes2
answers2416
viewsHow to get the first word of a text in Python?
frase = str("Eu como abacaxi").split() How do I show only the first word of the phrase ("I" in case)?
-
0
votes1
answer208
viewsMake attachment system with my python email sender
So, I’m developing a mass mailing, Only I’m not getting to use attachment in this shipment. The Code is found like this: #!/usr/bin/python3 import smtplib import os as sistema import getpass…
-
0
votes1
answer92
viewsError inserting CSV data into Mysql with Python
I am writing a Python code that inserts the data of a CSV into a Mysql table. if os.path.isfile('\\offline.csv'): try: csv = csv.reader(open('\\offline.csv', encoding='utf-8')) for row in csv: conn…