How to replace a cell value with each of its contour cells and yield the corresponding datasets seperately in a list according to a Pandas-way?
Thomas Passin
list1 at tompassin.net
Sun Jan 21 09:14:45 EST 2024
On 1/21/2024 7:37 AM, marc nicole via Python-list wrote:
> Hello,
>
> I have an initial dataframe with a random list of target cells (each cell
> being identified with a couple (x,y)).
> I want to yield four different dataframes each containing the value of one
> of the contour (surrounding) cells of each specified target cell.
>
> the surrounding cells to consider for a specific target cell are : (x-1,y),
> (x,y-1),(x+1,y);(x,y+1), specifically I randomly choose 1 to 4 cells from
> these and consider for replacement to the target cell.
>
> I want to do that through a pandas-specific approach without having to
> define the contour cells separately and then apply the changes on the
> dataframe
1. Why do you want a Pandas-specific approach? Many people would rather
keep code independent of special libraries if possible;
2. How big can these collections of target cells be, roughly speaking?
The size could make a big difference in picking a design;
3. You really should work on formatting code for this list. Your code
below is very complex and would take a lot of work to reformat to the
point where it is readable, especially with the nearly impenetrable
arguments in some places. Probably all that is needed is to replace all
tabs by (say) three spaces, and to make sure you intentionally break
lines well before they might get word-wrapped. Here is one example I
have reformatted (I hope I got this right):
list_tuples_idx_cells_all_datasets = list(filter(
lambda x: utils_tuple_list_not_contain_nan(x),
[list(tuples) for tuples in list(
itertools.product(*target_cells_with_contour))
]))
4. As an aside, it doesn't look like you need to convert all those
sequences and iterators to lists all over the place;
> (but rather using an all in one approach):
> for now I have written this example which I think is not Pandas specific:
[snip]
More information about the Python-list
mailing list