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
votes2
answers388
viewsCalculate working cut-off date
I have a project in which the user gives a day and a month where he would start some task and the program should, based on some rules, return a final date. Example of rules: maximum running days =…
-
1
votes0
answers31
viewsWhy (0.1 + 0.2 - 0.3) is 5.55111512313e-17?
It seems pretty obvious to us humans that 0.1 + 0.2 - 0.3 is 0 but why when I ask the Python interpreter to perform the following operation: print(0.1 + 0.2 - 0.3) he returns 5.55111512313e-17? It’s…
-
1
votes1
answer57
viewsPass list of numbers from cartesian to polar
I’m having trouble passing a list of numbers that are in Cartesian coordinates (u,v) and need to convert to polar coordinates. I tried for the package cmath, as follows: import cmath…
-
1
votes1
answer545
viewsSocket in python
I’m doing the discipline of networks and computers and I’m having trouble on the following question: Using TCP, deploy a server that offers two features: uppercase and Daytime. The client, when…
-
1
votes0
answers175
viewsBluetooth connection - Raspberry Pi 3 B + with ios devices
What is the procedure to enable Bluetooth from Raspberry Pi 3 B+ to send and receive data via bluetooth with Ios? I developed an application, where through bluetooth (Bluez, Pybluez and…
-
1
votes2
answers1450
viewsHow to extract information from table(html) and move to a Dataframe - Using Selenium
I am using Selenium to access the site http://www2.bmf.com.br/pages/portal/bmfbovespa/lumis/lum-ajustes-do-pregao-ptBR.asp and manipulate the date box and ok button. So far I managed to do the task…
-
1
votes3
answers63
viewsHow NOT to separate a number of two or more digits when adding to a Python list?
I have a problem that, when iterating over a string and adding only the numbers in a list, a number (for example 13) eventually becomes ['1', '3']. How to get around this and make the number…
-
1
votes1
answer1144
viewsImport: No module named 'telebot'
Hello! I am configuring the bot to send Zabbix alerts, I have installed Python and the necessary modules: sudo apt install python python-pip python-setuptools Then I installed the bot API to use in…
-
1
votes1
answer82
viewsHow can I know the title of a Youtube video while downloading?
I’m doing a show that downloads Youtube videos from a channel. But I don’t want to download all the videos, but only those that have a specific word. How can I do this? import youtube_dl import os…
-
1
votes1
answer51
viewsPython Dataframe dynamically
I have data with the following columns: "Date","Codproduct","Sale","Quantity" I need to create several data frames in python, filtering product and selecting the other columns and always saved with…
-
1
votes2
answers178
viewsFormat output in txt file
I have the following code: def verificaPrimo(num): if int(num) < 2: return False else: for n in range(2, int(num)): if int(num) % int(n) == 0: return False return True def…
-
1
votes4
answers1234
viewsPython - Calculate transposed matrix
I need to calculate the transposed matrix using the python map function. But, I’m not able to solve. def transp(a): for i in range(2): for j in a: return [a[i][j]] list (map(transp,matrix)) The…
-
1
votes1
answer97
viewsNameerror on Django, but the class ta defined
When rotating the python3 manage.py runsserver i get the bug : Watching for file changes with StatReloader Exception in thread django-main-thread: Traceback (most recent call last): File…
-
1
votes1
answer41
viewsFormat Python Query
I want to adjust my Python query so that I can correctly generate a chart in Chart.js. I have the following code for query and generation of json file def get(self, request, format=None):…
-
1
votes2
answers1391
viewsConcatenate two Dataframes
I need to generate a new dataframe with the concatenation of two dataframes. The following code works, but it takes a long time to run. df_concatena = pd.DataFrame() for x in range(len(df)): for y…
-
1
votes3
answers168
viewsCompare python 'E' letter
I have this code that basically goes through the list new_users and check if there are already some users within current_users. When mine if converts the names of new_users for uppercase, lowercase,…
-
1
votes1
answer83
viewsNumerical comparator
print ("Insira dois valores para serem comparados:") Valor1= float(input("Escreva um número:")) Valor2= float(input("Escreva outro número:")) print ("Os números que você inseriu foram esses?","\n",…
-
1
votes2
answers765
viewsRead file in previous python folder
so I’m wanting to save a python file in a folder previous to the one running the script ex:my script is in the /app/controllers/script.py directory i want to put the file I will create in the…
-
1
votes0
answers25
viewsWhy use re.Compile? What’s the difference between using only the desired Pattern?
We can find some difference when using re.Compile inside Python? Assuming a file with 10 lines composed by dates and a file with 10,000 lines of dates. A Pattern could be pattern =…
-
1
votes1
answer222
viewsHow to return a JSON with special characters in Flask?
When a JSON returns through the methods make_response(jsonify()), my browser can not understand the special characters, how to return JSON in UTF-8 encoding? Follows the code: @app.route('/',…
-
1
votes1
answer246
viewsDropdown with dynamic options in Django form
I have an expense form that has a field to select the category, but I need the options to be obtained from the database. These days this is mine forms.py: from django import forms from .models…
-
1
votes1
answer44
viewsPanda does not create new lines in Spreadsheet
When creating the program in Python I take some information and put it inside a list. When trying to write this list in an excel file the data ends up getting all in the same block without creating…
-
1
votes1
answer51
viewsHow to transform the subtraction field between dates in python into int?
Hello I have the following code that turns a "Brazilian" date into a standard date: df2['Start_Date'] = df2['Start_Date'].apply(lambda x: datetime.strptime(x, '%d/%m/%Y')) df2['End_Date'] =…
-
1
votes1
answer131
viewsHow to write a python module from a test?
I’m doing an inverse exercise on Python modules and tests with pytest, but I’m not succeeding. Whenever I run the code I get the message "E Attributeerror: 'str' Object has no attribute…
-
1
votes1
answer22
viewsDjango+Python Weasyprint printing only one PDF page
Good morning guys, I have a code already developed, however, I have tried in all ways to break page and bring all pages to this document, someone can help me with this case? I’m using python 2.7 I…
-
1
votes1
answer184
viewsForm in Django with more than one Model
I’m new to programming and I’m trying to make a form using more than one Model in Django. I even managed to list the Fields of Forms.py, but when asked to save it only records the data of the first…
-
1
votes1
answer247
viewsPassing arguments to python . exe with cx_Freeze
I have this code to test the script passage ola py. import sys for arg in sys.argv: print (arg) print ("Hello World!") setup py. from cx_Freeze import setup, Executable setup( name='Ola',…
-
1
votes1
answer56
viewsWhat is export for FLASK_APP and FLASK_ENV?
I’m learning flask now and understand that every time I run my application, I need to run before: export FLASK_APP=app.py export FLASK_ENV=development I just memorized that I need to do this, but I…
-
1
votes0
answers41
viewsWhy is my matrix rewriting itself?
I want to create a square matrix of order N (N is read), but when entering the loop, my matrices are rewriting themselves and always assuming the last number I typed. I tried to change the range,…
-
1
votes0
answers39
viewsCreate all possible paths from a two-dimensional Python matrix
I tried in every way to create all possible paths of elements of a matrix. As in the example below a matrix where I would have 8 total possibilities. [1][0, 1][0, 1] [1][1][0, 1] [2][1][0] [2][2][1]…
pythonasked 5 years, 1 month ago Jasson Carvalho da Silva 11 -
1
votes1
answer79
viewsPython - Data Analysis - Error reading file in xlsx format
Good afternoon, I am trying to read an xlsx file in python via pandas, but it returns errors; as if the file did not exist (however it is in the same folder as the python script). I tried to pass…
-
1
votes1
answer104
viewsHow to change the background of a chart with Python 'Seaborn'
I try to change the background of my chart with the 'Seaborn' module, however, I am not successful. I installed the module today (16/04/2021). code: import matplotlib.pyplot as plt import seaborn as…
-
1
votes1
answer55
viewsDoubt Python URL
Hello Community I’m beginner in python and wanted to create a tool so that in some part I got doubt. I made this little code that filters the tags <img> of the Page. import requests from bs4…
pythonasked 5 years ago Jose Pereira 19 -
1
votes0
answers16
viewsHow to export sqlite and python exceptions log using Import Error
I am using Python and giving import of sqlite3 library and sqlite3 giving import in Error for exception handling! import sqlite3 from sqlite3 import Error def errorlog(erro): errlog =…
-
1
votes2
answers351
viewsCompare Dataframes and show different information between them
I have 2 dataframes, the df_a and df_b. How do I compare them and show the information that is not contained in the dataframe df_a? I tried to perform the Uplicates drop method, however, the output…
-
1
votes1
answer135
viewsstudent register
I have made the following code for student registration: laluno=[] lemail=[] lcurso=[] todos =[laluno,lcurso,lemail] def menu(): print("Menu\n[1]Cadastrar novo aluno\n[2]Lista de alunos…
pythonasked 5 years ago igor roberto 29 -
1
votes0
answers81
viewsPython - Dictionary within list
I have a dictionary inside the list: A dictionary can be used to provide a "dependency table". For example, dependencies of disciplines in college. To do Calculus 3, I first need to do Calculus 2…
-
1
votes2
answers160
viewsComparison between Dictionary and List
I’m doing a show where the idea is to start by asking if the person is already registered, otherwise they go through one. I’m having trouble checking if the username is already existing, based on a…
-
1
votes0
answers39
viewsFunction does not recognize variable
p1pos = 0 def rodada(a): if a == 1: p1pos += sortear() print('Posição do P1: ', p1pos) acerto = pergunta() if p1pos in cAvanco and acerto == True: p1pos += 1 print('Mais uma casa. P1: ', p1pos) elif…
pythonasked 5 years ago Bruce Neco 19 -
1
votes0
answers24
viewsuser_login does not log last login done
I have a Python login function in the Django framework and would like to add the user_login log when the user logs in to the system. In this case, it would have to use this column already registered…
-
1
votes1
answer65
viewsHow to avoid too many Try/except?
I have the code below that plays values inside keys in a dictionary. However, I need several try / except so that the code works perfectly, since, in the absence of one of the fields, the code will…
-
1
votes2
answers33
viewsHow can I create update function in colab without restarting its kernel?
I have my functions done outside of colab, in py files, however I would like to change the function and not need to restart the colab kernel. For this function to work in the notebook I am currently…
-
1
votes1
answer50
viewsHow to call a function by a parameter using argparse?
I was able to call functions just by creating subparsers but there are two parameters left that are part of the parser, do you have any correct way to pass a function in the argument statement?…
-
1
votes1
answer401
viewsHow to use a quadratic regression model?
I’m trying to learn how to adjust a quadratic regression model. The dataset can be downloaded at: https://filebin.net/ztr9har5nio7x78v Let Adjsaleprice be the target variable and…
-
1
votes1
answer48
viewsHow to Capture Data with Pandas?
I work with a database that uses frequency, and I want to analyze the frequency data and transform it into several lines. Follow image example: I want to make line 6, for example, become 6 equal…
-
1
votes1
answer41
views -
1
votes1
answer171
viewsPython Hashlib Function: Typeerror: update() takes in keyword Arguments
I am working on a script where in one of the steps I will have to use the function hashlib to convert one string list to another via SHA256. However, I’m having some problems that I haven’t been…
-
1
votes3
answers1495
viewsMerge elements from a list with the last different tab
An exercise in a book I’m studying has the following question: Suppose you have a list value like: spam = ['apples,'bananas','tofu','cats] Create a function that accepts a list value as argument and…
-
1
votes3
answers1598
viewsBreak lines in a certain Python character space
Hello, I created a program in Python to create a sequence of P.A., but I want the print of the result of the numbers to break after 100 characters, so the result stays inside the screen. someone can…
pythonasked 5 years ago Fernando Mendes 13 -
1
votes1
answer218
viewsCEP for Latitude and Longitude Python
Hello I would like to run a CSV that contains more than 100 CEP and return to me, in another CSV, Latitude and Longitude. I already have the basis to transform the zip code. But I’m not able to read…
pythonasked 3 years, 5 months ago Henrique Oliveira Gomes de Lim 11