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
-
2
votes1
answer983
viewsPython + Tkinter Screen Management
I’m creating a system with a few screens, Every time I click on the button to call the screen it creates a new instance of the same screen, so if the user keeps clicking on the same button several…
-
2
votes2
answers240
viewsVector union in Python
Hello, I need to make a union between two vectors in python, but without using list functions for some reason my code is going wrong was to get out 7, 2, 5, 8, 4, 9, but it’s coming out as 7, 2, 5,…
pythonasked 4 years, 3 months ago Luis Henrique 29 -
2
votes1
answer517
viewsExtract phone number with API in Python pandas
I have an API that extracts the phone number. It works as follows. By passing a number on it, returns me 3 variable type string containing phone with country code, type if it is cellular or fixed…
-
2
votes2
answers110
viewsCompare dictionary key with an integer
My teacher gave a problem to be solved by the class. Given a sentence, we want to know which letter appears the most, always working with lowercase letter, that is, disregarding the distinction…
-
2
votes1
answer229
viewsPython Multidimensional Array Problem
Basically my algorithm imports all the photos I have inside a directory (dataset_train), saving these photos in vector X and the name of the folder where it was in vector Y. import os import cv2…
python array image-processing multidimensional-arrayasked 5 years, 5 months ago Felipe Ricardo dos Santos 46 -
2
votes2
answers93
viewsRuntimeexception when using colorbar() Spyder IDE
I am a code to show the use of self-organizing maps and error appears when using colorbar function. Error happens on line colorbar(). Before that the way out was: So when I run the line colorbar().…
-
2
votes1
answer154
viewsValidate date as holiday or not
Hello, good afternoon, sir! I am creating a Dataframe in which I need to validate whether a day is a holiday or not, so I created a time series in hand and made two loops to validate whether the…
-
2
votes1
answer2507
viewsToo Many values to unpack (expected 2) no Django
I have this piece of code in Django, the intention is to insert, if there is already the ds_user_id then it updates the user with this ds_user_id instead of creating a new ds_user_id =…
-
2
votes2
answers165
viewsHow can I get the highest value of a matrix with Lambda function in Python
In a list it is possible with the method "reduce" to achieve the highest value, but in a matrix I am not able to obtain the highest value of it: from functools import reduce matriz = [[4, 2, 56],…
-
2
votes1
answer133
viewsPython - Brute Force - Memory Error
I am working on this code that generates sequences with all the possibilities of the characters entered(your_list) your_list = 'abcdefghijklmnopqrstuvwxyz' complete_list = [] for current in…
-
2
votes3
answers158
viewsUse of virtualenv python
I’m starting to use virtualenv for projects and in the process I came up with a question, after activating the environment, every time I enter or exit the folder it activates and deactivates…
-
2
votes1
answer326
viewsCheck if Checkbox is checked
In the code below I have a Checkbox named cb. I wanted to know when it was selected/marked so that my program could run another account instead of adding. How do I detect that the Checkbox is…
-
2
votes1
answer74
viewsMake a function called soma_h to compute and return the value H with N terms where N is integer and given with input
I made the code but I don’t know why the output is 1. def soma_h(n): soma = 0 for i in range(1, n+1): soma = soma + float(1//i) return round(soma, 2) Note: H = 1 + 1/2 + 1/3 ... + 1/n…
pythonasked 4 years, 1 month ago Marco Raad 43 -
2
votes1
answer142
viewsjson.loads Jsondecodeerror
The cookies posted here, there is no validity, so if you want to do evil, look for another I have these cookies I saved using the PHP language…
-
2
votes2
answers2710
viewsConvert decimal to binary - python
Hello guys I’m new in python my code below displays the values of the ASCII table for a typed string. How can I take these values and convert to binary valor = input("Insira o valor a ser…
-
2
votes3
answers148
viewsCount recurrences in a list
I made the following code to count the recurrences in a list: n = int(input()) n <= 100 and n >= 1 lista = [] for c in range(n): lista.append(int(input())) for v in lista: repete =…
pythonasked 4 years, 1 month ago Gabriel Schrader 45 -
2
votes1
answer55
viewsRead file with list comprehension only works the first time
fhand = open('text.txt', mode = 'r') txtfile = [item.split()[0] for item in fhand] txtfile2 = [item.split()[1] for item in fhand] print(txtfile) print(txtfile2) Why the second comprehensilist on is…
-
2
votes1
answer285
viewsCombine multiple Regular Expressions into one
Is there any way to combine multiple regex patterns into a single expression, to be used in re.match() or re.search(), for example? starts_with_Y = '([Y][A-Za-z0-9]{6}([-][A-Za-z0-9]{1})?\s)'…
-
2
votes2
answers284
viewsHow to calculate division using subtraction operation only?
I’m trying to put a command line that does division from subtraction into a dictionary but would be causing error, would know where I’m going wrong? x = float(x) y = float(y) num = 0 if y != 0: if…
-
2
votes1
answer1417
viewsMount SQL query in Python3 from data in a dictionary
I’m trying to format a query and leave it this way: INSERT INTO users('username', 'password') VALUES ('meuusuario', 'minhasenha') But you’re returning me with []: INSERT INTO users(['username',…
-
2
votes1
answer347
viewsCalculate the average of a matrix
I was trying to calculate the average of a matrix without using numpy, but n managed to get to the desired algorithm def mediah(matriz:List): soma = 0 for linha in matriz: for aij in linha: soma +=…
-
2
votes1
answer93
viewsVery long broken values not being recognized within If, in Python
I wrote this code below that asks you a number between 0 and 180. It is completely protected against values outside of this set and against letters. I would like to know why, for example, when I…
pythonasked 4 years, 1 month ago Matheus Esteves 61 -
2
votes1
answer190
viewsConnection Tkinter - Database
Good night! Guys, I’m starting in the world of programming and today I was following a tutorial that for me didn’t work and I don’t know how to solve the problem, I tried everything. This is to…
-
2
votes1
answer892
viewsHow to create new routes dynamically python/flask
I am developing an application that makes predictions from models, and wanted to implement a feature that allows me to create new routes through a function. config =…
-
2
votes1
answer47
viewsThe function returns None although the variable saves the correct result
I must do a function that returns the odd elements of a list using recursion. I saved the list with the odd ones in the variable I, and when return this variable the result is None. def…
-
2
votes1
answer99
viewsTake an element from a list and search in another list
I am having a problem related to lists, I have some files to access and pass them to lists (3 files to 3 lists). Basically one of the files would have technical data of IBGE, and I need to take this…
-
2
votes2
answers2065
viewsDisplay the sum of each row of a randomly generated matrix
I have the following program that generates a random matrix according to the number of rows and columns desired. In it is also located and displayed the highest value of the elements, and their…
-
2
votes2
answers120
viewscmd closing when using the cls/clear command
I made a function that identifies if the person is using windows or linux, and with that runs the right command to clean cmd/terminal, worked on the visual studio code console, however when I will…
-
2
votes1
answer77
viewsHow to extract text from a selected Beautifulsoap element?
I’m making a simple Crawler to get some news from the financial market. The code below is working properly, but would like to extract only the headline and then delete the html/CSS codes. import…
-
2
votes2
answers85
viewsPerformance testing, how to reduce running time
I want to create a function that returns a list with all the powers of 2 of the numbers from 0 to 99, in the shortest possible time. So far I have performed 3 tests and my current script is this:…
pythonasked 5 years, 3 months ago Filipe Gonçalves 236 -
2
votes2
answers50
viewsReturn filtered values in Shell Bash for insertion in BD
I’m writing a script on python who captures the TOP 5 ram and CPU memory consumption processes of the machine, so far the script is functional only for LINUX, goes below: Script: #!/usr/bin/env…
-
2
votes2
answers181
viewsImport of python modules
I’m having a problem with python. I have a python code file working with Selenium, and I have another python file working on JSON. These two codes are inside the same folder, for me to import a…
-
2
votes2
answers456
viewsDraw triangle with repetition structure in Python
I need to draw a triangle of the shape: ....1 ...12 ..123 .1234 12345 I should use repeating structures. From what I understood as a hint, I should use two concatenated structures. I’m a beginner…
-
2
votes1
answer217
viewsCalculating numerical integrals from numpy arrays
I have the triple integral of the figure. I used the documentation of the scipy to solve her. Now I want to exchange the values of the upper limits of x, y and z, which in this problem are the…
-
2
votes1
answer1066
viewsPandas Excel Writer
I have a problem trying to write an excel file with pandas. When I try to write it presents the following message. ZIP does not support timestamps before 1980 Thinking that could be some problem…
-
2
votes1
answer198
viewsThread with python loading
I’m trying to run two threads where one is an animation of loading, and the other a print, but when finished executing the thread work which is the print, the loading keeps running, I’d like it to…
pythonasked 5 years, 3 months ago Luis Henrique 697 -
2
votes1
answer13445
viewsCommand errored out with Exit status 1: python setup.py egg_info
What’s up, you guys? I was trying to run the remote pip install MySQL-python and the console returned me this error: ERROR: Command errored out with exit status 1: command:…
-
2
votes3
answers84
viewsAccess values from a python json
I have the following python code import requests import json data = requests.get('https://proxycheck.io/v2/42.131.121.100?vpn=1&asn=1') print(data.text) That will return: { "status": "ok",…
-
2
votes2
answers35
viewsHow to apply a ribbon to a dataframe based on the last characters of each label?
I need to apply a line filter to a dataframe based on the last characters of a label, if it contains BRL after the hyphen. Ex.: BTC-BRL. Can someone help me? Current data: Data after applying…
-
2
votes1
answer842
viewsImplementation Dijkstra algorithm in Python
I am implementing Dijkstra’s algorithm in a graph, but it returns only the first call to the function. Even if I call again there is no return, does anyone know why? Follows the code: def…
-
2
votes1
answer467
viewsHow to go through all the data of a DF making calculation and return the value for it?
I am with DF after some calculations, but I am not able to pass the data to an account, every time gives this error: The truth value of a Series is ambiguous. Use a.empty, a.bool(), a.item(),…
-
2
votes1
answer72
viewsHow do greedy, non-greedy quantifiers work?
import re import requests #o req vai ser a requisição á uma página print(re.findall(r'(?<=href=["\'])https?://.+?(?=["\'])',req.text)) The code is to pick up links on a web page. I know he’s…
-
2
votes1
answer223
viewsWorking with sheet dates
Guys, I’m looking for data in a spreadsheet using python, and in one of the worksheets it contains only dates. The problem is that when I look for these dates they come in the form of tuples that…
-
2
votes2
answers62
viewsRemove numbers and special characters from a text, but not within a word
I would like to remove numbers and/or special characters from a text, but not within a word. Example: texto = "ol@ mundo, eu bebo H20 e nao fumo cig@rro !#& 123" The result should be: ol@ mundo,…
-
2
votes1
answer50
viewsFind diff between different arrays
GOAL I have two arrays where it contains different formatted information, but the data is the same, for example on ARRAY1 the CLIENTE1-00 and the same as CLIENTE1 of ARRAY2, I just need to do a…
-
2
votes1
answer2565
viewsCheck whether the number is positive, negative or zero
Hello. I am studying and learning Python, and at the right moment makes a code that reads a column of a given file where values vary between positive, negative and zero, and that writes an output…
pythonasked 5 years, 3 months ago Nathan Streisky 33 -
2
votes1
answer433
viewsPython Pandas: Dataframe convert Timestamp column to Datetime
How can I convert a Dataframe column from Timestamp to Datetime? btc_df = pd.DataFrame ( bars_day , columns=['date' , 'volume' , 'open' , 'high' , 'low' , 'close'] ) Summary date int64 volume object…
-
2
votes2
answers157
viewsSend data via Arduino serial communication - Raspberry
Good morning, I’m having problems receiving the data that the Arduino is sending, what I want to read the line information, play this information in a variable and compare the values in Raspberry.…
-
2
votes1
answer63
viewsRegex Python Remove everything before the first letter in a string
Another question from REGEX that none of the answers I found follows. I have a dataframe that some strings start erroneously with things that are not Letters, for example : t = ['. Subordinam-se ao…
-
2
votes2
answers329
viewsFunction that returns uppercase consonants
the function receives a sentence as input and returns the sentence with all its consonants in uppercase. def teste(frase): i=0 while i<len(frase): if frase[i]in 'bcdfghjklmnpqrstvxwyz':…