如果我有桌子的话:
a b c
15 15 5
20 10 7
25 30 9
并希望做两件事: 1)选择横轴上值最高的列,然后将其赋值给第2列),并将其赋值给另一列,例如:
a b c 1st 1st_value 2nd 2nd_value 3rd 3rd_value
15 15 5 a/b 15 c 5 NaN NaN
20 10 7 a 20 b 10 c 7
25 30 9 b 30 a 25 c 9
这个是可能的吗?
我试图从应该忽略NaN值的数据中抽取随机值,而不删除整个行或列。
我现在的取样功能如下:
def random_port(x, y):
port = df.sample(n=x, axis=1).sample(n=y)
return port
当输出中包含NaN值时,问题就会出现,如下所示:
IN: random_port(5, 5)
OUT:
name a b c d e
date