text stringlengths 46 37.3k | title stringlengths 12 162 |
|---|---|
Python : I have a largely empty dataframe of poorly formatted dates that I converted into DateTime format.Which producesI 'd expect that I could use df.any ( ) to find whether there was a value in a row or column . axis=0 behaves as expected : But axis=1 just returns false for all rows all the time . <code> from io imp... | Pandas any ( ) returning false with true values present |
Python : I have a line of code in my script that has both these operators chained together . From the documentation reference BOOLEAN AND has a lower precedence than COMPARISON GREATER THAN . I am getting unexpected results here in this code : I was expecting Second or Third test to happen before the fist one , since >... | Python operator precedence - and vs greater than |
Python : What is the best technique with rethinkb and python to deal with empty result.I try this , but catching exceptions is not satisfactory.If anyone has tried other techniques , I am very interested.Thanks for your help . <code> @ staticmethoddef get_by_mail ( mail ) : try : return User ( r.table ( 'users ' ) .fil... | Rethinkdb python handle empty result |
Python : It seems that the Python C API is not consistent with the const correctness of character arrays . For example , PyImport_ImportFrozenModule accepts a char* , whereas PyImport_ImportModule accepts a const char* . The implication of all this is that in my C++ application that I am writing with an embedded Python... | Const correctness of Python 's C API |
Python : How do you `` disable '' the __call__ method on a subclass so the following would be true : This and other ways of trying to set __call__ to some non-callable value still result in the child appearing as callable . <code> class Parent ( object ) : def __call__ ( self ) : returnclass Child ( Parent ) : def __in... | How to make an Python subclass uncallable |
Python : I have a mix-in class called WithAutoNumbering for classes that need a special numbering of a given attribute . Appart from that I have a nice class mix-in called WithIndexing for those classes that need indexing capabilities ... which needs the capabilities of WithAutoNumbering.Some classes need numbering but... | Should python mix-in classes inherit only from object ? |
Python : I am looking to vectorize a nested loop , which will work on a list of 300,000 lists , with each of these lists containing 3 values . The nested loop compares the values of each of the lists with the corresponding values in the other lists , and will only append the list indices which have corresponding values... | Vectorizing a Nested Loop |
Python : I understand that because Python has first-class functions , using the Strategy pattern is usually just a matter of passing a function as an argument , and does n't require futzing with classes . But what if the `` strategies '' are n't single functions , but rather groups of related functions that logically s... | Strategy pattern in Python when a `` strategy '' consists of more than one function |
Python : This is my second attempt at implementing gradient descent in one variable and it always diverges . Any ideas ? This is simple linear regression for minimizing the residual sum of squares in one variable.Result : <code> def gradient_descent_wtf ( xvalues , yvalues ) : tolerance = 0.1 # y=mx+b # some line to pr... | Why does simple gradient descent diverge ? |
Python : I want to split a string on any combination of delimiters I provide . For example , if the string is : And the delimiters are \. , , , and \s . However I want to capture all delimiters except whitespace \s . The output should be : My solution so far is is using the re module : However , this captures whitespac... | How to split up a string on multiple delimiters but only capture some ? |
Python : In the following example I use a twitter dataset to perform sentiment analysis . I use sklearn pipeline to perform a sequence of transformations , add features and add a classifer . The final step is to visualise the words that have the higher predictive power . It works fine when I do n't use feature selectio... | Sentiment analysis Pipeline , problem getting the correct feature names when feature selection is used |
Python : SymPy comes equipped with the nice sympify ( ) function which can parse arbitrary strings into SymPy expressions . But it has two major drawbacks : It is not safe , as it relies on the notorious eval ( ) It automatically simplifies the read expression . e.g . sympify ( 'binomial ( 5,3 ) ' ) will return the exp... | SymPy : Safely parsing strings |
Python : The GNU C Library has the function drem ( alias remainder ) .How can I simulate this function just using the modules supported by Google App Engine Python 2.7 runtime ? From the GNU manual for drem : These functions are like fmod except that they round the internal quotient n to the nearest integer instead of ... | How can I simulate GNU C Library drem / remainder function in Google App Engine Python 2.7 runtime ? |
Python : I have a dict , that looks like this : And I need to get it to look like : I should point out that there can and will be multiple top-level keys ( 'foo ' in this case ) . I could probably throw something together to get what i need , but I was hoping that there is a solution that 's more efficient . <code> { '... | Need to create a layered dict from a flat one |
Python : Running this code multiple times could print something like : ( If you are using the console to replicate it , make sure you click Rerun every time before you re-paste the code and execute it . If you still ca n't replicate , perhaps you have hash randomization not equal to random . On Python 3.3 and greater ,... | Why does a set of numbers appear to be sorted ? |
Python : I 'm trying to implement an unsupervised ANN using Hebbian updating in Keras . I found a custom Hebbian layer made by Dan Saunders here - https : //github.com/djsaunde/rinns_python/blob/master/hebbian/hebbian.py ( I hope it is not poor form to ask questions about another person 's code here ) In the examples I... | Custom Hebbian Layer Implementation in Keras - input/output dims and lateral node connections |
Python : I 'm implementing a rudimentary version of LISP in Ruby just in order to familiarize myself with some concepts . I 'm basing my implementation off of Peter Norvig 's Lispy ( http : //norvig.com/lispy.html ) .There 's something I 'm missing here though , and I 'd appreciate some help ... He subclasses Python 's... | Help me write my LISP : ) LISP environments , Ruby Hashes |
Python : I am trying to create a wrapper class that behaves almost like the wrapped object . So far , I have come up with the following code : I tried testing it with : However it comes up with the following error message : __init__ is being properly dispatched by isinstance ( attr , ( types.MethodType , method_wrapper... | Python Object Wrapper |
Python : Suppose I have : Suppose I already have an Level1 object : level1 , how can get all Level4 objects of Level1 ? Like the meaning : level1.level2_set.level3_set.level4_set . <code> Class Level1 : name = CharField ( ) Class Level2 : name = CharField ( ) level1 = ForeignKey ( Level1 ) Class Level3 : name = CharFie... | How to reverse query objects for multiple levels in django ? |
Python : I have a subplot of 28 lines x 2 columns ( it can change , actually ) . The yaxis scale of all the lines of the 1st column is supposed to be the same ( that must work for that 2nd column as well ) ... .All the xaxis are supposed to be the same.What I want to do is to make something inside the output figure tha... | Help with making a big subplot look nicer and clearer |
Python : I think this is perfectly valid.However , it gives me an invalid syntax error in Python REPL.Why is it ? On Python 3.6.5 ( x64 ) , Windows 10 RS4 <code> if False : print ( 1 ) print ( 2 ) | Why am I getting an invalid syntax error in Python REPL right after IF statement ? |
Python : Suppose I have successfully trained a XGBoost machine learning model in python.I want to port this model to another system which will be writte in C/C++ . To do this , I need to know the internal logic of the XGboost trained model and translate them into a series of if-then-else statements like decision trees ... | Port XGBoost model trained in python to another system written in C/C++ |
Python : I 've got an array of dates that can contain multiple date ranges in it.In this example , the list contains 2 separate consecutive date ranges ( 2020-01-01 to 2020-01-03 & 2020-01-06 to 2020-01-08 ) I 'm attempting to figure out how I would loop through this list and find all the consecutive date ranges.One of... | Split a list of dates into subsets of consecutive dates |
Python : start.py code is as below.Start it with python for two times.run.py code is as below.run.py is only one line different from start.py.Now start run.py for two times.startandrun.py code is as below.Now start startandrun.py for two times also.As JohanL say : When running two separate threads , all bets are off as... | same program different output in threading module |
Python : In order to investigate some Selenium test failures I would like to automatically enable the pause on exception feature in the Chrome Devtools when running the tests.There is the -- auto-open-devtools-for-tabs command line option for automatically opening the DevTools pane which I am already using but apparent... | Break on exception in Chrome using Selenium |
Python : I found the following mistake in my code this week : Yes , it should be d.isoweekday ( ) instead.I know , if I had had a test-case for this I would have been saved.Comparing a function with 5 is not very useful . Oh , I 'm not blaming Python for this.My question : Are there tools that can spot errors like this... | Are there tools that can spot errors like this one ? |
Python : Under Ubuntu Desktop ( Unity ) when a script marked as executable and then I click on the file I get pop-up window like the one here in the image : pyscript.py is an executable Python script file with a shebang : # ! /usr/bin/python where /usr/bin/python is the path to the Python interpreter . Since I 'm not r... | What are exactly the standard streams if there 's no terminal/console window open for the python interpreter ? |
Python : I would like to compute the maximum of `` a_priority '' for each group of ( b , c ) pairs.a_priority is an annotation based on a case/when mapping strings to priority values.I get the following error : I believe the qs.values ( `` b '' , `` c '' ) filters out my annotation a_priority . Behavior is different wi... | Maximum of an annotation after a group by |
Python : I 'm not good enough with decorators yet to do this ... Is it possible to define a decorator live_doc that allows me to get an interpolated doc string after a method or function call , filled in with the actual arguments and return value.After the code below : d should be `` f was called with 3 , `` marty '' ,... | How to define a decorator that will provide an interpolated doc string for a function/method call |
Python : I am using Popen to start a telnet process over ssh , send commands through the telnet and check the process for output to monitor the state of the telnet . The weird thing I encountered is that the code works fine with Python 3.2.3 but when I run it in Python 3.6.5 with no code changes , it fails to get the o... | Popen.stdout.readline ( ) works in Python 3.2 but returns empty string in Python 3.6 |
Python : The program in question prints stuff first thing . When I connect to it , via raw sockets , it does n't send anything . Here 's the output : Am I missing anything ? Thanks in advance . <code> print 'Preall test works ! 'from twisted.internet import reactor , protocolfrom twisted.python import logimport sysprin... | What 's wrong with my twisted server that 's supposed to take a .exe and send its stdio to anyone who asks . Instead , it does n't send anything |
Python : Is there a way to get back from a return value from inspect.getcallargs ( func ) to a *args , **kw pair that can actually be used to call the func ? Use case : say I am writing a decorator , and I want to change a particular argument of a function by name . Here 's the beginning of some code to do this : ( I '... | Is there an inverse operation to Python inspect.getcallargs in the standard library ? |
Python : Would what mentioned in the title be possible ? Python module style that is . See this example for what I exactly mean.index.phpHello/World.phpWould this be possible ? <code> < ? phpuse Hello\World ; World : :greet ( ) ; < ? phpnamespace Hello\World ; function greet ( ) { echo 'Hello , World ! ' ; } | Is it possible to autoload a file based on the namespace in PHP ? |
Python : I 'm writing a test for a program that will be used in multiple locales . While running the test in German , i got the errorDigging into this , i discovered that using locale.nl_langinfo ( locale.T_FMT ) while in German or Spanish ( and potentially other languages ) produces the format string ' % T ' . This is... | Why does Python store German and Spanish ( and other ? ) time format strings as % T in the locale module ? |
Python : It is design problem.Let 's assume that we have this kind of model in Django : We have also another file called actions.py and we implementthere others actions.Our problem is to determine which kind of methods should be placed in models.py , which in actions.py.Do you know any common approach , guide or someth... | What kind of methods should be method of model class ? |
Python : I want to use the in operator in my Google App Engine project which was introduced in Django 1.2 : I found out that is possible to use version 1.0 or 1.1on GAE , but nothing for 1.2 . Is it possible ? <code> { % if `` bc '' in `` abcdef '' % } This appears since `` bc '' is a substring of `` abcdef '' { % endi... | Is it possible to use Django 1.2 on Google App Engine ? |
Python : I have a strange problem with using mmap in python when writing to memory ( /dev/mem ) .To be clear , reading is done in the same manner and it works OK.But when it comes to writing , it seems that every second byte is unwritable.ex.When I try to write byte by byte , the same happens.ex.Code : Example run ( I ... | python mmap skipping every second byte when writing |
Python : I came across some urwid tutorial , which included an example with code such as this : That u'\N { MEDIUM SHADE } ' string literal drove me nuts for almost the entire day until I found out it was included — as comments ! — in files under /usr/lib/python3.5/encodings/ ... But nowhere did I find any hint as to u... | Where does `` \N { SPECIAL CHARACTER } '' in Python come from ? |
Python : Suppose a class has a method that modifies it 's internals.Should that method call save on itself before returning or should the save be left to the caller to explicitly save after the modifying method has been called ? Example : Explicitly calling save : or allowing method to call save : I 'm working with dja... | Should a modifying class method save itself or be explicity called after the method is called ? |
Python : I 'm trying to create a signed file using OpenSSL and Python , and I 'm not receiving any error mesage , but the proccess is not working properly and I ca n't find the reason.Below is my step-by-step to sign the file and check the signature : First I create the crt in command lineopenssl req -nodes -x509 -sha2... | Problems to verify a file signed with python |
Python : I 'd like to wrap df.groupby ( pd.TimeGrouper ( freq='M ' ) ) .sum ( ) in a function so that I can assign sum ( ) , mean ( ) or count ( ) as arguments in that function . I 've asked a similar question earlier here , but I do n't think I can use the same technique in this particular case.Here is a snippet with ... | Pandas : How to assign sum ( ) or mean ( ) to df.groupby inside a function ? |
Python : lets say I have two arraysI need to divide the arrays element-wise , thus using numpy.My issue is the `` secure division '' implemented.when doing : I get the output : My problem with this is that I need it to return the element that is not 0 when it divides by 0 , making the ideal output : Is there any workar... | Numpy division by 0 workaround |
Python : I have a web application which uses Google 's Datastore , and has been running out of memory after enough requests.I have narrowed this down to a Datastore query . A minimum PoC is provided below , a slightly longer version which includes memory measuring is on Github.Profiling the process RSS shows approximat... | How should I investigate a memory leak when using Google Cloud Datastore Python libraries ? |
Python : I tested two different ways to reverse a list in python.Interestingly , the 2nd method that inserts the value to the first element is pretty much slower than the first one . Why is this ? In terms of operation , inserting an element to the head does n't seem that expensive . <code> import timeitvalue = [ i for... | Why l.insert ( 0 , i ) is slower than l.append ( i ) in python ? |
Python : I install py3-pandas as following , Then I try to import pandas , it 's not avaialbleSo it turns out pandas are installed in the different python directoryHow do I make py3-pandas to use the python version which is already installed in the system ? <code> FROM alpine : latest RUN echo `` http : //dl-8.alpineli... | alpine docker : installing pandas / numpy |
Python : So litheor ( 2 ) is True and 2 in sieve ( 100 ) is True , so the if clause in the list comprehension is False . But why is 2 still in the output of the list comprehension ? <code> > > > [ l for l in range ( 2,100 ) if litheor ( l ) ! =l in sieve ( 100 ) ] [ 2 , 3 , 5 , 7 , 11 , 13 , 17 , 19 , 23 , 29 , 31 , 37... | Python : Something went wrong somewhere in the list comprehension ? |
Python : I 've written a script in Python to get only the name visible in my profile in SO . The thing is I would like to log in that site using requests module and once I 'm logged in I wish to get the profile name using Selenium . The bottom line is -- when I get the profile URL , I would like that URL to be reused b... | Ca n't fetch the profile name using Selenium after logging in using requests |
Python : I found a similar class definition as below in a Python code base . It seems there is no similar examples in the official documents . Very hard to find similar thing by Google and searching in the forum . May anyone help me to understand the principle in Python behind this ? <code> class a : passclass b : pass... | Python class definition based on a condition |
Python : I want to retrieve the value of the var modelCode . I made a regex function like this , but it does n't work at all . I 've posted the structure of the page below.Can somebody help me , please ? Structure of the page : } <code> regex2 = re.compile ( r ' '' var modelCode '' \s* : \s* ( .+ ? \ } ) ' , re.DOTALL ... | scrapy - How to retrieve a variable value using regex |
Python : I 'd like to create a `` class property '' that is declared in an abstract base class , and then overridden in a concrete implementation class , while keeping the lovely assertion that the implementation must override the abstract base class ' class property.Although I took a look at this question my naive att... | How can I combine abc.abstractproperty with a classmethod to make an `` abstract class property '' ? |
Python : I read Storm ORM 's tutorial at https : //storm.canonical.com/Tutorial , and I stumbled upon the following piece of code : I 'm not sure that the second argument of the find method will be evaluated to True/False . I think it will be interpreted as a lambda . If that is true , how can I achieve the same effect... | what python feature is illustrated in this code ? |
Python : I have been trying to find a way to continue my for loop to the previous element . Its hard to explain . Just two be clear , here is an example : - On executing this , when the loop reaches to ' c ' , it sees that bar is equal to ' c ' , it replaces that ' c ' in the list , continues to the next element & does... | 'continue ' the 'for ' loop to the previous element |
Python : I have the following objects and relations defined . This is actually quite a simple case , and I am providing all those fields just to show why I believe inhalation and injection anesthesia should be defined by two different classes.I would , however , like to define the anesthetic attribute of the Operation ... | multiple/split class associations in sqlalchemy |
Python : Suppose I have a matrix that is 100000 x 100I wish to go through this matrix , and if each row contains entirely either 1 or 0 I wish to change a state variable to that value . If the state is not changed , I wish to set the entire row the value of state . The initial value of state is 0 . Naively in a for loo... | How to vectorize a loop through a matrix numpy |
Python : I 'm looking for efficient alternate ways to compute cosine angle between 2D vectors . Your insights on this problem will be of much help.Problem Statement : vectors is a 2D array where vectors are stored . The shape of the vectors array is ( N , 2 ) where N is the number of vectors . vectors [ : , 0 ] has x-c... | Fastest way to compute angle between 2D vectors |
Python : I have a simple code named main.py that generates a folder and a file within it : If this script run in a folder , then the structure should be like : I use a setup.py file to pack the code up , where I assigned an entry point named foo . The setup.py looks like : I packed the code with the structure below : A... | Setuptools : How to make sure file generated by packed code be deleted by pip |
Python : If a template is missing deep inside the rendering of a django template , I get a exception like below.After searching very long I found the bogus part : form.template_name was empty in my context.How can I find the relevant template name without searching for hours ? I am missing a traceback like for normal p... | Better errors message if template is missing |
Python : I have to detect whether a file is a valid mp3 file . So far , I have found two solutions , including : this solution from Peter Carrollusing try-catch expression : Both solutions above work , but may have some drawbacks , the 1st solution seems too complicated while the 2nd solution is too slow ( in seconds d... | Best way to verify an mp3 file with python |
Python : How do I merge a list of lists ? intoEven better if I can add a value on the beginning and end of each item before merging the lists , like html tags.i.e. , the end result would be : <code> [ [ ' A ' , ' B ' , ' C ' ] , [ 'D ' , ' E ' , ' F ' ] , [ ' G ' , ' H ' , ' I ' ] ] [ ' A ' , ' B ' , ' C ' , 'D ' , ' E... | Merging a list of lists |
Python : Not sure if title is correct terminology.If you have to compare the characters in 2 strings ( A , B ) and count the number of matches of chars in B against A : is faster on % timeit thanI understand that the first one will create a list of bool , and then sum the values of 1.The second one is a generator . I '... | Why is summing list comprehension faster than generator expression ? |
Python : I have a somewhat bizarre metaclass question . I 'm using a meta class to dynamically create a 'sibling ' class that inherits from another superclass and assign it as an attribute on the original class . Below is a minimal setup : Something seems to be going wrong above with the creation of the 'sibling ' clas... | python metaclass inheritance issue |
Python : I have just started learning python and I have stumbled across a particularitypython version : Python 2.7.2 ( default , Jul 20 2011 , 02:32:18 ) [ GCC 4.2.1 ( LLVM , Emscripten 1.5 , Empythoned ) ] on linux2on : http : //repl.it/languages/PythonWorking with the interpreter assigning : Ok floating point precisi... | Float random ( ? ! ) precision quirk |
Python : having been looking for solution for this problem for a while but ca n't seem to find anything . For example , I have an numpy array of what I would like to achieve is the generate another array to indicate the elements between a pair of numbers , let 's say between 2 and -2 here . So I want to get an array li... | numpy array set ones between two values , fast |
Python : I have a Django project and I wanted to generate some objects ( from the models ) What I 'm trying to get at : Standalone Python Script to create bunch of objects and/or filter , delete.after importing the model with from apps.base.models import MyModeland setting up the configuration as the previous StackOver... | Django 2.0 Access Models ( CREATE/REMOVE/FILTER ) Standalone [ without manage.py shell ] |
Python : There are some URLs which are handled by my Pyramid application . When an unauthenticated user tries to open any URL then the user is redirected to login form : But for some urls ( routes ) I have to return not the login form , but a 401 Unauthorized status code with WWW-Authenticate header . How I can setup m... | Different login views in Pyramid |
Python : Why is the size of sets in Python noticeably larger than that of lists with same elements ? output : <code> a = set ( range ( 10000 ) ) b = list ( range ( 10000 ) ) print ( 'set size = ' , a.__sizeof__ ( ) ) print ( 'list size = ' , b.__sizeof__ ( ) ) set size = 524488list size = 90088 | Why are sets bigger than lists in python ? |
Python : I have this code : The output is a list of 45 tuples.I would like to divide 45 tuples into 9 groups of 5 tuples , each of which are unique items . For example like so : So each list contains tuples with items from 1 to 10 without repetition . <code> from itertools import groupbyfrom itertools import combinatio... | Groups of unique pairs where members appear once per group |
Python : I am running a python script on a remote machine , which runs fine , but soon after starting I get the warning : I did n't worry about this warning as it was n't stopping my code.I then tried to submit the same code using Slurm workload manager , using the command : When I do this , the code does n't work , an... | Error only when submitting python job in Slurm |
Python : I am trying to fit at TensorForestEstimator model with numerical floating-point data representing 7 features and 7 labels . That is , the shape of both features and labels is ( 484876 , 7 ) . I set num_classes=7 and num_features=7 in ForestHParamsappropriately . The format of the data is as follows : When call... | TensorFlow crashes when fitting TensorForestEstimator |
Python : I have seen here and here on how to return every nth row ; but my problem is different . A separate column in the file provides specifics about which nth element to return ; which are different depending on the group . Here is a sample of the dataset where the Nth column provides the rows to return . That is ,... | Take every nth row from a file with groups and n is a given in a column |
Python : Is there a way to add multiple items to a list in a list comprehension per iteration ? For example : output : [ [ 1,2,3 ] , ' a ' , [ 1,2,3 ] , ' b ' , [ 1,2,3 ] , ' c ' , [ 1,2,3 ] , 'd ' ] <code> y = [ ' a ' , ' b ' , ' c ' , 'd ' ] x = [ 1,2,3 ] return [ x , a for a in y ] | list comprehension question |
Python : I have an issue with Recurrentshop and Keras . I am trying to use Concatenate and multidimensional tensors in a Recurrent Model , and I get dimension issue regardless of how I arrange the Input , shape and batch_shape.Minimal code : ErrorCode : Please help . <code> from keras.layers import *from keras.models i... | Recurrentshop and Keras : multi-dimensional RNN results in a dimensions mismatch error |
Python : I have two HUGE Pandas dataframes with location based values , and I need to update df1 [ 'count ' ] with the number of records from df2 which are less than 1000m from each point in df1 . Here 's an example of my data , imported into PandasIn reality , df1 has ~10 million rows , and df2 has ~1 millionI created... | Improved efficiency versus iterating over two large Pandas Dataframes |
Python : I have this list : I need to then shuffle or randomize the list : And then I need to go through and find any adjacent 1 's and move them so that they are separated by at least one 0 . For example I need the result to look like this : I am not sure of what the most efficient way to go about searching for adjace... | How to check for adjacency in list , then fix adjacency in python |
Python : TL ; DR I 'm looking for help to implement the marble diagram below . The intention is to sort the non-sorted values to the extent possible without waiting time between scan executions.I 'm not asking for a full implementation . Any guidance will be welcome.I have an asynchronous slow ( forced for testing purp... | RxPy : Sort hot observable between ( slow ) scan executions |
Python : I have a model called Appointment which has the columns datetime which is a DateTime field and duration which is an Integer field and represents duration in minutes . Now I want to check if func.now ( ) is between the datetime of the appointment and the sum of the datetime and durationI am currently to try to ... | Sqlalchemy get row in timeslot |
Python : This may be a simple question , but I 'm having trouble making a unique search for it . I have a class that defines a static dictionary , then attempts to define a subset of that dictionary , also statically.So , as a toy example : This produces NameError : global name 'first_d ' is not definedHow should I be ... | Reference class variable in a comprehension of another class variable |
Python : I am creating random Toeplitz matrices to estimate the probability that they are invertible . My current code isCan this be sped up ? I would like to increase the value 50000 to get more accuracy but it is too slow to do so currently.Profiling using only for n in xrange ( 10,14 ) shows <code> import randomfrom... | Speed up random matrix computation |
Python : Answering this question I faced an interesting situation 2 similar code snippets performed quite differently . I 'm asking here just to understand the reason for that and to improve my intuition for such cases.I 'll adapt code snippets for Python 2.7 ( In Python 3 the performance differences are the same ) .Ou... | Understanding performance difference |
Python : Is there any way to compare two dates without calling strptime each time in python ? I 'm sure given my problem there 's no other way , but want to make sure I 've checked all options . I 'm going through a very large log file , each line has a date which I need to compare to see if that date is within the ran... | alternative to strptime for comparing dates ? |
Python : I am trying to click the tabs on the webpage as seen below . Unfortunately , it only seems to click some of the tabs despite correct correct xpath in inspect Chrome . I can only assume it ’ s not clicking all the tabs because the full xpath is not being used . However..I have tried changing the xpath : //div [... | Not clicking all tabs and not looping once issues |
Python : I have a pandas DataFrame with a secondary y axis and I need a bar plot with the legend in front of the bars . Currently , one set of bars is in front of the legend . If possible , I would also like to place the legend in the lower-left corner . Any ideas appreciated ! I have attempted to set the legend=false ... | Put the legend of pandas bar plot with secondary y axis in front of bars |
Python : I have the following 4 dictionaries in a MongoDB collection called favoriteColors : I 'm trying to create an ORDERED list of color values matching a different ordered list.For example , if I have the list [ `` Johnny '' , `` Steve '' , `` Ben '' , `` Johnny '' ] the new list will [ `` green '' , `` blue '' , `... | Iterating over a dictionary to create a list |
Python : I do understand how setattr ( ) works in python , but my question is when i try to dynamically set an attribute and give it an unbound function as a value , so the attribute is a callable , the attribute ends up taking the name of the unbound function when i call attr.__name__ instead of the name of the attrib... | Python setattr ( ) to function takes initial function name |
Python : What does the * mean in the following code ( found in the pprint library ) ? If it was *args then it would be an arbitrary number of positional parameters . The parameter values would be in the tuple called args . The first 4 parameters could be assigned either by name or by position , the parameter compact co... | What does a star * alone mean in a function declaration ? |
Python : I am scripting GDB with Python 2.7.I am simply stepping instructions with gdb.execute ( `` stepi '' ) . If the debugged program is idling and waiting for user interaction , gdb.execute ( `` stepi '' ) does n't return . If there is such a situation , I want to stop the debugging session without terminating gdb.... | gdb.execute blocks all the threads in python scripts |
Python : I have setup TwiMl on eroku in Python.When I call user A from user B , user A did n't get call and VOIP also , while user B is got bot message like `` thanks for calling '' .When I try to placeCall to user B from PostMan , user B gets call and also got bot message like `` thanks for calling '' .PostMan URL : h... | twilio App to App calling is not working |
Python : ( Data sample and attempts at the end of the question ) With a dataframe such as this : How can I find what percentage of each type [ A , B , C , D ] that belongs to each area [ North , South , East , West ] ? Desired output : My best attempt so far is : Which returns : And I guess I can build on that by calcu... | Pandas : How to find percentage of group members type per subgroup ? |
Python : I am new to programming and to Python . Not sure how to proceed to achieve this ( explained below ) problem , hence the question.I have n number of lists , each containing 1 or more items . I want to have a new list with all possible combinations , which uses one item from each list once , and always.Example :... | Python combination generation |
Python : Suppose I have the following list foo that I would like to sort : To inform the sort , I have the following dictionary of `` dependencies '' , where if a value is in a list for a key , that value must sort higher than the key in list foo : For example , looking at list foo , we see the value 63 at index 0 . Bu... | sorting python list based on `` dependencies '' from dictionary |
Python : I 'm trying to parse various pages on the web using lxml module , like : But it seems like I have to switch this lxml.html to lxml.html.html5parser in the case of html5 pages.http : //lxml.de/html5parser.htmlSo how can I determine if a page is html5-based ? Do I have to check the DOCTYPE char by char before pa... | How do I check if a page is html5-based in python ? |
Python : IssueLet 's say I have a function in python that returns a dict with some objects.At some point I notice that it would make sense to rename the key 'some string ' as it is misleading and not well describing what is actually stored with this key . However , if I were to just change the key , people who use this... | How to make a dict key deprecated ? |
Python : I am attempting to pass a shared secret to child processes . In a Linux environment this works . In a Windows environment the child does not receive the shared secret . The three files below are a simple example of what I 'm trying to do : main.pymodule1.pymodule2.pyIn an Ubuntu 14.04 environment , on Python 3... | Multiprocessing output differs between Linux and Windows - Why ? |
Python : Is there an algorithm to find ALL factorizations of an integer , preferably in Python/Java but any feedback is welcome.I have an algorithm to calculate the prime factors . For instance [ 2,2,5 ] are the prime factors of 20.I also have an algorithm to compute all factors ( prime and non-prime ) of an algorithm ... | Algorithm to find ALL factorizations of an integer |
Python : Problem : The input is a ( i , j ) -matrix M. The desired output is a ( i^n , j^n ) matrix K , where n is the number of products taken . The verbose way to get the desired output is as followsGenerate all arrays of n row permutations I ( total of i**n n-arrays ) Generate all arrays of n column permutations J (... | Numpy/Python : Efficient matrix as multiplication of cartesian product of input matrix |
Python : I have very simple task . After migration and adding new field ( repeated and composite property ) to existing NDB Entity ( ~100K entities ) I need to setup default value for it.I tried that code first : But it fails with such errors : The task runs on separate task queue so it have at least 10 mins to execute... | Update for big count of NDB Entities fails |
Python : The actual problem I wish to solve is , given a set of N unit vectors and another set of M vectors calculate for each of the unit vectors the average of the absolute value of the dot product of it with every one of the M vectors . Essentially this is calculating the outer product of the two matrices and summin... | Non-trivial sums of outer products without temporaries in numpy |
Python : I 've tried running the following code in IDLE : There is no result : But when I run it in the command line , i get this : Can someone explain the difference in what I did ? <code> import sysdir ( sys ) > > > > > > dir ( sys ) [ '__displayhook__ ' , '__doc__ ' , '__excepthook__ ' , '__name__ ' , '__package__ '... | dir ( ) function in commandline vs IDLE |
Python : Having a Matrix M of size m , n over integers , what would be a good algorithm to transform it such that the sum of all elements is maximal ? The only operations allowed are multiplying by -1 column-wise or row-wise . There can be executed as many such operations as required.Rough , overall idea : What I have ... | Make the sum of integers in a matrix maximal by multiplying rows and columns by -1 |
Python : I converted a JSON into DataFrame and ended up with a column 'Structure_value ' having below values as list of dictionary/dictionaries : Since it is an object so I guess it ended up in this format.I need to split it into below four columns : Structure_value_room_1Structure_value_length_1Structure_value_room_2S... | How to convert nested json structure to dataframe |
Subsets and Splits
No community queries yet
The top public SQL queries from the community will appear here once available.