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
votes3
answers1578
viewsSeparating numbers into even and odd lists - Python
My code needs to read multiple numbers and put them in a list, then create two extra lists containing only even and odd values respectively from the previous list. Example: Entrada = [3, 7, 8, 11,…
-
2
votes1
answer705
viewsHow to remove blanks
I have a list and need to remove blanks. I am using replace, but does not take the space from the beginning of the string after the minus sign, only from the end. This space is not a character?…
-
2
votes1
answer73
viewsPlot horizontally (column by column) - Python
Good afternoon, my friends All right? I have an XML file from which I would like to remove the data as shown below and plot in columns, not row by row as the code is performing, in case the data…
-
2
votes2
answers342
viewsValidate an expression based on which parentheses should close
I’m solving a Python exercise where I had to validate an expression based on which the parentheses should close right: Create a program where the user type an expression that uses parentheses. Your…
-
2
votes1
answer54
viewsReceive 12 elements and separate them into 3 lists
I need to receive three lists generated in the shell to process in Python: l1=4 3 2 1 l2=2 1 3 4 l3=1 2 3 4 In the shell script step this way: python3 orth_median.py ${o_l1[*]} ${o_l2[*]} ${o_l3[*]}…
-
2
votes1
answer107
viewsHow to generate pdf from a Django page with graphics, images and text (result of an Assessment)
I am developing an application with Django and need to display the result of an Assessment (test) that will have text, images and graphics. Initially I did this part using Chart.js based on this…
-
2
votes1
answer1686
viewsHow to run a python script from a directory inside another script that is in another directory?
I have a python script "dad": import subprocess # Executar script de outra pasta if __name__ == '__main__': cmd = "main.py -u abcd -p 1234" subprocess.call(cmd, Shell=True) Which calls the script…
-
2
votes1
answer83
viewsRemove Repeated Elements from a List[0] from the List Database[1]
I have a list structure inside the list (list=[[ ],[ ]]). Example: lista = [['pedro', 'marcos', 'mario', 'pedro', 'marcos', 'mario'],[5.2, 2.2, 6.1, 6.2, 1.1, 5.0]] I am trying to remove the…
-
2
votes1
answer88
viewsHow to access a function within a python dictionary?
We have the following functions: def oi(): print('oi') def ola(): print('ola') Now let’s store them inside a dictionary as follows: saudacoes = { 'chegada':{ 'simples': oi(), 'cult': ola(), } } I…
-
2
votes2
answers141
viewsPython value and reference
Disregarding the way it was made, this is a square matrix transposition code, the person who did came across the error in assigning the values in the latter for and neither I or he could solve: when…
-
2
votes2
answers69
viewsI can’t debug imported module in project in Visual Studio Community 2019
I’m using version 16.7.5 of Visual Studio Community 2019 where I’m implementing for the first time a pyproj (Python version 3.8.3) in a virtual environment env. I installed the library…
-
2
votes1
answer54
viewsRemoving strings from within a list
Hello I have a list I get from a file xls through the library xlrd workbook = xlrd.open_workbook(r"C:\Users\Expedição\Videos\CSV\produtos_filtrado.xls") # Escolhe o arquivo a ser lido. worksheet =…
-
2
votes2
answers172
viewsIntersection between lists without repeating elements
I have to make a code that reads two strings of numbers, convert them into int, store in a list and print list A (first string numbers), list B (second string numbers) and list C (common numbers in…
-
2
votes1
answer149
viewsChanging button colors after click
Good afternoon friends, I am starting the studies in python and need to do a job using Tkinter. I have 64 buttons and I must change their colors according to the user’s click. It has 6 color…
-
2
votes1
answer83
viewsformatting values of a dictionary
tamanho = int(input()) agenda = {} cont = 0 for c in range(tamanho): cont += 1 nome = str(input()).strip().lower().capitalize() cidade = str(input()).lower().capitalize() estado =…
-
2
votes2
answers61
viewsHow do you filter a list with multiple words in python?
How can I filter a list in the same way I can in SQL? Ex: In SQL I can do several AND in a text field with CHARINDEX SELECT * FROM TB_Produto AS A (NOLOCK) WHERE CHARINDEX('papel', NM_PRODUTO) >…
-
2
votes2
answers41
viewsHow to get the X coordinate if the Y condition is met with Numpy?
I created a function that gives me this array as output in which each line corresponds to a point : array([[0.57946528, 2. ], [0.35226154, 0. ], [0.26088698, 0. ], [0.56560726, 1. ], [0.41680759, 1.…
-
2
votes1
answer518
viewsAttributeerror - 'User' Object has no attribute 'project' - Django
I am new in Django and have a question. I made a system that saves the contents of the respective logged in user. Thus, each user will have their own content when viewing (multi-tenant system).…
-
2
votes1
answer101
viewsRename folders by changing lowercase characters to uppercase and get the total number of folders changed
I’m creating a python script to rename folder names that are lowercase to uppercase. In the code example below I already get this task. import os basedir = '/content/drive/My Drive/Colab…
-
2
votes2
answers258
viewsHow to divide the value of an element of a column by delimiter (p.e "|") in pandas?
Let’s say we have the following column: coluna1 ola | 52 hey sou ja da |5 24g The expected output would be: coluna1 ola 52 hey sou ja da 5 24g So far, I’m trying string manipulation with split and…
-
2
votes1
answer281
viewsHow to sort a list in Python
I’m solving a Python exercise that asks me to sort a list of 5 values typed by the user in ascending order, without using the Sort() method. The problem is my code isn’t working as it should. The…
-
2
votes2
answers97
viewsHow to access a list that is inside another list in Python?
I have a list that has within it another list with the students' names, and a list that has been divided into two more lists, representing the first note and the second note. For example:…
-
2
votes1
answer67
viewsInstantiate a class with private attributes
How can I take the attributes of the person class and instantiate them in the medical class and then display it? The doctor and the patient are people and both have class attributes Pessoa. I left…
-
2
votes1
answer39
viewsHow do I access an attribute(which is a list) of a class by a method outside that class in python?
I have a Shop class that one of her attributes is a list (self.products = [ ]). class Loja(Empresa): def __init__(self, nome, cnpj, razao_social): super().__init__(nome, cnpj) self._razao_social =…
-
2
votes1
answer467
viewsTurn row into column
Good night, I’m having a problem of putting together more than 500 csv files, where I need a very important data that is in a row (A8), but it needs to turn column (like this in the second image),…
-
2
votes1
answer97
viewsWhat is the bash equivalent of python’s sys.argv method?
In python, when I want to use a user-given string in the command line, I use the method sys.argv. For example, let’s say I have an executable called 2name.py consisting of the following code: import…
-
2
votes1
answer83
viewsHow do I return a character from a string in the Python function with Websockets and json library?
I’m new to Python and I have a question I’ve been trying to figure out for a long time. I’m creating a tick analysis program from an investment site, and I want to extract the value of a certain…
-
2
votes1
answer1653
viewsdoubts of logic in Python
I am a beginner in the world of programming and also in python. Solving some exercises I came across this Make a Program for a paint shop. The program should ask for the size in square meters of the…
-
2
votes1
answer69
views -
2
votes1
answer41
viewsPython-aligned JSON output
I have the following Json to be treated in python: { "lojas": { "todas":[ { "CodigoLoja": "001", "produtos":[ { "CodigoProduto": "001AAAAAAA", "dataFabricacao": "11/11/2019", "preco": "300,00" }, {…
-
2
votes2
answers187
viewsHow to check if the typed string is only '0' and '1'?
I want to validate if the typed string represents a binary number, but the way I did is not working very well: binario = str(input('Binário: ')) if '01' in binario: quebrar_string = [c for c in…
-
2
votes0
answers390
viewsWhy is my Python executable barred by Antivirus? And how do I fix it?
I was creating an executable with pyinstaller from a simple Python file. My antivirus Avast blocked the executable claiming to have viruses, although it did not have. So I made the following code in…
-
2
votes1
answer46
viewsHow do you put a Tkinter Text into a variable like str?
I created this code and intended that when I click on print, automatically write in Terminal everything you wrote in Text: from tkinter import * janela=Tk() #cores branco="white" preto="black"…
-
2
votes0
answers20
viewsPlot Dendrogram X-axis with TF-IDF
I’m trying to plot Dendrograma with data that was vectored by TF-idf, however the axis x always presents me with numbers. I would like to know how to move to the Graphics Labels option, the real…
python matplotlib machine-learning hierarchical-data clusterizationasked 3 years, 11 months ago CH97 21 -
2
votes1
answer143
viewsData Frame with information from the Central Bank of Brazil
I created a function to collect data from the Central Bank by separating by variables that I want to work. Now I wanted to create a data frame that had all this information, but I’m not getting it,…
-
2
votes1
answer110
viewsFormat difference between two dates
I calculated the period between two dates in the format d H : M : S, and now I’m trying to format it, but I still can’t, follow an example of what I want to, and my code: ENTRADA Dia 5 08 : 12 : 23…
-
2
votes1
answer48
viewsIncorrectly created chart
Hello, I am training in creating graphics in Python with matplotlib. For this, I am importing an HTML with WEGE3 action history. df_history =…
-
2
votes1
answer107
viewsHow to load . txt files from a directory including in the list or dataframe the name of this file in Python?
I’m at Jupyter Notebook working with Python. I have a directory with files in txt, I can iterate in the directory and load these files in txt, however, I also need to take the name of this file as…
-
2
votes1
answer65
viewsPython - Object-Oriented Programming
I created a module with two classes: I want to use both as if the mouse depended on the computer. E.g.: when using them: only when the Computer is turned on does the mouse have permission to turn on…
-
2
votes2
answers116
viewsOptimization through dataframe (Pandas)
I need to compare two. csv files for inconsistencies. The boleto.txt file contains information about the boletos issued by a company. This file has 500,000 lines. The.txt file contains information…
-
2
votes1
answer120
viewsPython Pysimplegui opening wrong screen
I have a Crawler using Pysimplegui to define the data to be collected and Selenium for data collection. After setting the data through a window created by Sg.Window(), I create a Sg.Popupanimated…
pythonasked 3 years, 10 months ago Lucas Claro 21 -
2
votes1
answer55
viewsOrdering of data Pandas
I have a table . cvs and accurate Print the employee with the highest amount billed each month, including employee name and total (example: "August 2020 - João - Total Billed: 150"); I got with the…
-
2
votes2
answers55
viewsHow to calculate the average for groups and identify the maximum value?
I have a spreadsheet where I need to find the month with the highest sales average. With the code below I managed, but when I print the object appears all the disordered information as can be seen…
-
2
votes2
answers53
viewsHow to change abbreviated values in a DF using Pandas in Python
I have the following problem, I have a df with more than 50 columns, in these columns, some have value of type "35,57B", "6,85T". How do I make iteratively and replace the examples cited above so…
-
2
votes1
answer37
viewsIs there a way to assign values to symbolic variables after deriving them using sympy?
Hello, I need to write a code that derives a user-informed function and then assign values to variables to perform the calculation. The problem is that it is necessary for the variables to be…
python numpy calculus ipython-notebook sympyasked 3 years, 10 months ago Leonardo Barbosa Brandão 23 -
2
votes2
answers131
viewsInsert data with pymysql into a mysql database error. How to resolve?
seqteste.txt or List: >gb:KX262887|Organism:Zika virus|Strain Name:103451|Segment:null|Subtype:Asian|Host:Human GTTGTTGATCTGTGTGAATCAGACTGCGACAGTTCGAGTTTGAAGCGAAAGCTAGCAACAGTATCAACAG…
-
2
votes1
answer76
viewsHow do I perform a normalization of curves in python?
Good afternoon everyone, I am doing an exploratory analysis of data in Python using the classic DF kc_house_data, and I came across the following problem. I would like to make some comparisons to…
-
2
votes1
answer50
viewsa function to generate a path through a point and segment map. ps: complicated, at least for me
Hello, I’m testing some ideas, doing some programs in python 3, and I need help with something complicated in which I don’t understand anything, nor can I come up with any viable solution. to…
-
2
votes1
answer30
viewsWhen using the . extend() command in Python, how do you store the result in a new object?
Considering the lists: lista1=["a","b","c","d"] lista2=[5,6,7,8] My goal is to get a new list that has the elements of these two ['a', 'b', 'c', 'd', 5, 6, 7, 8], but preserving them the way they…
-
2
votes1
answer182
viewsHow to simulate an input or store a future response
I’m making a Telegram chatbot via Python, through some lessons I’m doing, and in the middle of the process I came across a problem: I can’t in any way store the customer’s response in a variable.…