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
votes0
answers31
viewsIf there is no option, how to repeat the question in python?
How do I repeat the above question in case the answer does not get any of the options within the function if and elif? parcelax = int(input('Qual formato de parcelamento? \n 1) Á Vista \n 2) 12x \n…
-
0
votes1
answer680
viewsHow to turn Selenium into an executable (python)
I went to make a bot with Selenium, and on my machine ran smoothly until the executable, but when passing to a friend’s machine is giving a boring error and I can not solve. from selenium import…
-
0
votes1
answer71
viewsPython: How to assign values in n arbitrary dimensions?
I have two n-dimensional arrays (i.e. Len(A.Shape)==Len(B.Shape)), and one 'fits' in the other (be the first A, the second B, for all dimensao i of A and B, A.Shape[i]>=B.Shape[i]) I want to…
-
0
votes0
answers60
viewsMy Python class is working but has the result values not match
I’m creating a Chain Account class. In this class I want to have the balance of each account and the totaling of all accounts, but is giving error in the balance of the second account, the class is…
pythonasked 5 years, 6 months ago Construindo você mesmo 27 -
0
votes2
answers63
viewsHow to Catch the Smallest Value of a Series of Inputs
the user enters a code and the desired quantity, this code refers to some value of the list and then the value of the list is multiplied by the quantity. of this multiplication I want the most…
-
0
votes1
answer408
viewsString Formatting - PYTHON Alignment
my question is, instead of :>6, I wanted the user to be able to choose the amount of characters to be aligned to the right, for example, there instead of 6, I would put the variable n. However,…
-
0
votes1
answer1350
viewsHow to execute Python commands inside cmd using a script
I want to create an executable that opens a cmd and after that, enter a clear() function automatically so that you can clear the screen whenever necessary just by typing clear(). Fez: import os…
-
0
votes1
answer282
viewsDeploy python Django project to Heroku. I’m having errors
I’m trying to deploy a Python project using Django on Heroku. deploy is fine, but when trying to make Heroku run python Manage.py migrate the following error occurs. Traceback (Most recent call…
-
0
votes1
answer98
viewsPython - Ignore Nan values in a . csv and add the rest
Hello, I have a file . csv that I am trying to pass to json Produtos Quantidade Bala 50 Refri NaN Salgado 25 And I’m importing for a json, wanted to know how to ignore the Nan values and return the…
-
0
votes1
answer23
viewsHow can I compare a variable within a list of lists by reading/changing their content in Python?
board=[['1','2','3'], ['4','5','6'], ['7','8','9']] p_move = input('Enter your move: ')) # p_move = '4' for row in board: for column in row: if p_move ==…
-
0
votes1
answer466
viewsA = A.astype('double') Attributeerror: 'list' Object has no attribute 'astype'
I have this error but I can’t find the cause. Code: from __future__ import division import numpy as np from numpy import linalg def jacobi(A,b,x0,tol,N): #preliminares A = A.astype('double') b =…
-
0
votes1
answer109
viewsGet values from a list and column
I’m having trouble with a check, I have a certain matrix with N rows and N columns, I need to go through it and know in which row and column have only odd numbers. Go as far as I can go. matriz =…
-
0
votes0
answers41
viewsAscii problems running script
Good afternoon, I am developing a simple script that needs to take data from an ascii encoded database, however I am getting an error message regarding utf-8 formatting. code snippet:…
-
0
votes3
answers82
viewsHow to display matrix input values without [' ']
I made an array with 12 elements that has 4 rows and columns and wanted them to be displayed like this without [' '] in list form, but I don’t want the output to be displayed like this: Remembering:…
pythonasked 5 years, 6 months ago user141036 -
0
votes1
answer189
viewsHow to correlate 2 different txt in python?
Input data: Primeiro txt 77777777777777777777 Id x y 1 6655.5 -3132.0 2 1122.3 -1234.0 3 4455.6 -5678.9 Segundo txt Id e n z 1 111 222 333 2 444 555 666 3 777 888 999 Resultado qual eu preciso:…
pythonasked 5 years, 6 months ago Rafael Fernandes 1 -
0
votes1
answer491
viewsHow to add an image to Kivy Python
I need to add an image to my screen and was following what I was doing in all other widgets. My code: class MainApp(App): def build(self): layout1 = FloatLayout() button = Button(text='iniciar',…
-
0
votes1
answer241
viewsAccess Denied Error while trying to install my virtual environment in Python
When I try to install my virtual environment in Python, through the " Pip install virtualenv "command, the installation starts but then the following message appears: " ERROR: Could not install…
-
0
votes0
answers151
viewsOpen file . py on Vscode terminal
I’m starting to study python (first language) and I just installed Vscode (previously used Pycharm). I’m getting a lot from the Code settings. Before I could open my script (main.py) straight from…
-
0
votes1
answer49
viewsI need a recommendation on how to use bootstrap as template formatting in a Flask app
Hello, this question seems kind of basic but I still haven’t found a consistent answer. I would like to know if, when using Bootstrap as a template formatting in Flaskpy, the best option is via CDN,…
-
0
votes2
answers720
viewsAdd elements of the first matrix to those of the second matrix in Python
There are two matrices with 5 rows and 3 columns, how do I accomplish the sum of the elements of the first matrix and the elements of the second matrix. For example: -- 1a matriz -- 02 04 06 08 10…
pythonasked 5 years, 6 months ago user141036 -
0
votes1
answer183
viewsKivy Filechooser how to select a directory
I need to create an interface where the user can select a directory, my code: class MainScreen(FloatLayout): def __init__(self, **kwargs): super(MainScreen, self).__init__(**kwargs) b1 =…
-
0
votes1
answer46
viewsHow do I merge into two array, but toggle them. (python)
array0 = [1,2,3] array1 = ['a','b','c'] having the two arrays above, as return this value that is below? //[1,'a',2,'b',3,'c']
-
0
votes2
answers501
viewsCreate array/list with indexes
Good morning guys, I started learning Python a few days ago and, doing some tests with lists around here I got some questions. 1 - In PHP I can create an array by defining the indexes of its values:…
-
0
votes0
answers342
viewsImport error in Python
I’m trying to create a Python Bot: #-*- coding: utf-8 -*- from chatterbot.trainer import ListTrainer # trainador from chatterbot import ChatBot # chatbot import os bot = ChatBot('Teste')…
-
0
votes3
answers1384
viewsProblem with Python matrices
Hi, I’d like some help. I have to generate, in Python, a matrix with a number l of rows and a number c of columns, and calculate the sum of the main and secondary diagonal elements. The sum is done…
-
0
votes1
answer73
viewsSingle values average filter in dictionary list
I have the following dictionary list in Python 3.7: a = [ {'linha': 0, 'porcentagem': 1.0, 'id': 3, 'nome': 'bruno'}, {'linha': 8, 'porcentagem': 1.0, 'id': 7, 'nome': 'teste'}, {'linha': 12,…
-
0
votes1
answer181
viewsEmpty columns of a spreadsheet when using pandas read()
import pandas as pd wb = pd.ExcelFile("meus_dados.xlsx") sheet_1 = pd.read_excel("meus_dados.xlsx", sheet_name=0) print sheet_1 that line of code brings me that answer: Nome CPF ... Unnamed: 8…
-
0
votes1
answer115
viewsI can’t read column on pandas
I have this Dataframe: Nome CPF ... Senha Cargo 0 Silvio José 10575674451 ... 12345 Administrador 1 Carlos Alberto 10767764330 ... 12345 Administrador 2 Maria Madalena 23323234343 ... 12345…
-
0
votes1
answer83
viewsUpdate data from two worksheets without overwriting in the source file
I read the file sheets in the following way: sheet_Pessoas = pd.read_excel("meus_dados.xlsx", sheet_name=0) sheet_Clientes = pd.read_excel("meus_dados.xlsx", sheet_name=1) Then I add a line in the…
-
0
votes0
answers87
viewsHow to keep the last selection of a Tkinter radio button selected?
Good night! Is there any way to keep the last option clicked on radiobuttion buttons in python Tkinter lib selected? I would like, even when closing the program, when I opened it again, the option…
-
0
votes1
answer37
viewsMongodb does not return query correctly
I have the following code: from pymongo import MongoClient class ConectaMongodb: def conecta(self): client = MongoClient('mongodb://localhost:27017') db = client.starwars_api return db def…
-
0
votes0
answers77
viewsGet Low Consumption within 100m Radius?
I have a database with consumption and coordinates in Excel, like: In this sense, I need to write a code that allows me to find, from place to place, consumptions below the average consumption…
-
0
votes2
answers59
views"print()" does not display the elements of the inserted list
Why does the instruction below not work? It displays the last note, not the list of all notes. jnotas = int(input("quantas notas você já tem = ")) for c in range (0, jnotas): notas1 = [] n =…
-
0
votes1
answer1063
viewsHow to use pep8 in Vscode?
I added the extension to the file Settings.json, but when compiling it does not show the errors in the default it should, how can I add PEP8 and test in vscode?
-
0
votes1
answer73
viewsSomeone can help me understand this code!
Can someone help me by telling me what each part of this code does! from collections import Counter def jaccard_repeats(a, b): """Jaccard similarity measure between input iterables, allowing…
pythonasked 4 years, 4 months ago Mikael Carvalho 27 -
0
votes1
answer69
viewsFunction Return after Eoferror [Python]
Good afternoon, I need to solve the following problem using the While structure: Given a sequence of real values, calculate your average. The command given by the teacher was: while True: try: valor…
pythonasked 5 years, 6 months ago Diovana Valim 203 -
0
votes1
answer40
viewsmodify Python variable value
I need the value that is written in the variable "add_money" to be added and added in the variable "balance" saldo = 0 op = input('O que deseja fazer? ') if op == 'add': add_money = int(input('Qual…
-
0
votes1
answer302
viewsHow to remove all items from a Many-to-Many relation in Django?
I have the following models in my Django app: class Tag(models.Model): name = models.CharField(max_length=150) description = models.TextField(null=True, blank=True) created_at =…
-
0
votes0
answers85
viewsHow to run a Word Macro via Python?
import os import comtypes.client path=r"path to the .docm file where I saved the vba macro" word=comtypes.client.CreateObject("Word.Application") word.Documents.Open(path,ReadOnly=1)…
-
0
votes1
answer39
viewsHow to calculate the frequency the data appears on Django?
Hi, I’m making a search bar with filters, in it the user can choose whether to sort by frequency or sort by another field (which is ordering everything right), what gives problem is when searching…
-
0
votes1
answer111
viewsI cannot save scripts accentuated (Python)
Hello, everyone. I’m a beginner in python (and programming in general) and I’m trying to learn from small, easy code. I was trying to make a script and I noticed that when I wanted to save it just…
-
0
votes1
answer525
viewsPrinting specific attributes of a python XML file tag
Hello, I’m starting to use the Python language for a survey, and as "activity" I received an XML file from my teacher and I need to "unlock" it, printing tag contents and some attributes specific to…
-
0
votes1
answer1397
viewsTypeerror: '<' not supported between instances of 'float' and 'str'
I need to calculate the median of the variables in a database, but it’s giving error. This error does not occur when using np.Mean in order to calculate the average. The database can be found easily…
-
0
votes1
answer61
viewsDoubt in models Predict
I think it’s a simple question, but in all the courses I’m taking the instructor teaches you to separate training and test data from a csv or some base. But I want to test with the user input…
-
0
votes2
answers76
viewsHow do I remove alphabetic characters from a column of a pd. Series? (Python)
My question is quite simple. Given a pd.Series as described below, how do I remove "YEARS" and "MONTHS" characters from it? I looked at the documentation of Pandas but unfortunately I could not find…
-
0
votes1
answer132
viewsError with append with python csv file
I have a code that sends information to a csv. When it runs the first time it writes the file normally, but when it runs the second time it should add a new line in the file it ends up overwriting…
-
0
votes1
answer22
viewsUse pytest’s tmpdir fixture in a class
Hello, I have a question that is slowing me down in the use of TDD in my study projects. I’m trying to create a temporary directory with a json file using fixture tmpdir, but find the following…
-
0
votes1
answer2089
viewsCheck if Widget exists with Selenium
I’m making a kind of bruteforce using Selenium, when I error the password and login, the message appears on the invalid login screen or password, if the message does not appear, ie correct login and…
-
0
votes1
answer48
viewsdoubt text files in python
Can anyone help me with this python file exercise? Consider that each year there is a text file with information about the population world. Each line has the country, population, population growth…
-
0
votes1
answer38
viewsHow to turn all Dataset into monetary values, or at least round them
This is a part of a dataset column: 0 1.347688e+05 1 1.563599e+05 2 1.788441e+05 3 1.983543e+05 I tried that: from babel.numbers import format_decimal format_decimal(df.Receita_liquida,…