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
answer74
viewsI cannot extract data from a specific column
My Dataframe has several columns and one of them is not being read when I try to use indexing (e.g., bar_0617 = media_0617['Bar']). The following error appears: Keyerror: 'Bar'. I do not know what…
-
0
votes0
answers424
viewsexecute python script in google cloud VM
I created a vm in google cloud to run a script (bot) but every time I close my terminal the script is stopped for no apparent reason. the code itself has only one while True with a conditional in…
-
0
votes2
answers1751
viewsMedium, Minimum and Maximum in a python dictionary
I have a dictionary like that: {walt: 0.942342, disney: 0.324234, robert: 0.562354, help: 0.546912, ...} And I do it to find the average and the maximum: media =…
-
0
votes1
answer1386
viewsSave words with python accents
I have this json file maker: {"certa": 1, "vez": 7, "quando": 13, "tinha": 6, "seis": 7, "anos": 6, "vi": 4, "num": 4, "livro": 3, "sobre": 6, "a": 47, "floresta": 1, "virgem": 1,…
-
0
votes1
answer139
viewsHow to use Join in an object list?
class Pessoa: def __init__(self, nome, idade): self.nome = nome self.idade = idade p1 = Pessoa('João', 15) p2 = Pessoa('Maria', 17) lista_pessoas = [p1, p2] How to use the join() to print the list…
-
0
votes1
answer126
viewsCheck files that have a certain word - Python (Library os)
I have the code below which I access a certain folder and bring the name of all files with extension . Asp. import glob import os os.chdir('G:\PASTA\SUBPASTA') for file in glob.glob('*.asp'):…
-
0
votes1
answer100
viewsHow to remove repeated values from a dictionary?
For example: A = {2:5,4:5,7:8,9:8,11:10} Must return B={11:10} to remove the repeated values.
-
0
votes1
answer678
viewsTake data from a.txt file and store it in a list
What a function would look like to take this . txt and import in the lists? This function takes the data from the lists and stores the data in txt. def guardaTxt(lstModelo, lstCor, lstNumeracao,…
-
0
votes1
answer3022
viewsFind file using Python
I have a question, how to locate a file using python. The goal is to locate a file inside a directory and return all the way from the directory where the file is and if you do not find the file,…
-
0
votes0
answers39
viewsMove files in Python
I researched, and I saw people doing like this: import shutil shutil.move("este-arquivo", "/tmp") So I did it here in mine: import shutil shutil.move("arq.txt",…
-
0
votes2
answers127
viewsDifficulties with the FOR command in Python
I’m putting together a program that reads information about angles and distances from a text file and draws according to the information contained there. The program should also calculate azimuths,…
-
0
votes0
answers950
viewsNo module named 'cx_Oracle' - Python
Everybody, good afternoon, everybody. I am trying to make a connection to the oracle database, but when I run my script gives this error to No module named 'cx_Oracle'. But I have it installed on…
-
0
votes1
answer84
viewsWarning pandas, 2 loopings!
Guys I’m having trouble with this looping, because it’s a situation that I can’t solve with np.where, why does the DataFrame to find the value of the gain or loss from another condition, which comes…
-
0
votes1
answer191
viewsExport from pandas to MS SQL using to_sql and sqlalchemy
My problem is with Float values example: df = pd.DataFrame([1.45]) conn_str = 'mssql+pyodbc:///?odbc_connect={}'.format(params) engine = create_engine(conn_str) df.to_sql(name='teste',con=engine,…
-
0
votes1
answer181
viewsUse the split() and if method to create a statement that prints the words that start with’s'
I have the following string: string_1 = 'Print only the words that start with s in this sentence' and I need to use the split method and an if to output only the words started in s. But I have no…
-
0
votes1
answer1296
viewsHow to check if a character is uppercase or lowercase in Pyhton?
I have a string any and I need to know the amount of upper and lower case letters in that string. I started sketching something like this: def contaMaiuscula(string): ma = 0 mi = 0 for c in string:…
-
0
votes2
answers65
viewsInsert in Postgres with Python is not working
I need to include data and a database of my own, but I can’t and I’m not able to solve the problem. My code is this:: import psycopg2 conn=psycopg2.connect("dbname='teste' user='postgres'…
-
0
votes1
answer692
viewsCreation of flask-sqlalchemy tables
I am developing a small application in Flask and I am using the extensions Flask-Sqlalchemy, Flask-Migrate and Flask-Script to manage my migrations in the database, follow the configuration of my…
-
0
votes1
answer203
viewsName error: name 'variable' is not defined
In the second part, when printing 'Perd', the error "Name error: name 'Perd' is not defined" appears, as I correct? first part def test(usr,val): perd = 0 win = 0 if usr.upper() == 'A': print('SOMA…
pythonasked 5 years, 2 months ago O_torneiro 1 -
0
votes1
answer295
viewsdef post(request): or request.method == POST?
I’m doubting the title above about the best development practices in Django/python. Example: class Exemplo(View): def get(self, request): pass def post(self, request): pass OR if request.method ==…
-
0
votes1
answer80
viewsHow to create a function to remove unwanted characters, anti Injection
Hello, I searched on the internet which characters to remove, but the searches did not answer me the question.. So I looked up know about anti-sqlinjection in python, but I couldn’t find any way to…
pythonasked 5 years, 11 months ago Moto Taxi Patense 19 -
0
votes0
answers191
viewsHow to use 4 boxes after the comma in Python 3
I need to calculate the circumference area being: area = π . radius². Considering for this problem that π = 3.14159 (is my n) raio = float(input('insira o raio: ')) n = 3.14159 area = round…
-
0
votes2
answers791
viewsDjango Models - Foreignkey how to call method within the class by Admin
Good afternoon Galera, My situation is as follows. I have a nested class structure for a solution and I’m stuck in the following situation: I have these class structure: class…
-
0
votes1
answer451
viewsPoor performance when traversing an array
I’m traversing a matrix but face performance problems The idea would be to go through this matrix twice, in the second set of ties of the matriz_original if the condition is true the new matrix…
-
0
votes2
answers741
viewsIs it possible to install Python on Windows 10 without administrator privileges?
I have Python 3 installed, but the default installation was done, in the program files folder. And I work on a machine with a user profile, with strict proxy rules, etc that are long overdue to…
-
0
votes2
answers71
viewscut DNA nucleotide string
Could someone help me in this matter: I have a nucleotide sequence (letters: A,T,C,G), need to remove part of this sequence and leave only nine nucleotides starting with ATG and ending with TAA...…
-
0
votes3
answers158
viewsAccess a value on an if condition
Is there any way to access a value passed on the condition of a if? For example: a = int(input('Digite um numero: ')) b = int(input('Digite outro numero: ')) if((a-b) > 0): print(f'O numero…
-
0
votes0
answers274
viewsDjango form linked to registration
I have two tables in Django (Game and Goal) and I’m trying to create a form for them: class Jogo(models.Model): ativo = models.BooleanField(default = True) dataHoraInicio =…
-
0
votes1
answer33
viewsConcatenate two 2D arrays in parallel
How to concatenate two 2D arrays in parallel by returning an array 1D, example: ARRAYS/LISTS lista 1 = [['a'],['b'],['c']] lista 2 = [['A'],['B'],['C']] GOAL: lista 3 = ['a:A','b:B','c:C'] Trying:…
-
0
votes1
answer214
viewsHow do I make 3D work on pyglet?
I was trying to create using Opengl, Python and pyglet, a flat triangle in a 3D space, I saw some tutorials on the internet, some videos on Youtube, and in the end I wrote this code down there, the…
-
0
votes1
answer649
viewsExtract image text without using Tesseract
I want to extract a value from an image with a Python script, however, the main solution suggested is the Tesseract, which unfortunately I cannot implement, I have tried several ways. I would like…
pythonasked 5 years, 1 month ago Ewerton Belo 392 -
0
votes1
answer135
viewsHow to print with Pyqt5?
I made a little program in Pyqt5 where I type the Name, Number, Phone,Address, description of services and values. Now I want to print it out as a budget, but using that function: def…
-
0
votes0
answers119
viewsIndex column using data from my csv file
Good night to you all! I opened a csv file in python using the following command: caminhoarquivo = r'C:\Users\user\Desktop\teste.csv' basedados = pd.read_csv(caminhoarquivo,sep=';',decimal=',',…
-
0
votes4
answers60
viewsArray assigned to another does not hold the same value
key=[[1,2,3,4],[5,6],[7,8,9,10]] x=key i=0 print(1,key) while i<4: x[0][i]=x[2][i] i+=1 print(2,x) print(3,key) #key era para se manter o mesmo valor, mas quando altera x, key está se alterando…
-
0
votes1
answer267
viewsError using Lower(), upper() and title() functions
I have the following problem, when trying to use the functions lower(), title() and upper(). My compiler simply won’t allow and displays the error AttributeError:'list' object has no…
-
0
votes1
answer77
viewsseparate special characters
I have a text file of this kind: Olá podes dizer-me quando o 1 passa aqui? ele passa, quando passar o Carlos Alberto. I need to in python Remove special characters such as punctuation, numbers,…
-
0
votes1
answer273
viewsHow to transform excel file into list? Python
I wonder how I can turn the excel file into list after reading it df = pd.read_excel('Data.xlsx')…
-
0
votes2
answers489
viewsRecursive algorithm to check if an element belongs to a list
I have to do a recursive function that takes a list and a target element, and returns True, whether the element is in the list; and False, otherwise. EXAMPLES: busca([1,2,3], 2) --> retorna True…
-
0
votes0
answers64
viewsHow to multiply all values within a list?
Hi, I’m developing a program that gets a list of bases and exponents. Thus, it performs the potentiation between them and, soon after, multiplies the results. However, I am dubious about the…
-
0
votes0
answers46
viewsreference of a var inside the for global
then, I wanted to know by referencing the date variables, list" @app.route("/download", methods=['GET', 'POST']) def orac_detal(): global orac_detal state = {'gera':0, 'gera_total_csv':0,…
pythonasked 5 years, 10 months ago matheus teixeira 1 -
0
votes1
answer45
viewsTransform Pandas str objects into numeric values
How do I use Python to transform the following string: [[98 9] [55 16] [9 50] [68 0] [24 1] [80 16]] in two numerical vector chains (the first string containing the first values: 98 55 9 ... and the…
-
0
votes1
answer73
viewsremove duplicates by prespetiva of tuples
I have this code working, yet I wanted to do it from the perspective of the tuples. Can assist? def remove_repetidos(lst): lista = [] #lista vazia for i in lst: if i not in lista: lista.append(i)…
-
0
votes1
answer377
viewsin Sqlalchemy what is the difference between filter and filter_by
Is there any difference between the function filter and filter_by in Sqlalchemy? If it exists, when should I use each of them properly?
-
0
votes1
answer459
viewsError while using urllib library
I’m trying to make a simple application Hello World taking a look at documentation with the library urllib with the aim of picking up content from a specific website. I will refine the content I…
-
0
votes1
answer105
viewsProblems with special character (c...)
I’m making a system with Speech Recognition where as I speak it goes saving in a file . db (or .txt) but I noticed that the following characters appear when I speak a word with special characters…
-
0
votes1
answer139
viewsHow to read a JSON with missing fields to fill in a dictionary?
In Python 3 this code reads the Federal Senate API, the proposition data: import requests import pandas as pd headers = {"Accept" : "application/json"} url =…
-
0
votes1
answer771
viewsHow do you put a local file to download in flask or python?
had to download a file in python or flask I tried so but I think it just opens the file @app.route("/downloads/", methods=['GET', 'POST']) def orac_detal(): global datas, listaComTudo,…
-
0
votes1
answer60
viewsTensorflow CSV Data
Personal I would like to assemble my training_x and training_y from the CSV someone knows how to proceed, I started but could not finish. import tensorflow as tf from tensorflow import keras import…
-
0
votes1
answer65
viewsWeb Scrapping Python
It used code below to collect data of atms from the parameters in the terminal. Site was changed and I can not find the equivalent of this for data collection. Would anyone know if I could find on…
pythonasked 5 years ago Diogo Ribeiro 41 -
0
votes2
answers162
viewsIdentify zero sequences in a csv file using python
good morning! I’m having trouble identifying sequences of zero in a csv file, using Pyhton. Below is an example of my csv file: Index | Ponto de Medição | Data | Hora |ZeroApply 0 | User1 |…