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
votes3
answers280
viewsFinish a loop when a given string is typed
I’m trying to fill a list with numbers, so I made a loop: lista=[] i = float(input()) lista.append(i) while (i != '.'): i = float(input()) lista.append(i) However I wanted that when putting the…
-
1
votes1
answer59
viewsQuestion about list(zip) command and converting dictionaries to dataframes?
I am filling some lists with strings and other numeric entries and using them to fill some dictionaries with information that I need to view alternately. Then I came to doubt, the command…
-
1
votes1
answer187
viewsSum and Multiplication with items of a CSV
good night! I’m new to programming and I’m learning to code in python. Also, I’ve been trying to create something that’s relatively simple, but I’m finding it difficult to execute. I imported a list…
-
1
votes3
answers74
viewsDisplaying message of no number read and accepting different types of input
I have the following code: def maior(colecao): if len(colecao) > 1: r = maior(colecao[1:]) if r[0] < colecao[0]: r[0] = colecao[0] elif len(colecao) == 1: r = [colecao[0]] else: r = [None]…
-
1
votes1
answer170
viewsDoubt about simple Python encryption script
Can someone explain to me what exactly this line does, when I try to understand it, I end up curling up even more: #Vars definidas: import sys key = sys.argv[2] mode = sys.argv[3] posiçãoDoChar = 0…
pythonasked 3 years, 11 months ago Shadow Ghost 31 -
1
votes2
answers315
viewsGiven a number, get the digit of tens
Write a function that takes an integer number of up to three digits and returns to dozens quantity of that number. Do not make type transformations. Input: (2) Output: 0 Input: (85) Output: 8 Input:…
-
1
votes3
answers472
viewsHow to add a new key to a dictionary?
I have the following challenge: input : "conaz test" output: {'a': 1, ' ': 1, 'c': 1, 'e': 2, 'o': 1, 'n': 1, ’s': 1, ’t': 2, 'z': 1} And implemented the following code: def…
pythonasked 5 years, 3 months ago Diovana Valim 203 -
1
votes2
answers327
viewsDelete Root Directory in Python
I am creating a system that erases and creates again the folders of a directory until the creation of the folders is all ok, but I tried to use the calling below to delete a Root directory of my…
-
1
votes2
answers116
viewsShow smaller, average and larger until an empty line is typed
I have the following code: qtdNumeros = int(input()) if qtdNumeros <= 0: menor = "Nenhum" media = "Nenhuma" maior = "Nenhum" else: menor = maior = soma = float(input()) for proximo in range(1,…
-
1
votes2
answers279
viewsChanging a key value in a Python dictionary
I need to get the position of one of the key values 'Codigo', for example 321, and in the same position change the key value 'Status aluguel' for 'S'. How can I do that? Imoveis_Cadastrados = {…
-
1
votes1
answer94
viewsValue storage problem of a variable in Arduino: it reads a value and saves for two cycles, is there any way to solve this?
My project consists of an Arduino program using the RFID module, to read card frequencies, to release a ratchet (similar to buses). A program in Python will read this frequency printed in the…
-
1
votes3
answers224
viewsSelection of the first number from a list
Hello, I have a problem that I believe is relatively simple in python, but I can not solve it. I have a list of values that vary in positive and negative numbers. And I need to select from that list…
-
1
votes0
answers57
viewsError during forecast attempt using Xgbregressor
I was assembling some models for data prediction in Machine Learning and ended up stopping at an error during a prediction attempt using the Linearregressor and Xgbregressor algorithms. Below…
-
1
votes2
answers83
viewsFunction that creates list inside list
def add_divisors(list_num): final_list = [] divisors = [] for number in list_num: for x in range(1, number+1): if number % x == 0: divisors.append(x) final_list.extend(divisors.copy())…
-
1
votes1
answer464
viewsHow to group a column containing a list in pandas? - Python3
Talk to the guys! I have a problem with pandas who can’t find a solution. I have the following dataset: I wanted to make a group where, for each year, and in each category present that year, it…
-
1
votes1
answer220
viewsAdd tuple in Python set
I am creating a graph with the following rules: The graph is a dictionary. The vertices are the keys of this dictionary and the values are the edges. Since I can have more than one edge for a…
-
1
votes1
answer41
viewsHow do I create a variable with some columns of my data frame?
I have a data frame with 10 columns and wanted to extract 4 of these columns for a variable. I even tried to make a list and use the list but the code was not clean, I know there are ways to extract…
-
1
votes2
answers562
viewsHow to go through two lists of different sizes [PYTHON]?
The idea is as follows: Each team has 6 maps played (mapList) I made a web Rawler that takes all the information related to the team and the map and wanted to insert automatically in a spreadsheet…
-
1
votes4
answers241
viewsFilter list of python objects
Hello, I’m new to Python and I’m having doubts to filter an object from a list. I have the following list: [{ ID: 1, Name: 'Teste 1' }, { ID: 2, Name: 'Teste 2' }] And I am wanting to realize a…
-
1
votes2
answers47
viewsHow to remove dtype from dataframe line?
Running the code: def novacoluna(df): coluna_adicionada = {} coluna_adicionada['retorno_diario']= df['quota_value']/df['quota_deslocada'] return pd.Series(coluna_adicionada,…
-
1
votes1
answer82
viewsHow to group data from another grouping?
I have the following dataframe: x= {"Nome": ['Carla','Rafael','Juliana','Carla','Carla','Juliana','Rafael','Juliana','Rafael'], "Salario": [1200,1500,2000,1230,1250,2050,1700,2500,1750]}…
-
1
votes0
answers90
viewsOpenhardwaremonitor: Python.Runtime.Clrmodule.Addreference(String name)
My script is returning the output below: OUTPUT OpenHardwareMonitor: Traceback (most recent call last): File "sensors.py", line 62, in <module> HardwareHandle =…
pythonasked 5 years, 3 months ago Luis Henrique 697 -
1
votes1
answer70
viewsHow to print elements from a stack?
I have problem formatting output from this program. Below follows the code snippet making the stack impression, then follows the problem img def __repr__(self): r = "" pointer = self.top…
-
1
votes1
answer53
viewsHow to delete null lines in a Dataframe?
I am studying a dataset for the NBA games, and I need to know how I can remove data from the dataframe that is found as "None". Because they keep me from getting the exact amount of athletes. Below…
-
1
votes1
answer55
viewsPost with jquery
My python endpoint is working perfectly, I’ve done tests using Postman. The problem is when Javascript will call the method Follow my Javascript code: $("#Submit").click(function() { var info =…
-
1
votes0
answers93
viewsTypeerror: expected string or buffer
I’m trying to make an intersection between two arrays using the lib re, but is returning me the following output: OUTPUT: selectobj = filter(regex.search, result_psql) Typeerror: expected string or…
pythonasked 5 years, 3 months ago Luis Henrique 697 -
1
votes1
answer149
viewsForeignkey error with Sqlalchemy
Basically what I want is for him to register in Transaction() the Account he sends and the Account he receives the amount. However I am not able to link the two Foreign key with the accounts I am…
-
1
votes1
answer66
viewsHow do I check if there is a number in a string?
notas = input('Digite uma nota de 0 à 10: ') if notas.isnumeric() or 0 < notas < 10: print('Nota inválida!') Guys, I want to check if what the user typed contains any number, I’m trying this…
pythonasked 3 years, 11 months ago Hyago Santos 57 -
1
votes1
answer726
viewsHow to not count the "spaces" of a sentence in python
I wonder how to count only the typed letters without space. Even with the strip it counts the spaces. nomed = nome.split() numdi = len(nomed[0]) print('O seu nome tem letras {} e o seu primeiro nome…
-
1
votes1
answer123
viewshow to remove None from the list
I have to play the little game "Anoi Tower", in which I need to pass the data that are in the source tower to the destination tower, using an auxiliary tower. however when the data arrive at the…
pythonasked 5 years, 3 months ago user160189 -
1
votes1
answer88
viewsError printing HTML with Beautifulsoup
I have a simple code that accesses a quiz site and takes all the ul which contain the class square and prints on screen. url = "http://quizdomilhao.com.br/category/g1" question_page =…
-
1
votes1
answer30
viewsHow to check the Windows time zone in real time using Python?
I’m trying to get the time zone of the system in real time using Python, I made the code below: import tzlocal tzlocal.get_localzone().zone The problem is, by changing the Windows time zone, the…
-
1
votes0
answers338
viewsFrame Tkinter Python does not stand next to another frame
Well, I’m having a problem assembling my simple graphical interface for a program. I’m doing it with Tkinter using python 3 and a frame just doesn’t sit next to each other! I have tried to put…
-
1
votes1
answer53
viewsHow to modify a variable within a definition without globalizing the variable?
I need to modify a variable within a definition without globalizing the variable because then I can use the same definition with different variables. I’ve tried the following code: >>> n =…
pythonasked 3 years, 10 months ago Felipe Mercês 11 -
1
votes1
answer156
viewsNone return problem in python
I’m doing an exercise in Python and I don’t understand why the output is coming back with None together, I thank you def main(x,nomePlaneta) : if nomePlaneta == "Terra" : valordois = x//86400…
pythonasked 5 years, 2 months ago Gabriel_86400 11 -
1
votes2
answers105
viewsJoin lines from a Python column
I’m trying to group my data into one column. I have 43184 lines of data, and I need to group them every 60 data, in case I do a media every 60. I tried to do it and it did not generate error however…
pythonasked 3 years, 10 months ago user219748 -
1
votes3
answers66
viewsHow to remove values that are in another list?
I have two dictionaries, one with available schedules, and one with scheduled schedules: schedules_dict = {1: ['00:00'], 2: ['00:30', '00:45'], 3: ['00:00', '00:30', '00:45']} appointments_dict =…
-
1
votes1
answer175
viewsFlask only updates after clear browsing history
I am developing a site for study purposes with flask, only I need to clear the browser history whenever I make any changes to my css, I am doing this because the browsers (Chrome, edge and Mozilla…
-
1
votes2
answers376
viewspython search
I need to create a binary search function. The function should look for the target in the list. checks if list[middle] is the number I want. If it is, it returns True. If it is not, and the middle…
-
1
votes1
answer33
viewsIn Python E Jupyter Notebook, how to present a full screen record?
I’m at Jupyter Notebook working with Python. My columns are strings and very long, I need to see these complete on screen, how to do this? The image of the dataframe with the "incomplete strings":…
-
1
votes1
answer465
viewsPython script error for copying . txt files
I made the following script to study. The goal is to copy all files with the extension '.txt' from the 'teste1' folder to the 'teste2' folder'. import shutil import os #Para garantir que o path é o…
-
1
votes1
answer66
viewsDiscord bot python Choice color in embed
Hello, I’m having a problem, I try to choose a color, and it won’t, but already the title, Description will, someone can tell me the right one to do to pick the colors? laranjavermelho = 0xFF4500…
pythonasked 3 years, 10 months ago ChickChuck2 51 -
1
votes1
answer42
viewsPython: I need to get the y coordinate given to x coordinate
Good afternoon! x = [0, 5] y = [2, 4] plt.Plot(x, y) plt.show() I get the following figure. How do I get the value of the y coordinate for the x coordinate equal to 2.5? Thank you.…
-
1
votes1
answer52
viewsHow to split columns/data with a specific limit?
Hello, my friends! Currently I do a scientific research in the field of AI, Machine Learning - Classification, using the Python language. In view of this, I have some data to develop an algorithm,…
-
1
votes1
answer88
viewstransform data from a Dataframe column into a single string
I have a Dataframe with a column that has different texts in each row and I intend to join all the lines in a single string, it is possible? the idea is to turn all the sentences in the column into…
-
1
votes1
answer37
viewsPassing a list like loss_weights, it should have one input per model output. Keras tells me that the model has 1 output, but I thought I had more
I have a data set df for a multiclass classification problem. I have a huge class imbalance. That is to say, grade_F and grade_G. >>> percentage = 1. /…
-
1
votes2
answers88
viewsHow to save the output (stdout) of another program to a file using Python?
Example, I give the command on the terminal: import os os.system('ipconfig') This returns me the ipconfig equal to the command in CMD, but I need to take the result that showed in the terminal and…
-
1
votes1
answer229
viewsHow is the pymongo connection established?
I’m building a program that scans a database every minute, and if some conditions are met, the program makes several requests via Apis and talks to Mongodb to process and save the data. It is very…
-
1
votes1
answer46
viewsHow to convert 10:00:00 to 10
I’m making a program that calculates time and multiplies by a value. However, using the library datetime, i get time in format "10:00:00", and if I multiply by 14.00 it returns me an error, because…
-
1
votes2
answers310
viewsRegular expression to get number between two bars
I have a code that takes a certain URL, divides it and returns me a list. url = 'https://www.site.com.br/categoria-produto/category/page/67/? gclid=Cjkdksjkcm35522' last_page = url if…