Questions tagged [python]

530193 questions
0

votes
0

answer
14

Views

What is the time-complexity for the “in” function in Python for strings?

I am trying to find out what would be the time complexity if I m trying to look for a string B in A in Python? Here is the problem I am working on: Question :Given two strings A and B, find the minimum number of times A has to be repeated such that B is a sub-string of it. If no such solution, retur...
Jidnyasa Babar
1

votes
2

answer
37

Views

How can we replace the columns values of one dataframe based on different dataframe column using some conditions?

I have two dataframe, say df1 and df2, both of these dataframe are very large, having 1 million+ rows and 1000 columns. Now, df1 has a column, say X which has the characters in it (as shown below). And df2 has 900+ columns and each of which needs to be changed based on df1. df1: Index ColX ColY 1...
Shubham Rawlani
0

votes
1

answer
14

Views

Endlessly turning webcam On and Off?

I have wrote a code that will capture pictures eventually and will terminate when after it reaches a certain time. But once the script is over(i.e after terminating the code using time) how will i re-run automatically after a few seconds.? import cv2 import time import numpy capture = cv2.VideoCaptu...
Sai Krishnadas
0

votes
0

answer
11

Views

How to extract specific text from many pdf files and create a table

I have hundreds of pdf files from which I want to extract specific information by using command line or code. I have attached an image. I want to extract the highlighted information from all the pdf files I have and add this information in a single table/ spreadsheet. Any help/ suggestion will be m...
Ehsan
2

votes
1

answer
44

Views

Count votes of a survey by the answer

I'm working with a survey relative to income. I have my data like this: form Survey1 Survey2 Country 0 1 1 1 1 1 2 1 2 5 2 3 2 2 4 3 4 2 1 1 4 5 2 2 4 I want to group by th...
0

votes
3

answer
33

Views

How to combine array columns which have Nan values?

i'm a beginner in python and I have some problems with combining data. What I want to do is deal with my data, completely discarding columns that have Nan values. But the indices of Nan values are different in most of my data. For example, data1 = np.array([1, 2, np.nan, 4, 5]) data2 = np.array([1,...
SJ_Lee
0

votes
2

answer
28

Views

What does choice mean in “for choice in question.choice_set.all” from the Django poll tutorial?

I'm new to Django and am working through the first poll tutorial. I'm having trouble understanding the use of the word 'choice' in a for loop within the tutorial. I've read other questions related to this part of the tutorial, but most dealt with choice_set.all {% for choice in question.choice_set.a...
user11048935
0

votes
0

answer
12

Views

How to save 3 dimensional array in to csv file?

I had train a model which has 3 number of classes .Now i want to save the prediction in csv file its throwing me an error data must be 1 dimensional . prediction1= loaded_model.predict(X_test,verbose=1) prediction1 = pd.DataFrame({ 'phrase': test['Phrase'], 'predict':prediction1 }) [output] Erorr Da...
ashu
0

votes
1

answer
16

Views

Numba acceleration on nested funtions

I have tried to use numba to accelerate lambda function but I failed to do so. Seems like lambda is not supported by numba. So I rewrote the lambda function as def functions. I am constructing an implicit function f(x,y,z) = x^2+y^2-z^2 and some others, which will only be evaluated once after constr...
HSChan
-1

votes
0

answer
10

Views

Site local works correct,but deploy to the heroku ,it show teamplatesdoesnotexist

Thanks in advance.my english is poor. Django project works locally but not when deployed to Heroku. i am following the . but the strange part is it only fails on Heroku and not locally. ... TemplateDoesNotExist at /users/register/ learning_logs/base.html Request Method: GET Request URL: https:...
Arturia Pendragon
1

votes
4

answer
3.7k

Views

'NoneType' object has no attribute 'append' python

I run the following code: import sys def find_common(a,b,c): d=[] for i in a: if i in b: d=d.append(i) for i in d: if i not in c: c=c.append(i) print(c) return c if __name__ == '__main__': a=[1,1,2,4] b=[2,2,3,4] c=[] find_common(a,b,c) sys.exit() but get the following error: d=d.append(i) Attribu...
Junchi Liu
0

votes
0

answer
5

Views

Pyrup Alternative for Upsampling

I am trying to perform PyrUp on an image but without using OpenCV. How can I build a function of my own in Numpy?
Anubhav Dutt
0

votes
0

answer
9

Views

Convert list of value related with another list of id to matrices

