0

I would like something that looks like this :

for elements in ref_series_list:
    z = 100
    if len(ref_series_list)>=1:       
       if z_voxel_size in Series_table.at[elements, 'z_voxel_size']<z:
           z_min = z_voxel_size         
  
           df1.at[elements, 'ref_series_id'] = df2.ID[elements][z_voxel_size]

The part if z_voxel_size in Series_table.at[elements, 'z_voxel_size'] < z doesn't work because it says 'Numpy.float64' object is not iterable.

The elements in list represent ID that are in df2 and I would like to keep the element that has the lowest z_voxel_size in the df2 corresponding to the ID.

My list is [8,9]. The 8 correspond to the ID 8 in column ID in df2 and has a z_voxel_size of 1.25 in the column z_voxel_size of df2 and the 9 correspond to the ID 9 in column ID in df2 and has a z_voxel_size of 0.625 in the column z_voxel_size of df2. So I would like that my list contains only 9 and not 8 and after store this 9 in a new dataframe df1.

MarionEtp
  • 73
  • 5
  • 2
    Use [How to make good reproducible pandas examples](https://stackoverflow.com/questions/20109391/how-to-make-good-reproducible-pandas-examples) to create a [mre] that simplifies your problem and lets us execute the code to see somehting. Currently your code is out of context and not runnable. – Patrick Artner Jun 25 '21 at 08:53
  • 1
    First you may want to check [pandas-groupby-and-select-rows-with-the-minimum-value-in-a-specific-column](https://stackoverflow.com/questions/54470917/pandas-groupby-and-select-rows-with-the-minimum-value-in-a-specific-column) and see if that helps you . Grouping by ID and then keeping min might just be what you need. – Patrick Artner Jun 25 '21 at 08:54
  • Thank you for your answer ! Sorry I'm new here and I didn't want to put all my code to show the data frames because it's very long. I tried to explain more what's in the list, hopefully it will help you ! Thank you for the link, it shows how to do it in a DataFrame and not in a list so I didn't find a solution for now – MarionEtp Jun 25 '21 at 09:28

0 Answers0