Context: I work with satellite images that I filter to transform to arrays of 1s and 0s, based on the presence of snow (0 for snow, 1 for non-snow). My code creates an array of NaNs, searches for each snow pixel if at least one of the neighbor is non-snow (in a cross patter, cells painted red in the picture
Tag: python
Unsure how to set up for loops and if statements to filter the data that I want:
So I have a dataframe that kinda looks like this: I want to search the dataframe and return exactly: Cutting out the top and bottom. I was able to create a function that filtered out the “Titles” of each column of data. Now I am stuck trying to filter the data out cell by cell until I reach a R…
Algorithm for ordering data so that neighbor elements are as identical as possible
I have a (potentially large) list data of 3-tuples of small non-negative integers, like I want to order the tuples within data so that neighboring tuples (data[i] and data[i+1]) are “as similar as possible”. Define the dissimilarity of two 3-tuples as the number of elements which are unequal betwe…
Gtk.Spinner in Python GTK while importing large library
I have a GTK application in C that will spawn a Python GTK process to embed a matplotlib figure into a window in the C process using GtkSocket/GtkPlug (uses XEmbed Protocol). The problem I am having is that the import of the matplotlib library takes about 2.5 seconds and during that time the socket widget is …
Pandas: Date Format Changes from mmmyy to YYYY-MM-DD
I have a data frame column in mmmyy format and would like to change in yyyy-mm-dd format. Input : Output: tried: conv = lambda x: datetime.strptime(x, “%b %y”) Answer Sept doesn’t match the %b format as only 3 letters are valid. You could fix the string to keep only 3 letters: or .replace(r’…
Problems adding strings to 2D array
So i’m simply trying to add certain strings to a NxN array(matrix) using a for loop. First I create an empty 2D array using np.empty to later fill up with my values: When I run this code I get a correct NxN array matrixK that is however only filled with ‘a’ at all indexes instead of ‘a…
Python asyncio loop.run_forever()
I try to do a trading bot and the most things work fine. But everytime the internet connection is gone for a short time, the code fails. I use asyncio run_forever() function and I think that the code should run forever until it gets stopped, but it does not work. Here is my code: And I call the loop like
node pako.gizp() with python gzip issue
I was restoring the Node pako gzip method using Python and encountered the following problem: node: python: Why do they compress inconsistently? Answer Though there is no guarantee that they will, they are compressing identically. The compressed portions and trailer with checks on the uncompressed data are th…
Improve function that redistribute shares in a pandas dataframe column (possible to avoid nested for loops?)
Below I have dataframe (df) of ten rows, each row has a NAME and belongs to a GROUP. Each row has a value for SHARE that is 0.1. I want to manipulate the distribution of shares. For example, if I increase share value for NAME=’ONE’ from 0.1 to 0.175 I want a function that simultaneously decrease s…
how to sum values in a new column, based on conditions and occurrence of the same value in col (value recurrence) as a factor
I’m trying to find a way to update values in a new column having written a piece of code that in every step (row by row) displays the sum of buy/sell orders with the best price. Because of updates that may occur for a particular id, I need to find a way to use this factor to proper populate new