mercredi 13 janvier 2021

Select random, non Nan values from dataframe

I have a dataframe that looks like this:

rowNum   col1     col2     col3     col4  
0        4.1      2.1      1.0      NaN      
1        3.1      1.1      3.4      1.4      
2        2.8      NaN      1.7      NaN      
3        NaN      5.0      NaN      2.3      
4        NaN      NaN      NaN      NaN      
5        2.3      NaN      2.0      4.0      

I'm trying to make a method that takes in a number, n, and returns n number of "co-ordinates" of values that are not NaN.

I'm trying to select random values that are not NaN without iterating over the entire dataframe.

The naive approach I've tried so far is: select a random co-ordinate, if it's not NaN, add it to a list, if it is a NaN, select a different random co-ordinate.




Aucun commentaire:

Enregistrer un commentaire