Newest python Questions

Q&A for professional and enthusiast programmers

Detection of Eye movement in sleep state using a thermal recorded video

I want to detect the eye movement when it is closed in Far-infrared. I am able to detect the eye region in a thermal video. Once I cropped out the eye, to calculate the eye ball movement in closed eye ...

Looping through a list of pandas dataframes

Two quick pandas questions for you. I have a list of dataframes I would like to apply a filter to. countries = [us, uk, france] for df in countries: df = df[(df["Send Date"] > '2016-11-01') &...

parse unbalanced html file with Beautiful Soup 4

I am parsing partial of html files that are not with balanced html tags. Say the first line is missing in this partial html file. Is it possible that Beautiful Soup can still parse the rest of the ...

how to get next/previous page boto3 pagination

I am retrieving several files from s3, but i want to paginate the items, I am able to paginate the whole list, but how can i for example, show only the first 30 items and have a next page that will ...

Python os.fork()

How to I create a process for each for item, and make the parent process wait for everything to finish? I have this pseudo-code and want for create a fork for each requestImage(url) page = ...

What's an alternative to the python “functional” package for the function composition operation?

In particular, I'm looking for a package w/ support for function composition. Googling around, there's a lot of references to Collin Winter's functional and its compose() function. However ...

Messenger Python Chatbot Ai

I'm building a JARVIS smart home automation AI. And recently i found a issue. I wanted to send command to my Python Jarvis throught messenger, and want also Jarvis to reply in messenger. I can't find ...

Streaming Mean Computation in Python

I need to understand the following problem out with the Python algorithm: You see a stream of T numbers, each ranged 1 through 10 (inclusive), and store the numbers into two registers. The first is ...

What is the 'rdt' object in the error: 'KeyError: “Unable to open object (Object 'rdt' doesn't exist)”?

I am trying to execute the following code impot spacepy.time as spt import spacepy.omni as om ticks = spt.Ticktock(['2002-02-02T12:00:00', '2002-02-02T12:10:00'], 'ISO') d = om.get_omni(ticks) d....

CAST or TO_TIMESTAMP function in Oracle from SQL?

I have a SQL query that was written for a SQL Server table and would like to translate/convert it to an Oracle query. How should this query be written to use CAST or TO_TIMESTAMP instead of CONVERT? ...

The logic behind 'adapter'? (AttributeError: 'NoneType' object has no attribute 'adapter')

I'm trying to implement a code I found for a list that returns the item selected in kivy. The code works as an indepedent app. But I can't figure out how it is working step by step to implement it ...

sqlalchemy subquery as field

I am trying to make convert raw sql into sqlalchemy. The raw sql query: SELECT TABLE_A.*, (SELECT COUNT(*) FROM TABLE_B WHERE TABLE_B.TABLE_A_ID = TABLE_A.ID) AS TOT FROM TABLE_A WHERE ...

Converting string to Date Object with default backup Python

Currently I convert a string date in the format 18-Jan-2017 to date object using the following line of code. applicationdate = datetime.datetime.strptime(appdate, '%d-%b-%Y').date() I would like it ...

Errors from scipy curvefit

I am trying to fit the below defined function to the values stored in data = [0.22856475605121829, 0.37700169917714116]. My 1 sigma errors are [0.2,0.2], which I tell curve fit to use not as weights, ...

AWS Elastic Beanstalk - Script timed out before returning headers: application.py

I have an existing Elastic Beanstalk flask app on AWS that occasionally will not initialize and gives the following error: [Mon Jan 23 10:06:51.550205 2017] [core:error] [pid 7331] [client 127.0.0.1:...

How to pass parameters from Python to PHP

Basically, a python code will run all the time to check some situations on my server. If some conditions are satisfied, it will call a php script by inputting some arguments. But i could not find a ...

In Python, I am trying to read a file with open/close quotes, but need correct endocing

I am trying to specify the correct file open encoding to read a file with: ‘Oh dear! Oh dear! I shall be late!’ The facing quotes are the problem. Line.split chokes on that line. I even add the ...

Get a list of subprojects from Jenkins REST API

I am writing a python script which accepts a job url for a Jenkins job as a parameter, and I'd like to get back a list of all the subprojects for that specific job. I haven't been able to find a way ...

python + dataframe + count items in a single row based on boolean

I have a feeling there is a simple way to do this... I have a dataframe as follows: df1 = Index A B C 0 5 7 11 1 10 7 11 I am trying to figure out how ...

only printing first if statement python

I did very simple code, I literally just started python but I created some IF and elif statements and it always, prints the first If statement, sorry for bothering people with this petty problem. I ...

Getting data with ajax in django

I'm trying to get some data from an external server using django requests and then loop through that data. Url patterns are as follows : from django.conf.urls import url from .business.indicata ...

What is the Difference between sklearn's make_blobs and a Multivariate Gaussian?

Scikit-learn offers a utility make_blobs that generates Gaussian blobs. Is there any advantage to using this over, say, scipy's multivariate_normal?

Python 2.6.5 - <urlopen error [Errno 1] _ssl.c:480: error:14077438:SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert internal error>

Trying to read a website using Python 2.6.5 but getting the ssl error ''. I am using urllib2. I have seen solutions for 2.7 but not for 2.6.5. I can't upgrade the version to 2.7. Please can someone ...

PyDev (Eclipse) won't run individual test methods

Working with this simple example: import unittest import logging logger = logging.getLogger(__name__) logger.addHandler(logging.StreamHandler()) class LogTests(unittest.TestCase): def ...

Does tensorflow handle swapping GPU memory when a model exceeds memory capacity?

I've noticed that a recent model warns that 2.37G of memory wasn't able to be allocated: W tensorflow/core/common_runtime/bfc_allocator.cc:217] Ran out of memory trying to allocate 2.37GiB. The ...