I have data with list of id a = [1, 3, 5] b = [2, 4] c = [1, 2, 4, 5] and the score of id like above a = [0.75, 0.6, 0.89] b = [0.9, 0,86] c = [0.65, 0.78, 0.98, 0.63] I want to convert to matrices 3 x 5 like this matrices = [[0.75 0 0.6 0 0.89] [0 0.9 0 0.86 0 ] [0.65 0.78...
Novan Dwi Atmaja
0

votes
1

answer
19

Views

How to get the total CPU and memory used by one user in python (Linux)?

I am trying to get the memory and CPU usage of all the processes run by one single user, on a shared Unix box, in python. Basically, I want the aggregation of what is displayed by running top -U username in a shell, but from Python. I looked at psutil, but couldn't find any user filtering.
MarinD
1

votes
1

answer
0

Views

Grab Tkinter cursor

I would like to capture relative mouse motion using Tkinter. I attach a listener and am able to get mouse movement. However, I would like to be able to 'grab' / 'lock' the cursor so that it is invisible and cannot leave the window (the same way a game might). My goal would be to get relative mouse...
Philipp Ploder
0

votes
0

answer
8

Views

How can I add a legend to a Matplotlib pie chart without using proxy artists?

I'm trying to reduce the size of a pie chart I've made using matplotlib by incorporating a legend. I think the two biggest problems are that I have 18 pie wedges, and using a sample code I incorporated a color map in a funky numpy array I don't quite understand. I've done some digging and I think I...
champezius
4

votes
1

answer
35

Views

Pandas.get_dummies return to two columns(_Y and _N) instead of one

I am trying to use sklearn to train a decision tree based on my dataset. When I was trying to slicing the data to (outcome:Y, and predicting variables:X), it turns out that the outcome (my label) is in True/False: #data slicing X = df.values[:,3:27] #X are the sets of predicting variable, dropping...
WY G
0

votes
0

answer
5

Views

Statsmodel api in python giving the p value of all feature as 0

I doing a logistic regression on income census data of US. There are maximum column with categorical values so I created dummy variables for them. But when fitting the model using statsmodel api for all the features I am getting the P value as 0. So this tell that all the features are significant. B...
Sarthak Sahu
1

votes
1

answer
0

Views

How to detect black colour in a video cam using opencv?

I need to detect black objects in a real time video. I got a code in the internet for detecting blue objects. So I changed the upper and lower hsv value according to bgr colour code(am not clear about how to convert bgr to hsv), But its not detecting the black object in the video.the code am using b...
praveen kumar
1

votes
0

answer
16

Views

Mutli process on Single GPU

I have Single GPU machine, and I am running 3 process on single GPU using tensorflow GPU. I have mentioned gpu_options = tf.GPUOptions(per_process_gpu_memory_fraction=0.25) When I start process its Running well, but after some time processes are getting hang on one step only. Any small help will be...
Sachida
1

votes
0

answer
9

Views

Done status based on action in OpenAI Atari

I am attempting to create a neural network to play the emulated atari game 'BreakoutDeterministic'. The action space for the game is [0,1,2,3]. When inputting frame, reward, is_done, _ = env.step(env.action_space.sample()) The game will play out and and the 'is_done' variable will eventually be set...
niallmandal
1

votes
0

answer
8

Views

Need help in using Signals with Python Flask

I am new to Python Flask and need some information/basic knowledge on how to use Signals with Flask. My understandig so far: I can create and send own signals. I can use this signal, to make a function call. My Flask Application looks something like this: @app.route('/') def start(): return render_t...
Rasid Music
1

votes
3

answer
105

Views

Python regex find two groups

>>> text = '\nAnother diversion: The softmax output function [7 min]' >>> import re >>> re.findall(r'data-lecture-id='(\d+)'|(.*)',a) >>> [('47', ''), ('', 'Another diversion: The softmax output function [7 min]')] How do i extract the data out like this: >>> ['47', 'Another diversion: The softmax o...
MrROY
1

votes
1

answer
817

Views

Checking for __debug__ and some other condition in Python

In Python sometimes I want to do something like (1) if __debug__ and verbose: print 'whatever' If Python is run with -O, then I'd like for that whole piece of code to disappear, as it would if I just had (2) if __debug__: print 'whatever' or even (3) if __debug__: if verbose: print foo However, that...
user1717856
0

votes
1

answer
30

Views

Create nested python dictionary

I am using the python code below to extract some values from an excel spreadsheet and then push them to an html page for further processing. I would like to modify the code below so that I can add additional values against each task, any help the code below does spit out the following: {'line items'...
Ossama
0

votes
3

answer
30

Views

Python Script Unable to Get Cell Values

I am trying to accomplish a seemingly simple task in Python. This is now my third SO post in as many days and I am embarassed. I am hoping to open a csv file. I would like to loop through each row, and for every column in every row, if the value is NOT a 0 or a 1 (it is a '?'), to essentially rewri...
Jerry M.
2

votes
2

answer
17

Views

Python: List Reversing on One Line [duplicate]

This question already has an answer here: list.reverse does not return list? 8 answers ls = list(range(10)) ls.reverse() print(ls) Why does this work in producing a list that counts backwards from 9 not but not this: ls = list(range(10)).reverse() print(ls) These last two lines prints this instead:...
user7809450
3

votes
3

answer
34

Views

Some problem of comparing two multidimensional lists

Thanks for seeing my problem. I designed to make a_list and erase every element in b_list if b_list have one. But It doesn't work properly. It only works except a_list[0]. What is happening in my code? a_list = [[0, 1], [0, 2]] b_list = [[0, [0, 1], [0, 2], '3', [0, 4]], ['1', [0,1], [0, 2], [0, 3],...
user9095244
2

votes
2

answer
34

Views

How to crate multiple lists from another list based on condition/breakpoints in Python?

I'm looking for a way to create multiple lists from one large list. What I want to do is to filter out different digit groups (amounts of fruits sold each week) form a list. Each group of digits should be in a separate list when it hits '******' string that indicates where each group should end. Exa...
rootpl
-2

votes
0

answer
32

Views

Merging two functions in Python

I need help in combining two functions for converting from binary to decimal. So in here singles = [] while n > 9: t = n % 10 singles.append(t) n = round((n - (n % 10)) / 10) if n
hdsv
0

votes
2

answer
28

Views

Python, how can I change in-place a sub array?

For example, I have a function def foo(a): a[0],a[1] = a[1], a[0] And a = [1,2,3] The foo(a) changes value of a in-place but foo(a[:1]) does not. Please help to let me know how can I make foo(a[:1]) change value of a in-place
Son Nguyen
-1

votes
1

answer
25

Views

How do I use variable inside a parentheses and single quotes?

Using Python 2.7 I am trying to put a variable inside a (' ') Orignial string r = search.query('Hello World') What I have tried so far and is not working... r = search.query('{0}').format(company_name_search) r = search.query('s%') % (company_name_search) Both methods are not working and output th...
Mark Wollerman
0

votes
1

answer
21

Views

How to remove nan from pandas series index?

import pandas as pd import numpy as np df = pd.Series([1, 2, 3, 4], index=['a', 'b', 'c', np.nan]) df.pop(np.nan) Type error : can not do label indexing on class pandas.core.indexes.base.Index with these index [nan] of class float I tried doing df.reset_index().dropna().set_index('index') But then...
Shakti
2

votes
0

answer
23

Views

How does this solution to finding the maximum absolute difference relate to my solution?

I want to understand how the optimized code for finding the maximum absolute difference relates to how the maximum difference is calculated. This is the challenge. You are given an array of N integers, A1, A2 ,…, AN. Return maximum value of f(i, j) for all 1 ≤ i, j ≤ N. f(i, j) is defined as...
dk7518
0

votes
3

answer
19

Views

Connecting list and sublist for accessing the related data

i have a list like below mainlist=[10,20,30,40,50] i have a sublist which will have 6 numbers for each number in main list like below sublist=[10,12,14,16,18,20,20,22,24,26,28,30,30,32,34,36,38,40,40,42,44,46,48,50,50,52,54,56,58,60] i have a sublist1 which will have 5 numbers for each number in sub...
Techiesoft
-1

votes
0

answer
16

Views

Generate excel file in python? Assign name, directory and save?

Generate excel file in python? Assign name, directory and save? Hello everyone I found a very old question that you had no answer from the community so I spent all my time and design the code that gives the solution to this problem .. 'ALLOW USER TO SELECT THE DIRECTORY IN WHICH TO SAVE AN EXCEL SHE...
the_saltorman
-1

votes
0

answer
13

Views

Unable to import 'numpy'pylint(import-error)

I am new to python, using vs code throws me this error though I have correctly set the path. Unable to import 'numpy'pylint(import-error)
Abhishek Israni
0

votes
0

answer
3

Views

how to change size of picture using openpyxl

there. I want to change size of picture using openpyxl. width = 11.21 cm. height = 7.69 cm. or I want to change the size of picture same as the cell. my code is below. it makes very small size picture. could you help me? from openpyxl import load_workbook from openpyxl.drawing.image import Image fil...
박형렬
1

votes
1

answer
71

Views

Low Pass Filter for blurring an image

I'm trying to blur an image using fft by passing a low pass filter that I created but the output yields to be an image full of gray noise. from scipy import fftpack import numpy as np import imageio from PIL import Image, ImageDraw image1 = imageio.imread('image.jpg',as_gray=True) #convert image to...
sspatole
0

votes
0

answer
2

Views

Python error “expected LP_SDL_Window” when trying “SDL_GetWindowID”

I'm trying to get the Window ID of the SDL window, to give to VLC so it can play the video in the window. Being new to Python, I'm vaguely aware this has to do with variable type conversions to play nice with SDL, and using the correct python binding... The line with the error is 'win_id = SDL_GetWi...
Domarius

View additional questions