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
answers17
viewsHow to put a variable in the middle of print
I am beginner in programming with python so my doubt is very basic, I wanted to put the value of "average" in the middle of print, how do I do this? n1 = float(input("Informe sua primeira nota: "))…
-
0
votes1
answer273
viewsPython os.mkdir, file exists
I am trying to download videos, but when it goes to the next one, it returns the error saying that the folder already exists. There is no way to save more than one file? def json_decoder(file): file…
pythonasked 5 years ago Hudson Souza 53 -
0
votes1
answer46
viewsPython-Django - How to show template only items associated with logged in user
I have a small project that is an "to-do list", or to-do list, done in Python-Django and I will implement a login system as I have done with other projects. However, this time I wanted to show only…
-
0
votes2
answers67
viewsProblem when declaring 2 variables
The problem is this, I need to do a function to sum 2 numbers that the user must insert by separating them through commas, eg: 2.3, for such values 2 + 3 = 5, so the result should show 5 as a…
-
0
votes1
answer31
viewsCreate dataframe pandas 1 key and some non-standard values in the dictionary
I have a dictionary in Python: dict = {0:[['tela1'],['tela2'],['tela3']], 1:[['tela2']], 2:[['tela5'],['tela7']], 4:[['tela1'],['tela3']]} and would like to transform into a dataframe as follows: Id…
-
0
votes1
answer40
viewsHow do I guarantee unique numbers on a list of lists?
Good evening, I’m trying to make a 5x5 bingo card, using Andom to generate the values, however there can be no equal numbers. I tried to do it that way but it still comes up equal numbers: import…
-
0
votes1
answer95
viewsCreate column in dataframe that contains the list of row values except null values (Nan)
Code and file used: https://github.com/CaioEuzebio/Python-DataScience-MachineLearning/tree/master/SalesLogistics I’m working on an analysis using pandas. Basically I need to sort orders by quantity…
-
0
votes2
answers114
viewsA function stores specific elements of a list in another list
I want to make a function that takes a list of ordered numbers and two numbers (one bottom and one top) and returns a new list with the elements of the first list between the two numbers. Example:…
-
0
votes0
answers29
viewsError importing Sqlalchemy
I cannot import flask_sqlalchemy even after installing from flask import Flask, render_template from flask_sqlalchemy import SQLAlchemy ^aqui mostra o erro: ImportError: "flask_sqlalchemy" could not…
-
0
votes0
answers16
viewslocal error variable
g = 10 def b(): g = g + 1 b() When I do this error appears UnboundLocalError: local variable 'g' referenced before assignment I can’t put the g variable inside def b() For every time I call b() she…
-
0
votes1
answer99
viewsHow to improve the time cost of the algorithm - Python
Good night, you guys! I have the following problem in this algorithm, its cost is still high and I would like to know if there is a way to improve its cost even more, because this is a matter of…
-
0
votes2
answers66
viewsVIEW DICTIONARY ALPHABETICALLY - PYTHON
I have a dictionary that has 2 keys (name, age), within each there is a list of values. I need to put the names in alphabetical order and that the ages accompany the respective owners. That’s the…
python python-3.x classification dictionaryasked 3 years, 6 months ago Henrique Marvin Souza da Silva 28 -
0
votes2
answers39
viewsScroll through a string list and display the 2 in 2 result
in a certain part of the code, I need to go through a list with string values. However, the display of these values needs to be 2 in 2, instead of 1 to 1. I am using Python version 3. Example…
-
0
votes0
answers29
viewsSpecific type for attributes
I’m trying to define the type of information that attributes receive, but I’m not sure how to do it. I tried these methods, but they do nothing. class Lancamento: def __init__(self, tipo, data,…
-
0
votes2
answers339
viewsHow to save the result of this code in a list?
I made the following code in python: def exibir_menu(): print('''Escolha uma opção: 1. Cadastrar um aluno 2. Listar alunos matriculados 3. Procurar um aluno ''') def cadastrar(pessoas): nome =…
-
0
votes1
answer356
viewsObject movement
I would be creating a game for a college job, but I’m having some difficulties, among them, one in which I can’t get the character to move up or down, just sideways, accusing me of this mistake:…
-
0
votes0
answers14
viewshow to make algorithm for the second CPF checker code for Python?
while True: cpf = input("Digite n: ") novo_cpf = cpf[:-2] soma_digitos = 0 lista_digitos = [] for key, index in enumerate(novo_cpf): key_reverso = len(novo_cpf) + 1 - key…
-
0
votes1
answer79
viewsChallenge in python. Doubt
The challenge: to receive a string s and an integer k, then you must separate the string into sub-strings of length s/k and finally remove the repeated letters in each sub-string. Follows the code:…
pythonasked 5 years ago Thiago Benevides 43 -
0
votes0
answers51
viewspython - error in parameters
I did the initial procedure I saw in a forum, give name to the app, but did not solve, returns that I passed 3 parameters and is waiting for two. from django.urls.conf import include from…
-
0
votes2
answers97
viewsProblem with Python string formatting
First I would like to inform you that: (a) I am an accountant and I program only to help me with tasks with a large mass of data, so my code below will not be a professional code, and (b) this is my…
-
0
votes1
answer36
viewsWildkey is not displaying correctly on the screen, even with the __ str __ DJANGO 3.2 method
Even with the method placed in the POSITION class, isn’t it appearing as it should when it shows in the employees identity, how to solve this problem? obg…
-
0
votes0
answers29
viewsPython is not reading a conditional within a conditional
Hello, I’m playing a game of questions and in the part that the player misses I want to put an option to try again or not but Python does not read or execute the conditional inside Else. I thought…
-
0
votes2
answers1309
viewsHow to make Redirect on the page with Django
How to redirect passing an object as parameter in Django already tried redirect() and HttpResponseRedirect but I can’t send an object to page in Sponse, every time I hit F5 it wants to resend the…
-
0
votes1
answer205
viewsStore data from a variable that changes value at each instant
Hello, I’m trying to solve a problem that involves your questions. I’m using a python api to get data from the IQ Option investment platform, but I’m unable to work with the data. If I do dados =…
-
0
votes1
answer53
viewsHow to replace a column conditionally in Pandas?
I have a dataframe in Pandas and need to replace the value in the column semana conditionally. Where the value is 53, I want to replace with 1. cod; semana; A; 53; A; 1; A; 1; A; 2; B; 53; B; 1; B;…
-
0
votes1
answer63
viewsHow to use the Timestamp(). dayofweek method on a dataframe?
I started to study python a short time ago and a problem has arisen that I am not able to solve. I have a csv file containing two columns('ds' = dates and 'y'= data of any result of the respective…
-
0
votes1
answer62
viewsMinimum value of a list within another python list
Hello. I have a situation I managed to solve by looping. I would like to know if there is any way to simplify what I did, using Arabic or other language resource. I have a list and within it another…
-
0
votes0
answers6
viewsPython Equivalent to SAS Proc Logistic
all right? Guys, how do I write the following python SAS code? Proc Logistis Data = Name_dataset outmodel Result_dataset; model Var1 / Var2 = Var3 /lackfit; output out = Name_dataset_fit p =…
-
0
votes1
answer119
viewsPython counting by function, BASIC
Create a program in Python that, for any list of integer values, gets (through functions) and prints on the screen, the amount of positive, null and negative values of the list. My doubt is to do…
pythonasked 5 years ago Milton Vincius 33 -
0
votes2
answers75
viewsHow to repeat a code snippet given times?
How to repeat a code snippet as many times as the user informs? That’s what I tried: #Só um exemplo import random gerar= int(input("digite quantos números deseja gerar,o limite máximo é 20"))…
pythonasked 3 years, 5 months ago iniciantedavida 31 -
0
votes0
answers7
viewsif Else in assigning a Python variable
I want to understand that "ma" assignment on line 6 and "me" on line 7. I don’t even have a focus on understanding what the code does, I just want to understand this attribution with if I hadn’t…
-
0
votes0
answers183
viewsHTTP Error 429: Too Many Requests in Web scraping in repl
When executing the code below, find: HTTP Error 429: Too Many Requests the server must have a time limit between the requests. #Imports necessários do bs4 import bs4 from urllib.request import…
-
0
votes1
answer160
viewsPython Encoding Problem
I’m trying to pull the hashtags used in some Instagram profiles using the code: import pandas as pd import requests import re req = requests.get("https://www.instagram.com/globorural/") texto =…
-
0
votes0
answers64
viewscalculate the variables of a linear system n x n
Develop a Python program to calculate the variables of a linear system n x n . System dimensions must be provided by the user, as well as the values of matrices A and B. So far I’ve only been able…
pythonasked 5 years ago Vinícius Somenssi 1 -
0
votes1
answer78
viewsIs there a way to use Natural Language Processing (NLP) to transform strings into integers?
I saw some examples of codes to transform strings such as "four" into an integer 4, but it was always quite manual. Have some more automatic way to do this using NLP? One thing I noticed when I did…
-
0
votes1
answer40
viewsHow to change colors in graphics using matplotlib
I created a plot of points using matplotlib, but I want to put the following condition: For points above zero ( > 0) in Y paint green and for points below zero ( < 0) paint red.…
-
0
votes0
answers18
viewsDoes the true value of a number change when I change its float type.?
Change my data set to float32 or float16, is changing the "true" value of my data? If I have the value 3.6, using python and reading in float64 he remains 3.6, but it changes when I put in float32,…
-
0
votes1
answer126
viewscurve_fit: can’t Multiply Sequence by non-int of type 'numpy.float64'
I’m having trouble with the curve_fit of the scipy, the error that comes out tells me that it can’t multiply sequence by float, I’m trying to create a sequence based on the function I defined and…
-
0
votes1
answer430
viewsError "Indexerror: list assignment index out of range"
This program when executed a certain amount of times it shows a message shown right below. Agent Train 1 def Ttrem_Um(velocidade,linhas): velocidade = randint(55,100) return velocidade Agent Train 2…
-
0
votes1
answer49
viewsPython command does not work
As you can see, I cannot access python from the terminal I’ve checked the system variables…
-
0
votes1
answer335
viewsString handling with python and pandas
I’m trying to create a function that traverses a dataset and removes characters from strings like ('? *'), and returns the already corrected column within the dataset. As an example of dataset: df =…
-
0
votes1
answer503
viewsValueerror: Math Domain error
Can anyone help me with the error below: Sometimes it appears sometimes not , I am Noob and I do not understand why this. Code: import math a = float(input("digite o valor de a: ")) b =…
pythonasked 4 years, 12 months ago Dacio Veoito 1 -
0
votes1
answer27
viewsHow to make a Window always stay above the others in PYQT5?
I am creating a small application and need the main window to always be above the others, which attribute to use in pyqt 5 ? From now on I thank
-
0
votes2
answers1733
viewsFunction that returns all combinations of a string
Hello! I’m trying to develop a script so I can review some content covered while studying and training my logic and I proposed a challenge to myself: Develop a script capable of returning all…
pythonasked 4 years, 12 months ago Jose Edmario 23 -
0
votes2
answers54
viewsDjango: Optimize Database Searches
I am doubtful in the following exercise: The route /Albums/ is returning a listing of the albums with the artists of the album, but in some of our clients that use databases stored on own servers it…
-
0
votes1
answer39
viewsSave Timefield as blank
I have a function to save the data imported from excel, the problem is that I have a Timefield that can come blank, and with that I have the following message: Error saving object to database:…
-
0
votes0
answers10
viewsNeural Networks in Colab - Runtimeerror: CUDA error
I’m training a simple neural network for database classification Internet Firewall Data Data Set from the UCI Machine Learning site, but in the execution of the training occurs the following error…
-
0
votes2
answers196
viewsHow to display object name in Django template?
Hello! I’m in a learning process of Django, in fact, I started a little while ago and I’m finding it difficult to find a way to display the name of the publisher that is a Foreignkey. Follow the…
-
0
votes0
answers32
viewsHow to search for full name in List with name "incomplete"?
I wanted to do a Python program to find specific name in List: Example using random names: nomes = ['Melissa Renata Peixoto', 'Bruna Carla Henry Gomes', 'Carla Rosângela Brito', 'Carla Letícia…
-
0
votes2
answers73
viewsI can’t understand my mistake with FOR and Dataframe
I have a problem in my for, where all the results are coming out as the same value within Dataframe, but I can’t understand the error, someone could help me import pandas as pd…