Can we replace the 'Derivative' terms in sympy coming from the differentiation of sympy.Function variables?

When the following code is run Derivative(Ksi(uix, uiy), uix)) and Derivative(Ksi(uix, uiy), uiy)) terms appear: In [4]: dgN Out[4]: Matrix([ [-(x1x - x2x)*(-x1y + x2y)*((x1x - x2x)**2 + (-x1y + x2y)*...

How can I avoid the interpreter checking the function default arguments?

I have a program that can either be run as a module, or as an independent file with nothing else needed to run. When it is imported, it should import a file called 'globalSettings.py' that contains ...

How to show object's objects like in ipython

In ipython I can use TAB to view an object's objects: In [1]: import numpy as np In [2]: np. Display all 590 possibilities? (y or n) np.ALLOW_THREADS np.bartlett np....

PyQt using classes to show button

Getting very stuck here, I am trying to learn how to use classes, and so simply want to show a button on a window when the button is in a different class. Here is the code I am trying to use: #!/usr/...

Check if something is a number, or can be converted to a number

I'm new to Python and I have this code to convert value to a whole number: try: value = round(float("value")) except ValueError: raise AssertionError("It must be possible to convert 'value' ...

Progressively sort an array, like excel

I'd like to progressively sort an array, like I can in excel. For example: randomMatrix = np.asarray( [[0, 1, 0, 1, 0, 0, 2, 0, 1, 0], [1, 0, 0, 0, 0, 1, 0, 0, 1, 2], [1, 1, 0, 0, 2, 0, 0, 1, 0, 0]])...

pysal pip installation fails

Trying to install pysal using pip, but it is failing. I don't understand what the problem is. Could someone tell me how to fix the issue? Im not sure what the Not Available means but it keep appearing ...

How to disallow admin to change instance in Django admin?

I have a model Order and model Invoice. The Order has invoice = models.OneToOneField('Invoice', related_name='order', on_delete=models.CASCADE, blank=True, null=True) Invoice object is created right ...

Python math domain error [duplicate]

I am making a program that solves the quadratic equation and prints the roots. Before I get to the main program, I am just trying to make the square root work. The error I am getting says "math domain ...

`numpy` histogram and digitize for binning

General Setup Oftentimes in categorical or data analysis, I want to "lump" categories together. For instance, if users are given the ability to state their preference between values 1 - 6, I might ...

Convert strings to integers in pandas dataframe

I have a dataset like below: Name ARowss TotalRowss Percentage motors 11 11 100 trck1 2 ...

Python - Use same duplex Pipe() for multiple processes

I have two processes: proc_a, proc_b and I want the return of proc_a to be equal to the value of data_new. Is this possible or do I have to use multiple Pipes? if __name__ == '__main__': parent,...

Retrieving files from CVS repository by executing windows commands line from a python script based upon the input specified by the user

I have few command line interface command which are executable using windows command prompt.There are few commands that I have used to retrieve files from CVS repository using command prompt.Now I ...

Python split string not work

I want to search string in file and split to keep only id from each line. The string in file like this. v 436 HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows NT\CurrentVersion\PeerDist\Roaming\...

Trouble with utf-8 encoding/decoding

I am reading a .csv which is UTF-8 encoded. I want to create an index and rewrite the csv. The index is created as an ongoing number and the first letter of a word. Python 2.7.10, Ubuntu Server #!/...

python pandas - resample on trading day

I have a timeseries of stock prices in a Dataframe. Originally my index was DateTime, but after a quick pivot (df1 = df.pivot('time',"date",'close')) I'm left with: I'm trying to do a daily ...

Textract.process in a virtualenv with eclipse

I have the following small script: import textract text = textract.process('/Users/Eric/Development/GoogleCloud/cloud-vision/data/text/HP_Patronen_170112.pdf') print (text) When I run directly in ...

Plot Axis in Python with Log Scale for Negative Exponents of 10

I need to plot my y-axis using a logarithmic scale. yscale("log") or yscale("symlog") only scales the axis for positive powers of 10, i.e. 10^1, 10^2, 10^3, etc. My data are mainly less than one. ...

python requests post file using multipart form parameters [duplicate]

I have an API which requires a multipart/form-data content to be send in the body in order to upload a file(image) using POST. I have chosen to use python's requests module as it's easy for newbies ...

Connecting psycopg2 with Python in Heroku

I've been trying for some days to connect my python 3 script to PostgresSQL database(psycopg2) in Heroku, without Django. I found some article and related questions, but I had to invest a lot of time ...

How to handle versioning the logic and models in django?

We are building a django app with a REST API. The constraints that we have are We can't change the logic( the code base that the API uses eg: views.py and models.py) of a published API to avoid ...

How do i wait for an xpath to be present when loading with with PyQt5 qwebenginewidgets

I have the following code and it loads the webpage and javascript but doesn't wait for elements to load. class Render(QWebEngineView): """Render HTML with PyQt5 WebEngine.""" def ...

(Python, Scrapy) Taking data from txt file into Scrapy spider

I am new at Python and Scrapy. I have a project. In the spider there is a code like that: class MySpider(BaseSpider): name = "project" allowed_domains = ["domain.com"] start_urls = ["...

How do I load a QWebPage using Pyside?

I am trying to use Pyside to render a webpage's JavaScript generated HTML, then use that html for webscraping. I started off using this quick example, but I can't get it to work. The problem is that ...

Tensorflow: construct sparse matrix from its diagonals

Could you tell me, is there an analog of scipy.sparse.diags in tensorflow?
Translating... 0%