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
-
3
votes2
answers88
viewsReplacing Nan values with the subsequent not Nan of another column
I have a Dataframe with some columns (I’m only representing two in this post). I need to fill the Nan of one column with certain values of another. See below: Creating the Test Dataframe…
-
3
votes1
answer142
viewsHow to remove scientific notation on the y-axis using matplotlib?
When generating a graph using the library matplotlib in Python language in the Jupyter Notebook, I realized that the data presented in it were "reduced" (I think that would be the term) and with a…
-
3
votes1
answer35
viewsCenter values from each bar on matplotlib charts using Python
I’m doing studies on the library matplotlib in Python language extracting data from a local database, also using bilioteca sqlite3, the amount of cities that make birthday at home month of the year.…
-
3
votes2
answers53
viewsProcess command line arguments
Hello, I’m trying to work with command line argument process, I’ll show you an example command line I’m using: user@notebook$ python arquivo.py -nome Lucas --idade 12 --pais Brasil Code: import sys…
pythonasked 3 years, 8 months ago Afuro Terumi 231 -
3
votes1
answer90
viewsImage transformation according to parameters of a photo
I have an aerial photo of a lake and I have a file . geojson with a polygon that represents the outline of that lake on a real map. I am converting latitude, longitude and altitude to X, Y, Z using…
-
3
votes2
answers84
viewsHow to access the position of multiple matchs of a regex in a string?
I know I can access the position of a match of a regex in a string using the methods start, end and span. Example of a program that identifies repetitions in a text: import re from colorama import…
-
3
votes3
answers69
viewsMatplotlib sorting using index as bar denominator
I am at an impasse and cannot find a solution. I wish to generate a Bar Plot from a dataframe that is reordered in descending order. I would like the bar name to be the index (0 to 5) When I plot my…
-
3
votes2
answers102
viewsMy code is only returning half of what it should
I’m doing some simple exercises in Python and this code should return a list organized by the size of the fruit name, with the fruit with the shortest name first (in case, 'uva'). lista = ['maça',…
-
3
votes1
answer56
viewsDoubt with the counter at the while
Analyzing this code that serves to calculate arithmetic progression and that is working correctly: primeiro_termo = int (input ('Primeiro termo: ')) razao = int (input ('Razão: ')) contador = 1…
-
3
votes2
answers127
viewsHow to detect Start Codon and Stop Codon in a nucleotide sequence using Python?
I am trying to solve an exercise in which a function with a start and a stop, where the start should occur when you find "ATG" and the stop when you find the "TAA", "TAG", "TGA". With the help of…
-
3
votes2
answers202
viewsHow to prevent a class from being instantiated in Python?
I have a mother class and want to inherit it to a daughter class. But the mother class cannot be instantiated, only inherited. In other words, the mother class should be abstract. Although Python’s…
-
3
votes3
answers79
viewsSelect right line with Split in TXT
My doubt is on how after separating the lines into lists, I can also take these values and just do the append of the right line (numero_linha of function). But also, manage to catch the whole line,…
-
3
votes1
answer56
viewsHow to declare that a camp has the same kind of class?
I am trying to add typing to the Python code, and I came across an error when trying to annotate the type of a property that must have the same type of class in which it is declared: from typing…
-
3
votes1
answer65
viewsPygame how to make the character jump
I’m taking my first steps in pygame, and I’m trying to get the game character to jump, but I stumbled upon one mistake: the character just teleports up and down in 2 frames he did the whole move,…
-
3
votes0
answers54
viewsAttempt to compare values from a list in a function does not generate the expected result
I have a function that receives a list and inside it a loop of repetition in order to go through all the positions and compare the value of that particular position with the value that comes by…
-
3
votes1
answer42
viewsCreate a column filled with 0 or 1 based on other columns in Pandas
I have a data frame and need to fill a column with 0 or 1 based on the values of another 29 columns. If you have 1 in any of the columns 0 to 28 the column with Dor_leve receives 1, otherwise…
-
3
votes1
answer34
viewsCreate Moving Average column for various assets (python - finance)
would like to know how to do the media column next to each company on the list import numpy as np import pandas as pd import yfinance as yf empresas1 =…
-
2
votes1
answer226
viewsHow to upload with progress bar using pyside qftp?
How can I upload using pyside qftp? I already have a client ftp program that downloads. Below follows my ftp client code. #!/usr/bin/env python # -*- coding: latin-1 -*- import os, sys import sip…
-
2
votes2
answers3020
viewsHow to request Python 3 via an HTTP proxy
In Python, we can recover the contents of a URL in a very simple way: from urllib import request response = request.urlopen('http://www.google.com') However, in corporate environments we cannot…
-
2
votes1
answer1197
viewsCheck runtime with timeit
I need to check the running time of a function using the module timeit of Python 3, but it does not accept that I pass the value inside the function by a variable. If I replace the line: tempo =…
-
2
votes1
answer449
viewsBuild of Sublime Text 2 gives different result than ipython on the command line
I’m trying to migrate to Sublime Text 2 and do everything without leaving the program. Before I ran a script with the following line: from scipy.stats import beta, bernoulli, gaussian_kde In the…
-
2
votes3
answers307
viewsHow do I use Python to search and store data from the Stack Overflow API?
I need to develop a work to store data on the Stack Overflow. I want to know how to access the Stack Exchange API with Python, and how to use the API.
-
2
votes1
answer255
viewsProblem in importing User models
I am doing some tests in a Django project. I created a very simple module just for testing. Below: from django.contrib.auth.models import User def teste(): for i in User.objects.all(): print…
-
2
votes1
answer1489
viewsDjango - Error saving to Database
The data is not being saved in the database and Django is not generating Error, but when I create an object of Livro and try to save by shell it returns me the following error: Valueerror: invalid…
-
2
votes1
answer11259
viewsPython with Windows Form or graphical interface
Hello, I’m a beginner in Python 2.7 and I’m wondering how to apply GUI in applications developed with Python, just like html does the interface for php and visual studio is used to make windows form…
-
2
votes1
answer955
viewsI’m having trouble calling a python function
Hi. Here’s my problem: def arranque(): machine = raw_input("Bem vindo à màquina virtual(VM). Prima ENTER para iniciar o SO ou prima B para entrar no menu da BIOS.") if machine == "B".upper(): print…
-
2
votes1
answer297
viewsPython - HTTP Digest authentication with urllib2
I needed to authenticate on a test server to consume a service on a webservice, I managed to make the authentication and generate xml with the following code based on a code of Soen operacao =…
-
2
votes3
answers2056
viewsDelete text part with Python
How do I delete part of a Python text ? I have the following string """ texto textinho outro texto <div dir 'ltr'><div><div> bla bla .... """ I want to delete all HTML. I’m using…
pythonasked 10 years, 3 months ago Welington Carlos 81 -
2
votes1
answer460
viewsHow to save user changes
I’ve been searching how to save user changes (with raw_input) in Python and I did not find something that clarified me. What is the best way to do it (even after closing the program)? Example: def…
-
2
votes2
answers117
viewsAPI Stackoverflow, "quota_max"
Hello, I am using a collector to fetch data from all users of stackoverflow forum by API. Except I’m suffering from the "quota_max" which is only 300 searches a day. I already tried with the Sleep…
-
2
votes1
answer828
viewsGlobal variable is not defined
I have been investigating for hours why this mistake. I have used the global and it didn’t work and other programs I created worked. Code that gives error: def editor(): texto = raw_input("digite o…
-
2
votes1
answer479
viewsHow to simulate the Python title function [string.title()] in Java?
In python, the string has a function called title, which makes a text look like a title. Does it have a function like this in Java? If not, how to do it? Example: "Hi, my name is Goku". title()…
-
2
votes1
answer37
viewsCatching Event Detail from Elastic Beanstalk with Python and Boto
I have a script to deploy made with Fabric and Boto to deploy applications to AWS Beanstalk and would like to print the Event Details generated on beanstalk in the terminal during deploy. Does…
-
2
votes1
answer840
viewsHow to edit text
I’m trying to create an option where you can edit the initialization text, but since I already have some extensive lines of code I’m having a hard time finding a way to do it. How to do it (in a…
-
2
votes2
answers1258
viewsIs it possible to open an IDLE file from the terminal?
IDLE allows you to open a file to write our programs (by loading CRTL + N, if I’m not mistaken), but due to a problem with Python IDLE 3.4.1 or 3.4.0, I cannot use it properly. I can only use Python…
pythonasked 10 years, 2 months ago user14079 -
2
votes1
answer360
viewsHandling xml treat strings as if they were files
I’m getting a xml in the format of string in my Sponse. I want to manipulate this xml and generate a list of tags <item> xml returned by web service. Here’s the snippet of my code: if (op ==…
-
2
votes2
answers322
viewsHow to access menu item from a menu
I would like to know how to access an item from a menu, to connect it with a function or Handler. For example, I would like to control the behavior of the application when I do click in the item…
-
2
votes2
answers547
viewsColumn problems in Python XLRD
I am a beginner in Python and am trying to make a script to sum all the values of an excel column and write the sum value in the spreadsheet. I’m using the Python xlrd and xlwt packages. The code…
-
2
votes1
answer87
viewspython font error 2x
I am trying to create separate fonts for my project in a particular.py file, after creating them I care for the.py project, I do it this way as follows: py. """ Criando as fontes. """ def…
-
2
votes1
answer138
viewsDeploy queues to manage competition between Piders in Scrapyd
Is there any way that Scrapyd can create Piders queues so that when I send many Piders (with different functions) I can privilege/limit the competition between them? Today, all the Spiders I send…
-
2
votes2
answers113
viewsHow to protect my Scrapyd server from unauthorized calls?
Let’s say I have the following configuration in scrapy.cfg in Scrapyd. [deploy] url = http://example.com/api/scrapyd/ username = user password = secret project = projectX In the Scrapyd…
-
2
votes1
answer120
viewsCan you format a Python Traceback?
Is there any way to format Python Traceback to get a better reading of the error request? For example, I received the following request on my traceback:…
-
2
votes1
answer500
viewsHow to translate an image in python?
My intention is to do as in the figure below: http://postimg.org/image/pdb6urf1d/ My job: def translacao(imagem1): imagem1.save("translate.png") destino = Image.open("translate.png") destino =…
pythonasked 10 years, 1 month ago mikhailpedrosa 41 -
2
votes1
answer430
viewsWhat is the best way to organize views in Django?
I have views.py in my study project where I group it from methods to represent views (methods that return Httpresponse), to generic views based on class (such as Detailview, Listview). I was…
-
2
votes1
answer789
viewsHow to generate a username with its real name as a reference?
I have a question on how to generate user names automatically from the real name of the user, so that the result is reference to the real name. Knowing that the method should be called by informing…
-
2
votes1
answer5078
views -
2
votes1
answer97
viewsHow to calculate the total seconds in a date range list by ignoring intersections of intervals in Python?
I am trying to calculate the total time in a list of date ranges in Python, and if there is intersection between the intervals, it must merge to be calculated as if it were a new interval. Interval…
-
2
votes1
answer132
viewsImport Python Reportlab
Hello, I’m trying to import the following lib in my Python project 2.7: from reportlab.lib.rparsexml import simpleparse Error: Import: No module named reportlab.lib.rparsexml I tried to install the…
-
2
votes1
answer1551
viewsGet self variables from another class and custom event
Read only comments in English, the question of self is in comments in the code, now the events will be down there. class LOL: class Champions: class MasterYi: def __init__(self): #YiAttributes…
-
2
votes3
answers1630
viewsProblem with randint function
Hello, I’m having a little problem with my code. I try to generate a list of 4 random integer numbers that do not repeat, but... list_num = [] c = 0 v = random.randint(0, 9) while c < 4 and v not…